flat assembler
Message board for the users of flat assembler.

Index > Main > How to compare eight values in AVX register?

Author
Thread Post new topic Reply to topic
SeryZone



Joined: 20 Dec 2013
Posts: 38
Location: Ukraine, Kryviy Rih
SeryZone 07 Jun 2014, 10:37
How to compare eight values in AVX register?

Code:
maxvalue qqword 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0

vcmpps ymm0, [maxvalue]
;If ymm0[] = 1
;then ymm0[] = 0            


Here. I want to replace all 1.0 to 0.0

How I can do this?
Post 07 Jun 2014, 10:37
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 07 Jun 2014, 12:11
Sorry I don't have a machine to test this on - vpandn might be wrong but hopefully this is enough to get the idea:
Code:
const_1p0 dd 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
const_0p0 dd 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 

vcmpps ymm1,ymm0,qqword [const_1p0],0
                                        ; ymm1 has 1.0 mask 
vpandn ymm0,ymm1,ymm0                   ; zero 1.0 cells 
vpand ymm1,ymm1,qqword [const_0p0]      ; create 0.0 cells
vpor ymm0,ymm0,ymm1                     ; merge to complete the replacement    


Last edited by cod3b453 on 08 Jun 2014, 14:34; edited 1 time in total
Post 07 Jun 2014, 12:11
View user's profile Send private message Reply with quote
SeryZone



Joined: 20 Dec 2013
Posts: 38
Location: Ukraine, Kryviy Rih
SeryZone 07 Jun 2014, 12:44
cod3b453 wrote:
Sorry I don't have a machine to test this on - vpandn might be wrong but hopefully this is enough to get the idea:
Code:
const_1p0 dd 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
const_0p0 dd 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0

vcmpps ymm1,ymm0,[const_1p0],0
                                        ; ymm1 has 1.0 mask
vpandn ymm0,ymm1,ymm0                   ; zero 1.0 cells
vpand ymm1,ymm1,[const_0p0]             ; create 0.0 cells
vpor ymm0,ymm0,ymm1                     ; merge to complete the replacement    


operand size do not much... format MS COFF...
Post 07 Jun 2014, 12:44
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 08 Jun 2014, 14:35
I'd missed the "qqword" specifiers (previous snippet updated)
Post 08 Jun 2014, 14:35
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 16 Jun 2014, 02:15
Sery, this is the simplest way,
Code:
macro ReplaceOneWithZero a,b,t {
; for each i
;  if b[i] == 1.0
;   then a[i] = 0.0
;   else a[i] = b[i]
;  end if
; end for

; if a and b are the same register, t must be a different register
; if a and b are different registers, t can be the same register as a

       vcmpeqps  t,b,qqword[_ones]   ; t[i] = 0x00000000 in the case b[i]<>1.0 .  t[i] = 0xFFFFFFFF in the case b[i]=1.0 .
       vandnps   a,t,b               ; overwrite appropriate entries in a[i] with 0.0 (0x00000000)

}

align 32
_ones dd 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0

    
Post 16 Jun 2014, 02:15
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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.