source: rtems/cpukit/score/include/rtems/score/bitfield.h @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*  bitfield.h
2 *
3 *  This include file contains all bit field manipulation routines.
4 *
5 *  COPYRIGHT (c) 1989-1999.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#ifndef __RTEMS_BITFIELD_h
16#define __RTEMS_BITFIELD_h
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/*
23 *  _Bitfield_Find_first_bit
24 *
25 *  DESCRIPTION:
26 *
27 *  This routine returns the bit_number of the first bit set
28 *  in the specified value.  The correspondence between bit_number
29 *  and actual bit position is processor dependent.  The search for
30 *  the first bit set may run from most to least significant bit
31 *  or vice-versa.
32 *
33 *  NOTE:
34 *
35 *  This routine is used when the executing thread is removed
36 *  from the ready state and, as a result, its performance has a
37 *  significant impact on the performance of the executive as a whole.
38 */
39
40#if ( CPU_USE_GENERIC_BITFIELD_DATA == TRUE )
41
42#ifndef SCORE_INIT
43extern const unsigned char __log2table[256];
44#else
45const unsigned char __log2table[256] = {
46    7, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
47    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
48    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
49    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
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    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
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    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
62};
63#endif
64 
65#endif
66
67#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE )
68
69#define _Bitfield_Find_first_bit( _value, _bit_number ) \
70        _CPU_Bitfield_Find_first_bit( _value, _bit_number )
71
72#else
73
74/*
75 *  The following must be a macro because if a CPU specific version
76 *  is used it will most likely use inline assembly.
77 */
78
79#define _Bitfield_Find_first_bit( _value, _bit_number ) \
80  { \
81    register unsigned32 __value = (unsigned32) (_value); \
82    register const unsigned char *__p = __log2table; \
83    \
84    if ( __value < 0x100 ) \
85      (_bit_number) = __p[ __value ] + 8; \
86    else \
87      (_bit_number) = __p[ __value >> 8 ]; \
88  }
89
90#endif
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif
97/* end of include file */
Note: See TracBrowser for help on using the repository browser.