Author Topic: floating point math?  (Read 1062 times)

daydreamer

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
floating point math?
« on: July 25, 2021, 04:45:57 AM »
there is signbit and exponent and number
so is there a simple way to check exponent to tell the size of the number is between for example
10 million and one million,1 million and 100000,100000 and 10000...........?in decimal

use display in 16bit unicode instead,I want to exchange the display "INF" to "∞" =221Eh,when infinity
   
SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P

raymond

  • Member
  • ***
  • Posts: 261
    • Raymond's page
Re: floating point math?
« Reply #1 on: July 26, 2021, 03:32:27 AM »
From the FPU tutorial, you could find the following:

The relationship between a logarithm base 2 and a logarithm using some other base b is as follows:
logbx = log2x*(log2b)-1 = log2x*logb2

The FPU has both the log(2) and ln(2) as hard-coded constants which can be loaded with the FLDLG2 and FLDLN2 instructions respectively. As an example, the following code could be used to compute the common logarithm of a positive REAL number zzz located in memory.

fldlg2         ;ST(0)=log10(2), ST(1)=zzz
fld  real_var  ;ST(0)=real_var, ST(1)=log10(2), ST(2)=zzz
fyl2x          ;log2(real_var)*log10(2)=>ST(1) and ST(0) is POPed
               ;ST(0)=log10(real_var), ST(1)=zzz


The log(zzz) would then be in ST(0). You could store the integer portion with the FISTTP instruction (http://www.ray.masmcode.com/tutorial/fpuchap5.htm#fisttp) or use other means. This will give you the lower limit of the range you are looking for.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

daydreamer

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
Re: floating point math?
« Reply #2 on: July 26, 2021, 04:38:58 AM »
Thanks raymond  :thumbsup:
I am working on AVX calculator, and other exercises to do things in AVX
This is for Double2 ascii conversion proc


SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P

daydreamer

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
Re: floating point math?
« Reply #3 on: July 27, 2021, 06:37:07 AM »
Movss xmm0,z
Movd eax,xmm0
Mov string,'+'
Test eax,8000 0000h
Je L1
Mov string,'-'
L1: sar eax,23
And eax,7fh
Here I get strange results
When z 987654321, eax=25, when z -1000, eax is 8 =range 256?
After this I want to start with the range I detect above
To start toascii conversion loop
SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P

raymond

  • Member
  • ***
  • Posts: 261
    • Raymond's page
Re: floating point math?
« Reply #4 on: July 27, 2021, 07:21:40 AM »
Unfortunately, I am not at all familiar with the SSE instructions.

Furthermore, I don't know which assembler you may be using. And, for that reason, I would not know if an instruction such as "sar eax,23" would be interpreted by the assembler as meaning 23h or 23d without the specification. Similarly, would "eax=25" be a binary or decimal value of eax???
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

HSE

  • Member
  • *****
  • Posts: 1744
  • <AMD>< 7-32>
Re: floating point math?
« Reply #5 on: July 27, 2021, 09:05:37 AM »
I think is:
Code: [Select]
.data
  r4t real4 0.0
.code
  fild z
  fstp r4t
  mov eax, r4t
  shr eax, 23d
  and eax, 0FFh  ; mantissa is 8 bit
  sub eax, 127d  ; mantissa is biased

raymond

  • Member
  • ***
  • Posts: 261
    • Raymond's page
Re: floating point math?
« Reply #6 on: July 27, 2021, 11:05:39 AM »
I think is:
Code: [Select]
.data
  r4t real4 0.0
.code
  fild z
  fstp r4t
  mov eax, r4t
  shr eax, 23d
  and eax, 0FFh  ; mantissa is 8 bit
  sub eax, 127d  ; mantissa is biased

I can understand that but this would give the range in the binary system. His first post indicated he wants to know the range in the decimal system.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

HSE

  • Member
  • *****
  • Posts: 1744
  • <AMD>< 7-32>
Re: floating point math?
« Reply #7 on: July 27, 2021, 12:41:57 PM »
Hi Raymond!!

Quote from: raymond link=topic=9464.msg103615#msg103615
I can understand that but this would give the range in the binary system.

His first post indicated he wants to know the range in the decimal system.

Just following Daydreamer's code.

I don't know what he want  :biggrin:

daydreamer

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
Re: floating point math?
« Reply #8 on: July 27, 2021, 05:10:53 PM »
I think is:
Code: [Select]
.data
  r4t real4 0.0
.code
  fild z
  fstp r4t
  mov eax, r4t
  shr eax, 23d
  and eax, 0FFh  ; mantissa is 8 bit
  sub eax, 127d  ; mantissa is biased

I can understand that but this would give the range in the binary system. His first post indicated he wants to know the range in the decimal system.
I want todo it with a LUT,  from binary, speed like in converting lots of primes or other numbers, solving it with SSE/AVX  I am limited to +,-,*,/,,sqrt and without fpu fully equipped math functions

« Last Edit: July 27, 2021, 08:39:32 PM by daydreamer »
SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P

daydreamer

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
Re: floating point math?
« Reply #9 on: July 27, 2021, 08:14:34 PM »
I think is:
Code: [Select]
.data
  r4t real4 0.0
.code
  fild z
  fstp r4t
  mov eax, r4t
  shr eax, 23d
  and eax, 0FFh  ; mantissa is 8 bit
  sub eax, 127d  ; mantissa is biased
Thanks Héctor  :thumbsup:
SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P

HSE

  • Member
  • *****
  • Posts: 1744
  • <AMD>< 7-32>
Re: floating point math?
« Reply #10 on: July 28, 2021, 12:08:14 AM »
[ I am limited to +,-,*,/,,sqrt

Sorry to know your machine FPU is broken, but I think Raymond explanation will work even in your phone!

daydreamer

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
Re: floating point math?
« Reply #11 on: July 28, 2021, 05:33:39 AM »
[ I am limited to +,-,*,/,,sqrt

Sorry to know your machine FPU is broken, but I think Raymond explanation will work even in your phone!
Seem I need to add some checking nan's and infinity., same float or double independent of instruction set
I have partly working float2ascii, sometimes cvtss2si eax,xmm0 gets very high number,character becomes 0ffh+'0'
One divss maxrange and Multiple mulss 10.0,causes precision loss,causes this infinity,or nan?


SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 8497
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: floating point math?
« Reply #12 on: July 28, 2021, 09:00:51 AM »
Magnus,

The hardest part of a calculator is the interface, the calculations in SSE2 are trivial. If you want higher precision you would use the FP unit.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

daydreamer

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
Re: floating point math?
« Reply #13 on: July 28, 2021, 08:26:38 PM »
Magnus,

The hardest part of a calculator is the interface, the calculations in SSE2 are trivial. If you want higher precision you would use the FP unit.
this has been a nice avx exercise,singlestepping,because register usage is different from SSE
also exercise to SIMD version of ascii to double works
SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P

daydreamer

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
Re: floating point math?gui problems? :(
« Reply #14 on: August 09, 2021, 09:46:39 PM »
Magnus,

The hardest part of a calculator is the interface, the calculations in SSE2 are trivial. If you want higher precision you would use the FP unit.
I am trying to get unicode gui working in asm
But test button shows only ascii?
Whole create main window needs to be unicode first?
Newer. Inc files for createwindowW needed?
Different flags in invoke to treat string as 16bit unicode instead?
SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P