[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sc-devel] float->int casts in OscUGens.cpp (and elsewhere?)



Hi Dan

I don't have a viable setup here to built and test this stuff at the moment but...

I think lrint() is the C99 function, see here:
http://www.mega-nerd.com/FPcast

It's probably worth trying that, or the FLOAT_TO_INT macro on that page, at least to see whether it improves performance.

Given that we're only really targetting GCC and MSVC (or equivalent) it shouldn't be too hard to make a macro which covers all cases.

Ross.



----- Original Message ----- From: "Dan Stowell" <danstowell@xxxxxxxxx>
To: <sc-devel@xxxxxxxxxxxxxxx>
Sent: Thursday, January 10, 2008 3:02 AM
Subject: Re: [Sc-devel] float->int casts in OscUGens.cpp (and elsewhere?)


Hi -

I don't remember this ever having come up in discussion. Thanks for
pointing it out.

I personally wouldn't know what to do along the assembly route, others
here probably would; but do you have any hints re the C99? (Not sure
if you're thinking about specific functions, or specific ways to write
the expression for the compiler to optimise, etc.) If we can try
rejigging the C, the improvement could be very straightforward.

Dan


2008/1/9, Ross Bencina <rossb-lists@xxxxxxxxxxxxxx>:
Hi Guys



I notice that OscUGens.cpp contains a number of direct downcasts from double
to int32, such as line 1840:



phase += (int32)(cpstoinc * ZXP(freqin));



I assume it's been discussed here before, but this is a particularly
inefficient thing to do on IA32 processors. Luckily this assignment isn't
too sensitive to which way the rounding goes, so there are some simple
assembly solutions (such as using fistp to store the intermediate value into an integer location). I think there are even some standard C99 functions...



Is anyone in a position to take care of this?



Cheers

Ross.
_______________________________________________
Sc-devel mailing list
Sc-devel@xxxxxxxxxxxxxxx
http://lists.create.ucsb.edu/mailman/listinfo/sc-devel



--
http://www.mcld.co.uk
_______________________________________________
Sc-devel mailing list
Sc-devel@xxxxxxxxxxxxxxx
http://lists.create.ucsb.edu/mailman/listinfo/sc-devel