From 51dd6a042f2fae021ded1cdd06c6c8c6e5948e17 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Tue, 24 Sep 2024 20:34:24 +1200 Subject: [PATCH] Replace `#define`s with C++ constants and inline functions in `exor.h` (#656) * Remove support for `int` sizes other than 32 bits No viable platform uses anything other than 32 bits for `int`. * Replace `#define`s with enum constants and inline functions in `exor.h` This avoids issues with short/common identifiers like `BPI` and `DIFFERENT` colliding with identifiers used in other projects. --- lib/abcesop/eabc/exor.h | 60 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/lib/abcesop/eabc/exor.h b/lib/abcesop/eabc/exor.h index ed278c162..6a25ccf0a 100644 --- a/lib/abcesop/eabc/exor.h +++ b/lib/abcesop/eabc/exor.h @@ -55,38 +55,34 @@ namespace abc::exorcism { /// MACRO 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 maximum number of input variables -#define MAXVARS 1000 - -// the number of cubes that are allocated additionally -#define 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 - -#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 - - -#define VarWord(element) ((element)>>LOGBPI) -#define VarBit(element) ((element)&BPIMASK) - -#define TICKS_TO_SECONDS(time) ((float)(time)/(float)(CLOCKS_PER_SEC)) +enum { + // the number of bits per integer + BPI = 32, + BPIMASK = 31, + LOGBPI = 5, + + // the maximum number of input variables + MAXVARS = 1000, + + // the number of cubes that are allocated additionally + ADDITIONAL_CUBES = 33, + + // 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 + + DIFFERENT = 0x55555555, +}; + +extern unsigned char BitCount[]; + +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 ///