Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.

256 bit subtraction

garfield-lewis
Beginner
328 Views

Hi,

I've got the following datatype:

struct X { __m128i hi; __m128i lo; }

I need to use only SSE 4.2 and below instructions to do a subtraction of 2 of these taking into account possible borrow issues at bits 63-64, 127-128 and 191-192. Does anyone have a quick set of instructions that could be used to accomplish this? Again using SSE 4.2 and earlier instructions.

Thx...

0 Kudos
1 Reply
styc
Beginner
328 Views
garfield-lewis wrote:

Hi,

I've got the following datatype:

struct X { __m128i hi; __m128i lo; }

I need to use only SSE 4.2 and below instructions to do a subtraction of 2 of these taking into account possible borrow issues at bits 63-64, 127-128 and 191-192. Does anyone have a quick set of instructions that could be used to accomplish this? Again using SSE 4.2 and earlier instructions.

Thx...

The best solution is to break components of X into scalars:

[cpp] asm ("sub %4, %0;" "sbb %5, %1;" "sbb %6, %2;" "sbb %7, %3;" : "=r" (*(uint64*) &z.lo), "=r" (*((uint64*) &z.lo + 1)), "=r" (*(uint64*) &z.hi), "=r" (*((uint64*) &z.hi + 1)) : "g" (*(uint64*) &y.lo), "g" (*((uint64*) &y.lo + 1)), "g" (*(uint64*) &y.hi), "g" (*((uint64*) &y.hi + 1)), "0" (*(uint64*) &x.lo), "1" (*((uint64*) &x.lo + 1)), "2" (*(uint64*) &x.hi), "3" (*((uint64*) &x.hi + 1)) );[/cpp]
0 Kudos
Reply