-BfaGapLimitBits: Bitfield Gap Limit

Group

CODE GENERATION

Scope

Function

Syntax
  -BfaGapLimitBits<number> 
  
Arguments

<number>: positive number, there should be less than <number> bits in the gap (that is, at most <number>-1 bits)

Default

1

Defines

None

Pragmas

None

Description

The bitfield allocation tries to avoid crossing a byte boundary whenever possible. To achieve optimized accesses, the compiler may insert some padding or gap bits to reach this. This option enables you to affect the maximum number of gap bits allowed.

Example

In the example shown in the listing below, assume that you have specified a 3-bit maximum gap, that is, -BfaGapLimitBits3.

Listing: Bitfield Allocation


struct {
  unsigned char a: 7;

  unsigned char b: 5;

  
unsigned char c: 4;

} B;

The compiler allocates struct B with 3 bytes. First, the compiler allocates the 7 bits of a. Then the compiler tries to allocate the 5 bits of b, but this would cross a byte boundary. Because the gap of 1 bit is smaller than the specified gap of 3 bits, b is allocated in the next byte. Then the allocation starts for c. After the allocation of b there are 3 bits left. Because the gap is 3 bits, c is allocated in the next byte. If the maximum gap size were specified to 0, all 16 bits of B would be allocated in two bytes. Since the gap limit is set to 3, and the gap required for allocating c in the next byte is also 3, the compiler will use a 16-bit word as allocation unit. Both b and c will be allocated within this word.

Assuming we initialize an instance of B as below:

B s = {2, 7, 5},

we get the following memory layouts:

-BfaGapLimitBits1 : 53 82

- BfaGapLimitBits3 : 02 00 A7

-BfaGapLimitBits4 : 02 07 05

See also

Bitfield Allocation