mirror of
https://github.com/tribes2/engine.git
synced 2026-01-20 11:44:46 +00:00
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
//-----------------------------------------------------------------------------
|
|
// V12 Engine
|
|
//
|
|
// Copyright (c) 2001 GarageGames.Com
|
|
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#ifndef _BITTABLES_H_
|
|
#define _BITTABLES_H_
|
|
|
|
#ifndef _PLATFORM_H_
|
|
#include "Platform/platform.h"
|
|
#endif
|
|
|
|
class BitTables
|
|
{
|
|
private:
|
|
static bool mTablesBuilt; // For first time build
|
|
static S8 mHighBit[256]; // I.e. crude logarithm
|
|
static S8 mWhichOn[256][8]; // Unroll a bitset collection (note
|
|
static S8 mNumOn[256]; // ptr table wastes same amt.)
|
|
|
|
public:
|
|
BitTables();
|
|
static const S32 numOn(U8 b) { return mNumOn[b]; }
|
|
static const S8 * whichOn(U8 b) { return mWhichOn[b]; }
|
|
static const S32 highBit(U8 b) { return mHighBit[b]; }
|
|
|
|
static S32 getPower16(U16 x) { return x<256 ? mHighBit[x] : mHighBit[x>>8]+8; }
|
|
static S32 getPower32(U32 x){
|
|
if( x < (1<<16) )
|
|
return( x < (1<<8) ? mHighBit[x] : mHighBit[x>>8]+8 );
|
|
else
|
|
return( x < (1<<24) ? mHighBit[x>>16]+16 : mHighBit[x>>24]+24 );
|
|
}
|
|
};
|
|
|
|
#endif
|