This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

armclang:error: couldn't allocate output register for constraint 'w'

Hi,

     There is an inline assembler code, and compiled okay with arm-none-eabi-gcc,

but there is error when built with armclang.

     Here is the code:

//wrong-reg.c

#include <stdio.h>
#include <stdint.h>

#define __asm__ asm volatile
float __vabs(const float a) {
	//VABS{cond}.F32 Sd, Sm 
	float result;
	__asm volatile("vabs.f32 %0, %1" : "=w"(result) : "w"(a):);
	return result;
}

int __vcvta_s32(float a) {
	int result;
	__asm volatile("vcvta.s32.f32 %0, %1" : "=w"(result) : "w"(a):);
	return result;
}

int main(int argc, char *argv[])
{
    const uint8_t n4 = __vcvta_s32(__vabs(1 - 32.f / 100.0) * 100.0);

    printf("now n4 is %d", n4);
    return 0;
}

compiled with:

armclang --target=arm-arm-none-eabi -mcpu=cortex-m55 -O2 -g -c -mfpu=fp-armv8-fullfp16-sp-d16 wrong-regs.c -o wrong-regs.o

then it report:

wrong-regs.c:17:17: error: couldn't allocate output register for constraint 'w'
        __asm volatile("vcvta.s32.f32 %0, %1" : "=w"(result) : "w"(a):);

arm-none-eabi-gcc -mcpu=cortex-m55 -march=armv8.1-m.main+mve.fp+fp.dp -mfloat-abi=hard --specs=rdimon.specs -mfpu=auto -g -O2 wrong-regs.c -o wrong-regs-gcc

This command is okay.

Anyone has ideas?

PS,

armclang --version

Product: Arm Compiler for Embedded 6.17 Professional
Component: Arm Compiler for Embedded 6.17

arm-none-eabi-gcc --version

arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)

Br,

Yingchun

  • after change the function
     
    int __vcvta_s32(float a);
     
    to
     
    float __vcvta_s32(float a) 
     
    the armclang generate the correct result. armclang need more precise type.
     
    00000000 <__vcvta_s32>:
    0: febc 0ac0 vcvta.s32.f32 s0, s0
    4: 4770 bx lr
     
    gcc can do it more reasonable,if still use interger type, it will geneate:
     
    __vcvta_s32(float):
    vcvta.s32.f32 s15, s0
    vmov r0, s15 @ int
    bx lr
     
    Br,
    Yingchun