News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Was crt_printf and FPU

Started by cobold, October 09, 2007, 07:25:34 PM

Previous topic - Next topic

cobold

Raymond and Greg, thanks a lot again.
I understand now, that I have to be careful with the data types when using the FPU.
Still I have a question, because it seems to me that the FPU is converting data in some occasions "automatically"?
Thanks to your advice my little program works now, but I love it to play around with code to get a deeper understanding about what's happening "under the hood" (is that correct english, btw?)

So I found out that the following:

Ticksbefore, Ticksafter and overhead are all defined as QWORD.
overhead is the number of Ticks between two succesive calls of QueryPerformanceCounter
    invoke QueryPerformanceCounter, ADDR Ticksbefore
    invoke QueryPerformanceCounter, ADDR Ticksafter
    fild    Ticksafter    ; use fild so the FPU knows it should work with integers
    fild    Ticksbefore
    fsub
    fistp    overhead ; use fistp to tell FPU to store result as integer

and

    fld    Ticksafter
    fsub  Ticksvor
    fstp   overhead

both have the same effect.
output of version "FILD / FISTP"
Ticksafter = 3085357886
Ticksbefore  = 3085357882
Overhead = 4
freq = 3579545
1/freq = 0.00000027936511484001
output of version "FLD/FSTP"
Ticksafter = 3463290506
Ticksbefore  = 3463290503
Overhead = 3
freq = 3579545
1/freq = 0.00000027936511484001

Could you explain pls, why?

rgds
cobold

raymond

In the same chapter for which I gave you a link in the other thread, read the section on Denormalized REAL numbers (just before the section describing the packed BCD data type). It may help you understand what is happening. Don't be shy to ask if it does not explain it sufficiently.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

MichaelW

And to make it a little easier to see:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      t1    dq 3463290503
      ovr   dq 0
      buff  db 65 dup (0)
      lbl   db "seeeeeeeeeeeffffffffffffffffffff"
            db "ffffffffffffffffffffffffffffffff",0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
qw2bin proc qwValue:QWORD,lpBuffer:DWORD

    push edi
    mov edi,lpBuffer
    sub edi,1
   
    mov eax, DWORD PTR qwValue+4
    mov ecx,32
  @@:
    xor edx,edx
    add edi,1
    shl eax,1
    adc edx,'0'
    sub ecx,1
    mov [edi],dl
    jnz @B
    mov eax, DWORD PTR qwValue
    mov ecx,32
  @@:
    xor edx,edx
    add edi,1
    shl eax,1
    adc edx,'0'
    sub ecx,1
    mov [edi],dl
    jnz @B

    pop edi
    ret

qw2bin endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    print ADDR lbl,13,10
    invoke qw2bin,t1,ADDR buff
    print ADDR buff,13,10

    fild t1
    fstp ovr
    invoke qw2bin,ovr,ADDR buff
    print ADDR buff,13,10

    fld t1
    fstp ovr
    invoke qw2bin,ovr,ADDR buff
    print ADDR buff,13,10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


seeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffff
0000000000000000000000000000000011001110011011011001111010000111
0100000111101001110011011011001111010000111000000000000000000000
0000000000000000000000000000000011001110011011011001111010000111
eschew obfuscation