[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / rts / StgLongLong.c
1 /* -----------------------------------------------------------------------------
2  * $Id: StgLongLong.c,v 1.2 1998/12/02 13:28:51 simonm Exp $
3  *
4  * Primitive operations over (64-bit) long longs
5  * (only used on 32-bit platforms.)
6  *
7  * ---------------------------------------------------------------------------*/
8
9
10 /*
11 Miscellaneous primitive operations on StgInt64 and StgNat64s.
12
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'.
16
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.
21
22 The exceptions to the rule are primops that cast to and from
23 64-bit entities (these are defined in PrimOps.h)
24
25 NOTE: We prefix all these primops with "stg_". No particular
26 reason why.
27 */
28
29 #include "Rts.h"
30
31 #ifdef SUPPORT_LONG_LONGS
32 StgInt
33 stg_gtWord64(StgNat64 l1, StgNat64 l2)
34 { return ( l1 > l2); }
35
36 StgInt
37 stg_geWord64(StgNat64 l1, StgNat64 l2)
38 { return ( l1 >= l2); }
39
40 StgInt
41 stg_eqWord64(StgNat64 l1, StgNat64 l2)
42 { return ( l1 == l2); }
43
44 StgInt
45 stg_neWord64(StgNat64 l1, StgNat64 l2)
46 { return ( l1 != l2); }
47
48 StgInt
49 stg_ltWord64(StgNat64 l1, StgNat64 l2)
50 { return ( l1 < l2); }
51
52 StgInt
53 stg_leWord64(StgNat64 l1, StgNat64 l2)
54 { return ( l1 <= l2); }
55
56 /* ------------------ */
57
58 StgInt
59 stg_gtInt64(StgInt64 l1, StgInt64 l2)
60 { return ( l1 > l2); }
61
62 StgInt
63 stg_geInt64(StgInt64 l1, StgInt64 l2)
64 { return ( l1 >= l2); }
65
66 StgInt
67 stg_eqInt64(StgInt64 l1, StgInt64 l2)
68 { return ( l1 == l2); }
69
70 StgInt
71 stg_neInt64(StgInt64 l1, StgInt64 l2)
72 { return ( l1 != l2); }
73
74 StgInt
75 stg_ltInt64(StgInt64 l1, StgInt64 l2)
76 { return ( l1 < l2); }
77
78 StgInt
79 stg_leInt64(StgInt64 l1, StgInt64 l2)
80 { return ( l1 <= l2); }
81
82 /* Arithmetic operators */
83
84 StgNat64
85 stg_remWord64(StgNat64 a, StgNat64 b)
86 { return (a%b); }
87
88 StgNat64
89 stg_quotWord64(StgNat64 a, StgNat64 b)
90 { return (a/b); }
91
92 StgInt64
93 stg_remInt64(StgInt64 a, StgInt64 b)
94 { return (a%b); }
95
96 StgInt64
97 stg_quotInt64(StgInt64 a, StgInt64 b)
98 { return (a/b); }
99
100 StgInt64
101 stg_negateInt64(StgInt64 a)
102 { return (-a); }
103
104 StgInt64
105 stg_plusInt64(StgInt64 a, StgInt64 b)
106 { return (a+b); }
107
108 StgInt64
109 stg_minusInt64(StgInt64 a, StgInt64 b)
110 { return (a-b); }
111
112 StgInt64
113 stg_timesInt64(StgInt64 a, StgInt64 b)
114 { return (a*b); }
115
116 /* Logical operators: */
117
118 StgNat64
119 stg_and64(StgNat64 a, StgNat64 b)
120 { return (a&b); }
121
122 StgNat64
123 stg_or64(StgNat64 a, StgNat64 b)
124 { return (a|b); }
125
126 StgNat64
127 stg_xor64(StgNat64 a, StgNat64 b)
128 { return (a^b); }
129
130 StgNat64
131 stg_not64(StgNat64 a)
132 { return (~a); }
133
134 StgNat64
135 stg_shiftL64(StgNat64 a, StgInt b)
136 { return (a << b); }
137
138 StgNat64
139 stg_shiftRL64(StgNat64 a, StgInt b)
140 { return (a >> b); }
141
142 StgInt64
143 stg_iShiftL64(StgInt64 a, StgInt b)
144 { return ( a<<b ); }
145
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
149 */
150
151 StgInt64
152 stg_iShiftRA64(StgInt64 a, StgInt b)
153 { return ( a>>b ); }
154
155 StgInt64
156 stg_iShiftRL64(StgInt64 a, StgInt b)
157 { return ( a>>b ); }
158
159 /*
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).
163 */
164
165 StgInt64
166 stg_intToInt64(StgInt i)
167 { return ( (StgInt64)i ); }
168
169 StgInt
170 stg_int64ToInt(StgInt64 i)
171 { return ( (StgInt)i ); }
172
173 StgNat64
174 stg_int64ToWord64(StgInt64 i)
175 { return ( (StgNat64)i ); }
176
177 StgNat64
178 stg_wordToWord64(StgWord w)
179 { return ( (StgNat64)w ); }
180
181 StgWord
182 stg_word64ToWord(StgNat64 w)
183 { return ( (StgWord)w ); }
184
185 StgInt64
186 stg_word64ToInt64(StgNat64 w)
187 { return ( (StgInt64)w ); }
188
189 #endif /* SUPPORT_LONG_LONGS */