News:

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

decimal as KiB,Mib,GiB etc.

Started by sinsi, July 29, 2008, 12:38:02 PM

Previous topic - Next topic

GregL

Quote from: jj2007... for practical purposes it would be useful to invert the order of the multiple .IF hibit >= tests.

Yeah, you're right. I reversed it to test for the smallest first and uploaded a new file. Maybe slightly faster.


Mark Jones

AMD dual-core x64 4000+ (WinXP x32)
BSR, 128 bytes:
Test0   72 cycles
Test1   74 cycles
Test2   65 cycles
Test3   65 cycles
Test4   65 cycles

MMX, 150 bytes:
Test0   15 cycles
Test1   20 cycles
Test2   26 cycles
Test3   31 cycles
Test4   34 cycles

Greg, 222 bytes:
Test0   42 cycles
Test1   41 cycles
Test2   28 cycles
Test3   25 cycles
Test4   24 cycles
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

FORTRANS

Okay,

   Since Mark mentioned BSR, and sinsi used SHRD, I revisited
my code.  Cleaned it up a bit first, the algorithm is a bit clearer.
(I hope.)  Then used those instructions to do the same thing
using a different algorithm to select the bits to display.  There
are two EQUates to select the different options.  One selects
either the BSR and a jump table, or the test and branch code.
The other switches between using AAM or a divide to format
the fraction.

   Written as mostly 32 bit code, though a few things remain
as 16 bit.  The BSR code probably looks like it had a encounter
with a large, flat, programming rock.  But it is reasonably
commented, and works.  So some beginner may benefit.

Regards,

Steve N.

[attachment deleted by admin]

jj2007

Quote from: Mirno on August 06, 2008, 05:23:02 PM
The floating point code I posted is pretty compact, but printing out a floating point value is killing it performance wise (crt_sprintf adds 4k clocks to it - ouch).

Have you tried crt_sprintf? No invoke available, but it does the same as crt_printf except it writes to a buffer:

.data?
f2sBuffer dd 10 dup(?)

.data
Float8 REAL8  1234.5678901234567890

StrFormat db "Float is %.17g", 0
.code

mov eax, offset Float8
push [eax+4]
push [eax]
push OFFSET StrFormat
push OFFSET f2sBuffer
call crt_sprintf
pop edx ; f2sBuffer
add esp, 12
MsgBox 0, edx, "ST$ test:", MB_OK

GregL

jj2007,

You can use invoke:


    mov eax, OFFSET Float8
    INVOKE crt_sprintf, ADDR f2sBuffer, ADDR StrFormat, REAL8 PTR [eax]



jj2007

Quote from: Greg on August 19, 2008, 04:59:04 AM
jj2007,

You can use invoke:


    mov eax, OFFSET Float8
    INVOKE crt_sprintf, ADDR f2sBuffer, ADDR StrFormat, REAL8 PTR [eax]



I had not seen that one, thanks a lot Greg :thumbu

NightWare

::) divisions ?
:dazzled: fpu ?
:eek mmx/sse2 ?
what's wrong with you guys ? maybe i should post something before you attack the avx instruction set...  :cheekygreen:
.DATA
ALIGN 16
XBytes_Table BYTE " Ko",0
BYTE " Mo",0
BYTE " Go",0
BYTE " To",0
BYTE " Po",0
BYTE " Eo",0

.CODE
ALIGN 16
;
; syntax :
; mov eax,{low part (31-0 bits) of the value}
; mov edx,{high part (63-32 bits) of the value (or 0 if no high part)}
; mov esi,{OFFSET of the string to create (12 bytes needed)}
; call GetFileSizeString
;
; return :
; eax = string length
;
GetFileSizeString PROC
push ebx
push ecx
push edx
push esi
push edi

CaseEdx:
mov edi,OFFSET XBytes_Table
test edx,edx
jz CaseEax
add edi,DWORD
shrd eax,edx,10
shr edx,10
jz CaseEax
add edi,DWORD
shrd eax,edx,10
shr edx,10
jz CaseEax
add edi,DWORD
shrd eax,edx,10
shr edx,10
jz CaseEax
add edi,DWORD
shrd eax,edx,10

CaseEax:
test eax,11111111111111111111110000000000b
jz CaseBytes
test eax,11111111111100000000000000000000b
jz CaseXBytes
shr eax,10
add edi,DWORD
test eax,11111111111100000000000000000000b
jz CaseXBytes
shr eax,10
add edi,DWORD

CaseXBytes:
mov ebx,eax
shr eax,10
shl ebx,22
mov edx,4294968
mov ecx,10
mul edx
jc Label01
dec esi
mul ecx
jc Label02
dec esi
mul ecx
jc Label03
dec esi
jmp Label04
Label01: add dl,"0"
mov BYTE PTR [esi],dl
mul ecx
Label02: add dl,"0"
mov BYTE PTR [esi+1],dl
mul ecx
Label03: add dl,"0"
mov BYTE PTR [esi+2],dl
Label04: mul ecx
add dx,".0"
mov WORD PTR [esi+3],dx
mov eax,ebx
test ebx,ebx
jnz Couple
dec esi
xor edx,edx
jmp UniqueZero
Couple:
mul ecx
add dl,"0"
mov BYTE PTR [esi+5],dl
mul ecx
UniqueZero:
mov eax,DWORD PTR [edi]
add dl,"0"
mov BYTE PTR [esi+6],dl
mov DWORD PTR [esi+7],eax
lea eax,[esi+10]

pop edi
pop esi
pop edx
pop ecx
pop ebx
sub eax,esi
ret

CaseBytes:
mov ebx,4294968
mov ecx,10
mul ebx
jc Label21
dec esi
mul ecx
jc Label22
dec esi
mul ecx
jc Label23
dec esi
jmp Label24
Label21: add dl,"0"
mov BYTE PTR [esi],dl
mul ecx
Label22: add dl,"0"
mov BYTE PTR [esi+1],dl
mul ecx
Label23: add dl,"0"
mov BYTE PTR [esi+2],dl
Label24: mul ecx
add edx,"yB 0"
mov DWORD PTR [esi+3],edx
mov DWORD PTR [esi+7],"set"
lea eax,[esi+11]

pop edi
pop esi
pop edx
pop ecx
pop ebx
sub eax,esi
ret
GetFileSizeString ENDP