1 /* -----------------------------------------------------------------------------
2 * $Id: StgLongLong.c,v 1.4 1999/03/02 19:50:47 sof Exp $
4 * (c) The GHC Team, 1998-1999
6 * Primitive operations over (64-bit) long longs
7 * (only used on 32-bit platforms.)
9 * ---------------------------------------------------------------------------*/
13 Miscellaneous primitive operations on StgInt64 and StgWord64s.
15 Instead of going the normal (boring) route of making the list
16 of primitive operations even longer to cope with operations
17 over 64-bit entities, we implement them instead 'out-of-line'.
19 The primitive ops get their own routine (in C) that implements
20 the operation, requiring the caller to _ccall_ out. This has
21 performance implications of course, but we currently don't
22 expect intensive use of either Int64 or Word64 types.
24 The exceptions to the rule are primops that cast to and from
25 64-bit entities (these are defined in PrimOps.h)
27 NOTE: We prefix all these primops with "stg_". No particular
33 #ifdef SUPPORT_LONG_LONGS
35 stg_gtWord64(StgWord64 l1, StgWord64 l2)
36 { return ( l1 > l2); }
39 stg_geWord64(StgWord64 l1, StgWord64 l2)
40 { return ( l1 >= l2); }
43 stg_eqWord64(StgWord64 l1, StgWord64 l2)
44 { return ( l1 == l2); }
47 stg_neWord64(StgWord64 l1, StgWord64 l2)
48 { return ( l1 != l2); }
51 stg_ltWord64(StgWord64 l1, StgWord64 l2)
52 { return ( l1 < l2); }
55 stg_leWord64(StgWord64 l1, StgWord64 l2)
56 { return ( l1 <= l2); }
58 /* ------------------ */
61 stg_gtInt64(StgInt64 l1, StgInt64 l2)
62 { return ( l1 > l2); }
65 stg_geInt64(StgInt64 l1, StgInt64 l2)
66 { return ( l1 >= l2); }
69 stg_eqInt64(StgInt64 l1, StgInt64 l2)
70 { return ( l1 == l2); }
73 stg_neInt64(StgInt64 l1, StgInt64 l2)
74 { return ( l1 != l2); }
77 stg_ltInt64(StgInt64 l1, StgInt64 l2)
78 { return ( l1 < l2); }
81 stg_leInt64(StgInt64 l1, StgInt64 l2)
82 { return ( l1 <= l2); }
84 /* Arithmetic operators */
87 stg_remWord64(StgWord64 a, StgWord64 b)
91 stg_quotWord64(StgWord64 a, StgWord64 b)
95 stg_remInt64(StgInt64 a, StgInt64 b)
99 stg_quotInt64(StgInt64 a, StgInt64 b)
103 stg_negateInt64(StgInt64 a)
107 stg_plusInt64(StgInt64 a, StgInt64 b)
111 stg_minusInt64(StgInt64 a, StgInt64 b)
115 stg_timesInt64(StgInt64 a, StgInt64 b)
118 /* Logical operators: */
121 stg_and64(StgWord64 a, StgWord64 b)
125 stg_or64(StgWord64 a, StgWord64 b)
129 stg_xor64(StgWord64 a, StgWord64 b)
133 stg_not64(StgWord64 a)
137 stg_shiftL64(StgWord64 a, StgInt b)
141 stg_shiftRL64(StgWord64 a, StgInt b)
145 stg_iShiftL64(StgInt64 a, StgInt b)
148 /* Right shifting of signed quantities is not portable in C, so
149 the behaviour you'll get from using these primops depends
150 on the whatever your C compiler is doing. ToDo: fix. -- sof 8/98
154 stg_iShiftRA64(StgInt64 a, StgInt b)
158 stg_iShiftRL64(StgInt64 a, StgInt b)
162 Casting between longs and longer longs:
163 (the primops that cast from to/from Integers and long longs are
164 expressed as macros, since these may cause some heap allocation).
168 stg_intToInt64(StgInt i)
169 { return ( (StgInt64)i ); }
172 stg_int64ToInt(StgInt64 i)
173 { return ( (StgInt)i ); }
176 stg_int64ToWord64(StgInt64 i)
177 { return ( (StgWord64)i ); }
180 stg_wordToWord64(StgWord w)
181 { return ( (StgWord64)w ); }
184 stg_word64ToWord(StgWord64 w)
185 { return ( (StgWord)w ); }
188 stg_word64ToInt64(StgWord64 w)
189 { return ( (StgInt64)w ); }
191 #endif /* SUPPORT_LONG_LONGS */