pouët.net

Go to bottom

GNU Rocket on non-Windows platforms

category: code [glöplog]
Changing the rounding mode of all float->int casts seems dangerous... Wouldn't it be better for intros to implement _ftol themselves, or at the least setting the rounding mode at startup?
added on the 2016-02-10 10:03:23 by kusma kusma
Here's a very simple attempt at implementing _ftol with SSE (SSE wizards might do better):
Code: int ftol(float f) { return _mm_cvttps_epi32(_mm_load_ss(&f)).m128i_i32[0]; }
added on the 2016-02-10 10:39:22 by kusma kusma
Exactly, that's what I do. The problem with setting the rounding mode at startup is, that every floating point operation (even float with float) is affected by the rounding mode. Changing that also changes the result of fp arithmetic ops (multiplication, division, etc...).

Like you said, implementing ftol manually is the way to go :)
added on the 2016-02-10 11:08:58 by xTr1m xTr1m
That's a good point regarding fp arithmetic ops. So, if you can convince the compiler to pick up your ftol implementation instead of MSVCRTs, you should be pretty safe. AFAIK, it should simply be a matter of aliasing the symbol and drop /QIfist, but I haven't actually tried this.

Perhaps I should write a README for usync that mentions this pitfall?
added on the 2016-02-10 11:25:59 by kusma kusma
Quote:
So, if you can convince the compiler to pick up your ftol implementation instead of MSVCRTs, you should be pretty safe.


Or my implementation of <math.h>'s floor, both should do.
added on the 2016-02-10 13:06:46 by xTr1m xTr1m
xTr1m: while that will also work in this particular case, it might make other code misbehave. I think having a correct ftol is the way to go, and then remove the floor (and perhaps assert that the input is not negative).
added on the 2016-02-10 14:23:32 by kusma kusma
The problem isn't a negative value, it's a wrong scene number, the sync is completely off! It really needs to be floor.
added on the 2016-02-10 21:43:46 by xTr1m xTr1m
The negative value-thing is only about the difference between round to zero and floor. It shouldn't matter at all in this case, as the row cannot be negative.
added on the 2016-02-10 22:32:20 by kusma kusma
Ill have a look at this in the morning too
added on the 2016-02-11 01:43:55 by superplek superplek
i'll put it in my cereal!

login

Go to top