Skip to content

Commit

Permalink
Unpack more things, automatically use faster getNthWord if on x86
Browse files Browse the repository at this point in the history
Ignore-this: 7719b379f8d53e93af0dc6736634587

darcs-hash:20101008201210-cef97-a44166b045cfe3bfca8ff1d99bba2fc160365a14.gz
  • Loading branch information
TomMD committed Oct 8, 2010
1 parent 19cca34 commit b26e5fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Data/Digest/Pure/MD5.hs
Expand Up @@ -64,12 +64,12 @@ blockSizeBytesI64 = (fromIntegral blockSizeBytes) :: Int64
blockSizeBits = (fromIntegral md5BlockSize) :: Word64

-- | The type for intermediate results (from md5Update)
data MD5Partial = MD5Par !Word32 !Word32 !Word32 !Word32
data MD5Partial = MD5Par {-# UNPACK #-} !Word32 {-# UNPACK #-} !Word32 {-# UNPACK #-} !Word32 {-# UNPACK #-} !Word32
deriving (Ord, Eq)

-- | The type for final results.
data MD5Context = MD5Ctx { mdPartial :: !MD5Partial,
mdTotalLen :: !Word64 }
data MD5Context = MD5Ctx { mdPartial :: {-# UNPACK #-} !MD5Partial,
mdTotalLen :: {-# UNPACK #-} !Word64 }

-- |After finalizing a context, using md5Finalize, a new type
-- is returned to prevent 're-finalizing' the structure.
Expand Down Expand Up @@ -238,7 +238,7 @@ applyMD5Rounds par@(MD5Par a b c d) w = {-# SCC "applyMD5Rounds" #-}
{-# INLINE (!!) #-}
{-# INLINE applyMD5Rounds #-}

#ifdef LittleEndian
#ifdef FastWordExtract
getNthWord n b = inlinePerformIO (unsafeUseAsCString b (flip peekElemOff n . castPtr))
#else
getNthWord :: Int -> B.ByteString -> Word32
Expand Down
10 changes: 3 additions & 7 deletions pureMD5.cabal
@@ -1,5 +1,5 @@
name: pureMD5
version: 2.1.0.0
version: 2.1.0.1
license: BSD3
license-file: LICENSE
author: Thomas DuBuisson <thomas.dubuisson@gmail.com>
Expand All @@ -14,10 +14,6 @@ cabal-version: >= 1.6
tested-with: GHC == 6.12.1
extra-source-files: Test/MD5.hs Test/md5test.hs

flag LittleEndian
description: Set to true if the architecture is little endian (uses native Word32 loads instead of bytes + shifts, overall 40% speed-up)
default: False

flag test
description: Build a test program
default: False
Expand All @@ -27,8 +23,8 @@ Library
ghc-options: -O2 -funfolding-use-threshold66 -funfolding-creation-threshold66 -fexcess-precision -funbox-strict-fields
hs-source-dirs:
exposed-modules: Data.Digest.Pure.MD5
if flag(LittleEndian)
cpp-options: -DLittleEndian
if arch(i386) || arch(x86-64)
cpp-options: -DFastWordExtract

Executable md5Test
main-is: Test/main.hs
Expand Down

0 comments on commit b26e5fe

Please sign in to comment.