Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / gc / int-inf.h
1 /* Copyright (C) 2012,2014 Matthew Fluet.
2 * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
5 *
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
8 */
9
10 #if (defined (MLTON_GC_INTERNAL_TYPES))
11
12 /* Layout of intInfs.
13 * Note, the value passed around is a pointer to the obj member.
14 */
15 struct GC_intInf_obj {
16 mp_limb_t isneg;
17 mp_limb_t limbs[1];
18 };
19 typedef struct GC_intInf {
20 GC_arrayCounter counter;
21 GC_arrayLength length;
22 GC_header header;
23 struct GC_intInf_obj obj;
24 } __attribute__ ((packed)) *GC_intInf;
25
26 COMPILE_TIME_ASSERT(GC_intInf__obj_packed,
27 offsetof(struct GC_intInf, obj) ==
28 sizeof(GC_arrayCounter)
29 + sizeof(GC_arrayLength)
30 + sizeof(GC_header));
31 COMPILE_TIME_ASSERT(GC_intInf_obj__isneg_packed,
32 offsetof(struct GC_intInf_obj, isneg) ==
33 0);
34 COMPILE_TIME_ASSERT(GC_intInf_obj__limbs_packed,
35 offsetof(struct GC_intInf_obj, limbs) ==
36 0 + sizeof(mp_limb_t));
37
38 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
39
40 #if (defined (MLTON_GC_INTERNAL_FUNCS))
41
42 COMPILE_TIME_ASSERT(sizeof_mp_limb_t__is_four_or_eight,
43 (sizeof(mp_limb_t) == 4 || sizeof(mp_limb_t) == 8));
44 #define GC_INTINF_HEADER ( \
45 CHAR_BIT * sizeof(mp_limb_t) == 32 ? \
46 GC_WORD32_VECTOR_HEADER : ( \
47 CHAR_BIT * sizeof(mp_limb_t) == 64 ? \
48 GC_WORD64_VECTOR_HEADER : ( 0 ) ) )
49
50 COMPILE_TIME_ASSERT(sizeof_mp_limb_t__compat__sizeof_objptr,
51 sizeof(objptr) <= sizeof(mp_limb_t) ?
52 sizeof(mp_limb_t) % sizeof(objptr) == 0 :
53 sizeof(objptr) % sizeof(mp_limb_t) == 0);
54
55 #define LIMBS_PER_OBJPTR ( \
56 sizeof(mp_limb_t) >= sizeof(objptr) ? \
57 1 : (int)(sizeof(objptr) / sizeof(mp_limb_t)))
58
59 PRIVATE void initIntInf (GC_state s);
60 static inline void fillIntInfArg (GC_state s, objptr arg, __mpz_struct *res,
61 mp_limb_t space[LIMBS_PER_OBJPTR + 1]);
62 static inline void initIntInfRes (GC_state s, __mpz_struct *res, size_t bytes);
63 static inline objptr finiIntInfRes (GC_state s, __mpz_struct *res, size_t bytes);
64
65 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */
66
67 #if (defined (MLTON_GC_INTERNAL_BASIS))
68
69 PRIVATE objptr IntInf_binop (GC_state s, objptr lhs, objptr rhs, size_t bytes,
70 void(*binop)(__mpz_struct *resmpz,
71 const __mpz_struct *lhsspace,
72 const __mpz_struct *rhsspace));
73 PRIVATE objptr IntInf_unop (GC_state s, objptr arg, size_t bytes,
74 void(*unop)(__mpz_struct *resmpz,
75 const __mpz_struct *argspace));
76 PRIVATE objptr IntInf_shop (GC_state s, objptr arg, Word32_t shift, size_t bytes,
77 void(*shop)(__mpz_struct *resmpz,
78 const __mpz_struct *argspace,
79 unsigned long shift));
80 PRIVATE Int32_t IntInf_cmpop (GC_state s, objptr lhs, objptr rhs,
81 int(*cmpop)(const __mpz_struct *lhsspace,
82 const __mpz_struct *rhsspace));
83 PRIVATE objptr IntInf_strop (GC_state s, objptr arg, Int32_t base, size_t bytes,
84 char*(*strop)(char *str,
85 int base,
86 const __mpz_struct *argspace));
87
88 #endif /* (defined (MLTON_GC_INTERNAL_BASIS)) */