@@ -36,14 +36,62 @@ import Prelude hiding (max, min, read, sum)
36
36
import Foreign.Storable (sizeOf )
37
37
38
38
import GHC.Float
39
- import GHC.Int
39
+ import GHC.Int ( Int ( .. ), Int64 ( .. ))
40
40
import GHC.IO
41
41
import GHC.Prim
42
42
43
43
import Data.Array
44
44
import System.Metrics.Distribution.Internal (Stats (.. ))
45
45
import System.Metrics.ThreadId
46
46
47
+ -- 64-bit machine, Int ~ Int64, do it the fast way:
48
+ #if SIZEOF_HSINT == 8
49
+
50
+ #if MIN_VERSION_base(4,17,0)
51
+ int64ToDouble :: Int64 ## -> Double ##
52
+ int64ToDouble i = int2Double## (int64ToInt## i)
53
+
54
+ intToInt64 :: Int ## -> Int64 ##
55
+ intToInt64 = intToInt64##
56
+
57
+ plusInt64 :: Int64 ## -> Int64 ## -> Int64 ##
58
+ plusInt64 = plusInt64##
59
+
60
+ eqInt64 :: Int64 ## -> Int64 ## -> Int ##
61
+ eqInt64 = eqInt64##
62
+
63
+ readInt64Array :: MutableByteArray ## d -> Int ## -> State ## d -> (## State ## d , Int64 ## ## )
64
+ readInt64Array = readInt64Array##
65
+
66
+ writeInt64Array :: MutableByteArray ## d -> Int ## -> Int64 ## -> State ## d -> State ## d
67
+ writeInt64Array = writeInt64Array##
68
+
69
+ #else
70
+ int64ToDouble :: Int ## -> Double ##
71
+ int64ToDouble i = int2Double## i
72
+
73
+ intToInt64 :: Int ## -> Int ##
74
+ intToInt64 i = i
75
+
76
+ plusInt64 :: Int ## -> Int ## -> Int ##
77
+ plusInt64 a b = a +## b
78
+
79
+ eqInt64 :: Int ## -> Int ## -> Int ##
80
+ eqInt64 a b = a ==## b
81
+
82
+ readInt64Array :: MutableByteArray ## d -> Int ## -> State ## d -> (## State ## d , Int ## ## )
83
+ readInt64Array = readIntArray##
84
+
85
+ writeInt64Array :: MutableByteArray ## d -> Int ## -> Int ## -> State ## d -> State ## d
86
+ writeInt64Array = writeIntArray##
87
+ #endif
88
+
89
+ #else
90
+ -- I don't know a better way on 32-bit machines...
91
+ int64ToDouble i =
92
+ case fromIntegral (I64 ## i) of (D ## d) -> d
93
+ #endif
94
+
47
95
-- | An metric for tracking events.
48
96
newtype Distribution = Distribution { unD :: Array Stripe }
49
97
@@ -90,7 +138,7 @@ newDistrib = IO $ \s ->
90
138
-- probably unecessary
91
139
case atomicWriteIntArray## mba lockPos' 0 ## s1 of { s2 ->
92
140
case countPos of { (I ## countPos') ->
93
- case writeInt64Array## mba countPos' (intToInt64## 0 ## ) s2 of { s3 ->
141
+ case writeInt64Array mba countPos' (intToInt64 0 ## ) s2 of { s3 ->
94
142
case meanPos of { (I ## meanPos') ->
95
143
case writeDoubleArray## mba meanPos' 0.0 #### s3 of { s4 ->
96
144
case sumSqDeltaPos of { (I ## sumSqDeltaPos') ->
@@ -148,17 +196,6 @@ spinUnlock mba = \s ->
148
196
case writeIntArray## mba lockPos' 0 ## s of { s2 ->
149
197
s2 }}
150
198
151
- int64ToDouble :: Int64 ## -> Double ##
152
- -- 64-bit machine, Int ~ Int64, do it the fast way:
153
- #if SIZEOF_HSINT == 8
154
- int64ToDouble i = int2Double## (int64ToInt## i)
155
- #else
156
- -- I don't know a better way on 32-bit machines...
157
- int64ToDouble i =
158
- case fromIntegral (I64 ## i) of (D ## d) -> d
159
- #endif
160
-
161
- {-# INLINE int64ToDouble #-}
162
199
163
200
-- | Add the same value to the distribution N times.
164
201
-- Mean and variance are computed according to
@@ -169,7 +206,7 @@ addN distribution (D## val) (I64## n) = IO $ \s ->
169
206
case myStripe' s of { (## s1, (Stripe (Distrib mba)) ## ) ->
170
207
case spinLock mba s1 of { s2 ->
171
208
case countPos of { (I ## countPos') ->
172
- case readInt64Array## mba countPos' s2 of { (## s3, count ## ) ->
209
+ case readInt64Array mba countPos' s2 of { (## s3, count ## ) ->
173
210
case meanPos of { (I ## meanPos') ->
174
211
case readDoubleArray## mba meanPos' s3 of { (## s4, mean ## ) ->
175
212
case sumSqDeltaPos of { (I ## sumSqDeltaPos') ->
@@ -180,11 +217,11 @@ addN distribution (D## val) (I64## n) = IO $ \s ->
180
217
case readDoubleArray## mba minPos' s6 of { (## s7, dMin ## ) ->
181
218
case maxPos of { (I ## maxPos') ->
182
219
case readDoubleArray## mba maxPos' s7 of { (## s8, dMax ## ) ->
183
- case plusInt64## count n of { count' ->
220
+ case plusInt64 count n of { count' ->
184
221
case val -#### mean of { delta ->
185
222
case mean +#### ((int64ToDouble n) *#### delta /#### (int64ToDouble count')) of { mean' ->
186
223
case sumSqDelta +#### (delta *#### (val -#### mean') *#### (int64ToDouble n)) of { sumSqDelta' ->
187
- case writeInt64Array## mba countPos' count' s8 of { s9 ->
224
+ case writeInt64Array mba countPos' count' s8 of { s9 ->
188
225
case writeDoubleArray## mba meanPos' mean' s9 of { s10 ->
189
226
case writeDoubleArray## mba sumSqDeltaPos' sumSqDelta' s10 of { s11 ->
190
227
case writeDoubleArray## mba sumPos' (dSum +#### val) s11 of { s12 ->
@@ -204,9 +241,9 @@ combine :: Distrib -> Distrib -> IO ()
204
241
combine (Distrib bMBA) (Distrib aMBA) = IO $ \ s ->
205
242
case spinLock bMBA s of { s1 ->
206
243
case countPos of { (I ## countPos') ->
207
- case readInt64Array## aMBA countPos' s1 of { (## s2, aCount ## ) ->
208
- case readInt64Array## bMBA countPos' s2 of { (## s3, bCount ## ) ->
209
- case plusInt64## aCount bCount of { count' ->
244
+ case readInt64Array aMBA countPos' s1 of { (## s2, aCount ## ) ->
245
+ case readInt64Array bMBA countPos' s2 of { (## s3, bCount ## ) ->
246
+ case plusInt64 aCount bCount of { count' ->
210
247
case meanPos of { (I ## meanPos' ) ->
211
248
case readDoubleArray## aMBA meanPos' s3 of { (## s4, aMean ## ) ->
212
249
case readDoubleArray## bMBA meanPos' s4 of { (## s5, bMean ## ) ->
@@ -226,8 +263,8 @@ combine (Distrib bMBA) (Distrib aMBA) = IO $ \s ->
226
263
)
227
264
)
228
265
) of { sumSqDelta' ->
229
- case writeInt64Array## aMBA countPos' count' s7 of { s8 ->
230
- case (case eqInt64## count' (intToInt64## 0 ## ) of { 0 ## -> mean'; _ -> 0.0 #### }) of { writeMean ->
266
+ case writeInt64Array aMBA countPos' count' s7 of { s8 ->
267
+ case (case eqInt64 count' (intToInt64 0 ## ) of { 0 ## -> mean'; _ -> 0.0 #### }) of { writeMean ->
231
268
case writeDoubleArray## aMBA meanPos' writeMean s8 of { s9 ->
232
269
case writeDoubleArray## aMBA sumSqDeltaPos' sumSqDelta' s9 of { s10 ->
233
270
case sumPos of { (I ## sumPos') ->
@@ -258,7 +295,7 @@ read distrib = do
258
295
case sumPos of { (I ## sumPos') ->
259
296
case minPos of { (I ## minPos') ->
260
297
case maxPos of { (I ## maxPos') ->
261
- case readInt64Array## mba countPos' s of { (## s1, count ## ) ->
298
+ case readInt64Array mba countPos' s of { (## s1, count ## ) ->
262
299
case readDoubleArray## mba meanPos' s1 of { (## s2, mean ## ) ->
263
300
case readDoubleArray## mba sumSqDeltaPos' s2 of { (## s3, sumSqDelta ## ) ->
264
301
case readDoubleArray## mba sumPos' s3 of { (## s4, dSum ## ) ->
0 commit comments