Hi all,

I need an unsigned vector multiplication of words. Unfortunately, there's no MMX/SSE pmulluw instruction. There's only pmullw and pmulhuw. So does anyone know how I can nicely get the result I'm looking for with existing instructions?

Thanks,

c0d1f1ed
Posted on 2007-07-24 19:27:22 by C0D1F1ED
You don't need one. Such an instruction would perform the same function as a regular pmullw :)

Try this:
#include <stdio.h>

int main(int argc, char *argv[]) {
unsigned i, j;

for(j = 0; j < 256; ++j) {
for(i = 0; i < 256; ++i) {
unsigned char a, b;
signed char c, d;
unsigned char e, f;

a = i; b = j;
c = i; d = j;

e = a * b;
f = c * d;

if(e != f) {
printf("%d x %d", i, j);
return 1;
}
}
}

return 0;
}
Posted on 2007-07-24 19:30:23 by doynax
:shock:

Ha, that explains a lot. I'm gonna go bang my head against the wall now...

...everything I had tried to get unsigned multiplications suffered from precision issues or gave me downright incorrect results. :P What confused me is that the Intel documents say pmullw performs signed multiplications.

Anyway, thanks for pointing that out! It's so obvious once you realize what happens to the sign bits.
Posted on 2007-07-25 21:38:49 by C0D1F1ED