cancel
Showing results for 
Search instead for 
Did you mean: 

Inline Assembler: which constraint for double parameters?

HScha.1
Associate

Hi,

I want to use a double precision input parameter for an inline assembler function, for example

int32_t Double2Long(double a) {

   int32_t c;

   asm (

      "   vcvtr.s32.f64 s0,%[in]      \n\t"

      "   vmov      %[out],s0      \n\t"

      : [out] "=r" (c)            /* output */

      : [in]  "w" (a)            /* Input */

      : "s0"                     /* clobber */

   );

   return c;

}

Contraint "w" does not work, the assembler uses s14 instead of a double precision register (Error: invalid instruction shape -- `vcvtr.s32.f64 s0,s14'). "d" as constraint is not accepted, so I checked all letters from a to z and A to Z. Nothing works, the assembler either uses rn or sn or [sp] or says "impossible constraint" . Does anyone know how to do it?

Best regards

Hartmut

2 REPLIES 2
berendi
Principal

The magic incantation is

vcvtr.s32.f64 s0,%P[in]
//note the P here ^

Godbolt has some trouble compiling it except with gcc 5.4 https://godbolt.org/z/q5vW8F

but it works on my PC e.g. with gcc-arm-none-eabi-8-2018-q4-major too.

Source of the secrets: https://hardwarebug.org/2010/07/06/arm-inline-asm-secrets/

HScha.1
Associate

Thanks a lot, that works. I was always looking for the right constraint and did not think that it could be coded as an operand code...