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