Bill Woessner wrote:
On Jan 13, 4:59 am, Terje Mathisen<"terje.mathisen at
tmsw.no"@giganews.com>  wrote:
I'll second James' suggestion about SSE2!

I'm open to using SSE2.  The only reason I used x87 is that I started
with the assembly code that g++ generated.  By default, it generates
x87 instructions.  But I'm certainly willing to try with SSE2
instructions.

Anyway, it seem that what you are trying to do is to take the
difference between two angles and then make sure that said
difference will be in the [-pi .. pi>  range, right?

That's it exactly.  It's such a simple thing, but I can't come up with
a really elegant way to do it.  The code generated by g++ involves a
jump.  But I think this should be possible without a jump by using a
conditional move.

Anyway, trying your original algorithm:

I'll give your implementation a try.  A big part of the challenge (for
me, at least) is figuring out how to get this in to a form that g++
will understand.  I don't really care where or how this is
implemented, but I need to be able to call it from C++.  And it really
should be inline, as well.  Otherwise, all the efficiency gained by
tweaking the assembly will be lost.  :-p

Inline C isn't too hard to write:

inline double delta(double th1, th2)
{
    static double pi = 3.14159265357989;
    static double zero_or_twopi[2] = {0, 3.14159265357989*2};
    static double absmask = (double) 0x7fffffffffffffff;
    static double signmask = -0.0;

    double diff = th1-th2;
    double adiff = (double) ((int64_t) diff & (int64_t) absmask);
    int toolarge = adiff > pi;

    adiff -= zero_or_twopi[toolarge];

    adiff = (double) ((int64_t) adiff ^
       ((int64_t) signmask & (int64_t) diff));

    return adiff;
}


--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
https://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to