X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FCPUTime.lhs;h=86309a302650a04c0d2149dd0b334a2ae1cd4524;hb=1e2dc51066e0ebaf5d9baa8578386478078a430f;hp=27d540fad322aa748187d56aa4bdc61e63702503;hpb=ff99f2d33f3ea3d90f9739566f1e049a8bb851e8;p=ghc-hetmet.git diff --git a/ghc/lib/std/CPUTime.lhs b/ghc/lib/std/CPUTime.lhs index 27d540f..86309a3 100644 --- a/ghc/lib/std/CPUTime.lhs +++ b/ghc/lib/std/CPUTime.lhs @@ -4,29 +4,28 @@ \section[CPUTime]{Haskell 1.4 CPU Time Library} \begin{code} -{-# OPTIONS -fno-implicit-prelude -#include "cbits/stgio.h" #-} +{-# OPTIONS -#include "cbits/stgio.h" #-} module CPUTime ( getCPUTime, -- :: IO Integer cpuTimePrecision -- :: Integer ) where +\end{code} -#ifdef __HUGS__ -import PreludeBuiltin -#else -import PrelBase -import PrelArr ( ByteArray(..), newIntArray, unsafeFreezeByteArray ) -import PrelMaybe -import PrelNum -import PrelNumExtra -import PrelIOBase -import PrelST -#endif -import IO ( ioError ) -import PrelNum ( Num(..), Integral(..) ) -- To get fromInt/toInt -import Ratio +#ifndef __HUGS__ + +\begin{code} +import Prelude -- To generate the dependency +import PrelGHC ( indexIntArray# ) +import PrelBase ( Int(..) ) +import PrelByteArr ( ByteArray(..), newIntArray ) +import PrelArrExtra ( unsafeFreezeByteArray ) +import PrelNum ( fromInt ) +import PrelIOBase ( IOError(..), IOErrorType( UnsupportedOperation ), + unsafePerformIO, stToIO ) +import Ratio \end{code} Computation @getCPUTime@ returns the number of picoseconds CPU time @@ -38,30 +37,6 @@ in CPU time that the implementation can record, and is given as an integral number of picoseconds. \begin{code} -#ifdef __HUGS__ - -sizeof_int :: Int -sizeof_int = 4 - -getCPUTime :: IO Integer -getCPUTime = do - marr <- primNewByteArray (sizeof_int * 4) - rc <- primGetCPUTime marr - if rc /= 0 then do - x0 <- primReadIntArray marr 0 - x1 <- primReadIntArray marr 1 - x2 <- primReadIntArray marr 2 - x3 <- primReadIntArray marr 3 - return ((fromIntegral x0 * 1000000000 + fromIntegral x1 + - fromIntegral x2 * 1000000000 + fromIntegral x3) - * 1000) - else - ioError (IOError Nothing UnsupportedOperation - "getCPUTime" - "can't get CPU time") - -#else - getCPUTime :: IO Integer getCPUTime = do marr <- stToIO (newIntArray ((0::Int),3)) @@ -78,18 +53,34 @@ getCPUTime = do ioError (IOError Nothing UnsupportedOperation "getCPUTime" "can't get CPU time") -#endif cpuTimePrecision :: Integer cpuTimePrecision = round ((1000000000000::Integer) % fromInt (unsafePerformIO clockTicks)) -\end{code} -\begin{code} foreign import "libHS_cbits" "getCPUTime" unsafe primGetCPUTime :: ByteArray Int -> IO Int -foreign import "libHS_cbits" "clockTicks" clockTicks :: IO Int +foreign import "libHS_cbits" "clockTicks" unsafe clockTicks :: IO Int \end{code} +#else - +\begin{code} +import PrelPrim ( nh_getCPUtime + , nh_getCPUprec + , unsafePerformIO + ) + +getCPUTime :: IO Integer +getCPUTime + = do seconds <- nh_getCPUtime + return (round (seconds * 1.0e+12)) + +cpuTimePrecision :: Integer +cpuTimePrecision + = unsafePerformIO ( + do resolution <- nh_getCPUprec + return (round (resolution * 1.0e+12)) + ) +\end{code} +#endif