News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Test sign of two FP-numbers

Started by Rsir, July 30, 2009, 09:52:43 PM

Previous topic - Next topic

dedndave

Thanks Ray,
i'm glad you like it
it's great to see you get excited over some code that doesn't even have any instructions that start with "F"   :dance:
i love playing with little snippets like that one

i could get it down to a single branch
there are 2 simple ways to do it:
1) continue using and/or/xor and get a conditional branch at the end
2) manipulate the bits in a similar manner, but tailor them for SAHF, then branch on the flags

i could use JBE to get kind of a logical OR function (zf OR cf)
i am not sure if it would save many clock cycles to reduce it to one branch
in this case, it is more likely that both values are >0 or <0, so it may actually be a waste of time

Rsir

I'm impressed dedndave.
Very clever.
After the post of ToutEnMasm i came to this:

include \masm32\include\masm32rt.inc
.686
.const
ValueA real8 0.7788990
ValueB real8 0.00002233
.code
start:
xor       esi,esi
mov       eax,offset ValueA      ; addr real8 -> eax
mov       al,[eax+07h]           ; dereference
shl       al,1                   ; msb -> carry
.if carry?
          inc esi
.endif
mov       eax,offset ValueB
mov       al,[eax+07h]
shl       al,1
.if carry?
          inc esi
.endif
print     uhex$(esi),13,10     ; 2=both- 1=both different 0=both+
exit
        end     start

and i realize that i didn't check for V0=V2=0
your solution is more complete and more elegant.

In my app where i need the test (post 1), V0 and V2 are declared as real8.
V0 and V2 are between -1 and +1. In this app the test for V0=V2=0 is of minor relevance.
Again, you were a great and useful help.
Rsir


dedndave

well - that code will work for most real8 values, even if it only looks at the first 32 bits
it should work for real10's, now that i think of it
for real8's, replace "V1" with "dword ptr V1+4" and "V2" with "dword ptr V2+4"
for real10's, replace "V1" with "dword ptr V1+6" and "V2" with "dword ptr V2+6"
of course, NaN's and indefinites look like real non-zero values

jj2007

There is also the FSIGN macro developed by this thread - you might give it a try.

FSIGN MACRO rval
  ifb <rval>
    fst real8 ptr [esp-8]
    test byte ptr [esp-8+7], 80h ;; usage for sign of ST0: .if FSIGN()
  else
    test byte ptr [rval-1+sizeof rval], 80h ;; usage:  .if FSIGN(MyRealVar)
  endif
  EXITM <Sign?>
ENDM

dedndave

this is what we were shooting for, Jochen
QuoteIF (V0==0 && V2==0) BREAK;
IF (V0> 0 && V2> 0) BREAK;
IF (V0< 0 && V2< 0) BREAK;
.
.
if (both = 0) or (both > 0) or (both < 0) then break