flat assembler
Message board for the users of flat assembler.

Index > Main > Sse Increment text int in xmm reg

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 17 Aug 2023, 08:56
I want using xmm regs to store text int counter, and not using memory.
Code:
;data
align 16
        intTxt db 16 dup(0)
        tdigs  db  '00000000        '
        hjj1   db  '0000000000000000'
        ;hjj2   db  16 dup(1)  this wrong
        hjj2   db  1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1  ;this right
        afft   db  '::::::::::::::::' 
;code
macro Msg a { invoke MessageBox,0,a,0,0 }

Start:
movups xmm3,dqword [tdigs]
  mov    ebx,99_000_000
 
.ew:   movups xmm1,xmm3 ;dqword [tdigs]
   pextrb eax,xmm1,4+3
   inc    al
   pinsrb xmm1,eax,4+3
 
;if rept 1 and ebx=500 int text= 4:0.  If ebx=501 int txt= 501
 rept 6 {
   movups xmm2,dqword [afft]
   PCMPGTB xmm2,xmm1
   pand    xmm1,xmm2
   pmaxub  xmm1,dqword [hjj1]
   psrldq   xmm2,1      
   pandn     xmm2,dqword [hjj2]
   paddb    xmm1,xmm2             
         }
   movaps    xmm3,xmm1
   dec    ebx
   jnz    .ew
   movq   qword [intTxt], xmm1
   Msg intTxt
    

if ebx=99_000_000 int text = 99_000_005
if ebx = 16_000_000 int text = 16_000_000

Fixed now ebx=99_000_000 int text = 99_000_000
Post 17 Aug 2023, 08:56
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 17 Aug 2023, 09:17
Variant counter to 999_999_999

Code:
;data
align 16
        intTxt db 16 dup(0)
        tdigs  db  '000000000       '
        hjj1   db  '0000000000000000'
        ;hjj2   db  16 dup(1)  this wrong
        hjj2   db  1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1  ;this right
        afft   db  '::::::::::::::::' 
;code
macro Msg a { invoke MessageBox,0,a,0,0 }

Start:
movups xmm3,dqword [tdigs]
  mov    ebx,999_999_999
 
.ew:   movups xmm1,xmm3 ;dqword [tdigs]
   pextrb eax,xmm1,4+3+1
   inc    al
   pinsrb xmm1,eax,4+3+1
 
;if rept 1 and ebx=500 int text= 4:0.  If ebx=501 int txt= 501
 rept 6+1 {
   movups xmm2,dqword [afft]
   PCMPGTB xmm2,xmm1
   pand    xmm1,xmm2
   pmaxub  xmm1,dqword [hjj1]
   psrldq   xmm2,1      
   pandn     xmm2,dqword [hjj2]
   paddb    xmm1,xmm2             
         }
   movaps    xmm3,xmm1
   dec    ebx
   jnz    .ew
   movups  dqword [intTxt], xmm1
   mov     word [intTxt+9],0 
   Msg intTxt
    
Post 17 Aug 2023, 09:17
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 17 Aug 2023, 09:51
another variant
Code:
 align 16
    tdigs  db  '000000000       '
    endianSwitch    db 15, 14, 13, 12,   11, 10, 9, 8,   7, 6, 5, 4,   3, 2, 1, 0
wrapper         db 0C6h, 0C6h, 0C6h, 0C6h,   0C6h, 0C6h, 0C6h, 0C6h,   0C6h, 0C6h, 0C6h, 0C6h,   0C6h, 0C6h, 0C6h, 0C6h
spaceCorrector  db 10h,  10h,  10h,  10h,    10h,  10h,  10h,  10h,    10h,  10h,  10h,  10h,    10h,  10h,  10h,  10h
wrapper10       db 10,   10,   10,   10,     10,   10,   10,   10,     10,   10,   10,   10,     10,   10,   10,   10
carryMask       db 0FFh, 0FFh, 0FFh, 0FFh,   0FFh, 0FFh, 0FFh, 0FFh,   7,    7,    7,    7,      7,    7,    7,    7
spaceDecector   db '!',  '!',  '!',  '!',    '!',  '!',  '!',  '!',    '!',  '!',  '!',  '!',    '!',  '!',  '!',  '!'  
intTxt db 32 dup(0)
Start:
 movups  xmm0, dqword [tdigs]
 mov ebx,11 ;for test i do loop 
    ; pshufb  xmm0, dqword [endianSwitch]  ; switch little/big-endian
.uppp:    
    paddb   xmm0, dqword [wrapper]         ; shift digits from ASCII to wrapping edge ('0'->0F6h .. '9'->0FFh)
    
    ; increment low qword
    mov     eax, 1             
    xorps   xmm1, xmm1
    movd  xmm1, eax
    paddq   xmm0, xmm1
    ;psubq    xmm0,xmm1
    
    ; carry to high qword
    xorps   xmm1, xmm1
    pcmpeqb xmm1, xmm0                       ; byte == 0 ?
    pshufb  xmm1, dqword [ carryMask]        ; mask = 0XX_XX_XX_XX_XX_XX_XX_XX_00_00_00_00_00_00_00_00h, where XX = byte7
    psubq   xmm0, xmm1                       ; sub (-1) equivalent add 1
    
    ; correct wrapped digits
    xorps   xmm1, xmm1
    pcmpeqb xmm1, xmm0                       ; byte == 0 ?
    andps   xmm1, dqword [wrapper10]
    psubb   xmm0, xmm1
    
    psubb   xmm0, dqword [wrapper]          ; shift digits back to ASCII-codes
    
    ; detect spaces affected by carry
    movaps  xmm1, dqword [spaceDecector]
    pcmpeqb xmm1, xmm0                       ; check for spaces under carry
    andps   xmm1, dqword [spaceCorrector]   ; shift such spaces (actually '!') to '1'
    paddb   xmm0, xmm1
    dec ebx
    jnz  .uppp
    movaps  xmm1,xmm0
    pshufb  xmm1, dqword [endianSwitch]
    movups  dqword [intTxt], xmm1   
    Msg intTxt
    


Last edited by Roman on 18 Aug 2023, 06:26; edited 2 times in total
Post 17 Aug 2023, 09:51
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 17 Aug 2023, 12:18
My variant 32 bit program. 32 bits regs store max value 4294967295
Code:
align 16
        tdigs db '70000000000     '
        hjj1  db  '0000000000000000'
        hjj2  db  1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1
        afft  db  '::::::::::::::::' 
        intTxt db 16 dup(0)

Start:
 movups xmm3,dqword [tdigs]
  xorps  xmm0,xmm0
;replaced pextrb\pinsrb +50% faster
mov eax,1
movd xmm5,eax
pslldq xmm5,9
  mov    ebx,1_000_999_591 
 
.ew:   movaps xmm1,xmm3
   ;pextrb eax,xmm1,4+3+2
   ;inc    al
   ;pinsrb xmm1,eax,4+3+2
   paddb xmm1,xmm5          ;replaced pextrb\pinsrb +50% faster
 mov  al,2
.et:
   movaps xmm2,dqword [afft]
   PCMPGTB xmm2,xmm1
   pand    xmm1,xmm2
   pmaxub  xmm1,dqword [hjj1]
   psrldq   xmm2,1
   pandn     xmm2,dqword [hjj2]
   paddb    xmm1,xmm2
  comiss xmm2,xmm0
   ja     .et
  dec al
  jnz .et
   movaps    xmm3,xmm1

   dec    ebx
   jnz    .ew        
   movups  dqword [intTxt], xmm1 ;intTxt = '8000999591'
   mov     word [intTxt+10],0     
   Msg intTxt 
;easy changed int text to float
   mov eax,dword [intTxt+7]
   mov byte [intTxt+7],'.'
   mov dword [intTxt+8],eax
   mov     word [intTxt+11],0 ;intTxt = '8000999.591'

    
Post 17 Aug 2023, 12:18
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.