Skip to content

Commit

Permalink
Replace #defines with C++ constants and inline functions in exor.h
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rocallahan committed Jul 24, 2024
1 parent b78357b commit 74f938b
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions lib/abcesop/eabc/exor.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,41 +52,43 @@
namespace abc::exorcism {

////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
/// CONSTANT DEFINITIONS ///
////////////////////////////////////////////////////////////////////////

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

// the maximum number of input variables
#define MAXVARS 1000
constexpr int MAXVARS = 1000;

// the number of cubes that are allocated additionally
#define ADDITIONAL_CUBES 33
constexpr int ADDITIONAL_CUBES = 33;

// the factor showing how many cube pairs will be allocated
#define CUBE_PAIR_FACTOR 20
constexpr int CUBE_PAIR_FACTOR = 20;
// the following number of cube pairs are allocated:
// nCubesAlloc/CUBE_PAIR_FACTOR

#if BPI == 64
#define DIFFERENT 0x5555555555555555
#define BIT_COUNT(w) (BitCount[(w)&0xffff] + BitCount[((w)>>16)&0xffff] + BitCount[((w)>>32)&0xffff] + BitCount[(w)>>48])
#elif BPI == 32
#define DIFFERENT 0x55555555
#define BIT_COUNT(w) (BitCount[(w)&0xffff] + BitCount[(w)>>16])
#else
#define DIFFERENT 0x5555
#define BIT_COUNT(w) (BitCount[(w)])
#endif
constexpr int DIFFERENT = 0x55555555;

extern unsigned char BitCount[0x10000];

#define VarWord(element) ((element)>>LOGBPI)
#define VarBit(element) ((element)&BPIMASK)
static inline int BIT_COUNT(int w) {
return BitCount[(w)&0xffff] + BitCount[(w)>>16];
}

#define TICKS_TO_SECONDS(time) ((float)(time)/(float)(CLOCKS_PER_SEC))
static inline int VarWord(int element) {
return element >> LOGBPI;
}
static inline int VarBit(int element) {
return element & BPIMASK;
}

static inline int TICKS_TO_SECONDS(abctime time) {
return (float)(time)/(float)(CLOCKS_PER_SEC);
}

////////////////////////////////////////////////////////////////////////
/// CUBE COVER and CUBE typedefs ///
Expand Down

0 comments on commit 74f938b

Please sign in to comment.