[LLVMdev] LLVM frontend supporting arbitrary bit-width integral datatypes

Duncan Sands baldrick at free.fr
Wed Jun 24 06:23:04 PDT 2009


Hi Adam,

> One problem, I was trying to solve was, that I need to declare variables of let's say 5-bit width like  'i5 var',
> the maximal bit-width may be limited to 64 bits. I need such variables to represent instruction's operands,
> example is at the end this message.

any standard compliant C compiler supports i5, believe it or not.

Try this:

#include <stdio.h>

struct i3 { int i:3; };

int main(void) {
   struct i3 A, B, C;

   A.i = 2;
   B.i = 3;
   C.i = A.i + B.i;
   printf("%d + %d = %d\n", A.i, B.i, C.i);
   return 0;
}

I get:
2 + 3 = -3
which is correct for i3 arithmetic!
There might be some problems with signed vs unsigned bitfields,
depending on the compiler.

Ciao,

Duncan.



More information about the llvm-dev mailing list