Ticket #4092: partial-4092.patch

File partial-4092.patch, 8.4 KB (added by simonmar, 4 years ago)
  • compiler/cmm/CmmMachOp.hs

    diff --git a/compiler/cmm/CmmMachOp.hs b/compiler/cmm/CmmMachOp.hs
    index aa16684..199cc4d 100644
    a b data MachOp 
    102102  | MO_SS_Conv Width Width      -- Signed int -> Signed int
    103103  | MO_UU_Conv Width Width      -- unsigned int -> unsigned int
    104104  | MO_FF_Conv Width Width      -- Float -> Float
     105
     106  | MO_FU_Coerce Width          -- coerce IEEE 754 float to unsigned int
     107  | MO_UF_Coerce Width          -- coerce unsigned int to IEEE 754 float
    105108  deriving (Eq, Show)
    106109
    107110pprMachOp :: MachOp -> SDoc
    machOpResultType mop tys = 
    337340    MO_FS_Conv _ to     -> cmmBits to
    338341    MO_SF_Conv _ to     -> cmmFloat to
    339342    MO_FF_Conv _ to     -> cmmFloat to
     343
     344    MO_UF_Coerce to     -> cmmFloat to
     345    MO_FU_Coerce to     -> cmmBits to
    340346  where
    341347    (ty1:_) = tys
    342348
    machOpArgReps op = 
    404410    MO_FS_Conv from _   -> [from]
    405411    MO_FF_Conv from _   -> [from]
    406412
     413    MO_UF_Coerce to     -> [to]
     414    MO_FU_Coerce to     -> [to]
     415
    407416-----------------------------------------------------------------------------
    408417-- CallishMachOp
    409418-----------------------------------------------------------------------------
  • compiler/codeGen/CgPrimOp.hs

    diff --git a/compiler/codeGen/CgPrimOp.hs b/compiler/codeGen/CgPrimOp.hs
    index c2a57a4..9baa3d1 100644
    a b emitPrimOp [] CopyByteArrayOp [src,src_off,dst,dst_off,n] live = 
    374374emitPrimOp [] CopyMutableByteArrayOp [src,src_off,dst,dst_off,n] live =
    375375    doCopyMutableByteArrayOp src src_off dst dst_off n live
    376376
     377emitPrimOp [res] CoerceDoubleToWord64 [arg] _
     378  = stmtC (CmmAssign (CmmLocal res) (CmmMachOp (MO_FU_Coerce W64) [arg]))
     379emitPrimOp [res] CoerceWord64ToDouble [arg] _
     380  = stmtC (CmmAssign (CmmLocal res) (CmmMachOp (MO_UF_Coerce W64) [arg]))
     381
     382emitPrimOp [res] CoerceFloatToWord32 [arg] _
     383  = stmtC (CmmAssign (CmmLocal res)
     384                     (CmmMachOp (MO_UU_Conv W32 wordWidth)
     385                                [CmmMachOp (MO_FU_Coerce W32) [arg]]))
     386
     387emitPrimOp [res] CoerceWord32ToFloat [arg] _
     388  = stmtC (CmmAssign (CmmLocal res)
     389                     (CmmMachOp (MO_UF_Coerce W32)
     390                                [CmmMachOp (MO_UU_Conv wordWidth W32) [arg]]))
     391
    377392
    378393-- The rest just translate straightforwardly
    379394emitPrimOp [res] op [arg] _
  • compiler/nativeGen/X86/CodeGen.hs

    diff --git a/compiler/nativeGen/X86/CodeGen.hs b/compiler/nativeGen/X86/CodeGen.hs
    index 49ac543..efa7d1a 100644
    a b getRegister' is32Bit (CmmMachOp mop [x]) = do -- unary MachOps 
    580580        -- the form of a movzl and print it as a movl later.
    581581
    582582      MO_FF_Conv W32 W64
    583         | sse2      -> coerceFP2FP W64 x
     583        | sse2      -> convertFP2FP W64 x
    584584        | otherwise -> conversionNop FF80 x
    585585
    586       MO_FF_Conv W64 W32 -> coerceFP2FP W32 x
     586      MO_FF_Conv W64 W32 -> convertFP2FP W32 x
    587587
    588       MO_FS_Conv from to -> coerceFP2Int from to x
    589       MO_SF_Conv from to -> coerceInt2FP from to x
     588      MO_FS_Conv from to -> convertFP2Int from to x
     589      MO_SF_Conv from to -> convertInt2FP from to x
     590
     591      MO_FU_Coerce w -> coerceFP2Word w x
     592      MO_UF_Coerce w -> coerceWord2FP w x
    590593
    591594      _other -> pprPanic "getRegister" (pprMachOp mop)
    592595   where
    trivialUFCode size instr x = do 
    22922295
    22932296
    22942297--------------------------------------------------------------------------------
    2295 coerceInt2FP :: Width -> Width -> CmmExpr -> NatM Register
    2296 coerceInt2FP from to x = if_sse2 coerce_sse2 coerce_x87
     2298convertInt2FP :: Width -> Width -> CmmExpr -> NatM Register
     2299convertInt2FP from to x = if_sse2 coerce_sse2 coerce_x87
    22972300 where
    22982301   coerce_x87 = do
    22992302     (x_reg, x_code) <- getSomeReg x
    coerceInt2FP from to x = if_sse2 coerce_sse2 coerce_x87 
    23172320        -- works even if the destination rep is <II32
    23182321
    23192322--------------------------------------------------------------------------------
    2320 coerceFP2Int :: Width -> Width -> CmmExpr -> NatM Register
    2321 coerceFP2Int from to x = if_sse2 coerceFP2Int_sse2 coerceFP2Int_x87
     2323convertFP2Int :: Width -> Width -> CmmExpr -> NatM Register
     2324convertFP2Int from to x = if_sse2 coerceFP2Int_sse2 coerceFP2Int_x87
    23222325 where
    23232326   coerceFP2Int_x87 = do
    23242327     (x_reg, x_code) <- getSomeReg x
    coerceFP2Int from to x = if_sse2 coerceFP2Int_sse2 coerceFP2Int_x87 
    23422345     return (Any (intSize to) code)
    23432346         -- works even if the destination rep is <II32
    23442347
     2348--------------------------------------------------------------------------------
     2349coerceFP2Word :: Width -> CmmExpr -> NatM Register
     2350coerceFP2Word width x = if_sse2 coerceFP2Word_sse2 coerceFP2Word_x87
     2351  where
     2352   coerceFP2Word_x87 = do
     2353     (x_reg, x_code) <- getSomeReg x
     2354     let code dst = x_code `snocOL` GCOFTOI (intSize width) x_reg dst
     2355     return (Any (intSize width) code)
     2356   
     2357   coerceFP2Word_sse2 = do
     2358     (x_op, x_code) <- getSomeReg x
     2359     tmp_loc <- newTempLocNat -- question is how to implement this
     2360     let code dst = x_code `snocOL` MOV (intSize width) x_op (OpAddr tmp_loc)
     2361                           `snocOL` MOV (intSize width) (OpAddr tmp_loc) (OpReg dst)
     2362     return (Any (intSize width) code)
     2363
     2364--------------------------------------------------------------------------------
     2365coerceWord2FP :: Width -> CmmExpr -> NatM Register
     2366coerceWord2FP width x = if_sse2 coerceWord2FP_sse2 coerceWord2FP_x87
     2367  where
     2368   coerceWord2FP_x87 = do
     2369     (x_reg, x_code) <- getSomeReg x
     2370     let code dst = x_code `snocOL` GCOITOF (floatSize width) x_reg dst
     2371     return (Any (intSize width) code)
     2372   
     2373   coerceWord2FP_sse2 = do
     2374     (x_op, x_code) <- getSomeReg x
     2375     tmp_loc <- newTempLocNat -- question is how to implement this
     2376     let code dst = x_code `snocOL` MOV (floatSize width) x_op (OpAddr tmp_loc)
     2377                           `snocOL` MOV (intSize width) (OpAddr tmp_loc) (OpReg dst)
     2378     return (Any (intSize width) code)
    23452379
    23462380--------------------------------------------------------------------------------
    2347 coerceFP2FP :: Width -> CmmExpr -> NatM Register
    2348 coerceFP2FP to x = do
     2381convertFP2FP :: Width -> CmmExpr -> NatM Register
     2382convertFP2FP to x = do
    23492383  use_sse2 <- sse2Enabled
    23502384  (x_reg, x_code) <- getSomeReg x
    23512385  let
  • compiler/nativeGen/X86/Instr.hs

    diff --git a/compiler/nativeGen/X86/Instr.hs b/compiler/nativeGen/X86/Instr.hs
    index 0e70dbb..19482b9 100644
    a b data Instr 
    230230       
    231231        | GDTOF       Reg Reg -- src(fpreg), dst(fpreg)
    232232
    233         | GADD        Size Reg Reg Reg -- src1, src2, dst
     233        | GCOFTOI     Size Reg Reg -- coerce float to int
     234        | GCOITOF     Size Reg Reg -- coerce int to float
     235
     236        | GADD        Size Reg Reg Reg -- src1, src2, dst
    234237        | GDIV        Size Reg Reg Reg -- src1, src2, dst
    235238        | GSUB        Size Reg Reg Reg -- src1, src2, dst
    236239        | GMUL        Size Reg Reg Reg -- src1, src2, dst
  • compiler/prelude/primops.txt.pp

    diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp
    index 4949846..8fcc0cc 100644
    a b primop DoubleDecode_2IntOp "decodeDouble_2Int#" GenPrimOp 
    479479    respectively, and the last is the exponent.}
    480480   with out_of_line = True
    481481
     482primop   CoerceDoubleToWord64  "coerceDoubleToWord64#" GenPrimOp
     483   Double# -> WORD64
     484   {Place the literal IEEE-754 representation of a Double# in a
     485   Word64# (or Word# on a 64-bit platform).}
     486
     487primop   CoerceWord64ToDouble  "coerceWord64ToDouble#" GenPrimOp
     488   WORD64 -> Double#
     489   {Convert a {\tt Word64#} ({\tt Word#} on a 64-bit platform) containing an IEEE-754 double into a {\tt Double#}.}
     490
    482491------------------------------------------------------------------------
    483492section "Float#"
    484493        {Operations on single-precision (32-bit) floating-point numbers.}
    primop FloatDecode_IntOp "decodeFloat_Int#" GenPrimOp 
    597606    First {\tt Int\#} in result is the mantissa; second is the exponent.}
    598607   with out_of_line = True
    599608
     609primop   CoerceFloatToWord32  "coerceFloatToWord32#" GenPrimOp
     610   Float# -> Word#
     611   {Place the literal IEEE-754 representation of a Float# in a
     612   Word#.  On a 64-bit platform, the upper 32 bits of the Word# will be zero.}
     613
     614primop   CoerceWord32ToFloat  "coerceWord32ToFloat#" GenPrimOp
     615   Word# -> Float#
     616   {Convert a {\tt Word#} containing an IEEE-754 float into a {\tt Float#}.}
     617
    600618------------------------------------------------------------------------
    601619section "Arrays"
    602620        {Operations on {\tt Array\#}.}