flat assembler
Message board for the users of flat assembler.

 Index > Main > SSE convert string to decimal
Author
Roman

Joined: 21 Apr 2012
Posts: 1735
Roman 04 Jan 2014, 17:59
I search example SSE(2 or 4) convert string to 32bit decimal number.
And example SSE convert 32bit decimal number to string
04 Jan 2014, 17:59
typedef

Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 04 Jan 2014, 23:30
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.
04 Jan 2014, 23:30
Roman

Joined: 21 Apr 2012
Posts: 1735
Roman 05 Jan 2014, 08:47
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 !
05 Jan 2014, 08:47
Roman

Joined: 21 Apr 2012
Posts: 1735
Roman 05 Jan 2014, 08:53
If i want do this in SSE i can get more commands. This is sad
05 Jan 2014, 08:53
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20248
revolution 05 Jan 2014, 09:44
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.
05 Jan 2014, 09:44
cod3b453

Joined: 25 Aug 2004
Posts: 618
cod3b453 05 Jan 2014, 15:07
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.
05 Jan 2014, 15:07
Roman

Joined: 21 Apr 2012
Posts: 1735
Roman 11 Jan 2014, 09:49
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.
11 Jan 2014, 09:49
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum