Skip to content

Commit

Permalink
Review comments and CPP
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpj committed May 4, 2021
1 parent 03ff7c3 commit 9e6ccd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions plutus-core/plutus-core/src/Data/SatInt.hs
Expand Up @@ -155,6 +155,7 @@ efdtIntUp x1 x2 y -- Be careful about overflow!
in SI (I# x1) : go_up x2

-- Requires x2 >= x1
{-# INLINE [0] efdtIntUpFB #-}
efdtIntUpFB :: (SatInt -> r -> r) -> r -> Int# -> Int# -> Int# -> r
efdtIntUpFB c n x1 x2 y -- Be careful about overflow!
| isTrue# (y <# x2) = if isTrue# (y <# x1) then n else SI (I# x1) `c` n
Expand Down Expand Up @@ -186,6 +187,7 @@ efdtIntDn x1 x2 y -- Be careful about underflow!


-- Requires x2 <= x1
{-# INLINE [0] efdtIntDnFB #-}
efdtIntDnFB :: (SatInt -> r -> r) -> r -> Int# -> Int# -> Int# -> r
efdtIntDnFB c n x1 x2 y -- Be careful about underflow!
| isTrue# (y ># x2) = if isTrue# (y ># x1) then n else SI (I# x1) `c` n
Expand Down
@@ -1,9 +1,9 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
Expand All @@ -23,7 +23,6 @@ import PlutusCore.Universe
import PlutusPrelude

import Control.Monad.RWS.Strict
import Data.Bits
import qualified Data.ByteString as BS
import Data.Proxy
import Data.SatInt
Expand All @@ -34,6 +33,8 @@ import GHC.Integer
import GHC.Integer.Logarithms
import GHC.Prim

#include "MachDeps.h"

{- Note [Memory Usage for Plutus]
The base unit is 'ExMemory', which corresponds to machine words. For primitives,
Expand Down Expand Up @@ -72,7 +73,7 @@ just the overflow checks), but the wrapping behaviour of 'Int64' is unacceptable
One other wrinkle is that 'SatInt' is backed by an 'Int' (i.e. a machine integer with platform-dependent
size), rather than an 'Int64' since the primops that we need are only available for 'Int' until GHC 9.2
or so.
or so. So on 32bit platforms, we have much less header
However we mostly care about 64bit platforms, so this isn't too much of a problem. The only one where it could be a problem
is GHCJS, which does present as a 32bit platform. However, we won't care about *performance* on GHCJS, since
Expand All @@ -82,9 +83,14 @@ if we are not on a 64bit platform, then we can just fallback to the slower (but
-}

-- See Note [Integer types for costing]
-- This relies on the fact that TH is run on the *target* platform, so even if we're e.g. cross-compiling to GHCJS
-- this will give the right answer.
type CostingInteger = $(if finiteBitSize (0::SatInt) < 64 then [t|Integer|] else [t|SatInt|])
type CostingInteger =
#if WORD_SIZE_IN_BITS < 64
Integer
#else
SatInt
#endif

-- $(if finiteBitSize (0::SatInt) < 64 then [t|Integer|] else [t|SatInt|])

-- | Counts size in machine words (64bit for the near future)
newtype ExMemory = ExMemory CostingInteger
Expand Down

0 comments on commit 9e6ccd3

Please sign in to comment.