1 | /** |
---|
2 | * @file rtems/score/bitfield.h |
---|
3 | * |
---|
4 | * This include file contains all bit field manipulation routines. |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-2006. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_SCORE_BITFIELD_H |
---|
19 | #define _RTEMS_SCORE_BITFIELD_H |
---|
20 | |
---|
21 | /** |
---|
22 | * @defgroup ScoreBitfield Bitfield Handler |
---|
23 | * |
---|
24 | * This handler encapsulates functionality that is used to manipulate the |
---|
25 | * priority bitfields used to lookup which priority has the highest |
---|
26 | * priority ready to execute thread. |
---|
27 | */ |
---|
28 | /**@{*/ |
---|
29 | |
---|
30 | #ifdef __cplusplus |
---|
31 | extern "C" { |
---|
32 | #endif |
---|
33 | |
---|
34 | #if ( CPU_USE_GENERIC_BITFIELD_DATA == TRUE ) |
---|
35 | |
---|
36 | /** |
---|
37 | * This table is used by the generic bitfield routines to perform |
---|
38 | * a highly optimized bit scan without the use of special CPU |
---|
39 | * instructions. |
---|
40 | */ |
---|
41 | #ifndef SCORE_INIT |
---|
42 | extern const unsigned char __log2table[256]; |
---|
43 | #else |
---|
44 | const unsigned char __log2table[256] = { |
---|
45 | 7, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, |
---|
46 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
---|
47 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
48 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
---|
49 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
---|
50 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
---|
51 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
---|
52 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
---|
53 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
---|
54 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
---|
55 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
---|
56 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
---|
57 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
---|
58 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
---|
59 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
---|
60 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
---|
61 | }; |
---|
62 | #endif |
---|
63 | |
---|
64 | #endif |
---|
65 | |
---|
66 | /** |
---|
67 | * This routine returns the @a _bit_number of the first bit set |
---|
68 | * in the specified value. The correspondence between @a _bit_number |
---|
69 | * and actual bit position is processor dependent. The search for |
---|
70 | * the first bit set may run from most to least significant bit |
---|
71 | * or vice-versa. |
---|
72 | * |
---|
73 | * @param[in] _value is the value to bit scan. |
---|
74 | * @param[in] _bit_number is the position of the first bit set. |
---|
75 | * |
---|
76 | * @note This routine is used when the executing thread is removed |
---|
77 | * from the ready state and, as a result, its performance has a |
---|
78 | * significant impact on the performance of the executive as a whole. |
---|
79 | * |
---|
80 | * @note This routine must be a macro because if a CPU specific version |
---|
81 | * is used it will most likely use inline assembly. |
---|
82 | */ |
---|
83 | #if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) |
---|
84 | #define _Bitfield_Find_first_bit( _value, _bit_number ) \ |
---|
85 | _CPU_Bitfield_Find_first_bit( _value, _bit_number ) |
---|
86 | #else |
---|
87 | #define _Bitfield_Find_first_bit( _value, _bit_number ) \ |
---|
88 | { \ |
---|
89 | register uint32_t __value = (uint32_t) (_value); \ |
---|
90 | register const unsigned char *__p = __log2table; \ |
---|
91 | \ |
---|
92 | if ( __value < 0x100 ) \ |
---|
93 | (_bit_number) = (Priority_Bit_map_control)( __p[ __value ] + 8 ); \ |
---|
94 | else \ |
---|
95 | (_bit_number) = (Priority_Bit_map_control)( __p[ __value >> 8 ] ); \ |
---|
96 | } |
---|
97 | #endif |
---|
98 | |
---|
99 | #ifdef __cplusplus |
---|
100 | } |
---|
101 | #endif |
---|
102 | |
---|
103 | /**@}*/ |
---|
104 | |
---|
105 | #endif |
---|
106 | /* end of include file */ |
---|