-4

How can I multiply two signed 32-bit integers using SSE2 instruction set?

woz
  • 10,888
  • 3
  • 34
  • 64
user2003619
  • 49
  • 1
  • 4

1 Answers1

0

pmuldq is, unfortunately, an SSE4.1 instruction, but SSE2 has pmuludq and using the "convert unsigned higher order product to signed" algorithm (found in Hacker's Delight chapter 8.3) the high dword can be fixed. The low dword is, of course, already correct.

Here's my attempt at it in asm, I did not test this at all.

movdqa xmm2, xmm0
psrad xmm0, 31
movdqa xmm3, xmm1
psrad xmm1, 31
pand xmm2, xmm0
pand xmm3, xmm1
paddd xmm2, xmm3
pmuludq xmm0, xmm1
pshufd xmm2, xmm2, 0xB1
psubd xmm0, xmm2

The dwords other than the ones it's multiplying must be zero at the beginning. It looks a little different than in Hacker's Delight, because I rearranged the last bit of the algorithm to p = p - (t1 + t2) (saves a shuffle).

harold
  • 61,398
  • 6
  • 86
  • 164