The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: Gunther on January 04, 2015, 05:49:30 AM

Title: Validity of floating point numbers without FPU code
Post by: Gunther on January 04, 2015, 05:49:30 AM
We have a thread about this topic here (http://masm32.com/board/index.php?topic=3905.msg41107#msg41107). The kernel-mode driver is finished and works good. I've attached a small test program (sources are included) for some assembly language procedures, which are realized inside the driver software. The archive is cfn.zip and here is the output of the program:

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 4.76 s 1.95 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.76 s 2.23 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.65 s 1.98 s

Please, press enter to end the application ...

The results are not so bad. It's tested with an Intel machine. Some timings on other computers would be fine.

Gunther
Title: Re: Validity of floating point numbers without FPU code
Post by: jj2007 on January 04, 2015, 06:28:13 AM
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
Checking the REAL4 number 3.141593:
It's a finite floating point value.

         C-version       Assembly Language
         ---------       -----------------
Time     6.46 s          2.74 s

Please, press enter to continue...

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

         C-version       Assembly Language
         ---------       -----------------
Time     6.68 s          3.09 s

Please, press enter to continue...

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

         C-version       Assembly Language
         ---------       -----------------
Time     7.99 s          3.03 s
Title: Re: Validity of floating point numbers without FPU code
Post by: sinsi on January 04, 2015, 10:24:30 AM
AMD A10-7850K APU @3.70 GHz

Checking the REAL4 number 3.141593:
It's a finite floating point value.
         C-version       Assembly Language
Time     5.16 s          2.03 s

Checking the REAL8 number 3.141592653589793:
It's a finite floating point value.
         C-version       Assembly Language
Time     5.67 s          2.34 s

Checking the REAL10 number 3.1415926535897932385:
It's a finite floating point value.
         C-version       Assembly Language
Time     10.96 s         2.58 s

Title: Re: Validity of floating point numbers without FPU code
Post by: habran on January 04, 2015, 10:56:53 AM
Hi Gunther :biggrin:
Windows 8.1 is trowing an error in third asm function   ( value in [ecx] is wrong ) :(
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 04, 2015, 11:33:34 AM
Thank you, Jochen and Sinsi.

Quote from: habran on January 04, 2015, 10:56:53 AM
Windows 8.1 is trowing an error in third asm function   ( value in [ecx] is wrong ) :(

I've to test that. Thank you for the error report.

Gunther
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 04, 2015, 12:34:08 PM
Hi Habran,

you're right: the EXE crashes under Win 8.1-64 on my i3 laptop. It's a mess with those REAL10 values. So I've commented out this part of the application. The archive for Windows 8.1 user is cfnWin8.zip. That should work without crash. I must search the reason for that behavior and my driver is not ready yet.  :( But I learned a new hard lesson: If a program runs fine under Windows 7, don't assume that it'll run also under Windows 8. Test that in any case.

Gunther
Title: Re: Validity of floating point numbers without FPU code
Post by: habran on January 04, 2015, 03:55:57 PM
Windows 8.1 x64 Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz

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     4.13 s          2.55 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.65 s          2.55 s

Please, press enter to continue...

Quote from: Gunther on January 04, 2015, 12:34:08 PM
But I learned a new hard lesson: If a program runs fine under Windows 7, don't assume that it'll run also under Windows 8. Test that in any case.
That is not acceptable from Microsoft, that new system, which is just first generation after, is not able to run programs from former one.
Windows 8 SUCKS
Title: Re: Validity of floating point numbers without FPU code
Post by: Siekmanski on January 04, 2015, 06:47:03 PM
Windows 8.1 x64 i7-4930K @ 3.40GHz

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     5.42 s          2.53 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.72 s          2.23 s

Please, press enter to continue...
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 05, 2015, 03:31:03 AM
Habran,

Quote from: habran on January 04, 2015, 03:55:57 PM
That is not acceptable from Microsoft, that new system, which is just first generation after, is not able to run programs from former one.
Windows 8 SUCKS

the mistake was on my side. Windows 8 may suck or not, but it has nothing to do with the crash. The updated archive is cfnWin-64.zip under the first post. It runs fine under Win 7-64 and above (well, I hope so, it's to test). I've learned another hard lesson: Do not code important things late after midnight.

Marinus,

thank you for testing. Good machine!

Gunther
Title: Re: Validity of floating point numbers without FPU code
Post by: habran on January 05, 2015, 06:37:19 AM
Quotethank you for testing. Good machine!
$3500AU(!@#$%^&*)  :icon_redface:
I just wish it was Windows 7
I have a copy of "Windows 7 Home" and I hardly resisted not to install it
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 05, 2015, 09:27:04 AM
Hi Habran,

Quote from: habran on January 05, 2015, 06:37:19 AM
Quotethank you for testing. Good machine!
$3500AU(!@#$%^&*)  :icon_redface:
I just wish it was Windows 7
I have a copy of "Windows 7 Home" and I hardly resisted not to install it

Wow. That's a lot of money. Installing Win 7 could be a bit critical. Are the drivers for your hardware available? I did such a "downgrade" some years ago with my old AMD laptop. It was Vista pre-installed and I liked XP. So the driver question was very tricky. I found most drivers on a French site, but not all. The WLAN card didn't work under XP.

On the other hand, you can't use AVX 2 under Win 7. I think your CPU supports that instruction set, the OS not.

Gunther
Title: Re: Validity of floating point numbers without FPU code
Post by: habran on January 05, 2015, 09:54:43 AM
I am not going to downgrade it because I invested to much money to have AVX2
What do you think about Windows 10 RC?
Should I install it on my machine?
I would also like to build AVX-512 in JWasm, so I will probably need Windows 10 for that
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 06, 2015, 12:04:52 AM
Hi Habran,

Quote from: habran on January 05, 2015, 09:54:43 AM
What do you think about Windows 10 RC?
Should I install it on my machine?

I've no experiences with that, but sinsi has an installation running, I think.

Quote from: habran on January 05, 2015, 09:54:43 AM
I would also like to build AVX-512 in JWasm, so I will probably need Windows 10 for that

AVX512 is the future, no doubt about that. I think Intel provides a software emulator for the instruction set. The hardware seems to be not finished.

Gunther
Title: Re: Validity of floating point numbers without FPU code
Post by: habran on January 06, 2015, 06:17:04 AM
I believe that sinsi will see this post and answer :biggrin:
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 06, 2015, 11:48:14 AM
Hi Habran,

Quote from: habran on January 06, 2015, 06:17:04 AM
I believe that sinsi will see this post and answer :biggrin:

Probably. By the way, did you test the new version? It should run without crash on any 64-bit Windows since version 7. Thank you.

Gunther
Title: Re: Validity of floating point numbers without FPU code
Post by: sinsi on January 06, 2015, 01:33:01 PM
 :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.
Title: Re: Validity of floating point numbers without FPU code
Post by: rrr314159 on January 06, 2015, 03:00:30 PM
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

Title: Re: Validity of floating point numbers without FPU code
Post by: habran on January 06, 2015, 05:02:29 PM
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 ...
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 07, 2015, 07:06:02 AM
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
Title: Re: Validity of floating point numbers without FPU code
Post by: 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
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

Title: Re: Validity of floating point numbers without FPU code
Post by: qWord on January 08, 2015, 08:18:54 AM
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.
Title: Re: Validity of floating point numbers without FPU code
Post by: Antariy on January 08, 2015, 08:46:04 AM
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
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 08, 2015, 09:52:59 PM
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
Title: Re: Validity of floating point numbers without FPU code
Post by: rrr314159 on January 08, 2015, 10:06:18 PM
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.
Title: Re: Validity of floating point numbers without FPU code
Post by: Gunther on January 08, 2015, 11:33:54 PM
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