# Can SIMD do these things?

This topic is 4617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, some simple questions - I know SIMD basics but im not sure if these things are achieveable. Note I'm only interested in integers: 1)If I work with BYTEs, then I can work with 8 values at once with the 64bit MMX registers? 2)Can I 'scalarise' a SIMD data - ie can the last step of this be done in a single operation:
WORD data1[4],data2[4],data3[4];
data3 = MMX_mul(data1,data2);
int sum = data3[0]+data3[1]+data3[2]+data3[3];
3)C = min(A,B) is basically defined as:
if(A<B) C = A;
else C = B;
Is it possible to parallelise this - I think I've heard of MMX conditional/test operations?

##### Share on other sites
Quote:
 Original post by d000hg1)If I work with BYTEs, then I can work with 8 values at once with the 64bit MMX registers?

Yes, see instructions such as PADDB.

Quote:
 2)Can I 'scalarise' a SIMD data - ie can the last step of this be done in a single operation:int sum = data3[0]+data3[1]+data3[2]+data3[3];

Not AFAIK.

Quote:
 3)C = min(A,B) is basically defined as:`if(A

PCMPGTB is one example of an MMX comparision function - it sets the individual elements of the destination to 0 or 0xff depending on the result of the (greater-than) comparison. From this, you can easily compute a minimum.

##### Share on other sites
Is there an op which will set directly each element to be the min/max of the two arguments?

ie c = min(a,b)

##### Share on other sites
as for serialized sum of all components you may perhaps use the pavg,
which gives you the average of those components.
(pavgb for bytes of pavgw for words).

pavgw would be WORD avg = (data3[0]+2 + data3[1]+2 + data3[2]+2 + data3[3]+2) / 4;
The "+2" is for proper rounding.

##### Share on other sites
It's for the Topcoder contest, isn't it? ;)

operations in this table solve 1 and 3

##### Share on other sites
Not exactly. I've always been interested in a chance to use SIMD. The contest is one place I can do it, but I don't have my instruction-set reference.

I'm deliberately not asking anything specific to the contest, just "is there an op to do this"!

EDIT:
From those pages, PADDB can work on 64/128 bit operands in MMX/SSE2 respectively. How do I control which it uses on an SSE2-enabled system - just use the SSE registers instead of the MMn ones?

##### Share on other sites
When you use assembly you specify the register. The intrinsics are overloaded for the different types of data, so that's more or less the same.

##### Share on other sites
You cann with instuction PCMPGTB, and with logical AND and OR make this wery quick, without connditonal jumps. instuctions PAND and POR.

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011706
• ### Who's Online (See full list)

There are no registered users currently online

×