flat assembler
Message board for the users of flat assembler.

Index > Main > bfloat16

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 04 Aug 2023, 11:17
What about adding bfloat16 definition support? (https://en.wikipedia.org/wiki/Bfloat16_floating-point_format)
Code:
mov ax, 1.0bf
dw 1.0bf    

upd: Can I define such value (take high word of float32) now without using virtual + load keywords?


Last edited by Jin X on 04 Aug 2023, 11:44; edited 3 times in total
Post 04 Aug 2023, 11:17
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 04 Aug 2023, 11:33
I have one byte float value Very Happy
Code:
;int DB 1,2,3
;intResult DB 0
movzx eax,byte [int]
cvtsi2ss xmm1,eax
movzx eax,byte [int+1]
cvtsi2ss xmm2,eax
addss xmm1,xmm2
cvtss2si eax,xmm1
mov byte [intResult],al
    


Last edited by Roman on 04 Aug 2023, 11:43; edited 1 time in total
Post 04 Aug 2023, 11:33
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 04 Aug 2023, 11:42
Roman, your answer in out of subject.
Post 04 Aug 2023, 11:42
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 04 Aug 2023, 11:45
Dw 1.0 create many problems.
Fpu and sse not work with 16 bit float values, only 32bit or 64bit
We must always convert float16bit to float32bit
Post 04 Aug 2023, 11:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20142
Location: In your JS exploiting you and your system
revolution 04 Aug 2023, 11:56
Jin X wrote:
upd: Can I define such value (take high word of float32) now without using virtual + load keywords?
Yes.
Code:
my_float = dword 1.0
mov ax,my_float shr 16    
Post 04 Aug 2023, 11:56
View user's profile Send private message Visit poster's website Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 04 Aug 2023, 11:58
Roman, there're different instructions.
Some work with fp32 and fp64, some with fp16 (vaddph, vcmph, etc), some with bf16 (vdpbf16ps, AMX, etc).
Post 04 Aug 2023, 11:58
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 04 Aug 2023, 11:59
And what we get ?
my_float = dword -2.25
mov ax,my_float shr 16
Post 04 Aug 2023, 11:59
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 04 Aug 2023, 12:02
revolution, thanks!
Funny that:
Code:
x = (dword 1.0) shr 16  ; not compiled

x = dword 1.0
x = x shr 16  ; ok    


Last edited by Jin X on 04 Aug 2023, 12:11; edited 1 time in total
Post 04 Aug 2023, 12:02
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 04 Aug 2023, 12:05
Code:
; Define bfloat16 number (high word of 32-bit float number) with optional name
; If fp32l <> 0 (default) then name label is shifted up by a word (to use it for access to 32-bit float value with undefined low word)
macro   df16    n*, name, fp32l=1
{
  local fp32
  if ~ name eq
    if fp32l    
      label name dword at $-2
    else ; ~ fp32l
      label name word at $
    end if ; [~] fp32l
  end if ; ~ name eq
  fp32 = dword (n)
                dw      fp32 shr 16
} ; df16

; Define bfloat16 number (high word of 32-bit float number) with optional name (and not shifted label)
macro   dbf16   n*, name
{
  df16 n, name, 0
} ; dbf16    
Post 04 Aug 2023, 12:05
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 04 Aug 2023, 12:11
I don't know where is need float 16 bit ?
I parsed old game demon stone 2004
Vertices(3D mesh) was as float 16 bit.
That all I've seen it over 16 years, how I start write Directx games.


Last edited by Roman on 04 Aug 2023, 18:19; edited 2 times in total
Post 04 Aug 2023, 12:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20142
Location: In your JS exploiting you and your system
revolution 04 Aug 2023, 12:22
Jin X wrote:
What about adding bfloat16 definition support? (https://en.wikipedia.org/wiki/Bfloat16_floating-point_format)
Code:
mov ax, 1.0bf
dw 1.0bf    
This doesn't follow the fasm style.

Instead:
Code:
mov ax,1.0
mov bx,1.0f
dw 1.0
dw 1.0f
f1 = word 1.0    
The f suffix denotes the type, not the size. So f can mean qword, dword, or word sized floating point values.

That can also be extended to byte.
Code:
mov al,1.0    
But there are different competing formats for 16-bit floats, so choosing which one to use would need more thought on how to best denote the required format.

Edit: Just to be clear. At the time of writing fasm does not have any support for word or byte float values. The above is just a possibility.
Post 04 Aug 2023, 12:22
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.