2 % (c) The AQUA Project, Glasgow University, 1993-1998
14 #include "HsVersions.h"
16 import {-# SOURCE #-} StixPrim ( amodeToStix )
20 import AbsCSyn hiding (spRel) -- bits and bobs..
21 import Const ( Literal(..) )
22 import CallConv ( cCallConv )
23 import OrdList ( OrdList )
24 import PrimOp ( PrimOp(..) )
25 import PrimRep ( PrimRep(..) )
26 import SMRep ( arrWordsHdrSize )
27 import Stix ( sStLitLbl, StixTree(..), StixTreeList, arrWordsHS )
28 import UniqSupply ( returnUs, thenUs, UniqSM )
31 Although gmpCompare doesn't allocate space, it does temporarily use
32 some space just beyond the heap pointer. This is safe, because the
33 enclosing routine has already guaranteed that this space will be
34 available. (See ``primOpHeapRequired.'')
37 stgArrWords__words :: StixTree -> StixTree
38 stgArrWords__BYTE_ARR_CTS :: StixTree -> StixTree
40 stgArrWords__BYTE_ARR_CTS arr
41 = StIndex WordRep arr arrWordsHS
42 stgArrWords__words arr
44 StInt i -> StInd WordRep (StIndex PtrRep arr (StInt (i-1)))
47 :: CAddrMode -- result (boolean)
48 -> (CAddrMode,CAddrMode,CAddrMode,CAddrMode)
49 -- alloc hp + 2 arguments (2 parts each)
50 -> UniqSM StixTreeList
52 gmpCompare res args@(csa1,cda1, csa2,cda2)
54 result = amodeToStix res
55 sa1 = amodeToStix csa1
56 sa2 = amodeToStix csa2
57 aa1 = stgArrWords__words (amodeToStix cda1)
58 aa2 = stgArrWords__words (amodeToStix cda2)
59 da1 = stgArrWords__BYTE_ARR_CTS (amodeToStix cda1)
60 da2 = stgArrWords__BYTE_ARR_CTS (amodeToStix cda2)
62 (a1,a2,a3) = toStruct scratch1 (aa1,sa1,da1)
63 (a4,a5,a6) = toStruct scratch2 (aa2,sa2,da2)
64 mpz_cmp = StCall SLIT("mpz_cmp") cCallConv IntRep [scratch1, scratch2]
65 r1 = StAssign IntRep result mpz_cmp
67 returnUs (\xs -> a1 : a2 : a3 : a4 : a5 : a6 : r1 : xs)
71 :: CAddrMode -- result (boolean)
72 -> (CAddrMode,CAddrMode,CAddrMode)
73 -> UniqSM StixTreeList -- alloc hp + 1 arg (??)
75 gmpCompareInt res args@(csa1,cda1, cai)
77 result = amodeToStix res
78 sa1 = amodeToStix csa1
79 aa1 = stgArrWords__words (amodeToStix cda1)
80 da1 = stgArrWords__BYTE_ARR_CTS (amodeToStix cda1)
82 (a1,a2,a3) = toStruct scratch1 (aa1,sa1,da1)
83 mpz_cmp_si = StCall SLIT("mpz_cmp_si") cCallConv IntRep [scratch1, ai]
84 r1 = StAssign IntRep result mpz_cmp_si
86 returnUs (\xs -> a1 : a2 : a3 : r1 : xs)
91 :: CAddrMode -- result
92 -> (CAddrMode,CAddrMode) -- alloc hp + argument (2 parts)
93 -> UniqSM StixTreeList
95 gmpInteger2Int res args@(csa,cda)
97 result = amodeToStix res
99 aa = stgArrWords__words (amodeToStix cda)
100 da = stgArrWords__BYTE_ARR_CTS (amodeToStix cda)
102 (a1,a2,a3) = toStruct scratch1 (aa,sa,da)
103 mpz_get_si = StCall SLIT("mpz_get_si") cCallConv IntRep [scratch1]
104 r1 = StAssign IntRep result mpz_get_si
106 returnUs (\xs -> a1 : a2 : a3 : r1 : xs)
109 :: CAddrMode -- result
110 -> (CAddrMode,CAddrMode) -- alloc hp + argument (2 parts)
111 -> UniqSM StixTreeList
113 gmpInteger2Word res args@(csa,cda)
115 result = amodeToStix res
117 aa = stgArrWords__words (amodeToStix cda)
118 da = stgArrWords__BYTE_ARR_CTS (amodeToStix cda)
120 (a1,a2,a3) = toStruct scratch1 (aa,sa,da)
121 mpz_get_ui = StCall SLIT("mpz_get_ui") cCallConv IntRep [scratch1]
122 r1 = StAssign WordRep result mpz_get_ui
124 returnUs (\xs -> a1 : a2 : a3 : r1 : xs)
127 :: (CAddrMode,CAddrMode) -- result
128 -> (CAddrMode,CAddrMode) -- argument (2 parts)
129 -> UniqSM StixTreeList
131 gmpNegate (rcs, rcd) args@(cs, cd)
134 a = stgArrWords__words (amodeToStix cd)
135 d = stgArrWords__BYTE_ARR_CTS (amodeToStix cd)
137 ra = stgArrWords__words (amodeToStix rcd)
138 rd = stgArrWords__BYTE_ARR_CTS (amodeToStix rcd)
139 a1 = StAssign IntRep ra a
140 a2 = StAssign IntRep rs (StPrim IntNegOp [s])
141 a3 = StAssign PtrRep rd d
143 returnUs (\xs -> a1 : a2 : a3 : xs)
146 Support for the Gnu GMP multi-precision package.
149 -- size (in words) of __MP_INT
152 mpAlloc, mpSize, mpData :: StixTree -> StixTree
153 mpAlloc base = StInd IntRep base
154 mpSize base = StInd IntRep (StIndex IntRep base (StInt 1))
155 mpData base = StInd PtrRep (StIndex IntRep base (StInt 2))
161 -> (StixTree, StixTree, StixTree)
162 -> (StixTree, StixTree, StixTree)
164 toStruct str (alloc,size,arr)
166 f1 = StAssign IntRep (mpAlloc str) alloc
167 f2 = StAssign IntRep (mpSize str) size
168 f3 = StAssign PtrRep (mpData str) arr
172 scratch1 = StScratchWord 0
173 scratch2 = StScratchWord mpIntSize