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.
18 #define UData(Data) ((unsigned long) (Data))
20 #define UData(Data) (Data)
28 * The macro "Fld" encodes a bit field, given its size and its shift value
29 * with respect to bit 0.
32 * A more intuitive way to encode bit fields would have been to use their
33 * mask. However, extracting size and shift value information from a bit
34 * field's mask is cumbersome and might break the assembler (255-character
38 * Size Size of the bit field, in number of bits.
39 * Shft Shift value of the bit field with respect to bit 0.
42 * Fld Encoded bit field.
45 #define Fld(Size, Shft) (((Size) << 16) + (Shft))
49 * MACROS: FSize, FShft, FMsk, FAlnMsk, F1stBit
52 * The macros "FSize", "FShft", "FMsk", "FAlnMsk", and "F1stBit" return
53 * the size, shift value, mask, aligned mask, and first bit of a
57 * Field Encoded bit field (using the macro "Fld").
60 * FSize Size of the bit field, in number of bits.
61 * FShft Shift value of the bit field with respect to bit 0.
62 * FMsk Mask for the bit field.
63 * FAlnMsk Mask for the bit field, aligned on bit 0.
64 * F1stBit First bit of the bit field.
67 #define FSize(Field) ((Field) >> 16)
68 #define FShft(Field) ((Field) & 0x0000FFFF)
69 #define FMsk(Field) (((UData (1) << FSize (Field)) - 1) << FShft (Field))
70 #define FAlnMsk(Field) ((UData (1) << FSize (Field)) - 1)
71 #define F1stBit(Field) (UData (1) << FShft (Field))
78 * The macro "FInsrt" inserts a value into a bit field by shifting the
79 * former appropriately.
82 * Value Bit-field value.
83 * Field Encoded bit field (using the macro "Fld").
86 * FInsrt Bit-field value positioned appropriately.
89 #define FInsrt(Value, Field) \
90 (UData (Value) << FShft (Field))
97 * The macro "FExtr" extracts the value of a bit field by masking and
98 * shifting it appropriately.
101 * Data Data containing the bit-field to be extracted.
102 * Field Encoded bit field (using the macro "Fld").
105 * FExtr Bit-field value.
108 #define FExtr(Data, Field) \
109 ((UData (Data) >> FShft (Field)) & FAlnMsk (Field))
112 #endif /* __BITFIELD_H */