News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Validity of floating point numbers without FPU code

Started by Gunther, January 04, 2015, 05:49:30 AM

Previous topic - Next topic

sinsi

 :biggrin:
I wouldn't start using win10 exclusively yet, there are still a few things that break (like my software raid0 array set up in win7).
There's supposed to be a "significant" upgrade later this month so we'll see.

Gunther, the latest version works OK in 64-bit win10 with similar times.

rrr314159

Windows 8.1 x64 AMD A6-6310 APU 1.8 GHz
and
Windows 8 x64 i5-3330 @3.00GHz

Windows 8.1 x64 AMD A6-6310 APU 1.8 GHz

The C macro isfinite() returns whether X is a finite value.
A finite value is any floating point value that  is neither
infinite nor NaN (Not a Number).
The type of X shall  be float, double or  long double. A non
zero value (true) if X is finite; and zero (false) otherwise.
Here are some examples:

isfinite(0.0)        = 1
isfinite(1.0/0.0)    = 0
isfinite(-2.0/0.0)   = 0
isfinite(sqrt(-4.0)) = 0

Please, press enter to continue...
The different checks may take a while.

Checking the REAL4 number 3.141593:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     10.92 s         4.38 s

Please, press enter to continue...

Checking the REAL8 number 3.141592653589793:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     13.78 s         4.62 s

Please, press enter to continue...

Checking the REAL10 number 3.1415926535897932385:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     19.26 s         5.39 s

-------------------------------------------------------------
-------------------------------------------------------------

Windows 8 x64 i5-3330 @3.00GHz

Checking the REAL4 number 3.141593:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     5.39 s          2.38 s

Please, press enter to continue...

Checking the REAL8 number 3.141592653589793:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     5.75 s          2.41 s

Please, press enter to continue...

Checking the REAL10 number 3.1415926535897932385:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     6.61 s          3.03 s

I am NaN ;)

habran

Good job Gunther :t
this one runs fine

Thanks sinsi :biggrin:
Please let us know when it comes out and you test it
BTW where is your shop?
I am in Enfield. If you don't want to give address here send me a PM


The C macro isfinite() returns whether X is a finite value.
A finite value is any floating point value that  is neither
infinite nor NaN (Not a Number).
The type of X shall  be float, double or  long double. A non
zero value (true) if X is finite; and zero (false) otherwise.
Here are some examples:

isfinite(0.0)        = 1
isfinite(1.0/0.0)    = 0
isfinite(-2.0/0.0)   = 0
isfinite(sqrt(-4.0)) = 0

Please, press enter to continue...
The different checks may take a while.

Checking the REAL4 number 3.141593:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     3.58 s          1.94 s

Please, press enter to continue...

Checking the REAL8 number 3.141592653589793:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     4.14 s          1.92 s

Please, press enter to continue...

Checking the REAL10 number 3.1415926535897932385:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     5.99 s          2.23 s

Please, press enter to end the application ...
Cod-Father

Gunther

Hi sinsi,

Quote from: sinsi on January 06, 2015, 01:33:01 PM
I wouldn't start using win10 exclusively yet, there are still a few things that break (like my software raid0 array set up in win7).
There's supposed to be a "significant" upgrade later this month so we'll see.

Gunther, the latest version works OK in 64-bit win10 with similar times.

thank you for testing. I trust you sinsi, so let's wait until the new update is arriving.

rrr314159 and Habran

thanks for testing the new version. I think I can update the driver, because it's curruntly running with the slow macro version for REAL10 values. I am relieved.

Gunther
You have to know the facts before you can distort them.

Antariy

Just as an interesting info, after reading this thread and another, related to it (sorry for no timings, Gunther, my system is 32 bit, as you know), I thought about another way to test validity of float/double. This method "derived" from this my code http://masm32.com/board/index.php?topic=2242.msg23112#msg23112
Now some info and then what I've found.
CMPPS and CMPPD instructions in the equality comparsion mode (the immediate byte is 0) have the specification that they return false as a result of comparsion of the numbers where operand is NaN. No exceptions are raised also.

But now, if we compare the number with raw hex value as 0x7FF0000000000000 with itself, we get TRUE result. But the number is NaN, so there is "bug" in this SSE instruction? The same if the number is 0x7F80000000000000 (infinity) - the result is wrong.
If we compare the number, for an instance, 0x7FF0000000000001 with itself, then instruction works OK and returns true. But is there reason why it returns not proper result for 0x7FF0000000000000?

If not that bug, is it such or not, it would have possible to use these pieces as a check for finity.


Check float for finity:

cmpps xmm0,xmm0,0
movd eax,xmm0
ret

Check double for finity:

cmppd xmm0,xmm0,0
movd eax,xmm0
ret


qWord

Quote from: Antariy on January 08, 2015, 06:56:03 AMBut now, if we compare the number with raw hex value as 0x7FF0000000000000 with itself, we get TRUE result. But the number is NaN, so there is "bug" in this SSE instruction?
If you are referring to a double value (REAL8, binary64), it is the encoding for +∞, which can be compared.
MREAL macros - when you need floating point arithmetic while assembling!

Antariy

Quote from: qWord on January 08, 2015, 08:18:54 AM
If you are referring to a double value (REAL8, binary64), it is the encoding for +∞, which can be compared.

As double, you get right. Thanks for explanation :t

Gunther

Hi Alex,

good to see you again after a long time.  :t

Quote from: Antariy on January 08, 2015, 06:56:03 AM
Just as an interesting info, after reading this thread and another, related to it (sorry for no timings, Gunther, my system is 32 bit, as you know), I thought about another way to test validity of float/double. This method "derived" from this my code http://masm32.com/board/index.php?topic=2242.msg23112#msg23112

Never mind. I know your thread (I've posted in). I think that qWord gave the right answer. The idea for the code which I've used came from qWord, too.

Gunther
You have to know the facts before you can distort them.

rrr314159

Gunther, it's not even worth mentioning, but in your CheckFpNum.asm the comments for two of the CheckIn... routines are not right. All three say the purpose is to check if the REAL 4 number is finite, but the last two should say 8 and 10, of course.
I am NaN ;)

Gunther

rrr314159,

you're right. What can I say? It's the result of my laziness - you know: copy & paste. But in the original driver code (that's made with the inline assembler) and inside the documentation it is right.

Gunther
You have to know the facts before you can distort them.