diff options
| author | 2023-11-26 21:34:11 +0000 | |
|---|---|---|
| committer | 2026-11-07 02:13:38 +0000 | |
| commit | 252df6c74c7be9b82aa89cdb4972f91c87b06184 (patch) | |
| tree | 988497c67eb3d8d8789aa9bdea47bafd300e25b2 /src/arith.h | |
| download | coursework-master.tar.gz | |
Diffstat (limited to 'src/arith.h')
| -rw-r--r-- | src/arith.h | 48 |
1 files changed, 48 insertions, 0 deletions
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 @@ | |||
| 1 | #ifndef ARITH_H | ||
| 2 | #define ARITH_H | ||
| 3 | |||
| 4 | #include "utils.h" | ||
| 5 | |||
| 6 | #define BPD 4 | ||
| 7 | // #define DIGIT_MASK ((1 << BPD) - 1) | ||
| 8 | #define DIGIT_MASK 0b111 | ||
| 9 | |||
| 10 | #define I2C(I) ((I) + 'a') | ||
| 11 | #define C2I(C) ((C) - 'a') | ||
| 12 | |||
| 13 | #define PACK8u32(A, B, C, D, E, F, G, H) \ | ||
| 14 | ((A) << BPD*0 | \ | ||
| 15 | (B) << BPD*1 | \ | ||
| 16 | (C) << BPD*2 | \ | ||
| 17 | (D) << BPD*3 | \ | ||
| 18 | (E) << BPD*4 | \ | ||
| 19 | (F) << BPD*5 | \ | ||
| 20 | (G) << BPD*6 | \ | ||
| 21 | (H) << BPD*7) | ||
| 22 | #define UNPACK8u32(V, I) ((V) >> BPD*(I) & DIGIT_MASK) | ||
| 23 | |||
| 24 | #define TBL_LOOKUP(TBL, ROW, COL) ((TBL)[(ROW)] >> (COL)*2*BPD) | ||
| 25 | #define TBL_VALUE(RET) ((RET) & DIGIT_MASK) | ||
| 26 | #define TBL_CARRY(RET) ((RET) >> BPD & DIGIT_MASK) | ||
| 27 | |||
| 28 | #define MASK_NEG 0x80000000 | ||
| 29 | #define MASK_OVF 0x08000000 | ||
| 30 | #define MASK_NAN 0x00800000 | ||
| 31 | #define MASK_INF 0x00080000 | ||
| 32 | #define MASK_UNI 0x00008000 | ||
| 33 | #define MASK_EMP 0x00000800 | ||
| 34 | #define MASK_FLAGS (MASK_NEG | MASK_OVF | MASK_NAN | MASK_INF | MASK_UNI | MASK_EMP) | ||
| 35 | |||
| 36 | enum digit { A, B, C, D, E, F, G, H, DIGIT_COUNT }; | ||
| 37 | |||
| 38 | extern u32 order; | ||
| 39 | extern u64 addition_table[DIGIT_COUNT]; | ||
| 40 | extern u64 multiplication_table[DIGIT_COUNT]; | ||
| 41 | |||
| 42 | u32 str2num (const char *str); | ||
| 43 | u32 arith_min (u32 a, u32 b); | ||
| 44 | u32 arith_max (u32 a, u32 b); | ||
| 45 | int arith_cmp (u32 a, u32 b); | ||
| 46 | s32 arith2bin (u32 a); | ||
| 47 | |||
| 48 | #endif | ||
