flat assembler
Message board for the users of flat assembler.

Index > Main > SSE convert string to decimal

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
I search example SSE(2 or 4) convert string to 32bit decimal number.
And example SSE convert 32bit decimal number to string
Post 04 Jan 2014, 17:59
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
First you must know how to convert a number to string and vice versa.

Then (assuming you know how to use SSE) you can implement the algorithm using SSE.
Post 04 Jan 2014, 23:30
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
For example
mov eax,128
mov ebx,10
sub edx,edx
div ebx
edx=8 !

Then do again
sub edx,edx
div ebx
edx=2

But SSE not have comand like div !
Post 05 Jan 2014, 08:47
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
If i want do this in SSE i can get more commands. This is sad
Post 05 Jan 2014, 08:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
It is not clear what "string to decimal" means, but anyhow numeric conversion to/from ASCII format is generally best done in the integer domain. When dealing with floats you have to deal with the non-trivial problem of precision loss.

It is trivial scale your float first, then save as an integer and then covert to ASCII using integer arithmetic. The only time SSE would be involved is with the scaling operation. If you try to do it all in the float domain with SSE you will have many extra difficulties to solve. Using SSE is not worth the extra effort IMO.
Post 05 Jan 2014, 09:44
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
For the "to-string" example shown, division could be done by reciprocal multiplication using fixed point arithmetic; if you are converting a lot of numbers in parallel this might be worth it [more so with SSSE3 pshufb].

For a "string-to" function, SSE can easily convert to BCD using psubb and find a decimal point/null terminator using pcmp. You can then unpack these bytes into d/qwords and scale them using a precomputed LUT of base 10 values [integer or float]. The final stage is then adding all of these terms together with the help of packing/shuffling instructions. This probably has more overhead than using the general purpose registers in 64bit.
Post 05 Jan 2014, 15:07
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
My idea to convert text to integer number
Code:

TxtChislo db '9988000000000859'
AndChislo db 48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48
MulChislo db 10,1,1,1,0,0,0,0,0,0,0,0,100,10,10,1 


        movss    xmm1,dword [TxtChislo]
        movss    xmm2,dword [AndChislo]
        pxor      xmm1,xmm2
        movss    xmm2,dword [MulChislo]
        pmullw    xmm1,xmm2 

;Show int numbers
        movd      eax,xmm1
        sub        ecx,ecx
        mov        cl,ah
        PrintInt 'Chislo = ',ecx 
    


In ECX number 99 ! Its good. But if PrintInt 'Chislo = ',eax
Number in EAX wrong.
Post 11 Jan 2014, 09:49
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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. Also on YouTube, Twitter.

Website powered by rwasa.