Re: [linux-audio-dev] Float to int conversions

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Float to int conversions
From: Erik de Castro Lopo (erikd-lad_AT_mega-nerd.com)
Date: Thu Nov 01 2001 - 21:10:05 EET


It really blew my mind when Paul Davis <pbd_AT_Op.Net> said:

> >I have recently written a paper titled "Faster Floating Point to Integer Conve
> >rsions"
> >which can be read here:
> >
> > http://mega-nerd.com/FPcast/
>
> nice work. but i have a question: your timings how that lrintf and
> lrint basically take nearly twice as long as the optimal asm macro. if
> you're writing a program in which float<->int conversion is a
> significant issue, why would you move from the cast solution (which is
> obviously bad) to one thats only half as good as it could be?

This is a gcc optimisation issue which I don't have the guts to tackle :-).

> many other platforms (e.g. MIPS) do float<->int phenomenally well just
> via a cast. it seems to me that it would be "cleverer" to define a
> portable solution, if you're going to be willing to use autoconf, that
> defines FLOAT_TO_INT, but make it platform specific and possibly a
> no-op if the platform's cast does the job properly.
>
> did you consider this?

I did, but lrint/lrint is a nicer solution because its already in the C99
standard and hence more portable.

The macro has problems like possible macro side effects and being too ugly.

Erik

-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam_AT_mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
Java : A language from the C family of languages. It has all the bad
features of C++ but without the most powerful feature of C, pointers.


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Thu Nov 01 2001 - 21:05:21 EET