5 * Author Copyright (c) Marc A. Viredaz, 1998
6 * DEC Western Research Laboratory, Palo Alto, CA
7 * Date April 1998 (April 1997)
8 * System Advanced RISC Machine (ARM)
9 * Language C or ARM Assembly
10 * Purpose Definition of macros to operate on bit fields.
19 #define UData(Data) ((unsigned long) (Data))
21 #define UData(Data) (Data)
29 * The macro "Fld" encodes a bit field, given its size and its shift value
30 * with respect to bit 0.
33 * A more intuitive way to encode bit fields would have been to use their
34 * mask. However, extracting size and shift value information from a bit
35 * field's mask is cumbersome and might break the assembler (255-character
39 * Size Size of the bit field, in number of bits.
40 * Shft Shift value of the bit field with respect to bit 0.
43 * Fld Encoded bit field.
46 #define Fld(Size, Shft) (((Size) << 16) + (Shft))
50 * MACROS: FSize, FShft, FMsk, FAlnMsk, F1stBit
53 * The macros "FSize", "FShft", "FMsk", "FAlnMsk", and "F1stBit" return
54 * the size, shift value, mask, aligned mask, and first bit of a
58 * Field Encoded bit field (using the macro "Fld").
61 * FSize Size of the bit field, in number of bits.
62 * FShft Shift value of the bit field with respect to bit 0.
63 * FMsk Mask for the bit field.
64 * FAlnMsk Mask for the bit field, aligned on bit 0.
65 * F1stBit First bit of the bit field.
68 #define FSize(Field) ((Field) >> 16)
69 #define FShft(Field) ((Field) & 0x0000FFFF)
70 #define FMsk(Field) (((UData (1) << FSize (Field)) - 1) << FShft (Field))
71 #define FAlnMsk(Field) ((UData (1) << FSize (Field)) - 1)
72 #define F1stBit(Field) (UData (1) << FShft (Field))
79 * The macro "FInsrt" inserts a value into a bit field by shifting the
80 * former appropriately.
83 * Value Bit-field value.
84 * Field Encoded bit field (using the macro "Fld").
87 * FInsrt Bit-field value positioned appropriately.
90 #define FInsrt(Value, Field) \
91 (UData (Value) << FShft (Field))
98 * The macro "FExtr" extracts the value of a bit field by masking and
99 * shifting it appropriately.
102 * Data Data containing the bit-field to be extracted.
103 * Field Encoded bit field (using the macro "Fld").
106 * FExtr Bit-field value.
109 #define FExtr(Data, Field) \
110 ((UData (Data) >> FShft (Field)) & FAlnMsk (Field))
113 #endif /* __BITFIELD_H */