From 03871ae1cbf050310707faa8bcecd16d1c29586e Mon Sep 17 00:00:00 2001 From: sof Date: Fri, 14 Aug 1998 10:49:52 +0000 Subject: [PATCH] [project @ 1998-08-14 10:49:52 by sof] long long primitives --- ghc/runtime/prims/LongLong.lc | 206 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 ghc/runtime/prims/LongLong.lc diff --git a/ghc/runtime/prims/LongLong.lc b/ghc/runtime/prims/LongLong.lc new file mode 100644 index 0000000..d95acb3 --- /dev/null +++ b/ghc/runtime/prims/LongLong.lc @@ -0,0 +1,206 @@ +% +% +% + +Miscellaneous primitive operations on StgInt64 and StgWord64s. + +Instead of going the normal (boring) route of making the list +of primitive operations even longer to cope with operations +over 64-bit entities, we implement them instead 'out-of-line'. + +The primitive ops get their own routine (in C) that implements +the operation, requiring the caller to _ccall_ out. This has +performance implications of course, but we currently don't +expect intensive use of the Int64 and Word64 types. + +The exceptions to the rule are primops that cast to and from +64-bit entities. + +NOTE: We prefix all these primops with "stg_". No particular +reason why. + +% +% + +Comparison operators: + +\begin{code} +#include "rtsdefs.h" + +#if HAVE_LONG_LONG +StgInt +stg_gtWord64(StgWord64 l1, StgWord64 l2) +{ return ( l1 > l2); } + +StgInt +stg_geWord64(StgWord64 l1, StgWord64 l2) +{ return ( l1 >= l2); } + +StgInt +stg_eqWord64(StgWord64 l1, StgWord64 l2) +{ return ( l1 == l2); } + +StgInt +stg_neWord64(StgWord64 l1, StgWord64 l2) +{ return ( l1 != l2); } + +StgInt +stg_ltWord64(StgWord64 l1, StgWord64 l2) +{ return ( l1 < l2); } + +StgInt +stg_leWord64(StgWord64 l1, StgWord64 l2) +{ return ( l1 <= l2); } + +/* ------------------ */ + +StgInt +stg_gtInt64(StgInt64 l1, StgInt64 l2) +{ return ( l1 > l2); } + +StgInt +stg_geInt64(StgInt64 l1, StgInt64 l2) +{ return ( l1 >= l2); } + +StgInt +stg_eqInt64(StgInt64 l1, StgInt64 l2) +{ return ( l1 == l2); } + +StgInt +stg_neInt64(StgInt64 l1, StgInt64 l2) +{ return ( l1 != l2); } + +StgInt +stg_ltInt64(StgInt64 l1, StgInt64 l2) +{ return ( l1 < l2); } + +StgInt +stg_leInt64(StgInt64 l1, StgInt64 l2) +{ return ( l1 <= l2); } +\end{code} + +% +% + +Arithmetic operators + +\begin{code} + +StgWord64 +stg_remWord64(StgWord64 a, StgWord64 b) +{ return (a%b); } + +StgWord64 +stg_quotWord64(StgWord64 a, StgWord64 b) +{ return (a/b); } + +StgInt64 +stg_remInt64(StgInt64 a, StgInt64 b) +{ return (a%b); } + +StgInt64 +stg_quotInt64(StgInt64 a, StgInt64 b) +{ return (a/b); } + +StgInt64 +stg_negateInt64(StgInt64 a) +{ return (-a); } + +StgInt64 +stg_plusInt64(StgInt64 a, StgInt64 b) +{ return (a+b); } + +StgInt64 +stg_minusInt64(StgInt64 a, StgInt64 b) +{ return (a-b); } + +StgInt64 +stg_timesInt64(StgInt64 a, StgInt64 b) +{ return (a*b); } + +\end{code} + +% +% + +Logical operators: + +\begin{code} +StgWord64 +stg_and64(StgWord64 a, StgWord64 b) +{ return (a&b); } + +StgWord64 +stg_or64(StgWord64 a, StgWord64 b) +{ return (a|b); } + +StgWord64 +stg_xor64(StgWord64 a, StgWord64 b) +{ return (a^b); } + +StgWord64 +stg_not64(StgWord64 a) +{ return (~a); } + +StgWord64 +stg_shiftL64(StgWord64 a, StgInt b) +{ return (a << b); } + +StgWord64 +stg_shiftRL64(StgWord64 a, StgInt b) +{ return (a >> b); } + +StgInt64 +stg_iShiftL64(StgInt64 a, StgInt b) +{ return ( a<>b ); } + +StgInt64 +stg_iShiftRL64(StgInt64 a, StgInt b) +{ return ( a>>b ); } + +\end{code} + +% +% + +Casting between longs and longer longs: +(the primops that cast from to/from Integers and long longs are +expressed as macros, since these may cause some heap allocation). + +\begin{code} +StgInt64 +stg_intToInt64(StgInt i) +{ return ( (StgInt64)i ); } + +StgInt +stg_int64ToInt(StgInt64 i) +{ return ( (StgInt)i ); } + +StgWord64 +stg_int64ToWord64(StgInt64 i) +{ return ( (StgWord64)i ); } + +StgWord64 +stg_wordToWord64(StgWord w) +{ return ( (StgWord64)w ); } + +StgWord +stg_word64ToWord(StgWord64 w) +{ return ( (StgWord)w ); } + +StgInt64 +stg_word64ToInt64(StgWord64 w) +{ return ( (StgInt64)w ); } + +#endif + +\end{code} -- 1.7.10.4