VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prbit.h@ 43213

Last change on this file since 43213 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef prbit_h___
39#define prbit_h___
40
41#include "prtypes.h"
42
43#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
44#define PR_CeilingLog2 VBoxNsprPR_CeilingLog2
45#define PR_FloorLog2 VBoxNsprPR_FloorLog2
46#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
47
48PR_BEGIN_EXTERN_C
49
50/*
51** A prbitmap_t is a long integer that can be used for bitmaps
52*/
53typedef unsigned long prbitmap_t;
54
55#define PR_TEST_BIT(_map,_bit) \
56 ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] & (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
57#define PR_SET_BIT(_map,_bit) \
58 ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] |= (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
59#define PR_CLEAR_BIT(_map,_bit) \
60 ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] &= ~(1L << ((_bit) & (PR_BITS_PER_LONG-1))))
61
62/*
63** Compute the log of the least power of 2 greater than or equal to n
64*/
65NSPR_API(PRIntn) PR_CeilingLog2(PRUint32 i);
66
67/*
68** Compute the log of the greatest power of 2 less than or equal to n
69*/
70NSPR_API(PRIntn) PR_FloorLog2(PRUint32 i);
71
72/*
73** Macro version of PR_CeilingLog2: Compute the log of the least power of
74** 2 greater than or equal to _n. The result is returned in _log2.
75*/
76#define PR_CEILING_LOG2(_log2,_n) \
77 PR_BEGIN_MACRO \
78 PRUint32 j_ = (PRUint32)(_n); \
79 (_log2) = 0; \
80 if ((j_) & ((j_)-1)) \
81 (_log2) += 1; \
82 if ((j_) >> 16) \
83 (_log2) += 16, (j_) >>= 16; \
84 if ((j_) >> 8) \
85 (_log2) += 8, (j_) >>= 8; \
86 if ((j_) >> 4) \
87 (_log2) += 4, (j_) >>= 4; \
88 if ((j_) >> 2) \
89 (_log2) += 2, (j_) >>= 2; \
90 if ((j_) >> 1) \
91 (_log2) += 1; \
92 PR_END_MACRO
93
94/*
95** Macro version of PR_FloorLog2: Compute the log of the greatest power of
96** 2 less than or equal to _n. The result is returned in _log2.
97**
98** This is equivalent to finding the highest set bit in the word.
99*/
100#define PR_FLOOR_LOG2(_log2,_n) \
101 PR_BEGIN_MACRO \
102 PRUint32 j_ = (PRUint32)(_n); \
103 (_log2) = 0; \
104 if ((j_) >> 16) \
105 (_log2) += 16, (j_) >>= 16; \
106 if ((j_) >> 8) \
107 (_log2) += 8, (j_) >>= 8; \
108 if ((j_) >> 4) \
109 (_log2) += 4, (j_) >>= 4; \
110 if ((j_) >> 2) \
111 (_log2) += 2, (j_) >>= 2; \
112 if ((j_) >> 1) \
113 (_log2) += 1; \
114 PR_END_MACRO
115
116PR_END_EXTERN_C
117#endif /* prbit_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette