Skip to content

Commit

Permalink
Replace #defines with enum constants and inline functions in exor.h
Browse files Browse the repository at this point in the history
This avoids issues with short/common identifiers like `BPI`
and `DIFFERENT` colliding with identifiers used in other projects.
  • Loading branch information
rocallahan committed Sep 23, 2024
1 parent 3e56b42 commit ce24711
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions lib/abcesop/eabc/exor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,34 @@ namespace abc::exorcism {
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////

// the number of bits per integer
#define BPI 32
#define BPIMASK 31
#define LOGBPI 5
enum {
// the number of bits per integer
BPI = 32,
BPIMASK = 31,
LOGBPI = 5,

// the maximum number of input variables
#define MAXVARS 1000
// the maximum number of input variables
MAXVARS = 1000,

// the number of cubes that are allocated additionally
#define ADDITIONAL_CUBES 33
// the number of cubes that are allocated additionally
ADDITIONAL_CUBES = 33,

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

#define DIFFERENT 0x55555555
#define BIT_COUNT(w) (BitCount[(w)&0xffff] + BitCount[(w)>>16])
DIFFERENT = 0x55555555,
};

#define VarWord(element) ((element)>>LOGBPI)
#define VarBit(element) ((element)&BPIMASK)
extern unsigned char BitCount[];

#define TICKS_TO_SECONDS(time) ((float)(time)/(float)(CLOCKS_PER_SEC))
static inline int BIT_COUNT(int w) { return BitCount[(w)&0xffff] + BitCount[(w)>>16]; }

static inline int VarWord(int element) { return element>>LOGBPI; }
static inline int VarBit(int element) { return element&BPIMASK; }

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

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

0 comments on commit ce24711

Please sign in to comment.