kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

agg_bitfield.c (513B)


      1 /* A bitfield struct: fields packed into sub-byte/sub-word ranges. Reading and
      2  * writing bitfields exercises the mask/shift sequences (and/orr/ubfx/bfi-style
      3  * encodings) the codegen emits for bitfield access. All values fit their widths
      4  * (no overflow). a(5) + b(9) + c(28) = 42. */
      5 struct Bits {
      6   unsigned a : 4;
      7   unsigned b : 5;
      8   unsigned c : 6;
      9 };
     10 int test_main(void) {
     11   volatile unsigned va = 5, vb = 9, vc = 28;
     12   struct Bits s;
     13   s.a = va;
     14   s.b = vb;
     15   s.c = vc;
     16   return (int)(s.a + s.b + s.c);
     17 }