Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Speculation: does inlining siphash24 help?

This doesn't get inlined under clang on OS X 10.8 :-(
  • Loading branch information...
commit 1fbf6c21ab4ce210282a95bcab46c8caf9a808b1 1 parent 3734c7f
@bos authored
Showing with 26 additions and 1 deletion.
  1. +14 −0 benchmarks/Benchmarks.hs
  2. +12 −1 benchmarks/cbits/siphash.c
View
14 benchmarks/Benchmarks.hs
@@ -55,6 +55,9 @@ main = do
cSipHash (PS fp off len) =
inlinePerformIO . withForeignPtr fp $ \ptr ->
return $! c_siphash 2 4 k0 k1 (ptr `plusPtr` off) (fromIntegral len)
+ cSipHash24 (PS fp off len) =
+ inlinePerformIO . withForeignPtr fp $ \ptr ->
+ return $! c_siphash24 k0 k1 (ptr `plusPtr` off) (fromIntegral len)
sse41SipHash (PS fp off len) =
inlinePerformIO . withForeignPtr fp $ \ptr ->
return $! sse41_siphash k0 k1 (ptr `plusPtr` off) (fromIntegral len)
@@ -114,6 +117,15 @@ main = do
, bench "512" $ whnf cSipHash bs512
, bench "2^20" $ whnf cSipHash bs1Mb
]
+ , bgroup "cSipHash24"
+ [ bench "5" $ whnf cSipHash24 bs5
+ , bench "8" $ whnf cSipHash24 bs8
+ , bench "11" $ whnf cSipHash24 bs11
+ , bench "40" $ whnf cSipHash24 bs40
+ , bench "128" $ whnf cSipHash24 bs128
+ , bench "512" $ whnf cSipHash24 bs512
+ , bench "2^20" $ whnf cSipHash24 bs1Mb
+ ]
, bgroup "sse41SipHash"
[ bench "5" $ whnf sse41SipHash bs5
, bench "8" $ whnf sse41SipHash bs8
@@ -144,5 +156,7 @@ new (I# n#) = unBA (runST $ ST $ \s1 ->
foreign import ccall unsafe "siphash" c_siphash
:: CInt -> CInt -> Word64 -> Word64 -> Ptr Word8 -> CSize -> Word64
+foreign import ccall unsafe "siphash24" c_siphash24
+ :: Word64 -> Word64 -> Ptr Word8 -> CSize -> Word64
foreign import ccall unsafe "siphash_sse41" sse41_siphash
:: Word64 -> Word64 -> Ptr Word8 -> CSize -> Word64
View
13 benchmarks/cbits/siphash.c
@@ -16,7 +16,8 @@ typedef uint8_t u8;
v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \
} while(0)
-u64 siphash(int c, int d, u64 k0, u64 k1, const u8 *str, size_t len)
+static inline u64 _siphash(int c, int d, u64 k0, u64 k1,
+ const u8 *str, size_t len)
{
u64 v0 = 0x736f6d6570736575ull ^ k0;
u64 v1 = 0x646f72616e646f6dull ^ k1;
@@ -72,3 +73,13 @@ u64 siphash(int c, int d, u64 k0, u64 k1, const u8 *str, size_t len)
b = v0 ^ v1 ^ v2 ^ v3;
return b;
}
+
+u64 siphash(int c, int d, u64 k0, u64 k1, const u8 *str, size_t len)
+{
+ return _siphash(c, d, k0, k1, str, len);
+}
+
+u64 siphash24(u64 k0, u64 k1, const u8 *str, size_t len)
+{
+ return _siphash(2, 4, k0, k1, str, len);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.