-
Notifications
You must be signed in to change notification settings - Fork 16
/
int56_stubs.c
59 lines (49 loc) · 1.07 KB
/
int56_stubs.c
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
#include <stdint.h>
#include <string.h>
#include <caml/alloc.h>
#include <caml/custom.h>
#include <caml/fail.h>
#include <caml/intext.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>
#include "int56.h"
static const int64_t mask = 0xFFFFFFFFFFFFFF00LL;
CAMLprim value
int56_mul(value v1, value v2)
{
CAMLparam2(v1, v2);
CAMLreturn (copy_int56(Int56_val(v1) * Int64_val(v2)));
}
CAMLprim value
int56_div(value v1, value v2)
{
CAMLparam2(v1, v2);
int64_t divisor = Int64_val(v2);
if (divisor == 0)
caml_raise_zero_divide();
CAMLreturn (copy_int56((Int64_val(v1) / divisor) << 8));
}
CAMLprim value
int56_xor(value v1, value v2)
{
CAMLparam2(v1, v2);
CAMLreturn (copy_int56((Int64_val(v1) ^ Int64_val(v2)) & mask));
}
CAMLprim value
int56_shift_right(value v1, value v2)
{
CAMLparam2(v1, v2);
CAMLreturn (copy_int56((Int64_val(v1) >> Long_val(v2)) & mask));
}
CAMLprim value
int56_max_int(void)
{
CAMLparam0();
CAMLreturn (copy_int56(INT64_MAX & mask));
}
CAMLprim value
int56_min_int(void)
{
CAMLparam0();
CAMLreturn (copy_int56(INT64_MIN & mask));
}