Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active October 18, 2022 09:06
Show Gist options
  • Select an option

  • Save pervognsen/8aa8489ebf7249e83fa260d3610dbc60 to your computer and use it in GitHub Desktop.

Select an option

Save pervognsen/8aa8489ebf7249e83fa260d3610dbc60 to your computer and use it in GitHub Desktop.
typedef struct { uint64_t b[4]; } uint4x64_t;
// Bitsliced 4-bit adder
uint4x64_t add_sliced(uint4x64_t x, uint4x64_t y) {
uint4x64_t s;
uint64_t c = 0;
for (int i = 0; i < 4; i++) {
uint64_t p = x.b[i] ^ y.b[i]
s.b[i] = p ^ c;
c = (x.b[i] & y.b[i]) | (p & c);
}
return s;
}
// Packed 4-bit adder with even/odd parallelism
uint4x64_t add_packed(uint4x64_t x, uint4x64_t y) {
enum { E = 0x0F0F0F0F0F0F0F0Full, O = ~E };
uint4x64_t s;
for (int i = 0; i < 4; i++) {
uint64_t se = (x.b[i] & E) + (y.b[i] & E);
uint64_t so = (x.b[i] & O) + (y.b[i] & O);
s.b[i] = (se & E) | (so & O);
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment