Fastest way to test quadword equality on SPU?

Technical discussion on the newly released and hard to find PS3.

Moderators: cheriff, emoon

Post Reply
kroe
Posts: 6
Joined: Mon Apr 02, 2007 12:22 pm

Fastest way to test quadword equality on SPU?

Post by kroe »

I may be overlooking something really obvios, but I can't find a good way to test equality of two quadwords.

I have two vector unsigned chars and I need to stop iterating when they are equal. The "==" comparator doesn't work with quadwords, and the spu_cmpeq intrinsic would require other subsequent operations to check the result of the equality test.

What is the best way to compare two quadwords for equality?

Thanks,
-Ken
Mihawk
Posts: 29
Joined: Tue Apr 03, 2007 2:04 am

Post by Mihawk »

If you're looking for a method without "other subsequent operations", then I believe there is none.

But this should be the shortest way I think:

Code: Select all

ceq	$5, $3, $4	# compare words
gb	$6, $5		# gather bits from words
ceqi	$7, $6, 15
# then branch or selb
or something like that (didn't test).
User avatar
emoon
Posts: 91
Joined: Sun Jan 18, 2004 10:03 pm
Location: Stockholm, Sweden
Contact:

Post by emoon »

Maybe something like this (untested)

Code: Select all

inline bool spu_all_eq(vector unsigned int a, vector unsigned int b)
{
    return((spu_extract(spu_gather(spu_cmpeq(a, b)), 0) == 0xf));
}
pheon
Posts: 1
Joined: Fri Aug 31, 2007 3:17 pm
Location: the concrete jungle

Post by pheon »

or maybe

xor r1, r2, r3
orx r1, r1
brz / brnz
Warren
Posts: 175
Joined: Sat Jan 24, 2004 8:26 am
Location: San Diego, CA

Post by Warren »

emoon wrote:Maybe something like this (untested)

Code: Select all

inline bool spu_all_eq(vector unsigned int a, vector unsigned int b)
{
    return((spu_extract(spu_gather(spu_cmpeq(a, b)), 0) == 0xf));
}
spu_extract et al are somewhat slow routines and should be avoided if possible.
unsolo
Posts: 155
Joined: Mon Apr 16, 2007 2:39 am
Location: OSLO Norway

Post by unsolo »

result=spu_gather(spu_cmpeq(A,B)))

if any B is equal to A then you will have a value in the element 0 of result
Don't do it alone.
Post Reply