Re: [linux-audio-dev] Traps in floating point code

2004-07-02 Thread Jussi Laako
On Fri, 2004-07-02 at 00:40, Erik de Castro Lopo wrote: > > Eric what do you think ? can something like that be coded efficiently > > using SSE/SSE2 ? > > Probably not. There are some algorithms which simply can't be vectorized. SSE2 is usually significantly faster for non-vectorized code also.

Re: [linux-audio-dev] Traps in floating point code

2004-07-02 Thread Erik de Castro Lopo
On Thu, 1 Jul 2004 09:14:46 +0100 Steve Harris <[EMAIL PROTECTED]> wrote: > On Wed, Jun 30, 2004 at 11:09:28 +0200, Tim Goetze wrote: > > so if you want quick fractional sample lookups, the best option on x86 > > i see is to manually "fldcw" before and after your sample loop, and > > use lrintf()

Re: [linux-audio-dev] Traps in floating point code

2004-07-02 Thread Jens M Andreasen
On tor, 2004-07-01 at 23:40, Erik de Castro Lopo wrote: > On Thu, 01 Jul 2004 18:18:41 +0200 > Benno Senoner <[EMAIL PROTECTED]> wrote: > > > Eric what do you think ? can something like that be coded efficiently > > using SSE/SSE2 ? > > Probably not. There are some algorithms which simply can't

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Erik de Castro Lopo
On Thu, 1 Jul 2004 15:15:22 -0700 (PDT) Dan Hollis <[EMAIL PROTECTED]> wrote: > On Fri, 2 Jul 2004, Erik de Castro Lopo wrote: > > On Thu, 01 Jul 2004 18:18:41 +0200 > > Benno Senoner <[EMAIL PROTECTED]> wrote: > > > Eric what do you think ? can something like that be coded efficiently > > > usin

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Dan Hollis
On Fri, 2 Jul 2004, Erik de Castro Lopo wrote: > On Thu, 01 Jul 2004 18:18:41 +0200 > Benno Senoner <[EMAIL PROTECTED]> wrote: > > Eric what do you think ? can something like that be coded efficiently > > using SSE/SSE2 ? > Probably not. There are some algorithms which simply can't be vectorized.

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Erik de Castro Lopo
On Thu, 01 Jul 2004 18:18:41 +0200 Benno Senoner <[EMAIL PROTECTED]> wrote: > Eric what do you think ? can something like that be coded efficiently > using SSE/SSE2 ? Probably not. There are some algorithms which simply can't be vectorized. Erik -- +

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Benno Senoner
Ruben van Royen wrote: First of all, I was not yet talking about vectorizing your code which is often hard, especially for a compiler. but SSE can be used on scalars as well (as you probably know). The fact is that the intel pentium 4 optimization guide says that SSE code is generally as fast as

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Ruben van Royen
First of all, I was not yet talking about vectorizing your code which is often hard, especially for a compiler. but SSE can be used on scalars as well (as you probably know). The fact is that the intel pentium 4 optimization guide says that SSE code is generally as fast as or faster than regular

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Ruben van Royen
On Thursday 01 July 2004 14:41, Tim Goetze wrote: > [Ruben van Royen] > > >please note that SSE2 has support for 64bit floats (doubles) and contains > > an instruction that truncates to int, irregardless of controlwords. A new > > enough gcc with (-march=pentium4 or -msse2) and -mfpmath=sse will

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Benno Senoner
Jens M Andreasen wrote: Why not just use modf? double fullindex, increment, integer, fraction; // int i; fullindex += increment; fraction = modf(fullindex, &integer); // i = integer; C99 have float and long double versions as well. The problem of modf is that it is slow (it generates "cal

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Tim Goetze
[Ruben van Royen] >please note that SSE2 has support for 64bit floats (doubles) and contains an >instruction that truncates to int, irregardless of controlwords. A new enough >gcc with (-march=pentium4 or -msse2) and -mfpmath=sse will use sse instead of >the old fp unit. This has more advantages, s

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Tim Goetze
[Ruben van Royen] >The problem is that the rounding mode affects all floating point operations, >such as multiply and divide. And normally you must do rounding and not >truncation. Thus changing the mode will change the results, and a compiler is >not allowed to do that. yes, and it is wise to ch

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Erik de Castro Lopo
On Thu, 1 Jul 2004 10:25:51 +0200 Ruben van Royen <[EMAIL PROTECTED]> wrote: > Hi all, > > please note that SSE2 has support for 64bit floats (doubles) and contains an > instruction that truncates to int, irregardless of controlwords. A new enough > gcc with (-march=pentium4 or -msse2) and -mf

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Steve Harris
On Thu, Jul 01, 2004 at 10:25:51AM +0200, Ruben van Royen wrote: > Hi all, > > please note that SSE2 has support for 64bit floats (doubles) and contains an > instruction that truncates to int, irregardless of controlwords. A new enough > gcc with (-march=pentium4 or -msse2) and -mfpmath=sse wil

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Ruben van Royen
The problem is that the rounding mode affects all floating point operations, such as multiply and divide. And normally you must do rounding and not truncation. Thus changing the mode will change the results, and a compiler is not allowed to do that. Only in very specific cases, such as a loop t

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Ruben van Royen
Hi all, please note that SSE2 has support for 64bit floats (doubles) and contains an instruction that truncates to int, irregardless of controlwords. A new enough gcc with (-march=pentium4 or -msse2) and -mfpmath=sse will use sse instead of the old fp unit. This has more advantages, since sse

Re: [linux-audio-dev] Traps in floating point code

2004-07-01 Thread Steve Harris
On Wed, Jun 30, 2004 at 11:09:28 +0200, Tim Goetze wrote: > so if you want quick fractional sample lookups, the best option on x86 > i see is to manually "fldcw" before and after your sample loop, and > use lrintf() or "fistpl" directly to obtain integer indices inside > the loop. I wonder why gcc

Re: [linux-audio-dev] Traps in floating point code

2004-06-30 Thread Tim Goetze
[Jens M Andreasen] >On tis, 2004-06-29 at 17:15, Steve Harris wrote: >> >integer = lrintf(fullindex); >> >fractional = fullindex - integer; >> >> I dont think this is right, fractional will be [-0.5, 0.5], rather than >> [0,1] which is more noirmal as lrintf() rounds to the nearest. >> >>

Re: [linux-audio-dev] Traps in floating point code

2004-06-30 Thread Erik de Castro Lopo
On Wed, 30 Jun 2004 15:25:53 -0400 Pete Bessman <[EMAIL PROTECTED]> wrote: > Ah. Now I get to find all the places in my code that can benefit from > that. If you assign a float value into an int variable, is that an > implicit cast? Yes, see my paper here: http://www.mega-nerd.com/FPcast/

Re: [linux-audio-dev] Traps in floating point code

2004-06-30 Thread Pete Bessman
At Wed, 30 Jun 2004 16:37:59 +0100 (BST), Mike Rawes wrote: > > --- Pete Bessman <[EMAIL PROTECTED]> wrote: > > At Mon, 28 Jun 2004 19:56:50 +1000, > > Erik de Castro Lopo wrote: > > > > > > double fractional = 0.0, increment = 0.1; > > > int integer = 0; > > > > > > for (;;) > > >

Re: [linux-audio-dev] Traps in floating point code

2004-06-30 Thread Jens M Andreasen
On tis, 2004-06-29 at 17:15, Steve Harris wrote: > On Tue, Jun 29, 2004 at 10:19:32AM +0200, Benno Senoner wrote: > > for (;;) > > { > >/* Bunch of other code. */ > > > >fullindex += increment; > >integer = lrintf(fullindex); > >fractional = fullindex - integer; > > I dont think

Re: [linux-audio-dev] Traps in floating point code

2004-06-30 Thread Mike Rawes
--- Pete Bessman <[EMAIL PROTECTED]> wrote: > At Mon, 28 Jun 2004 19:56:50 +1000, > Erik de Castro Lopo wrote: > > > > double fractional = 0.0, increment = 0.1; > > int integer = 0; > > > > for (;;) > > { > > /* Bunch of other code. */ > > > > fractional += increm

Re: [linux-audio-dev] Traps in floating point code

2004-06-30 Thread Pete Bessman
At Mon, 28 Jun 2004 19:56:50 +1000, Erik de Castro Lopo wrote: > > > People who play around with floating point code (especially on x86) > quickly learn about the evils of comparing the equality of one floating > point value with another. I got my first lesson just a couple of days ago, in fact

Re: [linux-audio-dev] Traps in floating point code

2004-06-30 Thread Benno Senoner
Erik de Castro Lopo wrote: On Tue, 29 Jun 2004 10:19:32 +0200 Benno Senoner <[EMAIL PROTECTED]> wrote: In LinuxSampler we do double increment; double fullindex; int integer; double fractional; for (;;) { /* Bunch of other code. */ fullindex += increment; integer = lrintf(fullindex

Re: [linux-audio-dev] Traps in floating point code

2004-06-29 Thread Erik de Castro Lopo
On Tue, 29 Jun 2004 10:19:32 +0200 Benno Senoner <[EMAIL PROTECTED]> wrote: > In LinuxSampler we do > > double increment; > double fullindex; > int integer; > double fractional; > for (;;) > { > /* Bunch of other code. */ > > fullindex += increment; > integer = lrintf(ful

Re: [linux-audio-dev] Traps in floating point code

2004-06-29 Thread Steve Harris
On Tue, Jun 29, 2004 at 10:19:32AM +0200, Benno Senoner wrote: > for (;;) > { >/* Bunch of other code. */ > >fullindex += increment; >integer = lrintf(fullindex); >fractional = fullindex - integer; I dont think this is right, fractional will be [-0.5, 0.5], rather than [0,1] whi

Re: [linux-audio-dev] Traps in floating point code

2004-06-29 Thread Benno Senoner
Erik de Castro Lopo wrote: The fix in this case was this: for (;;) { /* Bunch of other code. */ fractional += increment ; rem = fmod (fractional, 1.0); /* floating point modulus */ integer += lrint (round (fractional - rem)); fractional = rem;

Re: [linux-audio-dev] Traps in floating point code

2004-06-28 Thread Steve Harris
On Mon, Jun 28, 2004 at 12:23:37 +0200, Maarten de Boer wrote: > Hi Erik, > > Depending on the ranges of your increment, and the accuracy you > want to obtain, you might consider doing this with integers only. Yes, for this kind of accumulator thing I often use a hacked up fixedpoint representati

Re: [linux-audio-dev] Traps in floating point code

2004-06-28 Thread Maarten de Boer
Hi Erik, Depending on the ranges of your increment, and the accuracy you want to obtain, you might consider doing this with integers only. Maarten > The fix in this case was this: > > for (;;) > { > /* Bunch of other code. */ > > fractional += increment ; > rem

[linux-audio-dev] Traps in floating point code

2004-06-28 Thread Erik de Castro Lopo
Hi all, People who play around with floating point code (especially on x86) quickly learn about the evils of comparing the equality of one floating point value with another. There are other related evils with floating point one of which I was bitten by just recently and I thought I'd share it wi