flat assembler
Message board for the users of flat assembler.

Index > Main > How reset bits for one asm command?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1766
Roman 29 Apr 2023, 06:34
For example.
I want reset bits from 23 to 31
I could using loop and btr, but I want reset faster in one asm command.
How do this?
Post 29 Apr 2023, 06:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 29 Apr 2023, 06:58
Code:
and eax,0x007fffff    
Post 29 Apr 2023, 06:58
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2493
Furs 29 Apr 2023, 17:29
You can also use bzhi if you have BMI2 and a non-constant bit position.
Post 29 Apr 2023, 17:29
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1766
Roman 29 Apr 2023, 20:05
My CPU ryzen 5 3600
Support:

MMX
SSE
SSE2
SSE3
SSSE3
SSE4A
SSE4.1
SSE4.2
AES
AVX
AVX2
BMI1
BMI2
SHA
F16C
FMA3
AMD64
EVP
AMD-V
SMAP
SMEP
SMT
Precision Boost 2
Post 29 Apr 2023, 20:05
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1766
Roman 30 Apr 2023, 10:25
My Idea put in rax 8 bytes text and rdx 8 bytes text.
Cut all symbols until 32
And compare rax and rdx
Code:
Text db 'defxyz defzxy1 '
Mov rax, qword [Text]
Some way in rax reset to null this part " d"

Mov rdx, qword [Text+7]
Some way in rdx reset rdx bits to null
;rax=defxyz Rdx=defzxy1
Cmp rax, rdx
    

My variant
Code:
tmp dq 0,0
Mov rax, "r01234 d"
Mov qword [tmp], rax
Mov ebx, tmp-1
.1: Inc ebx
Cmp byte [ebx], 0
Jz .2
Cmp byte [ebx], 32
Jnz .1
Mov qword [ebx], 0
.2:
Mov rax, qword [tmp]
    
Post 30 Apr 2023, 10:25
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 30 Apr 2023, 11:40
Code:
Text db 'defxyz defzxy1 '
Mask dq 0x0000FFFFFFFFFFFF
mov rax, qword [Text]
and rax, qword [Mask]
mov rdx, qword [Text + 7]
and rdx, qword [Mask]
cmp rax, rdx    

Code:
Text db 'defxyz defzxy1 '
mov rax, 0x0000FFFFFFFFFFFF
mov rdx, rax
and rax, qword [Text]
and rdx, qword [Text + 7]
cmp rax, rdx    

Code:
Text db 'defxyz defzxy1 '
mov rax, qword [Text]
mov rdx, qword [Text + 7]
mov cl, 16
shl rax, cl
shl rdx, cl
shr rax, cl
shr rdx, cl
cmp rax, rdx    
Post 30 Apr 2023, 11:40
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1766
Roman 30 Apr 2023, 11:52
Thanks ! Cool variant.
Code:
Text db 'defxyz defzxy1 '
mov rax, 0x0000FFFFFFFFFFFF
mov rdx, rax
and rax, qword [Text]
and rdx, qword [Text + 7]
cmp rax, rdx  
    


But not universal and failed on this:
Code:
Text db 'defxyz22 defzxy1 '
Text2 dq 0,0

mov rax, 0x0000FFFFFFFFFFFF
mov rdx, rax
and rax, qword [Text]
and rdx, qword [Text + 7]
mov [Text2],rax      ;='defxyz' but must be 'defxyz22'
mov [Text2+7],rdx    ;='2 defzxy' but must be '2'
    
Post 30 Apr 2023, 11:52
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1766
Roman 30 Apr 2023, 13:17
https://www.officedaytime.com/simd512e/simdimg/pcmp.php?f=pcmpeqb
Code:
 Text   db 'def xyz22 defzxy1 22'
 Text3 dq 0,0

 movups  xmm1,dqword [Text]
 movaps  xmm0,xmm1
 movups  xmm2,dqword [Text+10]
 PCMPEQB xmm1, xmm2         ;result out to xmm1
 andps   xmm0,xmm1
 movups  dqword[Text3],xmm0 

 movq rax,xmm0
 mov ebx,2
 bsf rax,rbx  ;eax=1 because all 3 bits = 1
    

_ mean 0 (if not equal byte xmm1,xmm2)
After Text3 = d,e,f,_,x,y,_,_,2,_,_,_,_,_,_,_
Post 30 Apr 2023, 13:17
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 30 Apr 2023, 13:56
Roman wrote:
But not universal and failed on this:

My example works correctly. Resets what is set. It is you who expect from him what cannot be. Why on earth should it define spaces in a string. What did you write in the title of the topic. What you wanted, you got...
Post 30 Apr 2023, 13:56
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1766
Roman 30 Apr 2023, 18:42
New variant:
Code:
Text db 'def xyz22 defzxy1 22'
TexB db 16 dup(32)  

      movups xmm1,dqword [Text]
      movaps xmm0,xmm1
      xorps  xmm3,xmm3
      movups xmm2,dqword [TexB]
      jmp    .22
.20:  vpslldq xmm0,  xmm0, 1
      movaps  xmm1,xmm0
.22:  PCMPEQB xmm1, xmm2
 
      comisd  xmm1,xmm3   ;5 loops
      jnz     .20
      movq    rax,xmm0    ;rax=0x6665640000000000
    
Post 30 Apr 2023, 18:42
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.