[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / runtime / prims / LongLong.lc
1 %
2 %
3 %
4
5 Miscellaneous primitive operations on StgInt64 and StgWord64s.
6
7 Instead of going the normal (boring) route of making the list
8 of primitive operations even longer to cope with operations
9 over 64-bit entities, we implement them instead 'out-of-line'.
10
11 The primitive ops get their own routine (in C) that implements
12 the operation, requiring the caller to _ccall_ out. This has
13 performance implications of course, but we currently don't
14 expect intensive use of the Int64 and Word64 types.
15
16 The exceptions to the rule are primops that cast to and from
17 64-bit entities.
18
19 NOTE: We prefix all these primops with "stg_". No particular
20 reason why.
21
22 %
23 %
24
25 Comparison operators:
26
27 \begin{code}
28 #include "rtsdefs.h"
29
30 #if HAVE_LONG_LONG
31 StgInt
32 stg_gtWord64(StgWord64 l1, StgWord64 l2)
33 { return ( l1 > l2); }
34
35 StgInt
36 stg_geWord64(StgWord64 l1, StgWord64 l2)
37 { return ( l1 >= l2); }
38
39 StgInt
40 stg_eqWord64(StgWord64 l1, StgWord64 l2)
41 { return ( l1 == l2); }
42
43 StgInt
44 stg_neWord64(StgWord64 l1, StgWord64 l2)
45 { return ( l1 != l2); }
46
47 StgInt
48 stg_ltWord64(StgWord64 l1, StgWord64 l2)
49 { return ( l1 < l2); }
50
51 StgInt
52 stg_leWord64(StgWord64 l1, StgWord64 l2)
53 { return ( l1 <= l2); }
54
55 /* ------------------ */
56
57 StgInt
58 stg_gtInt64(StgInt64 l1, StgInt64 l2)
59 { return ( l1 > l2); }
60
61 StgInt
62 stg_geInt64(StgInt64 l1, StgInt64 l2)
63 { return ( l1 >= l2); }
64
65 StgInt
66 stg_eqInt64(StgInt64 l1, StgInt64 l2)
67 { return ( l1 == l2); }
68
69 StgInt
70 stg_neInt64(StgInt64 l1, StgInt64 l2)
71 { return ( l1 != l2); }
72
73 StgInt
74 stg_ltInt64(StgInt64 l1, StgInt64 l2)
75 { return ( l1 < l2); }
76
77 StgInt
78 stg_leInt64(StgInt64 l1, StgInt64 l2)
79 { return ( l1 <= l2); }
80 \end{code}
81
82 %
83 %
84
85 Arithmetic operators
86
87 \begin{code}
88
89 StgWord64
90 stg_remWord64(StgWord64 a, StgWord64 b)
91 { return (a%b); }
92
93 StgWord64
94 stg_quotWord64(StgWord64 a, StgWord64 b)
95 { return (a/b); }
96
97 StgInt64
98 stg_remInt64(StgInt64 a, StgInt64 b)
99 { return (a%b); }
100
101 StgInt64
102 stg_quotInt64(StgInt64 a, StgInt64 b)
103 { return (a/b); }
104
105 StgInt64
106 stg_negateInt64(StgInt64 a)
107 { return (-a); }
108
109 StgInt64
110 stg_plusInt64(StgInt64 a, StgInt64 b)
111 { return (a+b); }
112
113 StgInt64
114 stg_minusInt64(StgInt64 a, StgInt64 b)
115 { return (a-b); }
116
117 StgInt64
118 stg_timesInt64(StgInt64 a, StgInt64 b)
119 { return (a*b); }
120
121 \end{code}
122
123 %
124 %
125
126 Logical operators:
127
128 \begin{code}
129 StgWord64
130 stg_and64(StgWord64 a, StgWord64 b)
131 { return (a&b); }
132
133 StgWord64
134 stg_or64(StgWord64 a, StgWord64 b)
135 { return (a|b); }
136
137 StgWord64
138 stg_xor64(StgWord64 a, StgWord64 b)
139 { return (a^b); }
140
141 StgWord64
142 stg_not64(StgWord64 a)
143 { return (~a); }
144
145 StgWord64
146 stg_shiftL64(StgWord64 a, StgInt b)
147 { return (a << b); }
148
149 StgWord64
150 stg_shiftRL64(StgWord64 a, StgInt b)
151 { return (a >> b); }
152
153 StgInt64
154 stg_iShiftL64(StgInt64 a, StgInt b)
155 { return ( a<<b ); }
156
157 /* Right shifting of signed quantities is not portable in C, so
158    the behaviour you'll get from using these primops depends
159    on the whatever your C compiler is doing. ToDo: fix. -- sof 8/98
160 */
161
162 StgInt64
163 stg_iShiftRA64(StgInt64 a, StgInt b)
164 { return ( a>>b ); }
165
166 StgInt64
167 stg_iShiftRL64(StgInt64 a, StgInt b)
168 { return ( a>>b ); }
169
170 \end{code}
171
172 %
173 %
174
175 Casting between longs and longer longs:
176 (the primops that cast from to/from Integers and long longs are
177 expressed as macros, since these may cause some heap allocation).
178
179 \begin{code}
180 StgInt64
181 stg_intToInt64(StgInt i)
182 { return ( (StgInt64)i ); }
183
184 StgInt
185 stg_int64ToInt(StgInt64 i)
186 { return ( (StgInt)i ); }
187
188 StgWord64
189 stg_int64ToWord64(StgInt64 i)
190 { return ( (StgWord64)i ); }
191
192 StgWord64
193 stg_wordToWord64(StgWord w)
194 { return ( (StgWord64)w ); }
195
196 StgWord
197 stg_word64ToWord(StgWord64 w)
198 { return ( (StgWord)w ); }
199
200 StgInt64
201 stg_word64ToInt64(StgWord64 w)
202 { return ( (StgInt64)w ); }
203
204 #endif
205
206 \end{code}