1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# pragma once
# include <caml/callback.h>
# include <caml/stack.h>
#define Is_uint63(v) (Tag_val(v) == Custom_tag)
#define uint_of_value(val) (((uint32_t)(val)) >> 1)
# define DECLARE_NULLOP(name) \
value uint63_##name() { \
static value* cb = 0; \
CAMLparam0(); \
if (!cb) cb = caml_named_value("uint63 " #name); \
CAMLreturn(*cb); \
}
# define DECLARE_UNOP(name) \
value uint63_##name##_ml(value x) { \
static value* cb = 0; \
CAMLparam1(x); \
if (!cb) cb = caml_named_value("uint63 " #name); \
CAMLreturn(caml_callback(*cb, x)); \
}
# define CALL_UNOP_NOASSIGN(name, x) \
value uint63_return_value__; \
value uint63_arg_x__ = (x); \
Setup_for_gc; \
uint63_return_value__ = uint63_##name##_ml(uint63_arg_x__); \
Restore_after_gc
# define CALL_UNOP(name, x) do{ \
CALL_UNOP_NOASSIGN(name, x); \
accu = uint63_return_value__; \
}while(0)
# define CALL_PREDICATE(r, name, x) do{ \
CALL_UNOP_NOASSIGN(name, x); \
(r) = Int_val(uint63_return_value__); \
}while(0)
# define DECLARE_BINOP(name) \
value uint63_##name##_ml(value x, value y) { \
static value* cb = 0; \
CAMLparam2(x, y); \
if (!cb) cb = caml_named_value("uint63 " #name); \
CAMLreturn(caml_callback2(*cb, x, y)); \
}
# define CALL_BINOP_NOASSIGN(name, x, y) \
value uint63_return_value__; \
value uint63_arg_x__ = (x); \
value uint63_arg_y__ = (y); \
Setup_for_gc; \
uint63_return_value__ = uint63_##name##_ml(uint63_arg_x__, uint63_arg_y__); \
Restore_after_gc
# define CALL_BINOP(name, x, y) do{ \
CALL_BINOP_NOASSIGN(name, x, y); \
accu = uint63_return_value__; \
}while(0)
# define CALL_RELATION(r, name, x, y) do{ \
CALL_BINOP_NOASSIGN(name, x, y); \
(r) = Int_val(uint63_return_value__); \
}while(0)
# define DECLARE_TEROP(name) \
value uint63_##name##_ml(value x, value y, value z) { \
static value* cb = 0; \
CAMLparam3(x, y, z); \
if (!cb) cb = caml_named_value("uint63 " #name); \
CAMLreturn(caml_callback3(*cb, x, y, z)); \
}
# define CALL_TEROP(name, x, y, z) do{ \
value uint63_return_value__; \
value uint63_arg_x__ = (x); \
value uint63_arg_y__ = (y); \
value uint63_arg_z__ = (z); \
Setup_for_gc; \
uint63_return_value__ = uint63_##name##_ml(uint63_arg_x__, uint63_arg_y__, uint63_arg_z__); \
Restore_after_gc; \
accu = uint63_return_value__; \
}while(0)
DECLARE_NULLOP(one)
DECLARE_BINOP(add)
#define Uint63_add(x, y) CALL_BINOP(add, x, y)
DECLARE_BINOP(addcarry)
#define Uint63_addcarry(x, y) CALL_BINOP(addcarry, x, y)
DECLARE_TEROP(addmuldiv)
#define Uint63_addmuldiv(x, y, z) CALL_TEROP(addmuldiv, x, y, z)
DECLARE_BINOP(div)
#define Uint63_div(x, y) CALL_BINOP(div, x, y)
DECLARE_BINOP(eq)
#define Uint63_eq(r, x, y) CALL_RELATION(r, eq, x, y)
DECLARE_UNOP(eq0)
#define Uint63_eq0(r, x) CALL_PREDICATE(r, eq0, x)
DECLARE_UNOP(head0)
#define Uint63_head0(x) CALL_UNOP(head0, x)
DECLARE_BINOP(land)
#define Uint63_land(x, y) CALL_BINOP(land, x, y)
DECLARE_BINOP(leq)
#define Uint63_leq(r, x, y) CALL_RELATION(r, leq, x, y)
DECLARE_BINOP(lor)
#define Uint63_lor(x, y) CALL_BINOP(lor, x, y)
DECLARE_BINOP(lsl)
#define Uint63_lsl(x, y) CALL_BINOP(lsl, x, y)
DECLARE_UNOP(lsl1)
#define Uint63_lsl1(x) CALL_UNOP(lsl1, x)
DECLARE_BINOP(lsr)
#define Uint63_lsr(x, y) CALL_BINOP(lsr, x, y)
DECLARE_UNOP(lsr1)
#define Uint63_lsr1(x) CALL_UNOP(lsr1, x)
DECLARE_BINOP(lt)
#define Uint63_lt(r, x, y) CALL_RELATION(r, lt, x, y)
DECLARE_BINOP(lxor)
#define Uint63_lxor(x, y) CALL_BINOP(lxor, x, y)
DECLARE_BINOP(mod)
#define Uint63_mod(x, y) CALL_BINOP(mod, x, y)
DECLARE_BINOP(mul)
#define Uint63_mul(x, y) CALL_BINOP(mul, x, y)
DECLARE_BINOP(sub)
#define Uint63_sub(x, y) CALL_BINOP(sub, x, y)
DECLARE_BINOP(subcarry)
#define Uint63_subcarry(x, y) CALL_BINOP(subcarry, x, y)
DECLARE_UNOP(tail0)
#define Uint63_tail0(x) CALL_UNOP(tail0, x)
DECLARE_TEROP(div21_ml)
# define Uint63_div21(x, y, z, q) do{ \
value uint63_return_value__; \
value uint63_arg_x__ = (x); \
value uint63_arg_y__ = (y); \
value uint63_arg_z__ = (z); \
Setup_for_gc; \
uint63_return_value__ = \
uint63_div21_ml_ml(uint63_arg_x__, uint63_arg_y__, uint63_arg_z__); \
Restore_after_gc; \
*q = Field(uint63_return_value__, 0); \
accu = Field(uint63_return_value__, 1); \
}while(0)
DECLARE_BINOP(mulc_ml)
# define Uint63_mulc(x, y, h) do{ \
value uint63_return_value__; \
value uint63_arg_x__ = (x); \
value uint63_arg_y__ = (y); \
Setup_for_gc; \
uint63_return_value__ = \
uint63_mulc_ml_ml(uint63_arg_x__, uint63_arg_y__); \
Restore_after_gc; \
*(h) = Field(uint63_return_value__, 0); \
accu = Field(uint63_return_value__, 1); \
}while(0)
|