Annotation of sbbs/javascript/include/mozilla/js/jsbit.h, revision 1.1.1.1

1.1       root        1: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
                      2: /*
                      3:  * The contents of this file are subject to the Netscape Public
                      4:  * License Version 1.1 (the "License"); you may not use this file
                      5:  * except in compliance with the License. You may obtain a copy of
                      6:  * the License at http://www.mozilla.org/NPL/
                      7:  *
                      8:  * Software distributed under the License is distributed on an "AS
                      9:  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
                     10:  * implied. See the License for the specific language governing
                     11:  * rights and limitations under the License.
                     12:  *
                     13:  * The Original Code is Mozilla Communicator client code, released
                     14:  * March 31, 1998.
                     15:  *
                     16:  * The Initial Developer of the Original Code is Netscape
                     17:  * Communications Corporation.  Portions created by Netscape are
                     18:  * Copyright (C) 1998 Netscape Communications Corporation. All
                     19:  * Rights Reserved.
                     20:  *
                     21:  * Contributor(s):
                     22:  *
                     23:  * Alternatively, the contents of this file may be used under the
                     24:  * terms of the GNU Public License (the "GPL"), in which case the
                     25:  * provisions of the GPL are applicable instead of those above.
                     26:  * If you wish to allow use of your version of this file only
                     27:  * under the terms of the GPL and not to allow others to use your
                     28:  * version of this file under the NPL, indicate your decision by
                     29:  * deleting the provisions above and replace them with the notice
                     30:  * and other provisions required by the GPL.  If you do not delete
                     31:  * the provisions above, a recipient may use your version of this
                     32:  * file under either the NPL or the GPL.
                     33:  */
                     34: 
                     35: #ifndef jsbit_h___
                     36: #define jsbit_h___
                     37: 
                     38: #include "jstypes.h"
                     39: JS_BEGIN_EXTERN_C
                     40: 
                     41: /*
                     42: ** A jsbitmap_t is a long integer that can be used for bitmaps
                     43: */
                     44: typedef JSUword     jsbitmap_t;     /* NSPR name, a la Unix system types */
                     45: typedef jsbitmap_t  jsbitmap;       /* JS-style scalar typedef name */
                     46: 
                     47: #define JS_TEST_BIT(_map,_bit) \
                     48:     ((_map)[(_bit)>>JS_BITS_PER_WORD_LOG2] & (1L << ((_bit) & (JS_BITS_PER_WORD-1))))
                     49: #define JS_SET_BIT(_map,_bit) \
                     50:     ((_map)[(_bit)>>JS_BITS_PER_WORD_LOG2] |= (1L << ((_bit) & (JS_BITS_PER_WORD-1))))
                     51: #define JS_CLEAR_BIT(_map,_bit) \
                     52:     ((_map)[(_bit)>>JS_BITS_PER_WORD_LOG2] &= ~(1L << ((_bit) & (JS_BITS_PER_WORD-1))))
                     53: 
                     54: /*
                     55: ** Compute the log of the least power of 2 greater than or equal to n
                     56: */
                     57: extern JS_PUBLIC_API(JSIntn) JS_CeilingLog2(JSUint32 i);
                     58: 
                     59: /*
                     60: ** Compute the log of the greatest power of 2 less than or equal to n
                     61: */
                     62: extern JS_PUBLIC_API(JSIntn) JS_FloorLog2(JSUint32 i);
                     63: 
                     64: /*
                     65: ** Macro version of JS_CeilingLog2: Compute the log of the least power of
                     66: ** 2 greater than or equal to _n. The result is returned in _log2.
                     67: */
                     68: #define JS_CEILING_LOG2(_log2,_n)                                             \
                     69:     JS_BEGIN_MACRO                                                            \
                     70:         JSUint32 j_ = (JSUint32)(_n);                                         \
                     71:         (_log2) = 0;                                                          \
                     72:         if ((j_) & ((j_)-1))                                                  \
                     73:             (_log2) += 1;                                                     \
                     74:         if ((j_) >> 16)                                                       \
                     75:             (_log2) += 16, (j_) >>= 16;                                       \
                     76:         if ((j_) >> 8)                                                        \
                     77:             (_log2) += 8, (j_) >>= 8;                                         \
                     78:         if ((j_) >> 4)                                                        \
                     79:             (_log2) += 4, (j_) >>= 4;                                         \
                     80:         if ((j_) >> 2)                                                        \
                     81:             (_log2) += 2, (j_) >>= 2;                                         \
                     82:         if ((j_) >> 1)                                                        \
                     83:             (_log2) += 1;                                                     \
                     84:     JS_END_MACRO
                     85: 
                     86: /*
                     87: ** Macro version of JS_FloorLog2: Compute the log of the greatest power of
                     88: ** 2 less than or equal to _n. The result is returned in _log2.
                     89: **
                     90: ** This is equivalent to finding the highest set bit in the word.
                     91: */
                     92: #define JS_FLOOR_LOG2(_log2,_n)                                               \
                     93:     JS_BEGIN_MACRO                                                            \
                     94:         JSUint32 j_ = (JSUint32)(_n);                                         \
                     95:         (_log2) = 0;                                                          \
                     96:         if ((j_) >> 16)                                                       \
                     97:             (_log2) += 16, (j_) >>= 16;                                       \
                     98:         if ((j_) >> 8)                                                        \
                     99:             (_log2) += 8, (j_) >>= 8;                                         \
                    100:         if ((j_) >> 4)                                                        \
                    101:             (_log2) += 4, (j_) >>= 4;                                         \
                    102:         if ((j_) >> 2)                                                        \
                    103:             (_log2) += 2, (j_) >>= 2;                                         \
                    104:         if ((j_) >> 1)                                                        \
                    105:             (_log2) += 1;                                                     \
                    106:     JS_END_MACRO
                    107: 
                    108: JS_END_EXTERN_C
                    109: #endif /* jsbit_h___ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.