From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CD4A51F910 for ; Sun, 20 Nov 2022 09:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1668938120; bh=rCdSC2Py/x+st6MZb7zH6Eg1kv71igFe6CZfkMtl28k=; h=From:To:Subject:Date:From; b=FwPDifHDgTwm/ocOsYw25ZsC4dTjuR+PzSOvbm25tA2Ci4FsaSMqU5wKHbMvtJdLw e4uy2/qZoqc18W/+c8AgTc91DYQFsg6XrU2iFlokstv4a6cl5MDLV76A/kJYtFsctz oBPJ+LshPWGH9aUZTvv4ihE4tZhwJ7JMZ9Wy6lX8= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH] build: optionally support XXH3 from xxHash Date: Sun, 20 Nov 2022 09:55:20 +0000 Message-Id: <20221120095520.2424659-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This seems to provide a 2% speedup or so in my test case compared to jhash, but we are only picking 32 of the 64 output bits from XXH3_64bits. Using the 32-bit XXH32 variant did not show any measurable improvement over jhash. --- Makefile.PL | 12 ++++++++++++ mwrap_core.h | 27 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Makefile.PL b/Makefile.PL index 7ea7929..eab1edb 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -31,6 +31,17 @@ END # may be empty chomp(my $INC = `$pkg_config --cflags liburcu-cds liburcu-bp`); my @writemakefile_args = (); +my $ccflags = ''; + +print '# checking libxxhash... '; +chomp(my $xxhash_inc = `$pkg_config --cflags libxxhash`); +if ($? == 0) { + $INC .= " $xxhash_inc"; + $ccflags .= ' -DHAVE_XXHASH'; + say 'yes'; +} else { + say 'no'; +} use IO::Handle; STDOUT->autoflush(1); @@ -68,6 +79,7 @@ say " no on $^O" if $@; push @writemakefile_args, ( NAME => 'Devel::Mwrap', VERSION_FROM => 'lib/Devel/Mwrap.pm', + CCFLAGS => "$Config{ccflags} $ccflags", PREREQ_PM => {}, ABSTRACT_FROM => 'lib/Devel/Mwrap.pm', EXE_FILES => [qw(script/mwrap-perl)], diff --git a/mwrap_core.h b/mwrap_core.h index f3b25b7..dab3e77 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -46,7 +46,23 @@ #include #include #include -#include "jhash.h" + +/* + * XXH3 (truncated to 32-bits) seems to provide a ~2% speedup. + * XXH32 doesn't show improvements over jhash despite rculfhash + * only supporting 32-bit hash values. + */ +#if defined(HAVE_XXHASH) +# define XXH_INLINE_ALL +# include +# if !defined(XXH3_64bits) +# warning XXH3_64bits not defined +# endif +#endif + +#if !defined(XXH3_64bits) +# include "jhash.h" +#endif /* * Perl doesn't have a GC the same way (C) Ruby does, so no GC count. @@ -277,7 +293,16 @@ static const COP *mwp_curcop(void) static void hash_loc(struct src_loc *k, size_t len) { +#if defined(XXH3_64bits) + union { + XXH64_hash_t u64; + uint32_t u32[2]; + } u; + u.u64 = XXH3_64bits(k->k, len); + k->hval = u.u32[1]; +#else k->hval = jhash(k->k, len, 0xdeadbeef); +#endif } static struct src_loc *assign_line(size_t size, const char *file, unsigned line)