Browse Subversion Repository
Contents of /branches/mty-makai/util.h
Parent Directory
| Revision Log
Revision 255 -
( show annotations)
( download)
( as text)
Wed Dec 29 15:17:17 2010 UTC
(13 years, 3 months ago)
by notanpe
File MIME type: text/x-chdr
File size: 1288 byte(s)
漢字コードがらみでマクロをちょっと変更。
| 1 |
/*********************************************************************** |
| 2 |
* |
| 3 |
* file: util.h |
| 4 |
* |
| 5 |
* $Id$ |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef UTIL_H__ |
| 10 |
#define UTIL_H__ |
| 11 |
|
| 12 |
#include "mtytypes.h" |
| 13 |
|
| 14 |
/*************************************************************** |
| 15 |
* |
| 16 |
* 頻出するようなマクロ |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
/* n での剰余系 */ |
| 21 |
#define WRAP(a,n) (IS_POWER2(n) ? (a) & ((n) - 1) : (a) % (n)) |
| 22 |
|
| 23 |
/*************************************************************** |
| 24 |
* |
| 25 |
* 便利なワリには直感的ではないビット判定 |
| 26 |
* - Hacker's Delight より引用 |
| 27 |
* |
| 28 |
*/ |
| 29 |
|
| 30 |
#define IS_POWER2(n) (!((n) & ((n) - 1))) |
| 31 |
|
| 32 |
/*************************************************************** |
| 33 |
* |
| 34 |
* ビット数え上げ - Hacker's Delight より引用 |
| 35 |
* |
| 36 |
*/ |
| 37 |
|
| 38 |
static |
| 39 |
unsigned |
| 40 |
popcnt32(uint32_t x) |
| 41 |
{ |
| 42 |
x = x - ((x >> 1) & 0x55555555); |
| 43 |
x = (x & 0x33333333) + ((x >> 2) & 0x33333333); |
| 44 |
x = (x + (x >> 4)) & 0x0F0F0F0F; |
| 45 |
x = x + (x >> 8); |
| 46 |
x = x + (x >> 16); |
| 47 |
return x & 0x3F; /* 32 が返ることもあるので 0x1F ではダメ */ |
| 48 |
} |
| 49 |
|
| 50 |
static |
| 51 |
unsigned |
| 52 |
popcnt64(uint64_t x) |
| 53 |
{ |
| 54 |
return popcnt32(x) + popcnt32(x >> 32); |
| 55 |
} |
| 56 |
|
| 57 |
#ifdef DEBUG |
| 58 |
#define DPRINT( ... ) \ |
| 59 |
printf( "[DBG] %s:%d ", SRCFILE, __LINE__ ); \ |
| 60 |
printf( __VA_ARGS__ ) |
| 61 |
#else |
| 62 |
#define DPRINT( ... ) |
| 63 |
#endif |
| 64 |
|
| 65 |
#define OLDPRINT( ... ) |
| 66 |
|
| 67 |
#endif /* UTIL_H__ */ |
| 68 |
|
| 69 |
/* |
| 70 |
* Local Variables: |
| 71 |
* tab-width: 4 |
| 72 |
* End: |
| 73 |
* |
| 74 |
* EOF */ |
Properties
| svn:eol-style |
native
|
| svn:keywords |
Author Date Id Rev URL
|
|