1 /* -----------------------------------------------------------------------------
2 * $Id: StgLongLong.c,v 1.2 1998/12/02 13:28:51 simonm Exp $
4 * Primitive operations over (64-bit) long longs
5 * (only used on 32-bit platforms.)
7 * ---------------------------------------------------------------------------*/
11 Miscellaneous primitive operations on StgInt64 and StgNat64s.
13 Instead of going the normal (boring) route of making the list
14 of primitive operations even longer to cope with operations
15 over 64-bit entities, we implement them instead 'out-of-line'.
17 The primitive ops get their own routine (in C) that implements
18 the operation, requiring the caller to _ccall_ out. This has
19 performance implications of course, but we currently don't
20 expect intensive use of either Int64 or Word64 types.
22 The exceptions to the rule are primops that cast to and from
23 64-bit entities (these are defined in PrimOps.h)
25 NOTE: We prefix all these primops with "stg_". No particular
31 #ifdef SUPPORT_LONG_LONGS
33 stg_gtWord64(StgNat64 l1, StgNat64 l2)
34 { return ( l1 > l2); }
37 stg_geWord64(StgNat64 l1, StgNat64 l2)
38 { return ( l1 >= l2); }
41 stg_eqWord64(StgNat64 l1, StgNat64 l2)
42 { return ( l1 == l2); }
45 stg_neWord64(StgNat64 l1, StgNat64 l2)
46 { return ( l1 != l2); }
49 stg_ltWord64(StgNat64 l1, StgNat64 l2)
50 { return ( l1 < l2); }
53 stg_leWord64(StgNat64 l1, StgNat64 l2)
54 { return ( l1 <= l2); }
56 /* ------------------ */
59 stg_gtInt64(StgInt64 l1, StgInt64 l2)
60 { return ( l1 > l2); }
63 stg_geInt64(StgInt64 l1, StgInt64 l2)
64 { return ( l1 >= l2); }
67 stg_eqInt64(StgInt64 l1, StgInt64 l2)
68 { return ( l1 == l2); }
71 stg_neInt64(StgInt64 l1, StgInt64 l2)
72 { return ( l1 != l2); }
75 stg_ltInt64(StgInt64 l1, StgInt64 l2)
76 { return ( l1 < l2); }
79 stg_leInt64(StgInt64 l1, StgInt64 l2)
80 { return ( l1 <= l2); }
82 /* Arithmetic operators */
85 stg_remWord64(StgNat64 a, StgNat64 b)
89 stg_quotWord64(StgNat64 a, StgNat64 b)
93 stg_remInt64(StgInt64 a, StgInt64 b)
97 stg_quotInt64(StgInt64 a, StgInt64 b)
101 stg_negateInt64(StgInt64 a)
105 stg_plusInt64(StgInt64 a, StgInt64 b)
109 stg_minusInt64(StgInt64 a, StgInt64 b)
113 stg_timesInt64(StgInt64 a, StgInt64 b)
116 /* Logical operators: */
119 stg_and64(StgNat64 a, StgNat64 b)
123 stg_or64(StgNat64 a, StgNat64 b)
127 stg_xor64(StgNat64 a, StgNat64 b)
131 stg_not64(StgNat64 a)
135 stg_shiftL64(StgNat64 a, StgInt b)
139 stg_shiftRL64(StgNat64 a, StgInt b)
143 stg_iShiftL64(StgInt64 a, StgInt b)
146 /* Right shifting of signed quantities is not portable in C, so
147 the behaviour you'll get from using these primops depends
148 on the whatever your C compiler is doing. ToDo: fix. -- sof 8/98
152 stg_iShiftRA64(StgInt64 a, StgInt b)
156 stg_iShiftRL64(StgInt64 a, StgInt b)
160 Casting between longs and longer longs:
161 (the primops that cast from to/from Integers and long longs are
162 expressed as macros, since these may cause some heap allocation).
166 stg_intToInt64(StgInt i)
167 { return ( (StgInt64)i ); }
170 stg_int64ToInt(StgInt64 i)
171 { return ( (StgInt)i ); }
174 stg_int64ToWord64(StgInt64 i)
175 { return ( (StgNat64)i ); }
178 stg_wordToWord64(StgWord w)
179 { return ( (StgNat64)w ); }
182 stg_word64ToWord(StgNat64 w)
183 { return ( (StgWord)w ); }
186 stg_word64ToInt64(StgNat64 w)
187 { return ( (StgInt64)w ); }
189 #endif /* SUPPORT_LONG_LONGS */