forum-msg-id-130679-edit

Original date:2017-01-01 07:16:21 Edited by: petelomax Subject: Re: Phix: peek8u deprecated.

Oh, ffs - I read something on the internet and it was WRONG! shockedshockedshocked
I knew there was a problem with unsigned 64 bit ints in 80-bit floats, so just accepted his word (/diagram) as the gospel truth.
(Figure 2.3 shows a literal 1, which I thought was odd, but y'know the whole "well, that explains it" thing.. It ain't a fixed 1.)
To my shame, I already knew there was a problem getting them in, what I missed was the (simple) problem in getting them out.

http://forum.pellesc.de/index.php?topic=5938.10;wap2 said...

The FP instructions fild/fist/fistp work with *integers* there is no instruction for unsigned integers.
The Floating Point Unit doesn't know of unsigned integers existence, so if the number won't fit in a signed integer then it is an overflow (0x80000000....).

There may be a better way (suggestions welcome) but this will load an unsigned int (already in rax):

    -- to load unsigned, right shift rax by 1, save odd bit in rcx, then *2+[0|1] 
    xor rcx,rcx 
    shr rax,1 
    rcl rcx,1 
    push rax 
    push rcx 
    fild qword[rsp] 
    fild qword[rsp+8] 
    add rsp,16 
    fadd st0,st0        -- *2 
    faddp               -- +0|1 

Extracting an uinsigned int (from an 80-bit float already in st0) is not really any better or worse:

    -- if uint>#7FFF... then uint-=#1_0000... 
    push r15            -- #4000_0000_0000_0000 
    fild qword[rsp] 
    fadd st0,st0        -- #8000_0000_0000_0000 
    fld st1 
    fcomp 
    fnstsw ax 
    sahf 
    jb @f 
        fadd st0,st0    -- #1_0000_0000_0000_0000 
        fsub st1,st0 
  @@: 
    fstp st0            -- discard 
    fistp qword[rsp] 
    pop rax 

(Obviously, do a mov r15,h4 first when unsure, but that will be unneccessary more often than not.)
[Some further care may also be needed when dealing with already signed values, and it may be easier in hll]

So that just needs applying in ten dozen or so places throughout the backend, and peek8u can live on oops

Pete

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu