From 252df6c74c7be9b82aa89cdb4972f91c87b06184 Mon Sep 17 00:00:00 2001 From: Comrade Martin Miroslavovich Michalec Date: Mon, 27 Nov 2023 00:34:11 +0300 Subject: publish --- src/arith.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/arith.h (limited to 'src/arith.h') diff --git a/src/arith.h b/src/arith.h new file mode 100644 index 0000000..f43c830 --- /dev/null +++ b/src/arith.h @@ -0,0 +1,48 @@ +#ifndef ARITH_H +#define ARITH_H + +#include "utils.h" + +#define BPD 4 +// #define DIGIT_MASK ((1 << BPD) - 1) +#define DIGIT_MASK 0b111 + +#define I2C(I) ((I) + 'a') +#define C2I(C) ((C) - 'a') + +#define PACK8u32(A, B, C, D, E, F, G, H) \ + ((A) << BPD*0 | \ + (B) << BPD*1 | \ + (C) << BPD*2 | \ + (D) << BPD*3 | \ + (E) << BPD*4 | \ + (F) << BPD*5 | \ + (G) << BPD*6 | \ + (H) << BPD*7) +#define UNPACK8u32(V, I) ((V) >> BPD*(I) & DIGIT_MASK) + +#define TBL_LOOKUP(TBL, ROW, COL) ((TBL)[(ROW)] >> (COL)*2*BPD) +#define TBL_VALUE(RET) ((RET) & DIGIT_MASK) +#define TBL_CARRY(RET) ((RET) >> BPD & DIGIT_MASK) + +#define MASK_NEG 0x80000000 +#define MASK_OVF 0x08000000 +#define MASK_NAN 0x00800000 +#define MASK_INF 0x00080000 +#define MASK_UNI 0x00008000 +#define MASK_EMP 0x00000800 +#define MASK_FLAGS (MASK_NEG | MASK_OVF | MASK_NAN | MASK_INF | MASK_UNI | MASK_EMP) + +enum digit { A, B, C, D, E, F, G, H, DIGIT_COUNT }; + +extern u32 order; +extern u64 addition_table[DIGIT_COUNT]; +extern u64 multiplication_table[DIGIT_COUNT]; + +u32 str2num (const char *str); +u32 arith_min (u32 a, u32 b); +u32 arith_max (u32 a, u32 b); +int arith_cmp (u32 a, u32 b); +s32 arith2bin (u32 a); + +#endif -- cgit v1.3.1