Commit 7dee9e10 authored by sewardj's avatar sewardj
Browse files

[project @ 2001-12-14 15:26:14 by sewardj]

Get rid of multiple-result MachOps (MO_NatS_AddC, MO_NatS_SubC,
MO_NatS_MulC) which implement {add,sub,mul}IntC#.  Supporting gunk
in the NCG disappears as a result.

Instead:

* {add,sub}IntC# are translated out during abstract C simplification,
  turning into the xor-xor-invert-and-shift sequence previously defined
  in PrimOps.h.

* mulIntC# is more difficult to get rid of portably.  Instead we have
  a new single-result PrimOp, mulIntMayOflo, with corresponding MachOp
  MO_NatS_MulMayOflo.  This tells you whether a W x W -> W signed
  multiply might overflow, where W is the word size.  When W=32, is
  implemented by computing a 2W-long result.  When W=64, we use the
  previous approximation.

PrelNum.lhs' implementation of timesInteger changes slightly, to use
the new PrimOp.
parent 8cb83b66
%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
% $Id: AbsCSyn.lhs,v 1.42 2001/12/06 11:50:07 sewardj Exp $
% $Id: AbsCSyn.lhs,v 1.43 2001/12/14 15:26:14 sewardj Exp $
%
\section[AbstractC]{Abstract C: the last stop before machine code}
......@@ -52,7 +52,6 @@ import Unique ( Unique )
import StgSyn ( StgOp )
import TyCon ( TyCon )
import BitSet -- for liveness masks
import Maybes ( Maybe012(..) )
import FastTypes
import Outputable
......@@ -123,7 +122,7 @@ stored in a mixed type location.)
-- NEW CASES FOR EXPANDED PRIMOPS
| CMachOpStmt -- Machine-level operation
(Maybe012 CAddrMode) -- 0, 1 or 2 results
(Maybe CAddrMode) -- 0 or 1 results
MachOp
[CAddrMode] -- Arguments
(Maybe [MagicId]) -- list of regs which need to be preserved
......
This diff is collapsed.
......@@ -10,7 +10,6 @@ where
#include "HsVersions.h"
import PrimRep ( PrimRep(..) )
import Maybes ( Maybe012(..) )
import Outputable
......@@ -49,19 +48,16 @@ data MachOp
| MO_NatU_Gt
| MO_NatU_Lt
| MO_NatS_Mul -- signed *
| MO_NatS_Mul -- low word of signed *
| MO_NatS_MulMayOflo -- nonzero if high word of signed * might contain useful info
| MO_NatS_Quot -- signed / (same semantics as IntQuotOp)
| MO_NatS_Rem -- signed % (same semantics as IntRemOp)
| MO_NatS_Neg -- unary -
| MO_NatU_Mul -- unsigned *
| MO_NatU_Mul -- low word of unsigned *
| MO_NatU_Quot -- unsigned / (same semantics as WordQuotOp)
| MO_NatU_Rem -- unsigned % (same semantics as WordRemOp)
| MO_NatS_AddC -- signed +, first result sum, second result carry
| MO_NatS_SubC -- signed -, first result sum, second result borrow
| MO_NatS_MulC -- signed *, first result sum, second result carry
| MO_Nat_And
| MO_Nat_Or
| MO_Nat_Xor
......@@ -192,6 +188,7 @@ pprMachOp MO_NatU_Gt = text "MO_NatU_Gt"
pprMachOp MO_NatU_Lt = text "MO_NatU_Lt"
pprMachOp MO_NatS_Mul = text "MO_NatS_Mul"
pprMachOp MO_NatS_MulMayOflo = text "MO_NatS_MulMayOflo"
pprMachOp MO_NatS_Quot = text "MO_NatS_Quot"
pprMachOp MO_NatS_Rem = text "MO_NatS_Rem"
pprMachOp MO_NatS_Neg = text "MO_NatS_Neg"
......@@ -200,10 +197,6 @@ pprMachOp MO_NatU_Mul = text "MO_NatU_Mul"
pprMachOp MO_NatU_Quot = text "MO_NatU_Quot"
pprMachOp MO_NatU_Rem = text "MO_NatU_Rem"
pprMachOp MO_NatS_AddC = text "MO_NatS_AddC"
pprMachOp MO_NatS_SubC = text "MO_NatS_SubC"
pprMachOp MO_NatS_MulC = text "MO_NatS_MulC"
pprMachOp MO_Nat_And = text "MO_Nat_And"
pprMachOp MO_Nat_Or = text "MO_Nat_Or"
pprMachOp MO_Nat_Xor = text "MO_Nat_Xor"
......@@ -340,139 +333,136 @@ isComparisonMachOp :: MachOp -> Bool
isComparisonMachOp mop = comp `elem` snd (machOpProps mop)
-- Find the PrimReps for the returned value(s) of the MachOp.
resultRepsOfMachOp :: MachOp -> Maybe012 PrimRep
resultRepsOfMachOp :: MachOp -> Maybe PrimRep
resultRepsOfMachOp mop = fst (machOpProps mop)
-- This bit does the real work.
machOpProps :: MachOp -> (Maybe012 PrimRep, [MO_Prop])
machOpProps MO_Nat_Add = (Just1 IntRep, [inline, comm])
machOpProps MO_Nat_Sub = (Just1 IntRep, [inline])
machOpProps MO_Nat_Eq = (Just1 IntRep, [inline, comp, comm])
machOpProps MO_Nat_Ne = (Just1 IntRep, [inline, comp, comm])
machOpProps MO_NatS_Ge = (Just1 IntRep, [inline, comp])
machOpProps MO_NatS_Le = (Just1 IntRep, [inline, comp])
machOpProps MO_NatS_Gt = (Just1 IntRep, [inline, comp])
machOpProps MO_NatS_Lt = (Just1 IntRep, [inline, comp])
machOpProps MO_NatU_Ge = (Just1 IntRep, [inline, comp])
machOpProps MO_NatU_Le = (Just1 IntRep, [inline, comp])
machOpProps MO_NatU_Gt = (Just1 IntRep, [inline, comp])
machOpProps MO_NatU_Lt = (Just1 IntRep, [inline, comp])
machOpProps MO_NatS_Mul = (Just1 IntRep, [inline, comm])
machOpProps MO_NatS_Quot = (Just1 IntRep, [inline])
machOpProps MO_NatS_Rem = (Just1 IntRep, [inline])
machOpProps MO_NatS_Neg = (Just1 IntRep, [inline])
machOpProps MO_NatU_Mul = (Just1 WordRep, [inline, comm])
machOpProps MO_NatU_Quot = (Just1 WordRep, [inline])
machOpProps MO_NatU_Rem = (Just1 WordRep, [inline])
machOpProps MO_NatS_AddC = (Just2 IntRep IntRep, [])
machOpProps MO_NatS_SubC = (Just2 IntRep IntRep, [])
machOpProps MO_NatS_MulC = (Just2 IntRep IntRep, [])
machOpProps MO_Nat_And = (Just1 IntRep, [inline, comm])
machOpProps MO_Nat_Or = (Just1 IntRep, [inline, comm])
machOpProps MO_Nat_Xor = (Just1 IntRep, [inline, comm])
machOpProps MO_Nat_Not = (Just1 IntRep, [inline])
machOpProps MO_Nat_Shl = (Just1 IntRep, [inline])
machOpProps MO_Nat_Shr = (Just1 IntRep, [inline])
machOpProps MO_Nat_Sar = (Just1 IntRep, [inline])
machOpProps MO_32U_Eq = (Just1 IntRep, [inline, comp, comm])
machOpProps MO_32U_Ne = (Just1 IntRep, [inline, comp, comm])
machOpProps MO_32U_Ge = (Just1 IntRep, [inline, comp])
machOpProps MO_32U_Le = (Just1 IntRep, [inline, comp])
machOpProps MO_32U_Gt = (Just1 IntRep, [inline, comp])
machOpProps MO_32U_Lt = (Just1 IntRep, [inline, comp])
machOpProps MO_Dbl_Eq = (Just1 IntRep, [inline, comp, comm])
machOpProps MO_Dbl_Ne = (Just1 IntRep, [inline, comp, comm])
machOpProps MO_Dbl_Ge = (Just1 IntRep, [inline, comp])
machOpProps MO_Dbl_Le = (Just1 IntRep, [inline, comp])
machOpProps MO_Dbl_Gt = (Just1 IntRep, [inline, comp])
machOpProps MO_Dbl_Lt = (Just1 IntRep, [inline, comp])
machOpProps MO_Dbl_Add = (Just1 DoubleRep, [inline, comm])
machOpProps MO_Dbl_Sub = (Just1 DoubleRep, [inline])
machOpProps MO_Dbl_Mul = (Just1 DoubleRep, [inline, comm])
machOpProps MO_Dbl_Div = (Just1 DoubleRep, [inline])
machOpProps MO_Dbl_Pwr = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Sin = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Cos = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Tan = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Sinh = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Cosh = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Tanh = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Asin = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Acos = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Atan = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Log = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Exp = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Sqrt = (Just1 DoubleRep, [])
machOpProps MO_Dbl_Neg = (Just1 DoubleRep, [inline])
machOpProps MO_Flt_Add = (Just1 FloatRep, [inline, comm])
machOpProps MO_Flt_Sub = (Just1 FloatRep, [inline])
machOpProps MO_Flt_Mul = (Just1 FloatRep, [inline, comm])
machOpProps MO_Flt_Div = (Just1 FloatRep, [inline])
machOpProps MO_Flt_Pwr = (Just1 FloatRep, [])
machOpProps MO_Flt_Eq = (Just1 IntRep, [inline, comp, comm])
machOpProps MO_Flt_Ne = (Just1 IntRep, [inline, comp, comm])
machOpProps MO_Flt_Ge = (Just1 IntRep, [inline, comp])
machOpProps MO_Flt_Le = (Just1 IntRep, [inline, comp])
machOpProps MO_Flt_Gt = (Just1 IntRep, [inline, comp])
machOpProps MO_Flt_Lt = (Just1 IntRep, [inline, comp])
machOpProps MO_Flt_Sin = (Just1 FloatRep, [])
machOpProps MO_Flt_Cos = (Just1 FloatRep, [])
machOpProps MO_Flt_Tan = (Just1 FloatRep, [])
machOpProps MO_Flt_Sinh = (Just1 FloatRep, [])
machOpProps MO_Flt_Cosh = (Just1 FloatRep, [])
machOpProps MO_Flt_Tanh = (Just1 FloatRep, [])
machOpProps MO_Flt_Asin = (Just1 FloatRep, [])
machOpProps MO_Flt_Acos = (Just1 FloatRep, [])
machOpProps MO_Flt_Atan = (Just1 FloatRep, [])
machOpProps MO_Flt_Log = (Just1 FloatRep, [])
machOpProps MO_Flt_Exp = (Just1 FloatRep, [])
machOpProps MO_Flt_Sqrt = (Just1 FloatRep, [])
machOpProps MO_Flt_Neg = (Just1 FloatRep, [inline])
machOpProps MO_32U_to_NatS = (Just1 IntRep, [inline])
machOpProps MO_NatS_to_32U = (Just1 WordRep, [inline])
machOpProps MO_NatS_to_Dbl = (Just1 DoubleRep, [inline])
machOpProps MO_Dbl_to_NatS = (Just1 IntRep, [inline])
machOpProps MO_NatS_to_Flt = (Just1 FloatRep, [inline])
machOpProps MO_Flt_to_NatS = (Just1 IntRep, [inline])
machOpProps MO_NatS_to_NatU = (Just1 WordRep, [inline])
machOpProps MO_NatU_to_NatS = (Just1 IntRep, [inline])
machOpProps MO_NatS_to_NatP = (Just1 PtrRep, [inline])
machOpProps MO_NatP_to_NatS = (Just1 IntRep, [inline])
machOpProps MO_NatU_to_NatP = (Just1 PtrRep, [inline])
machOpProps MO_NatP_to_NatU = (Just1 WordRep, [inline])
machOpProps MO_Dbl_to_Flt = (Just1 FloatRep, [inline])
machOpProps MO_Flt_to_Dbl = (Just1 DoubleRep, [inline])
machOpProps MO_8S_to_NatS = (Just1 IntRep, [inline])
machOpProps MO_16S_to_NatS = (Just1 IntRep, [inline])
machOpProps MO_32S_to_NatS = (Just1 IntRep, [inline])
machOpProps MO_8U_to_NatU = (Just1 WordRep, [inline])
machOpProps MO_16U_to_NatU = (Just1 WordRep, [inline])
machOpProps MO_32U_to_NatU = (Just1 WordRep, [inline])
machOpProps (MO_ReadOSBI offset rep) = (Just1 rep, [inline])
machOpProps (MO_WriteOSBI offset rep) = (Just0, [inline])
machOpProps :: MachOp -> (Maybe PrimRep, [MO_Prop])
machOpProps MO_Nat_Add = (Just IntRep, [inline, comm])
machOpProps MO_Nat_Sub = (Just IntRep, [inline])
machOpProps MO_Nat_Eq = (Just IntRep, [inline, comp, comm])
machOpProps MO_Nat_Ne = (Just IntRep, [inline, comp, comm])
machOpProps MO_NatS_Ge = (Just IntRep, [inline, comp])
machOpProps MO_NatS_Le = (Just IntRep, [inline, comp])
machOpProps MO_NatS_Gt = (Just IntRep, [inline, comp])
machOpProps MO_NatS_Lt = (Just IntRep, [inline, comp])
machOpProps MO_NatU_Ge = (Just IntRep, [inline, comp])
machOpProps MO_NatU_Le = (Just IntRep, [inline, comp])
machOpProps MO_NatU_Gt = (Just IntRep, [inline, comp])
machOpProps MO_NatU_Lt = (Just IntRep, [inline, comp])
machOpProps MO_NatS_Mul = (Just IntRep, [inline, comm])
machOpProps MO_NatS_MulMayOflo = (Just IntRep, [inline, comm])
machOpProps MO_NatS_Quot = (Just IntRep, [inline])
machOpProps MO_NatS_Rem = (Just IntRep, [inline])
machOpProps MO_NatS_Neg = (Just IntRep, [inline])
machOpProps MO_NatU_Mul = (Just WordRep, [inline, comm])
machOpProps MO_NatU_Quot = (Just WordRep, [inline])
machOpProps MO_NatU_Rem = (Just WordRep, [inline])
machOpProps MO_Nat_And = (Just IntRep, [inline, comm])
machOpProps MO_Nat_Or = (Just IntRep, [inline, comm])
machOpProps MO_Nat_Xor = (Just IntRep, [inline, comm])
machOpProps MO_Nat_Not = (Just IntRep, [inline])
machOpProps MO_Nat_Shl = (Just IntRep, [inline])
machOpProps MO_Nat_Shr = (Just IntRep, [inline])
machOpProps MO_Nat_Sar = (Just IntRep, [inline])
machOpProps MO_32U_Eq = (Just IntRep, [inline, comp, comm])
machOpProps MO_32U_Ne = (Just IntRep, [inline, comp, comm])
machOpProps MO_32U_Ge = (Just IntRep, [inline, comp])
machOpProps MO_32U_Le = (Just IntRep, [inline, comp])
machOpProps MO_32U_Gt = (Just IntRep, [inline, comp])
machOpProps MO_32U_Lt = (Just IntRep, [inline, comp])
machOpProps MO_Dbl_Eq = (Just IntRep, [inline, comp, comm])
machOpProps MO_Dbl_Ne = (Just IntRep, [inline, comp, comm])
machOpProps MO_Dbl_Ge = (Just IntRep, [inline, comp])
machOpProps MO_Dbl_Le = (Just IntRep, [inline, comp])
machOpProps MO_Dbl_Gt = (Just IntRep, [inline, comp])
machOpProps MO_Dbl_Lt = (Just IntRep, [inline, comp])
machOpProps MO_Dbl_Add = (Just DoubleRep, [inline, comm])
machOpProps MO_Dbl_Sub = (Just DoubleRep, [inline])
machOpProps MO_Dbl_Mul = (Just DoubleRep, [inline, comm])
machOpProps MO_Dbl_Div = (Just DoubleRep, [inline])
machOpProps MO_Dbl_Pwr = (Just DoubleRep, [])
machOpProps MO_Dbl_Sin = (Just DoubleRep, [])
machOpProps MO_Dbl_Cos = (Just DoubleRep, [])
machOpProps MO_Dbl_Tan = (Just DoubleRep, [])
machOpProps MO_Dbl_Sinh = (Just DoubleRep, [])
machOpProps MO_Dbl_Cosh = (Just DoubleRep, [])
machOpProps MO_Dbl_Tanh = (Just DoubleRep, [])
machOpProps MO_Dbl_Asin = (Just DoubleRep, [])
machOpProps MO_Dbl_Acos = (Just DoubleRep, [])
machOpProps MO_Dbl_Atan = (Just DoubleRep, [])
machOpProps MO_Dbl_Log = (Just DoubleRep, [])
machOpProps MO_Dbl_Exp = (Just DoubleRep, [])
machOpProps MO_Dbl_Sqrt = (Just DoubleRep, [])
machOpProps MO_Dbl_Neg = (Just DoubleRep, [inline])
machOpProps MO_Flt_Add = (Just FloatRep, [inline, comm])
machOpProps MO_Flt_Sub = (Just FloatRep, [inline])
machOpProps MO_Flt_Mul = (Just FloatRep, [inline, comm])
machOpProps MO_Flt_Div = (Just FloatRep, [inline])
machOpProps MO_Flt_Pwr = (Just FloatRep, [])
machOpProps MO_Flt_Eq = (Just IntRep, [inline, comp, comm])
machOpProps MO_Flt_Ne = (Just IntRep, [inline, comp, comm])
machOpProps MO_Flt_Ge = (Just IntRep, [inline, comp])
machOpProps MO_Flt_Le = (Just IntRep, [inline, comp])
machOpProps MO_Flt_Gt = (Just IntRep, [inline, comp])
machOpProps MO_Flt_Lt = (Just IntRep, [inline, comp])
machOpProps MO_Flt_Sin = (Just FloatRep, [])
machOpProps MO_Flt_Cos = (Just FloatRep, [])
machOpProps MO_Flt_Tan = (Just FloatRep, [])
machOpProps MO_Flt_Sinh = (Just FloatRep, [])
machOpProps MO_Flt_Cosh = (Just FloatRep, [])
machOpProps MO_Flt_Tanh = (Just FloatRep, [])
machOpProps MO_Flt_Asin = (Just FloatRep, [])
machOpProps MO_Flt_Acos = (Just FloatRep, [])
machOpProps MO_Flt_Atan = (Just FloatRep, [])
machOpProps MO_Flt_Log = (Just FloatRep, [])
machOpProps MO_Flt_Exp = (Just FloatRep, [])
machOpProps MO_Flt_Sqrt = (Just FloatRep, [])
machOpProps MO_Flt_Neg = (Just FloatRep, [inline])
machOpProps MO_32U_to_NatS = (Just IntRep, [inline])
machOpProps MO_NatS_to_32U = (Just WordRep, [inline])
machOpProps MO_NatS_to_Dbl = (Just DoubleRep, [inline])
machOpProps MO_Dbl_to_NatS = (Just IntRep, [inline])
machOpProps MO_NatS_to_Flt = (Just FloatRep, [inline])
machOpProps MO_Flt_to_NatS = (Just IntRep, [inline])
machOpProps MO_NatS_to_NatU = (Just WordRep, [inline])
machOpProps MO_NatU_to_NatS = (Just IntRep, [inline])
machOpProps MO_NatS_to_NatP = (Just PtrRep, [inline])
machOpProps MO_NatP_to_NatS = (Just IntRep, [inline])
machOpProps MO_NatU_to_NatP = (Just PtrRep, [inline])
machOpProps MO_NatP_to_NatU = (Just WordRep, [inline])
machOpProps MO_Dbl_to_Flt = (Just FloatRep, [inline])
machOpProps MO_Flt_to_Dbl = (Just DoubleRep, [inline])
machOpProps MO_8S_to_NatS = (Just IntRep, [inline])
machOpProps MO_16S_to_NatS = (Just IntRep, [inline])
machOpProps MO_32S_to_NatS = (Just IntRep, [inline])
machOpProps MO_8U_to_NatU = (Just WordRep, [inline])
machOpProps MO_16U_to_NatU = (Just WordRep, [inline])
machOpProps MO_32U_to_NatU = (Just WordRep, [inline])
machOpProps (MO_ReadOSBI offset rep) = (Just rep, [inline])
machOpProps (MO_WriteOSBI offset rep) = (Nothing, [inline])
......@@ -45,7 +45,7 @@ import Literal ( Literal(..) )
import TyCon ( tyConDataCons )
import Name ( NamedThing(..) )
import DataCon ( dataConWrapId )
import Maybes ( Maybe012(..), maybe012ToList, maybeToBool, catMaybes )
import Maybes ( maybeToBool, catMaybes )
import PrimOp ( primOpNeedsWrapper )
import MachOp ( MachOp(..) )
import ForeignCall ( ForeignCall(..) )
......@@ -60,7 +60,7 @@ import BitSet ( BitSet, intBS )
import Outputable
import GlaExts
import Util ( nOfThem, lengthExceeds, listLengthCmp )
import Maybe ( isNothing )
import Maybe ( isNothing, maybeToList )
import ST
......@@ -255,7 +255,7 @@ pprAbsC stmt@(COpStmt results (StgPrimOp op) args vol_regs) _
-- NEW CASES FOR EXPANDED PRIMOPS
-- We have to deal with some of these specially
pprAbsC (CMachOpStmt (Just1 res) (MO_ReadOSBI offw scaleRep)
pprAbsC (CMachOpStmt (Just res) (MO_ReadOSBI offw scaleRep)
[baseAmode, indexAmode] maybe_vols)
_
| isNothing maybe_vols
......@@ -266,7 +266,7 @@ pprAbsC (CMachOpStmt (Just1 res) (MO_ReadOSBI offw scaleRep)
| otherwise
= panic "pprAbsC:MO_ReadOSBI -- out-of-line array indexing ?!?!"
pprAbsC (CMachOpStmt Just0 (MO_WriteOSBI offw scaleRep)
pprAbsC (CMachOpStmt Nothing (MO_WriteOSBI offw scaleRep)
[baseAmode, indexAmode, vAmode] maybe_vols)
_
| isNothing maybe_vols
......@@ -277,18 +277,10 @@ pprAbsC (CMachOpStmt Just0 (MO_WriteOSBI offw scaleRep)
| otherwise
= panic "pprAbsC:MO_WriteOSBI -- out-of-line array indexing ?!?!"
pprAbsC (CMachOpStmt (Just2 res carry) mop [arg1,arg2] maybe_vols) _
| mop `elem` [MO_NatS_AddC, MO_NatS_SubC, MO_NatS_MulC]
= hcat [ pprMachOp_for_C mop,
lparen,
ppr_amode res, comma, ppr_amode carry, comma,
pprAmode arg1, comma, pprAmode arg2,
rparen, semi ]
-- The rest generically.
pprAbsC stmt@(CMachOpStmt (Just1 res) mop [arg1,arg2] maybe_vols) _
= let prefix_fn = mop `elem` [MO_Dbl_Pwr, MO_Flt_Pwr]
pprAbsC stmt@(CMachOpStmt (Just res) mop [arg1,arg2] maybe_vols) _
= let prefix_fn = mop `elem` [MO_Dbl_Pwr, MO_Flt_Pwr, MO_NatS_MulMayOflo]
in
case ppr_maybe_vol_regs maybe_vols of {(saves,restores) ->
saves $$
......@@ -302,7 +294,7 @@ pprAbsC stmt@(CMachOpStmt (Just1 res) mop [arg1,arg2] maybe_vols) _
$$ restores
}
pprAbsC stmt@(CMachOpStmt (Just1 res) mop [arg1] maybe_vols) _
pprAbsC stmt@(CMachOpStmt (Just res) mop [arg1] maybe_vols) _
= case ppr_maybe_vol_regs maybe_vols of {(saves,restores) ->
saves $$
hcat [ppr_amode res, equals,
......@@ -664,6 +656,7 @@ pprMachOp_for_C MO_NatU_Gt = text ">"
pprMachOp_for_C MO_NatU_Lt = text "<"
pprMachOp_for_C MO_NatS_Mul = char '*'
pprMachOp_for_C MO_NatS_MulMayOflo = text "mulIntMayOflo"
pprMachOp_for_C MO_NatS_Quot = char '/'
pprMachOp_for_C MO_NatS_Rem = char '%'
pprMachOp_for_C MO_NatS_Neg = char '-'
......@@ -672,10 +665,6 @@ pprMachOp_for_C MO_NatU_Mul = char '*'
pprMachOp_for_C MO_NatU_Quot = char '/'
pprMachOp_for_C MO_NatU_Rem = char '%'
pprMachOp_for_C MO_NatS_AddC = text "addIntCzh"
pprMachOp_for_C MO_NatS_SubC = text "subIntCzh"
pprMachOp_for_C MO_NatS_MulC = text "mulIntCzh"
pprMachOp_for_C MO_Nat_And = text "&"
pprMachOp_for_C MO_Nat_Or = text "|"
pprMachOp_for_C MO_Nat_Xor = text "^"
......@@ -1718,7 +1707,7 @@ ppr_decls_AbsC (CInitHdr cl_info reg_rel cost_centre _)
where
info_lbl = infoTableLabelFromCI cl_info
ppr_decls_AbsC (CMachOpStmt res _ args _) = ppr_decls_Amodes (maybe012ToList res ++ args)
ppr_decls_AbsC (CMachOpStmt res _ args _) = ppr_decls_Amodes (maybeToList res ++ args)
ppr_decls_AbsC (COpStmt results _ args _) = ppr_decls_Amodes (results ++ args)
ppr_decls_AbsC (CSimultaneous abc) = ppr_decls_AbsC abc
......
......@@ -30,7 +30,7 @@ import ClosureInfo ( infoTableLabelFromCI, entryLabelFromCI,
staticClosureNeedsLink
)
import Literal ( Literal(..), word2IntLit )
import Maybes ( Maybe012(..), maybeToBool )
import Maybes ( maybeToBool )
import StgSyn ( StgOp(..) )
import MachOp ( MachOp(..), resultRepsOfMachOp )
import PrimRep ( isFloatingRep, is64BitRep,
......@@ -414,7 +414,7 @@ Now the PrimOps, some of which may need caller-saves register wrappers.
-- Translate out array indexing primops right here, so that
-- individual targets don't have to deal with them
gencode (CMachOpStmt (Just1 r1) (MO_ReadOSBI off_w rep) [base,index] vols)
gencode (CMachOpStmt (Just r1) (MO_ReadOSBI off_w rep) [base,index] vols)
= returnUs (\xs ->
mkStAssign
rep
......@@ -425,7 +425,8 @@ Now the PrimOps, some of which may need caller-saves register wrappers.
: xs
)
gencode (CMachOpStmt Just0 (MO_WriteOSBI off_w rep) [base,index,val] vols)
-- Ordinary MachOps are passed through unchanged.
gencode (CMachOpStmt Nothing (MO_WriteOSBI off_w rep) [base,index,val] vols)
= returnUs (\xs ->
StAssignMem
rep
......@@ -436,33 +437,14 @@ Now the PrimOps, some of which may need caller-saves register wrappers.
: xs
)
-- Gruesome cases for multiple-result primops
gencode (CMachOpStmt (Just2 r1 r2) mop [arg1, arg2] vols)
| mop `elem` [MO_NatS_AddC, MO_NatS_SubC, MO_NatS_MulC]
= getUniqueUs `thenUs` \ u1 ->
getUniqueUs `thenUs` \ u2 ->
let vr1 = StixVReg u1 IntRep
vr2 = StixVReg u2 IntRep
r1s = a2stix r1
r2s = a2stix r2
in
returnUs (\xs ->
StAssignMachOp (Just2 vr1 vr2) mop [a2stix arg1, a2stix arg2]
: mkStAssign IntRep r1s (StReg (StixTemp vr1))
: mkStAssign IntRep r2s (StReg (StixTemp vr2))
: xs
)
-- Ordinary MachOps are passed through unchanged.
gencode (CMachOpStmt (Just1 r1) mop args vols)
= let (Just1 rep) = resultRepsOfMachOp mop
in
returnUs (\xs ->
mkStAssign rep (a2stix r1)
(StMachOp mop (map a2stix args))
: xs
)
gencode (CMachOpStmt (Just r1) mop args vols)
= case resultRepsOfMachOp mop of
Just rep
-> returnUs (\xs ->
mkStAssign rep (a2stix r1)
(StMachOp mop (map a2stix args))
: xs
)
\end{code}
Now the dreaded conditional jump.
......
......@@ -237,8 +237,6 @@ stixStmt_ConFold stmt
(StAssignMem pk baseRegAddr src)
StAssignMem pk addr src
-> StAssignMem pk (stixExpr_ConFold addr) (stixExpr_ConFold src)
StAssignMachOp lhss mop args
-> StAssignMachOp lhss mop (map stixExpr_ConFold args)
StVoidable expr
-> StVoidable (stixExpr_ConFold expr)
StJump dsts addr
......
......@@ -27,7 +27,7 @@ import CLabel ( CLabel, labelDynamic )
#if sparc_TARGET_ARCH || alpha_TARGET_ARCH
import CLabel ( isAsmTemp )
#endif
import Maybes ( maybeToBool, Maybe012(..) )
import Maybes ( maybeToBool )
import PrimRep ( isFloatingRep, is64BitRep, PrimRep(..),
getPrimRepArrayElemSize )
import Stix ( getNatLabelNCG, StixStmt(..), StixExpr(..),
......@@ -103,8 +103,6 @@ stmtToInstrs stmt = case stmt of
| ncg_target_is_32bit
&& is64BitRep pk -> assignReg_I64Code reg (derefDLL src)
| otherwise -> assignReg_IntCode pk reg (derefDLL src)
StAssignMachOp lhss mop rhss
-> assignMachOp lhss mop rhss
StFallThrough lbl
-- When falling through on the Alpha, we still have to load pv
......@@ -165,9 +163,6 @@ derefDLL tree
StReg _ -> t
_ -> pprPanic "derefDLL: unhandled case"
(pprStixExpr t)
assignMachOp :: Maybe012 StixVReg -> MachOp -> [StixExpr]
-> NatM InstrBlock
\end{code}
%************************************************************************
......@@ -968,6 +963,7 @@ getRegister (StMachOp mop [x, y]) -- dyadic MachOps
MO_NatU_Rem -> trivialCode (REM L) Nothing x y
MO_NatS_Mul -> let op = IMUL L in trivialCode op (Just op) x y
MO_NatU_Mul -> let op = MUL L in trivialCode op (Just op) x y
MO_NatS_MulMayOflo -> imulMayOflo x y
MO_Flt_Add -> trivialFCode FloatRep GADD x y
MO_Flt_Sub -> trivialFCode FloatRep GSUB x y
......@@ -1002,6 +998,31 @@ getRegister (StMachOp mop [x, y]) -- dyadic MachOps
promote x = StMachOp MO_Flt_to_Dbl [x]
demote x = StMachOp MO_Dbl_to_Flt [x]
--------------------
imulMayOflo :: StixExpr -> StixExpr -> NatM Register
imulMayOflo a1 a2
= getNewRegNCG IntRep `thenNat` \ t1 ->
getNewRegNCG IntRep `thenNat` \ t2 ->
getNewRegNCG IntRep `thenNat` \ res_lo ->
getNewRegNCG IntRep `thenNat` \ res_hi ->
getRegister a1 `thenNat` \ reg1 ->
getRegister a2 `thenNat` \ reg2 ->
let code1 = registerCode reg1 t1
code2 = registerCode reg2 t2
src1 = registerName reg1 t1
src2 = registerName reg2 t2
code dst = toOL [
MOV L (OpReg src1) (OpReg res_hi),
MOV L (OpReg src2) (OpReg res_lo),
IMUL64 res_hi res_lo, -- result in res_hi:res_lo
SAR L (ImmInt 31) (OpReg res_lo), -- sign extend lower part
SUB L (OpReg res_hi) (OpReg res_lo), -- compare against upper
MOV L (OpReg res_lo) (OpReg dst)
-- dst==0 if high part == sign extended low part
]
in
returnNat (Any IntRep code)
--------------------
shift_code :: (Imm -> Operand -> Instr)
-> StixExpr
......@@ -1173,41 +1194,6 @@ getRegister leaf
imm = maybeImm leaf
imm__2 = case imm of Just x -> x
assignMachOp (Just2 sv_rr sv_cc) mop [aa,bb]
| mop `elem` [MO_NatS_AddC, MO_NatS_SubC, MO_NatS_MulC]
= getRegister aa `thenNat` \ registeraa ->
getRegister bb `thenNat` \ registerbb ->
getNewRegNCG IntRep `thenNat` \ tmp ->
getNewRegNCG IntRep `thenNat` \ tmpaa ->
getNewRegNCG IntRep `thenNat` \ tmpbb ->
let stixVReg_to_VReg (StixVReg u rep) = mkVReg u rep
rr = stixVReg_to_VReg sv_rr
cc = stixVReg_to_VReg sv_cc
codeaa = registerCode registeraa tmpaa
srcaa = registerName registeraa tmpaa
codebb = registerCode registerbb tmpbb
srcbb = registerName registerbb tmpbb
insn = case mop of MO_NatS_AddC -> ADD; MO_NatS_SubC -> SUB
MO_NatS_MulC -> IMUL
cond = if mop == MO_NatS_MulC then OFLO else CARRY
str = showSDoc (pprMachOp mop)