Thanks for the replies. Out of interest I thought I´d list the actual optimized asm code produced by VS 2008, which is about as compact as it could be with an FPU, and looks about as good as any handwritten ASM could be.
As fabs only used 5 lines of code compared to 7 for the <> tests, depending on FPU speed, it is probably the fastest. Not much of a difference unless there are lots of calls per second to functions like this.
Whichever method is used in C++, there is :-
Code: Select all
; 279 : // test one
; 280 : if ( fabs( m_af3Spin.X) >= 360.f )
0072f f3 0f 10 07 movss xmm0, DWORD PTR [edi]
00733 f3 0f 11 45 e4 movss DWORD PTR tv1356[ebp], xmm0
00738 e8 00 00 00 00 call _fabsf
0073d 0f 2f 05 00 00
00 00 comiss xmm0, DWORD PTR __real@43b40000
00744 72 1c jb SHORT $LN8@animateNod@3
; 281 : m_af3Spin.X = fmodf( m_af3Spin.X, 360.f );
00746 d9 45 e4 fld DWORD PTR tv1356[ebp]
00749 d9 5d e4 fstp DWORD PTR $T952717[ebp]
0074c d9 45 e4 fld DWORD PTR $T952717[ebp]
0074f dd 05 00 00 00
00 fld QWORD PTR __real@4076800000000000
00755 e8 00 00 00 00 call __CIfmod
0075a d9 5d e4 fstp DWORD PTR tv1416[ebp]
0075d d9 45 e4 fld DWORD PTR tv1416[ebp]
00760 d9 1f fstp DWORD PTR [edi]
$LN8@animateNod@3:
; 282 : // test two
; 283 : if ( fabs( m_af3Spin.Y ) >= 360.f )
; 284 : {
; 285 : // m_af3Spin.Y = fmodf( m_af3Spin.Y, 360.f );
; 286 : float fY = m_af3Spin.Y / 360.f;
; 287 : fY = fY -(float)(int)fY;
; 288 : fY = fY * 360.f;
; 289 : }
; 290 : // test three
; 291 : if ( m_af3Spin.Z >= 360.f || m_af3Spin.Z <= -360.f )
00762 f3 0f 10 86 d8
00 00 00 movss xmm0, DWORD PTR [esi+216]
0076a f3 0f 11 45 e4 movss DWORD PTR tv1366[ebp], xmm0
0076f 0f 2f 05 00 00
00 00 comiss xmm0, DWORD PTR __real@43b40000
00776 73 0d jae SHORT $LN5@animateNod@3
00778 f3 0f 10 0d 00
00 00 00 movss xmm1, DWORD PTR __real@c3b40000
00780 0f 2f c8 comiss xmm1, xmm0
00783 72 20 jb SHORT $LN6@animateNod@3
$LN5@animateNod@3: