Skip to content

Commit 74f938b

Browse files
committed
Replace #defines with C++ constants and inline functions in exor.h
Using `#define` for short/common names like `BPI` and `DIFFERENT` can break the build when #included alongside unrelated code that uses those identifiers. I have also removed the code that supports `int` sizes other than 32 bits. There aren't any viable architectures where `int` is not 32 bits.
1 parent b78357b commit 74f938b

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lib/abcesop/eabc/exor.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,43 @@
5252
namespace abc::exorcism {
5353

5454
////////////////////////////////////////////////////////////////////////
55-
/// MACRO DEFINITIONS ///
55+
/// CONSTANT DEFINITIONS ///
5656
////////////////////////////////////////////////////////////////////////
5757

58-
// the number of bits per integer (can be 16, 32, 64 - tested for 32)
59-
#define BPI 32
60-
#define BPIMASK 31
61-
#define LOGBPI 5
58+
// the number of bits per integer
59+
constexpr int BPI = 32;
60+
constexpr int BPIMASK = 31;
61+
constexpr int LOGBPI = 5;
6262

6363
// the maximum number of input variables
64-
#define MAXVARS 1000
64+
constexpr int MAXVARS = 1000;
6565

6666
// the number of cubes that are allocated additionally
67-
#define ADDITIONAL_CUBES 33
67+
constexpr int ADDITIONAL_CUBES = 33;
6868

6969
// the factor showing how many cube pairs will be allocated
70-
#define CUBE_PAIR_FACTOR 20
70+
constexpr int CUBE_PAIR_FACTOR = 20;
7171
// the following number of cube pairs are allocated:
7272
// nCubesAlloc/CUBE_PAIR_FACTOR
7373

74-
#if BPI == 64
75-
#define DIFFERENT 0x5555555555555555
76-
#define BIT_COUNT(w) (BitCount[(w)&0xffff] + BitCount[((w)>>16)&0xffff] + BitCount[((w)>>32)&0xffff] + BitCount[(w)>>48])
77-
#elif BPI == 32
78-
#define DIFFERENT 0x55555555
79-
#define BIT_COUNT(w) (BitCount[(w)&0xffff] + BitCount[(w)>>16])
80-
#else
81-
#define DIFFERENT 0x5555
82-
#define BIT_COUNT(w) (BitCount[(w)])
83-
#endif
74+
constexpr int DIFFERENT = 0x55555555;
8475

76+
extern unsigned char BitCount[0x10000];
8577

86-
#define VarWord(element) ((element)>>LOGBPI)
87-
#define VarBit(element) ((element)&BPIMASK)
78+
static inline int BIT_COUNT(int w) {
79+
return BitCount[(w)&0xffff] + BitCount[(w)>>16];
80+
}
8881

89-
#define TICKS_TO_SECONDS(time) ((float)(time)/(float)(CLOCKS_PER_SEC))
82+
static inline int VarWord(int element) {
83+
return element >> LOGBPI;
84+
}
85+
static inline int VarBit(int element) {
86+
return element & BPIMASK;
87+
}
88+
89+
static inline int TICKS_TO_SECONDS(abctime time) {
90+
return (float)(time)/(float)(CLOCKS_PER_SEC);
91+
}
9092

9193
////////////////////////////////////////////////////////////////////////
9294
/// CUBE COVER and CUBE typedefs ///

0 commit comments

Comments
 (0)