flat assembler
Message board for the users of flat assembler.
Index
> Main > load 128 bit signed integer to st0 |
Author |
|
revolution 31 Jul 2017, 10:23
I guess the process could be like this:
|
|||
31 Jul 2017, 10:23 |
|
Furs 31 Jul 2017, 12:28
Load rax into st1, rdx into st0, multiply st0 by 2^64 (adjusting exponent only really), add st0 and st1 and pop?
EDIT: hmm seems the numbers are signed, I guess you'll have to convert them to abs value somehow (not individually) or the simple method won't work |
|||
31 Jul 2017, 12:28 |
|
Tomasz Grysztar 31 Jul 2017, 15:25
The 80-bit format used by FPU is actually quite simple and you can do such conversion without any FPU instructions. I quickly scribbled this version:
Code: int128_to_float80: ; in: rdx:rax = singed 128-bit integer ; out: dx:rax = 80-bit float test rdx,rdx jns uint128_to_float80 not rdx ;\ not rax ; \ this is just a add rax,1 ; / neg rdx:rax adc rdx,0 ;/ call uint128_to_float80 or dx,8000h retn uint128_to_float80: ; in: rdx:rax = unsigned 128-bit integer ; out: dx:rax = 80-bit float bsr r8,rdx jz .low mov cl,63 sub cl,r8l shld rdx,rax,cl mov rax,rdx lea rdx,[16383+64+r8] retn .low: bsr r8,rax jz .zero mov cl,63 sub cl,r8l shl rax,cl lea rdx,[16383+r8] retn .zero: xor eax,eax xor edx,edx retn Code: call int128_to_float80 mov qword [tmp],rax mov word [tmp+8],dx fld tword [tmp] |
|||
31 Jul 2017, 15:25 |
|
Furs 31 Jul 2017, 15:56
You could shave off a few instructions with lzcnt instead of bsr (check the carry flag instead of zero though).
(also if optimizing for size -- xor eax, eax/xor edx, edx can be replaced by xor eax, eax/cdq) |
|||
31 Jul 2017, 15:56 |
|
petelomax 31 Jul 2017, 19:49
Tomasz Grysztar wrote: I quickly scribbled this version: Excellent stuff, works perfectly. As a bonus, I don't feel quite so stupid for asking now! Many thanks, Pete |
|||
31 Jul 2017, 19:49 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.