round to zero TRUNC.S gcc intrinsic / inline asm
Posted: Wed Mar 06, 2019 9:00 am
Hi,
Is there any gcc C intrinsic or inline function which will convert a float to int by rounding to zero by simply producing the native TRUNC.S instruction?
Or as an alternative:
How would an inline assembler implementation look like?
How could i instruct the build system to run my script (which exchanges the FLOOR.S with the TRUNC.S instruction in the object file) before linking.
How could i disassemble an objects file to assembler or instruct gcc to produce assembler for this file.
Background:
In my implementation of a jpeg encoder i need to convert a float value to an integer with rounding to zero.
Timing measurement results in my C code to round to zero
being executed much slower than the code to round to -infinite like this
Looking at the instruction set it tuns out the TRUNC.S instruction would fit. But gcc does not seem to optimize my C code to this instruction.
Thanks
Is there any gcc C intrinsic or inline function which will convert a float to int by rounding to zero by simply producing the native TRUNC.S instruction?
Or as an alternative:
How would an inline assembler implementation look like?
How could i instruct the build system to run my script (which exchanges the FLOOR.S with the TRUNC.S instruction in the object file) before linking.
How could i disassemble an objects file to assembler or instruct gcc to produce assembler for this file.
Background:
In my implementation of a jpeg encoder i need to convert a float value to an integer with rounding to zero.
Timing measurement results in my C code to round to zero
Code: Select all
float in = ...;
int out = (in < 0) ? -int(-in) : int(in);
Code: Select all
float in = ...;
int out = int(in);
Thanks