With the increasing popularity of 64-bit computers, I thought that allowing the use of 64-bit integers as source/destination should be part of the Fpulib functions whenever integers can be used. While at it, I also added code to allow the use of 32-bit and 64-bit floats (REAL4 and REAL8). Furthermore, I included my procedures for converting dwords and qwords to ascii using "magic numbers".
With all the modifications, I needed something to test the library as much as posible before posting it. I thus designed a "tester". It did allow me to find some errors, some potential bugs, and one inadequate function (FpuArcsinh with a negative input). I included this tester into the new package on my site, i.e. FPULIB2_3.ZIP.
http://www.ray.masmcode.com/fpu.html#fpulib
For those who may only want to see the "tester", I'm attaching it here. The .zip file contains a text file giving a short explanation of how it works.
Thanks i'll grab it,I hope you added a MOD function :D
QuoteI hope you added a MOD function
I don't remember having seen such a request before. I'll give it some consideration.
MOD is a essential basic to mathematics, so is pretty vital, I wrote one below, which is just your FpuDiv slightly modified using dave's advice I believe.
FpuMod proc public lpSrc1:DWORD, lpSrc2:DWORD, lpDest:DWORD, uID:DWORD
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
; Because a library is assembled before its functions are called, all
; references to external memory data must be qualified for the expected
; size of that data so that the proper code is generated.
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
LOCAL content[108] :BYTE
LOCAL tempst :TBYTE
test uID,SRC1_FPU or SRC2_FPU ;is data taken from FPU?
jz continue
;-------------------------------
;check if top register is empty
;-------------------------------
fxam ;examine its content
fstsw ax ;store results in AX
fwait ;for precaution
sahf ;transfer result bits to CPU flag
jnc continue ;not empty if Carry flag not set
jpe continue ;not empty if Parity flag set
jz srcerr1 ;empty if Zero flag set
continue:
fsave content
test uID,SRC1_FPU
jz @F
lea eax,content
fld tbyte ptr[eax+28]
jmp src2
@@:
mov eax,lpSrc1
test uID,SRC1_FPU ;is Src1 taken from FPU?
jnz src2 ;check next parameter for Src2
test uID,SRC1_REAL ;is Src1 an 80-bit REAL in memory?
jz @F ;check next source for Src1
fld tbyte ptr [eax]
jmp src2 ;check next parameter for Src2
@@:
test uID,SRC1_DMEM ;is Src1 a 32-bit integer in memory?
jz @F ;check next source for Src1
fild dword ptr [eax]
jmp src2 ;check next parameter for Src2
@@:
test uID,SRC1_DIMM ;is Src1 an immediate 32-bit integer?
jz @F ;check next source for Src1
fild lpSrc1
jmp src2 ;check next parameter for Src2
@@:
test uID,SRC1_CONST ;is Src1 one of the FPU constants?
jnz @F ;otherwise no valid ID for Src1
srcerr:
frstor content
srcerr1:
xor eax,eax ;error code
ret
@@:
test eax,FPU_PI
jz @F
fldpi
jmp src2
@@:
test eax,FPU_NAPIER
jz srcerr ;no correct CONST flag for Src1
fld1
fldl2e
fsub st,st(1)
f2xm1
fadd st,st(1)
fscale
fstp st(1)
;----------------------------------------
;check source for Src2 and load it to FPU
;----------------------------------------
src2:
test uID,SRC2_FPU ;is Src2 taken from FPU?
jz @F ;check next source for Src2
lea eax,content
fld tbyte ptr[eax+28]
jmp dest0 ;go complete process
@@:
mov eax,lpSrc2
test uID,SRC2_REAL ;is Src2 an 80-bit REAL in memory?
jz @F
fld tbyte ptr [eax]
jmp dest0 ;go complete process
@@:
test uID,SRC2_DMEM ;is Src2 a 32-bit integer in memory?
jz @F
fild dword ptr [eax]
jmp dest0 ;go complete process
@@:
test uID,SRC2_DIMM ;is Src2 an immediate 32-bit integer?
jz @F
fild lpSrc2
jmp dest0 ;go complete process
@@:
test uID,SRC2_CONST ;is Src2 one of the FPU constants?
jz srcerr ;no correct flag for Src2
test eax,FPU_PI
jz @F
fldpi ;load pi (3.14159...) on FPU
jmp dest0 ;go complete process
@@:
test eax,FPU_NAPIER
jz srcerr ;no correct CONST flag for Src2
fld1
fldl2e
fsub st,st(1)
f2xm1
fadd st,st(1)
fscale
fstp st(1)
dest0:
fprem
fstsw ax ;retrieve exception flags from FPU
fwait
shr al,1 ;test for invalid operation
jc srcerr ;clean-up and return error
test uID,DEST_FPU ;check where result should be stored
jnz @F ;destination is the FPU
mov eax,lpDest
fstp tbyte ptr[eax] ;store result at specified address
jmp restore
@@:
fstp tempst ;store it temporarily
restore:
frstor content ;restore all previous FPU registers
test uID,SRC1_FPU or SRC2_FPU ;was any data taken from FPU?
jz @F
fstp st ;remove source
@@:
test uID,DEST_FPU
jz @F ;the new value has been stored in memory
;none of the FPU data was modified
ffree st(7) ;free it if not already empty
fld tempst ;load the new value on the FPU
@@:
or al,1 ;to insure EAX!=0
ret
FpuMod endp
BEAUTIFUL!!! :clap: :clap: :clap:
Couldn't have done better myself. :P
very cool, Cube :U
i didn't think it would be that complicated, though - lol
but, your proc covers all the bases
I'm getting a 404 when clicking on the download on your page Ray.
James
try this link, James
it looks like Ray updated the file using lower case, but updated the link in the html using upper case :P
http://www.ray.masmcode.com/downloads/Fpulib2_31.zip
Network Timeout
The server at www.ray.masmcode.com is taking too long to respond.
i hope Ray doesn't mind if i put it here for you :bg
Quote from: dedndave on January 07, 2010, 02:16:58 PM
i hope Ray doesn't mind if i put it here for you :bg
Thanks. I got it from the link you supplied.
I've added E^ Cube's FpuMod, tweaked the include file , and produced a working library using JWasm on Ubuntu 32.
This version makes it quite usable on linux as the help file is in chm format. This is read nicely with the Firefox chm reader add on.
James
Great update Raymond :U
and thanks but the FpuMod really is literally all of raymonds code, I copy pasted the FpuDiv and I think the only thing I changed was
dest0:
fdiv
to
dest0:
fprem
haha so thanks Raymond :bg
Quoteit looks like Ray updated the file using lower case, but updated the link in the html using upper case
Thanks Dave for pointing out my stupid error. It's now corrected.
I have now uploaded an updated version 2_31 which contains the modikfied tester complete with the mod function. I've also corrected the mod function of the library because I was not loading the FPU correctly with the sources as in the description, yielding erroneous results (noticed that with the tester). I should never have uploaded the modified library in the middle of the night without fully testing it. There's an old latin saying which translate loosely like this: HURRY UP SLOWLY!!!
Sorry for any inconvenience.
I'm also editing my first post to upload the modified tester package.
If I don't receive any error report within the next week, I'll also ask Hutch to update the other sites carrying the lib.
Quote from: raymond on January 07, 2010, 07:16:56 PM
Quoteit looks like Ray updated the file using lower case, but updated the link in the html using upper case
Thanks Dave for pointing out my stupid error. It's now corrected.
I have now uploaded an updated version 2_31 which contains the modikfied tester complete with the mod function. I've also corrected the mod function of the library because I was not loading the FPU correctly with the sources as in the description, yielding erroneous results (noticed that with the tester). I should never have uploaded the modified library in the middle of the night without fully testing it. There's an old latin saying which translate loosely like this: HURRY UP SLOWLY!!!
Sorry for any inconvenience.
I'm also editing my first post to upload the modified tester package.
If I don't receive any error report within the next week, I'll also ask Hutch to update the other sites carrying the lib.
:(, i've used it only abit, thought it worked alright, my apologies, atleast you fixed it before it's mainstream
Quotethought it worked alright, my apologies,
There's no need to apologize. Your provided procedure would work perfectly by loading the moduolus first followed by the other source, yielding Src2 modulo Src1. There being no description of the order for the parameters, I simply made a wrong assumption before testing it. I for one should know about the risk of making assumptions. :snooty: :naughty: :bdg :eek
i fixed my links above
UtillMasm has a hard time with your site, for some reason - maybe due to being in China
I'm using a slightly modified FLtoA in the tester in order to display 17 digits (as compared to a maximum of 15 digits with the FpuFLtoA function. However, the decimal delimiter was being positioned off by one digit for scientific notation. This has been now corrected and all downloads have been updated. Sorry again for any inconvenience.
It would seem that Hutch has not succeeded yet in convincing China to allow their population access to his site. It's totally absurd on their part.
well - UtillMasm seems to come in here fine - it is your site he can't d/l from - lol
that's why i posted the lib here
they probably have a "committee" of anal-retentives that approve or dis-approve sites
i am sure they have their work cut out for em - lol
if it is anything that educates their people (technically - not socially) - they don't object
it's just that there are so many sites to review, it may take forever
Quoteit is your site he can't d/l from
My "site" is graciously provided by Hutch from his own website.
Raymond,
Thanks for the update. Very nice. :thumbu
Greg
:lol
long long time ago, masm32.com is not available too.
(so american sale me a VPN account, a month 8rmb. :naughty:)
those damn American salesmen - lol
I think its just the location of the servers, the forum is located in the UK where Ray's site is east coast US up around Boston and it would seem that the firewall used in mainland China does not allow much access to continental US.
QuoteRoger Dingledine, creator of Tor, reports that "some tens of thousands" of people appear to be using Tor from China on a weekly basis.23 (Why the Chinese government has, as of this writing, chosen not to block the proxy nodes used by Tor is unknown.)
Wouldn't a web browser with tor built-in (like OperaTor or whatever) allow him unrestricted web access?
Quote from: brethren on January 09, 2010, 10:13:21 PM
QuoteRoger Dingledine, creator of Tor, reports that "some tens of thousands" of people appear to be using Tor from China on a weekly basis.23 (Why the Chinese government has, as of this writing, chosen not to block the proxy nodes used by Tor is unknown.)
Wouldn't a web browser with tor built-in (like OperaTor or whatever) allow him unrestricted web access?
china did block tor, thats why the tor team created bridges.
I've expanded the tester to also display the binary representation of the data in the source and destination memory locations used by the function. This may be useful for those who may want to visualize primarily how floats may appear in memory.
The download file of my original post has been updated accordingly.
I have recently noticed a flaw in the Fpulibtester, which was affecting the use of its FpuXexpY function.
The source of the flaw was the addition of the FpuMod function to the library after the tester was designed. The function was later added to the tester but some of the parsing code related to the integer conversion functions was inadvertantly left as it was. The FpuXexpY function being the last one in alphabetical order, its parameters were being interpreted as those of the smdtoa function! :red The integer conversion functions were also not being treated correctly, in addition to the umqtoa not even being shown in the drop down list.
Corrections have now been made. The download file of my original post has again been updated accordingly. The zip file for the Fpulib (Fpulib2_33.zip) has also been updated accordingly to include the corrected tester.
Thank you gentlemen :U
Thanks again Ray for your great tutorials and libraries. I use Simply FPU all the time for reference.
glad you found it, Ray :U
the forum without you would be like a day without er um whiskey :P