flat assembler
Message board for the users of flat assembler.

Index > Main > dword to ascii, ascii to dword

Goto page Previous  1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Fixed in the above post.
Post 11 Feb 2013, 07:12
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Here is slightly faster version of my code (at least on my work computer Intel code duo):
Code:
johnfound_ascii2d:
        xor     eax, eax
        mov     ecx, [esp+4]
        mov     edx, eax
        mov     [esp+4], eax

        cmp     byte [ecx], '-'
        jne     .loop
        add     ecx, 1
        sub     dword [esp+4], 1
.loop:
        mov     dl, [ecx]
        inc     ecx
        test    dl, dl
        jz      .ends

        lea     eax, [5*eax]
        sub     dl, '0'
        shl     eax, 1

        add     eax, edx
        jmp     .loop

.ends:
        xor     eax, [esp+4]
        sub     eax, [esp+4]
        retn 4    
Post 11 Feb 2013, 09:37
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
JohnFound wrote:
Code:
        shl     eax, 1

        add     eax, edx    
What about:
Code:
lea eax,[eax*2+edx]    
Question
Post 11 Feb 2013, 11:12
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
revolution wrote:
What about:
Code:
lea eax,[eax*2+edx]    
Question


Yes, it is better! But not faster on my tests. Sad Strange.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 11 Feb 2013, 11:17
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
IMO testing for "faster" is rather futile for minor changes. There are far too many factors that can change the results that make it a very unsatisfying experience.
Post 11 Feb 2013, 11:20
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
But this is really faster from 2620ms for the previous variant to 1545ms for this (for 100000000 conversions):

Code:
johnfound_ascii2d:
        push    esi

        xor     eax, eax
        mov     esi, [esp+8]
        mov     edx, eax
        mov     ecx, eax

        cmp     byte [esi], '-'
        jne     .loop

        add     esi, 1
        sub     ecx, 1

.loop:
        lodsb
        sub     al, '0'
        jc      .ends

        lea     edx, [5*edx]
        lea     edx, [2*edx+eax]
        jmp     .loop

.ends:
        xor     edx, ecx
        sub     edx, ecx
        mov     eax, edx
        pop     esi
        retn 4    


This evening I will test on Intel Atom. I expect, the result will be different.
Post 11 Feb 2013, 11:27
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
JohnFound wrote:
But this is really faster from 2620ms for the previous variant to 1545ms for this (for 100000000 conversions): ...
How much of that data is coming from cache and how much is fresh from disk / other source?

So many things to check before we know if it will be faster in the "real world".
Post 11 Feb 2013, 11:30
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
revolution, you are right of course. But the faster algorithm is always faster. Of course, it is not so important if the bottleneck is somewhere else - for example on the disk operations. That is why I always argue that it is always better to optimize for size, not for speed.
But here it is a game - isn't it? Smile
Post 11 Feb 2013, 11:33
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
JohnFound wrote:
But the faster algorithm is always faster.
Well that is also a myth it seems. Even theoretically asymptotically faster algorithms can be slower than naive algorithms if the input size is small. One must know the domain of the expected source data before one can conclude the "best"* algorithm to apply.

* where the definition of best is left open to interpretation.
Post 11 Feb 2013, 11:38
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Revolution, when I use the word "faster" I mean "In the same conditions" of course. Another type of comparison is impossible at all. And of course on some conditions even theoretically faster algorithm can be slower - for example Bubble sort is faster than Quick sort on very small arrays.
Post 11 Feb 2013, 11:51
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
@uart777:
Why load the address into EDX?
It can be shorter:
Code:
mov cx, [table + eax*2]
    
Post 11 Feb 2013, 12:05
View user's profile Send private message Send e-mail Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:34; edited 2 times in total
Post 11 Feb 2013, 19:59
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8901
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
ok guys,
will come back to work after 2 days holiday,

what i would do is, copy paste ur code and run it,

i would use my proc and every of ur guys submitted proc and cmp the EAX returned,

to verify that each proc return valid value,

then i will test the speed =)

will announce the winner on 16th Feb 2013

u can use MMX SSE1 SSE2 or etc if u think that could help.

*plez note that, i am not suppose to do anything with your code in case they are not in the form that i proposed, i only will copi paste and call it then time it.
Post 12 Feb 2013, 00:18
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
what does give my atoi function?

Code:
mov esi,test
call atoi
mov [result],eax
...
test db '-1235697',0

;on return:
;value from signed decimal string at [esi] in eax
;esi will point directlly after the command.
;carry set if valid decimal number

atoi:
.seekend:
        lodsb
        case al,' ',@f
        case al,'.',@f
        case al,',',@f
        case al,'!',@f
        casne al,0,.seekend
@@:
        dec esi
        push esi
        dec esi
        xor ebx,ebx
        mov edx,1
.next:
        movzx eax,byte[esi]
        dec esi
        case al,'-',.neg
        case al,' ',.end
        case al,',',.end
        case al,'.',.end
        casl al,'0',@f
        casg al,'9',@f
        sub al,'0'
        imul eax,edx
        add ebx,eax
        imul edx,10
        jmp .next
@@:
        pop esi
        clc
        mov eax,ebx
        ret
.neg:
        mov al,[esi]
        casne al,' ',@b
        neg ebx
.end:
        pop esi
        stc
        mov eax,ebx
        ret
.null:
        xor ebx,ebx
        clc
        mov eax,ebx
        ret
                                                    
    

need that:
Code:
macro case var,value,jmp {
        cmp var,value
        je jmp
}

macro casne var,value,jmp {
        cmp var,value
        jne jmp
}

macro casa var,value,jmp {
        cmp var,value
        ja jmp
}

macro casle var,value,jmp {
        cmp var,value
        jle jmp
}

macro casg var,value,jmp {
        cmp var,value
        jg jmp
}

macro casge var,value,jmp {
        cmp var,value
        jge jmp
}

macro casl var,value,jmp {
        cmp var,value
        jl jmp
}

    
Post 12 Feb 2013, 01:53
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
I will also test these routines -- keep posting!
Post 12 Feb 2013, 13:32
View user's profile Send private message Send e-mail Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8901
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
if got any better method or what you see more suitable, please let us know, so everybody will get more fair assessment,

and for our future game as well
Post 12 Feb 2013, 14:40
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
What if my code is the slowest!?...
First I'll measure it and then post it -- you know, not to be embarassed...

Basically, my idea is an unrolled loop.
The maximum of digits is 10, so I call my macro for converting a digit ten times.
Should be simple enough. No jumps -- well, only one jump if no more digits found.
But the measurement will actually decide if it is really fast code or not.
Maybe not... we''ll see. It is all very intriguing!
Post 12 Feb 2013, 17:46
View user's profile Send private message Send e-mail Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:33; edited 2 times in total
Post 12 Feb 2013, 20:48
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
I will still post my code, even if it will be slow.
Post 12 Feb 2013, 23:16
View user's profile Send private message Send e-mail Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:33; edited 1 time in total
Post 12 Feb 2013, 23:25
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.