]>
Commit | Line | Data |
---|---|---|
1cb8e980 | 1 | /* |
53677ef1 | 2 | * FILE bitfield.h |
1cb8e980 | 3 | * |
53677ef1 WD |
4 | * Version 1.1 |
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) | |
1cb8e980 | 9 | * Language C or ARM Assembly |
53677ef1 | 10 | * Purpose Definition of macros to operate on bit fields. |
1cb8e980 WD |
11 | */ |
12 | ||
13 | ||
1cb8e980 WD |
14 | #ifndef __BITFIELD_H |
15 | #define __BITFIELD_H | |
16 | ||
17 | #ifndef __ASSEMBLY__ | |
18 | #define UData(Data) ((unsigned long) (Data)) | |
19 | #else | |
20 | #define UData(Data) (Data) | |
21 | #endif | |
22 | ||
23 | ||
24 | /* | |
25 | * MACRO: Fld | |
26 | * | |
27 | * Purpose | |
28 | * The macro "Fld" encodes a bit field, given its size and its shift value | |
29 | * with respect to bit 0. | |
30 | * | |
31 | * Note | |
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 | |
35 | * line-size limit). | |
36 | * | |
37 | * Input | |
53677ef1 WD |
38 | * Size Size of the bit field, in number of bits. |
39 | * Shft Shift value of the bit field with respect to bit 0. | |
1cb8e980 WD |
40 | * |
41 | * Output | |
53677ef1 | 42 | * Fld Encoded bit field. |
1cb8e980 WD |
43 | */ |
44 | ||
45 | #define Fld(Size, Shft) (((Size) << 16) + (Shft)) | |
46 | ||
47 | ||
48 | /* | |
49 | * MACROS: FSize, FShft, FMsk, FAlnMsk, F1stBit | |
50 | * | |
51 | * Purpose | |
52 | * The macros "FSize", "FShft", "FMsk", "FAlnMsk", and "F1stBit" return | |
53 | * the size, shift value, mask, aligned mask, and first bit of a | |
54 | * bit field. | |
55 | * | |
56 | * Input | |
53677ef1 | 57 | * Field Encoded bit field (using the macro "Fld"). |
1cb8e980 WD |
58 | * |
59 | * Output | |
53677ef1 WD |
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. | |
1cb8e980 WD |
65 | */ |
66 | ||
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)) | |
72 | ||
73 | ||
74 | /* | |
75 | * MACRO: FInsrt | |
76 | * | |
77 | * Purpose | |
78 | * The macro "FInsrt" inserts a value into a bit field by shifting the | |
79 | * former appropriately. | |
80 | * | |
81 | * Input | |
53677ef1 WD |
82 | * Value Bit-field value. |
83 | * Field Encoded bit field (using the macro "Fld"). | |
1cb8e980 WD |
84 | * |
85 | * Output | |
53677ef1 | 86 | * FInsrt Bit-field value positioned appropriately. |
1cb8e980 WD |
87 | */ |
88 | ||
89 | #define FInsrt(Value, Field) \ | |
8bde7f77 | 90 | (UData (Value) << FShft (Field)) |
1cb8e980 WD |
91 | |
92 | ||
93 | /* | |
94 | * MACRO: FExtr | |
95 | * | |
96 | * Purpose | |
97 | * The macro "FExtr" extracts the value of a bit field by masking and | |
98 | * shifting it appropriately. | |
99 | * | |
100 | * Input | |
53677ef1 WD |
101 | * Data Data containing the bit-field to be extracted. |
102 | * Field Encoded bit field (using the macro "Fld"). | |
1cb8e980 WD |
103 | * |
104 | * Output | |
53677ef1 | 105 | * FExtr Bit-field value. |
1cb8e980 WD |
106 | */ |
107 | ||
108 | #define FExtr(Data, Field) \ | |
8bde7f77 | 109 | ((UData (Data) >> FShft (Field)) & FAlnMsk (Field)) |
1cb8e980 WD |
110 | |
111 | ||
112 | #endif /* __BITFIELD_H */ |