round to zero TRUNC.S gcc intrinsic / inline asm

pentagolo
Posts: 2
Joined: Wed Mar 06, 2019 6:08 am

round to zero TRUNC.S gcc intrinsic / inline asm

Postby pentagolo » 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

Code: Select all

float in = ...;
int out = (in < 0) ? -int(-in) : int(in);
being executed much slower than the code to round to -infinite like this

Code: Select all

float in = ...;
int out = int(in);
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

Who is online

Users browsing this forum: No registered users and 121 guests