2

I am working on a feature which needs to keep track of a bit-map of length 96. I use this map to program asic below. Is there a standard integer type to hold 96 bits. For 64 bits, we have unsigned long long. Anything similar for 96 bits? Any alternate suggestion welcome as well.

PS: This is Cisco OS based on linux. Language is C.

Deepanjan Mazumdar
  • 1,447
  • 3
  • 13
  • 20

4 Answers4

3

GCC has __int128 for 128-bit integers on targets that support it, but nothing for 96 bits specifically.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
3

I'd probably go with an array of 3 uint's. That should be fast enough, and not a lot more complex.

EG, to set a bit:

wordNo = i / 32
bitNo = i - (32*wordNo)
mask = 2 ** bitNo

array[wordNo] |= mask

...or thereabout.

user1277476
  • 2,871
  • 12
  • 10
3

There is a way to create one variable that size is exact 96 bits: Bitfields in a union or struct.

typedef union { // you can use union or struct here
    __uint128_t i : 96;
} __attribute__((packed)) uint96_t;

uint96_t var;  // new uint96_t variable
var.i = 123;   // set the value to 123 (for example)

This worked for me with gcc. If you test the size of uint96_t with sizeof you should get 12 bytes (12 * 8 = 96).

qwertz
  • 14,614
  • 10
  • 34
  • 46
0

You should use clang's new feature _ExtInt. It is in clang 11, so you may not have it. Look here for details and usage.

xilpex
  • 3,097
  • 2
  • 14
  • 45