News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Accuracy of FPU

Started by gman, December 22, 2021, 05:07:16 PM

Previous topic - Next topic

gman

Hi,
I know I am trying to 'invent' the wheel. I know that masm32 has the floating point library done by Raymond.My work laptop is Linux based, and to translate from Masm32 to nasm can be a pain. I do not know if anyone reading this query, uses or works in Linux.

I wrote a simple program to convert decimal string -> 'floating point' -> decimal string, using table and division. Using a reference string of value "387.87609',, the fraction part converted to E047h. Using both table and division of 2, I get the almost same result of 0.876083.

Is the FPU able to re-convert the binary fraction back to the exact value? If so, how does the it do so? I hope someone may know the answer. I enclosed the binary and source if anyone is interested to check it out. I use a 32-bit laptop based on ELF format.

Thanks

hutch--

Have a look at the SSE2 SD instructions, they will do both 32 and 64 bit and are easy enough to use.

mineiro

hello sir gman;
Linux in this case is not a problem. You need convert that symbolic number into a format used internally.
Check this link, I think this help:
https://en.wikipedia.org/wiki/Single-precision_floating-point_format
Also look to sir Raymond:
https://www.website.masmforum.com/tutorials/fptute/index.html

Outside context:
I looked to your code, sometimes you're using CRLF (0d0ah), and others functions you used LF (0ah). In linux, "enter" key is LF, in windows thats CRLF.

---edited---
If you need compare if your converted values are equal to the ones generated by assembler IEEE you can try this simple code:
test.nasm

;nasm -f bin test.nasm
section .data
dd    367.87609         ;43b7f024h

So, it's necessary a hex dump in file "test" created.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

mineiro

You need work a bit more with this code, I think can be usefull to you.


;nasm -f elf32 test1.nasm
;ld -m elf_i386 test.o -o test

section .data
;dd    367.87609         ;43b7f024h
integer_part dd 367
fractional_part dd 87609
dot_one dd 0.00001       ;8*1/10, 7*1/100,6*1/1000,... .

section .code
global  _start                                  ; entry address to start code
_start:
cvtsi2ss xmm0,[integer_part]                    ;convert integer_part to floating point
cvtsi2ss xmm1,[fractional_part]                 ;convert fractional_part to floating point
movss xmm2,[dot_one]                            ;move floating point dot_one to register xmm2
mulss xmm1,xmm2                                 ;multiply
addss xmm0,xmm1                                 ;sum
movd eax,xmm0                                   ;move floating point result to eax=43b7f024h

mov     eax,1           ; The system call for exit (sys_exit)
mov     ebx,0           ; Exit with return code
int     80h


;division example
;mov eax,1                  ;int
;mov ecx,10                 ;int
;cvtsi2ss xmm0,eax           ;convert interger in eax to real4 floating point and store in xmm0 register
;cvtsi2ss xmm1,ecx           ;
;divss xmm0,xmm1             ;divide 1/10, result in xmm0==0.1



You need check in linux shell with command "cat /proc/cpuinfo" if your processor accepts SSE instructions.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything