flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 17 Oct 2023, 12:04
You can make a macro to construct floats from integers.
Or you can store integers in the source and load them at runtime into the float registers and let the hardware do the conversion. |
|||
![]() |
|
revolution 17 Oct 2023, 12:59
I tried float and double but it can't exceed 2^31 for the value.
Code: struc float value { rept 1 v:value \{ dd v\#f \} } struc double value { rept 1 v:value \{ dq v\#f \} } a float 4 - 3 b float 23 + 34 c double 1999999999 ; can't use >= 2^31 d double -1999999999 ; can't use < -2^31 |
|||
![]() |
|
ProMiNick 17 Oct 2023, 13:21
Code: macro dsingle [val] { dd ($7F+bsr ((val) or 1)) shl 23 + (((val) shr (bsr ((val) or 1)-23)) and not $FF800000) } macro ddouble [val] { dq ($3FF+bsr ((val) or 1)) shl 52 + (((val) shr (bsr ((val) or 1)-52)) and not $FFF0000000000000) } macro dtbyte [val] { dq ((val) shr ((bsr ((val) or 1))-63)) dw ($3FFF+bsr ((val) or 1)) } dsingle 1,1+2,(6+2)*4 shl 1;dd 1f,3f,64f ddouble 1,1+2,(6+2)*4 shl 1;dq 1f,3f,64f dtbyte 1,1+2,(6+2)*4 shl 1;dt 1f,3f,64f limitation of current computation: only positive expression of integer operands with integer operations. I more like revolution variant then mine. getting sign addend could be reached via "(val) and $80000000" for single via "(val) and $8000000000000000" for double via "((val) and $8000000000000000) shr 24" for doubleext but for counting negates instead of val in rest of calculation must be absolute value of val (no idea how to construct) for zero handling could be added multiplier (1-1 shl ((val) and -(val))) Last edited by ProMiNick on 17 Oct 2023, 13:43; edited 1 time in total |
|||
![]() |
|
Roman 17 Oct 2023, 13:34
Thanks revolution and ProMiNick
|
|||
![]() |
|
ProMiNick 17 Oct 2023, 14:53
Code: macro dsingle [val] { dd (1-1 shl ((val) or -(val)))*\ ( \ ((val) and $80000000) or \ (($7F+bsr (((val)*(1-((val) and $80000000) shr 30)) or 1) ) shl 23) or \ ((((val)*(1-((val) and $80000000) shr 30)) shr ((bsr (((val)*(1-((val) and $80000000) shr 30))or 1))-23)) and not $FF800000)\ ) } macro ddouble [val] { dq (1-1 shl ((val) or -(val)))*\ ( \ ((val) and $8000000000000000) or \ (($3FF+bsr (((val)*(1-((val) and $8000000000000000) shr 62)) or 1)) shl 52) or \ ((((val)*(1-((val) and $8000000000000000) shr 62)) shr (bsr (((val)*(1-((val) and $8000000000000000) shr 62)) or 1)-52)) and not $FFF0000000000000)\ ) } macro dtbyte [val] { dq (1-1 shl ((val) or -(val)))*((((val)*(1-((val) and $8000000000000000) shr 62)) shr ((bsr (((val)*(1-((val) and $8000000000000000) shr 62)) or 1))-63))) dw (1-1 shl ((val) or -(val)))*((((val) and $8000000000000000) shr 24 + $3FFF+bsr (((val)*(1-((val) and $8000000000000000) shr 62)) or 1))) } no limits variant where multiplier zerotest = (1-1 shl ((val) or -(val))) dword absolute of value = ((val)*(1-((val) and $80000000) shr 30)) qword absolute of value = ((val)*(1-((val) and $8000000000000000) shr 62)) |
|||
![]() |
|
ProMiNick 17 Oct 2023, 20:05
final:
Code: macro dsingle [val] { dd (1-1 shl ((val) or -(val)))*\ ( \ ((val) shr 64 shl 31) or \ (($7F+bsr (((val)*(val) shr 64 or 1) or 1) ) shl 23) or \ ((((val)*(val) shr 64 or 1) shr ((bsr (((val)*(val) shr 64 or 1)or 1))-23)) and not $FF800000)\ ) } macro ddouble [val] { dq (1-1 shl ((val) or -(val)))*\ ( \ ((val) shr 64 shl 63) or \ (($3FF+bsr (((val)*(val) shr 64 or 1) or 1)) shl 52) or \ ((((val)*(val) shr 64 or 1) shr (bsr (((val)*(val) shr 64 or 1) or 1)-52)) and not $FFF0000000000000)\ ) } macro dtbyte [val] { dq (1-1 shl ((val) or -(val)))*((((val)*(val) shr 64 or 1) shr ((bsr (((val)*(val) shr 64 or 1) or 1))-63))) dw (1-1 shl ((val) or -(val)))*(((val) shr 64 and $8000 + $3FFF+bsr (((val)*(val) shr 64 or 1) or 1))) } allow val within range of all possible fasm integers from (-1) shl 64 to +1 shl 63 |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.