From 6fc0034e8960cd070a4ef0485efedd2bd0828e96 Mon Sep 17 00:00:00 2001 From: Duncan Coutts <duncan.coutts@worc.ox.ac.uk> Date: Sun, 28 Jan 2007 00:31:03 +0100 Subject: [PATCH] CULong follows the machine word size, unlike CUInt This doubles memory throughput on 64bit arches (tested on x86-64) --- tests/CBenchmark.c | 12 ++++++------ tests/CBenchmark.h | 4 ++-- tests/MemBench.hs | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/CBenchmark.c b/tests/CBenchmark.c index ade422d..c9b6d32 100644 --- a/tests/CBenchmark.c +++ b/tests/CBenchmark.c @@ -19,19 +19,19 @@ unsigned char byteread(unsigned char *a, int bytes) { return n; } -void wordwrite(unsigned int *a, int bytes) { - unsigned int n = 0; +void wordwrite(unsigned long *a, int bytes) { + unsigned long n = 0; int i = 0; - int iterations = bytes / sizeof(unsigned int) ; + int iterations = bytes / sizeof(unsigned long) ; while (i < iterations) { a[i++] = n++; } } -unsigned int wordread(unsigned int *a, int bytes) { - unsigned int n = 0; +unsigned int wordread(unsigned long *a, int bytes) { + unsigned long n = 0; int i = 0; - int iterations = bytes / sizeof(unsigned int); + int iterations = bytes / sizeof(unsigned long); while (i < iterations) { n += a[i++]; } diff --git a/tests/CBenchmark.h b/tests/CBenchmark.h index 4298bbf..3f5d524 100644 --- a/tests/CBenchmark.h +++ b/tests/CBenchmark.h @@ -1,4 +1,4 @@ void bytewrite(unsigned char *a, int bytes); unsigned char byteread(unsigned char *a, int bytes); -void wordwrite(unsigned int *a, int bytes); -unsigned int wordread(unsigned int *a, int bytes); +void wordwrite(unsigned long *a, int bytes); +unsigned int wordread(unsigned long *a, int bytes); diff --git a/tests/MemBench.hs b/tests/MemBench.hs index 91963eb..fb19a0b 100644 --- a/tests/MemBench.hs +++ b/tests/MemBench.hs @@ -48,18 +48,18 @@ hs_byteread ptr bytes = loop 0 0 | otherwise = do x <- peekByteOff ptr i loop (i+1) (n+x) -hs_wordwrite :: Ptr CUInt -> Int -> IO () +hs_wordwrite :: Ptr CULong -> Int -> IO () hs_wordwrite ptr bytes = loop 0 0 - where iterations = bytes `div` sizeOf (undefined :: CUInt) - loop :: Int -> CUInt -> IO () + where iterations = bytes `div` sizeOf (undefined :: CULong) + loop :: Int -> CULong -> IO () loop !i !n | i == iterations = return () | otherwise = do pokeByteOff ptr i n loop (i+1) (n+1) -hs_wordread :: Ptr CUInt -> Int -> IO CUInt +hs_wordread :: Ptr CULong -> Int -> IO CULong hs_wordread ptr bytes = loop 0 0 - where iterations = bytes `div` sizeOf (undefined :: CUInt) - loop :: Int -> CUInt -> IO CUInt + where iterations = bytes `div` sizeOf (undefined :: CULong) + loop :: Int -> CULong -> IO CULong loop !i !n | i == iterations = return n | otherwise = do x <- peekByteOff ptr i loop (i+1) (n+x) -- GitLab