+/* HEAVISIDE_STEP (shifted by one)
+ function f(x): x->0, when x=0
+ x->1, when x>0
+ Can also be seen as a bitwise operation:
+ f(x): x -> y
+ y[0]=(OR x[i]) for all i (all bits)
+ y[i]=0 for all i>0
+ Run in constant time (log2(<bitsize of x>))
+ Useful to run constant time checks
+*/
+#define HEAVISIDE_STEP_UINT64(x) {unsigned long t; \
+ t=(((uint64_t)x>>32) | (unsigned long)x); \
+ t=((t>>16) | t); \
+ t=((t>>8) | t); \
+ t=((t>>4) | t); \
+ t=((t>>2) | t); \
+ t=((t>>1) | t); \
+ x=t & 0x1;}
+
+#define HEAVISIDE_STEP_UINT32(x) {uint16_t t; \
+ t=(((unsigned long)x>>16) | (uint16_t)x); \
+ t=((t>>8) | t); \
+ t=((t>>4) | t); \
+ t=((t>>2) | t); \
+ t=((t>>1) | t); \
+ x=t & 0x1;}
+
+#define HEAVISIDE_STEP_UINT16(x) {uint8_t t; \
+ t=(((uint16_t)x>>8) | (uint8_t)x); \
+ t=((t>>4) | t); \
+ t=((t>>2) | t); \
+ t=((t>>1) | t); \
+ x=t & 0x1;}
+
+#define HEAVISIDE_STEP_UINT8(x) {uint8_t t; \
+ t=(((uint8_t)x>>4) | (uint8_t)x); \
+ t=((t>>2) | t); \
+ t=((t>>1) | t); \
+ x=t & 0x1;}
+
+#define CC_HEAVISIDE_STEP(x) { \
+ if (sizeof(x) == 1) {HEAVISIDE_STEP_UINT8(x);} \
+ else if (sizeof(x) == 2) {HEAVISIDE_STEP_UINT16(x);} \
+ else if (sizeof(x) == 4) {HEAVISIDE_STEP_UINT32(x);} \
+ else if (sizeof(x) == 8) {HEAVISIDE_STEP_UINT64(x);} \
+ else {x=((x==0)?0:1);} \
+ }
+
+
+/* Set a variable to the biggest power of 2 which can be represented */
+#define MAX_POWER_OF_2(x) ((__typeof__(x))1<<(8*sizeof(x)-1))
+
+