diff --git a/hashable-bench/hashable-bench.cabal b/hashable-bench/hashable-bench.cabal index 54e3582..6b67b1f 100644 --- a/hashable-bench/hashable-bench.cabal +++ b/hashable-bench/hashable-bench.cabal @@ -34,8 +34,8 @@ tested-with: extra-source-files: include/HsHashable.h - xxhash/include/HsXXHash.h - xxhash/xxHash-0.8.2/xxhash.h + include/HsXXHash.h + xxHash-0.8.2/xxhash.h flag integer-gmp description: @@ -52,14 +52,20 @@ library other-modules: Data.Hashable.Class + Data.Hashable.FFI Data.Hashable.Generic.Instances Data.Hashable.Imports Data.Hashable.LowLevel Data.Hashable.Mix - + Data.Hashable.XXH3 c-sources: cbits/fnv.c - include-dirs: include + include-dirs: include xxHash-0.8.2/ + includes: + HsHashable.h + HsXXHash.h + xxhash.h + hs-source-dirs: src build-depends: base >=4.10.1.0 && <4.21 @@ -119,15 +125,7 @@ library UnliftedFFITypes ghc-options: -Wall -fwarn-tabs - ghc-options: -optc=-march=native -optc-mtune=native - - include-dirs: xxhash/xxHash-0.8.2/ xxhash/include/ - includes: - HsXXHash.h - xxhash.h - - other-modules: XXH3 FFI - hs-source-dirs: xxhash/src + ghc-options: -optc=-march=native -optc-mtune=native benchmark hashable-benchmark -- We cannot depend on the hashable library directly as that creates @@ -158,8 +156,6 @@ benchmark hashable-benchmark ghc-options: -Wall -O2 default-language: Haskell2010 - - source-repository head type: git location: diff --git a/hashable-bench/xxHash-0.8.2 b/hashable-bench/xxHash-0.8.2 new file mode 120000 index 0000000..6959ef2 --- /dev/null +++ b/hashable-bench/xxHash-0.8.2 @@ -0,0 +1 @@ +../xxHash-0.8.2 \ No newline at end of file diff --git a/hashable-bench/xxhash b/hashable-bench/xxhash deleted file mode 120000 index e2c23f9..0000000 --- a/hashable-bench/xxhash +++ /dev/null @@ -1 +0,0 @@ -../xxhash \ No newline at end of file diff --git a/hashable.cabal b/hashable.cabal index 92d866c..2619315 100644 --- a/hashable.cabal +++ b/hashable.cabal @@ -47,9 +47,9 @@ tested-with: extra-source-files: CHANGES.md include/HsHashable.h + include/HsXXHash.h README.md - xxhash/include/HsXXHash.h - xxhash/xxHash-0.8.2/xxhash.h + xxHash-0.8.2/xxhash.h flag integer-gmp description: @@ -58,6 +58,14 @@ flag integer-gmp manual: False default: True +flag march-native + description: + Use @-march=native@ when compiling C sources. + You may need to disable this flag if you are building distributable binaries + + manual: True + default: True + flag random-initial-seed description: Randomly initialize the initial seed on each final executable invocation @@ -76,12 +84,19 @@ library other-modules: Data.Hashable.Class + Data.Hashable.FFI Data.Hashable.Generic.Instances Data.Hashable.Imports Data.Hashable.LowLevel Data.Hashable.Mix + Data.Hashable.XXH3 + + include-dirs: include xxHash-0.8.2 + includes: + HsHashable.h + HsXXHash.h + xxhash.h - include-dirs: include hs-source-dirs: src build-depends: , base >=4.12.0.0 && <4.21 @@ -150,25 +165,18 @@ library TypeOperators UnliftedFFITypes - ghc-options: -Wall -fwarn-tabs + ghc-options: -Wall + + if flag(march-native) + -- Cabal doesn't pass cc-options to "ordinary" Haskell source compilation + -- https://github.com/haskell/cabal/issues/9801 + ghc-options: -optc=-march=native -optc-mtune=native if impl(ghc >=9.0) -- these flags may abort compilation with GHC-8.10 -- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3295 ghc-options: -Winferred-safe-imports -Wmissing-safe-haskell-mode - include-dirs: xxhash/xxHash-0.8.2/ xxhash/include/ - includes: - HsXXHash.h - xxhash.h - - -- Cabal doesn't pass cc-options to "ordinary" Haskell source compilation - -- https://github.com/haskell/cabal/issues/9801 - ghc-options: -optc=-march=native -optc-mtune=native - - other-modules: XXH3 FFI - hs-source-dirs: xxhash/src - test-suite hashable-tests type: exitcode-stdio-1.0 hs-source-dirs: tests @@ -197,12 +205,36 @@ test-suite hashable-tests if !os(windows) build-depends: unix cpp-options: -DHAVE_MMAP - other-modules: Regress.Mmap other-extensions: CApiFFI ghc-options: -Wall -fno-warn-orphans default-language: Haskell2010 +test-suite xxhash-tests + type: exitcode-stdio-1.0 + hs-source-dirs: tests src + main-is: xxhash-tests.hs + other-modules: + Data.Hashable.FFI + Data.Hashable.XXH3 + + default-language: Haskell2010 + build-depends: + , base + , bytestring + , primitive ^>=0.9.0.0 + , tasty ^>=1.5 + , tasty-hunit ^>=0.10.1 + , tasty-quickcheck ^>=0.10.3 + + include-dirs: include xxHash-0.8.2 + includes: + HsXXHash.h + xxhash.h + + if !impl(ghc >=9.4) + build-depends: data-array-byte >=0.1.0.1 && <0.2 + test-suite hashable-examples type: exitcode-stdio-1.0 build-depends: diff --git a/include/HsHashable.h b/include/HsHashable.h index 120a326..5dee9ef 100644 --- a/include/HsHashable.h +++ b/include/HsHashable.h @@ -1,6 +1,8 @@ #ifndef HS_HASHABLE_H #define HS_HASHABLE_H +#include + uint64_t hs_hashable_init(); #endif diff --git a/xxhash/include/HsXXHash.h b/include/HsXXHash.h similarity index 94% rename from xxhash/include/HsXXHash.h rename to include/HsXXHash.h index 6b3bfae..6373e76 100644 --- a/xxhash/include/HsXXHash.h +++ b/include/HsXXHash.h @@ -1,5 +1,5 @@ -#ifndef HS_XXHASH -#define HS_XXHASH +#ifndef HS_XXHASH_H +#define HS_XXHASH_H #include @@ -32,4 +32,4 @@ static inline void hs_XXH3_64bits_update_u32(XXH3_state_t *statePtr, uint32_t va XXH3_64bits_update(statePtr, &val, sizeof(val)); } -#endif /* HS_XXHASH */ +#endif /* HS_XXHASH_H */ diff --git a/src/Data/Hashable/Class.hs b/src/Data/Hashable/Class.hs index f8117c7..6aec411 100644 --- a/src/Data/Hashable/Class.hs +++ b/src/Data/Hashable/Class.hs @@ -188,8 +188,7 @@ import GHC.Num.Orphans () import Data.Hashable.Imports import Data.Hashable.LowLevel - -import XXH3 +import Data.Hashable.XXH3 #include "MachDeps.h" diff --git a/xxhash/src/FFI.hs b/src/Data/Hashable/FFI.hs similarity index 99% rename from xxhash/src/FFI.hs rename to src/Data/Hashable/FFI.hs index ca32508..e417e54 100644 --- a/xxhash/src/FFI.hs +++ b/src/Data/Hashable/FFI.hs @@ -2,7 +2,7 @@ {-# LANGUAGE MagicHash #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE UnliftedFFITypes #-} -module FFI ( +module Data.Hashable.FFI ( -- * One shot unsafe_xxh3_64bit_withSeed_ptr, unsafe_xxh3_64bit_withSeed_ba, diff --git a/src/Data/Hashable/LowLevel.hs b/src/Data/Hashable/LowLevel.hs index 336768a..bb0b9da 100644 --- a/src/Data/Hashable/LowLevel.hs +++ b/src/Data/Hashable/LowLevel.hs @@ -23,8 +23,7 @@ import System.IO.Unsafe (unsafePerformIO) import Data.Hashable.Imports import Data.Hashable.Mix - -import XXH3 +import Data.Hashable.XXH3 ------------------------------------------------------------------------------- -- Initial seed diff --git a/xxhash/src/XXH3.hs b/src/Data/Hashable/XXH3.hs similarity index 99% rename from xxhash/src/XXH3.hs rename to src/Data/Hashable/XXH3.hs index e8f8e7e..7d7a53d 100644 --- a/xxhash/src/XXH3.hs +++ b/src/Data/Hashable/XXH3.hs @@ -6,7 +6,7 @@ {-# LANGUAGE Trustworthy #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE ViewPatterns #-} -module XXH3 ( +module Data.Hashable.XXH3 ( -- * One shot xxh3_64bit_withSeed_ptr, xxh3_64bit_withSeed_bs, @@ -32,7 +32,7 @@ import Foreign (Ptr) import GHC.Exts (Int (..), MutableByteArray#, newAlignedPinnedByteArray#) import GHC.ST (ST (..)) -import FFI +import Data.Hashable.FFI #if MIN_VERSION_base(4,15,0) import GHC.ForeignPtr (unsafeWithForeignPtr) diff --git a/xxhash/tests/xxhash-tests.hs b/tests/xxhash-tests.hs similarity index 98% rename from xxhash/tests/xxhash-tests.hs rename to tests/xxhash-tests.hs index 28c2c1c..3dd6dfb 100644 --- a/xxhash/tests/xxhash-tests.hs +++ b/tests/xxhash-tests.hs @@ -9,7 +9,7 @@ import Test.Tasty (defaultMain, testGroup) import Test.Tasty.HUnit (testCase, (@=?)) import Test.Tasty.QuickCheck (testProperty, (===)) -import XXH3 +import Data.Hashable.XXH3 main :: IO () main = defaultMain $ testGroup "xxhash" diff --git a/xxhash/xxHash-0.8.2/LICENSE b/xxHash-0.8.2/LICENSE similarity index 100% rename from xxhash/xxHash-0.8.2/LICENSE rename to xxHash-0.8.2/LICENSE diff --git a/xxhash/xxHash-0.8.2/xxhash.h b/xxHash-0.8.2/xxhash.h similarity index 100% rename from xxhash/xxHash-0.8.2/xxhash.h rename to xxHash-0.8.2/xxhash.h