[project @ 1999-12-20 10:34:27 by simonpj]
[ghc-hetmet.git] / ghc / lib / std / CPUTime.lhs
index 27d540f..9d7e6a7 100644 (file)
@@ -4,29 +4,27 @@
 \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, 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 +36,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 +52,29 @@ 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
 
 \end{code}
 
+#else
+
+\begin{code}
+getCPUTime :: IO Integer
+getCPUTime 
+   = do seconds <- nh_getCPUtime
+        return (round (seconds * 1.0e+12))
 
+cpuTimePrecision :: Integer
+cpuTimePrecision
+   = primRunST (
+        do resolution <- nh_getCPUprec
+           return (round (resolution * 1.0e+12))
+     )
+\end{code} 
+#endif