aboutsummaryrefslogtreecommitdiff
path: root/src/arith.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/arith.h')
-rw-r--r--src/arith.h48
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
36enum digit { A, B, C, D, E, F, G, H, DIGIT_COUNT };
37
38extern u32 order;
39extern u64 addition_table[DIGIT_COUNT];
40extern u64 multiplication_table[DIGIT_COUNT];
41
42u32 str2num (const char *str);
43u32 arith_min (u32 a, u32 b);
44u32 arith_max (u32 a, u32 b);
45int arith_cmp (u32 a, u32 b);
46s32 arith2bin (u32 a);
47
48#endif