I would like to write some gcc inline assembly for armv7em on Cortex-M7 to perform conversion between floating point numbers and fixed point numbers. ARM provides the vcvt instruction with #fbits to achieve exactly this: ARM instruction documentation. I struggle to find the correct double precision implementation.
For a float implementation I came up with the following code:
float fractional_to_float(int32_t op1){ float result; asm ("vmov.32 %0, %1\n\t""vcvt.f32.s32 %0, %0, %2" :"=w"(result) :"r" (op1), "I" (FRACTIONAL_BITS) : /* no clobber */); return result;}int32_t float_to_fractional(float op1){ int32_t result; asm ("vcvt.s32.f32 %1, %1, %2\n\t""vmov.f32 %0, %1" :"=r"(result) :"w" (op1), "I" (FRACTIONAL_BITS) : /* no clobber */); return result;}
What would the double precision implementation look like? I'm trying to come up with functions like:
double fractional_to_double(int32_t op1);int32_t double_to_fractional(double op1);