This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Floating point to int casts


Erik de Castro Lopo <nospam@mega-nerd.com> writes:

> At the moment, the only solution to this is a rather ugly assembler macro:
> 
> #define	FLOAT_TO_INT(in,out)		\
> 	__asm__ __volatile__ ("fistpl %0" : "=m" (out) : "t" (in) : "st") ;
> 
> called as follows:
> 
>    float in = 1233.45 ;
>    int out ;
> 
>    FLOAT_TO_INT(in, out) ;
> 
> This macro does fix the problem but is far from an optimal solution.

You might consider using 'lrint' (or lrintf or lrintl or llrint...  or
even rint) instead, which is the standard C function implemented using
this instruction.  With current glibc versions, this produces code
identical to your macro.

-- 
- Geoffrey Keating <geoffk@geoffk.org>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]