Original Post
Hi ,
I have an itoa ASM implementation. I would like to us
SIMD for it. But trying to figure out which parts can be
written with SIMD instruction or how can it be changed
for use SIMD instructions ?
The mentioned ASM implemetation :
I have an itoa ASM implementation. I would like to us
SIMD for it. But trying to figure out which parts can be
written with SIMD instruction or how can it be changed
for use SIMD instructions ?
The mentioned ASM implemetation :
void myitoa(int num, char * numstr)
{
__asm {
mov ebx,numstr ; point ebx to numstr
mov esi, num ; store number in esi
cmp esi, 0 ; if number is 0
jne nextdigit
mov [ebx],48 ; just set numstr to "0"
mov [ebx+1],0 ; add terminatting null character
jmp enditoa ; and end
nextdigit: mov eax, 66666667h ; 66666667h = 2^34 / 10
imul esi ; edx:eax = number * (2^34 / 10)
; therefore edx = number * (2^2 / 10)
sar edx, 2 ; edx = edx / 2^2
; therefore edx = number / 10 (integer division)
lea ecx, [edx + edx*4] ; ecx = edx * 5
add ecx,ecx ; ecx = edx * 10
; therfore ecx = (number div 10)*10
mov eax,esi ; store original number in eax
sub eax,ecx ; subtract ecx to leave remainder in eax
add eax,48 ; add 48 to make eax the digit's ASCII code
mov [ebx],al ; store digit character in numstr
inc ebx
mov esi,edx ; move number div 10 back into esi
cmp esi,0 ; if number div 10 = 0, we've finished
jnz nextdigit
mov [ebx],0 ; so add terminating null character
;reverse string
mov edx,numstr ; the number is in reverse order of digits
nextChar: dec ebx ; so we need to reverse the string
cmp ebx,edx
jle enditoa
mov eax,[edx]
mov ecx,[ebx]
mov [ebx],al
mov [edx],cl
inc edx
jmp nextChar
enditoa:
}
}