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.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 #if (defined (MLTON_GC_INTERNAL_TYPES))
13 * Note, the value passed around is a pointer to the obj member.
15 struct GC_intInf_obj
{
19 typedef struct GC_intInf
{
20 GC_arrayCounter counter
;
21 GC_arrayLength length
;
23 struct GC_intInf_obj obj
;
24 } __attribute__ ((packed
)) *GC_intInf
;
26 COMPILE_TIME_ASSERT(GC_intInf__obj_packed
,
27 offsetof(struct GC_intInf
, obj
) ==
28 sizeof(GC_arrayCounter
)
29 + sizeof(GC_arrayLength
)
31 COMPILE_TIME_ASSERT(GC_intInf_obj__isneg_packed
,
32 offsetof(struct GC_intInf_obj
, isneg
) ==
34 COMPILE_TIME_ASSERT(GC_intInf_obj__limbs_packed
,
35 offsetof(struct GC_intInf_obj
, limbs
) ==
36 0 + sizeof(mp_limb_t
));
38 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
40 #if (defined (MLTON_GC_INTERNAL_FUNCS))
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 ) ) )
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);
55 #define LIMBS_PER_OBJPTR ( \
56 sizeof(mp_limb_t) >= sizeof(objptr) ? \
57 1 : (int)(sizeof(objptr) / sizeof(mp_limb_t)))
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
);
65 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */
67 #if (defined (MLTON_GC_INTERNAL_BASIS))
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
,
86 const __mpz_struct
*argspace
));
88 #endif /* (defined (MLTON_GC_INTERNAL_BASIS)) */