From: Nick Mathewson Date: Sat, 26 Apr 2025 00:44:06 +0000 (-0400) Subject: polyval: Remove precomputation for ctmul64 case. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af2015abd2f74f66d6f638c7b464f0b29bd4e666;p=thirdparty%2Ftor.git polyval: Remove precomputation for ctmul64 case. In my benchmarks it saved less than 1%, so it really doesn't make sense to keep it. --- diff --git a/src/ext/polyval/ctmul64.c b/src/ext/polyval/ctmul64.c index 1b10aa196f..c7fc1c3acd 100644 --- a/src/ext/polyval/ctmul64.c +++ b/src/ext/polyval/ctmul64.c @@ -82,9 +82,8 @@ pv_mul_y_h(polyval_t *pv) y1 = pv->y.hi; h0 = pv->key.h.lo; h1 = pv->key.h.hi; - // TODO(nm) does it actually make sense for us to precompute this? - h0r = pv->key.hr.lo; - h1r = pv->key.hr.hi; + h0r = rev64(h0); + h1r = rev64(h1); h2 = h0 ^ h1; h2r = h0r ^ h1r; diff --git a/src/ext/polyval/polyval.c b/src/ext/polyval/polyval.c index cc31a92be9..9109f70479 100644 --- a/src/ext/polyval/polyval.c +++ b/src/ext/polyval/polyval.c @@ -63,10 +63,6 @@ static inline void u128_to_bytes(u128, uint8_t *bytes_out); * (Within the polyval struct, perform "y ^= v"). */ static inline void pv_xor_y(polyval_t *, u128 v); -/** - * Initialize any derived fields in pv. - */ -static inline void pv_init_extra(polyval_key_t *pv); /* ======== * The function which we expect our backend to implement. @@ -139,11 +135,6 @@ pv_xor_y(polyval_t *pv, u128 v) { pv->y = _mm_xor_si128(pv->y, v); } -static inline void -pv_init_extra(polyval_key_t *pv) -{ - (void)pv; -} #elif defined(PV_USE_CTMUL64) #include "ext/polyval/ctmul64.c" @@ -172,12 +163,6 @@ pv_xor_y(polyval_t *pv, u128 val) pv->y.lo ^= val.lo; pv->y.hi ^= val.hi; } -static inline void -pv_init_extra(polyval_key_t *pv) -{ - pv->hr.lo = rev64(pv->h.lo); - pv->hr.hi = rev64(pv->h.hi); -} #elif defined(PV_USE_CTMUL) #include "ext/polyval/ctmul.c" @@ -207,18 +192,12 @@ pv_xor_y(polyval_t *pv, u128 val) pv->y.v[i] ^= val.v[i]; } } -static inline void -pv_init_extra(polyval_key_t *pv) -{ - (void)pv; -} #endif void polyval_key_init(polyval_key_t *pvk, const uint8_t *key) { pvk->h = u128_from_bytes(key); - pv_init_extra(pvk); } void polyval_init(polyval_t *pv, const uint8_t *key) diff --git a/src/ext/polyval/polyval.h b/src/ext/polyval/polyval.h index 5bfaae1e88..a0e71e81bd 100644 --- a/src/ext/polyval/polyval.h +++ b/src/ext/polyval/polyval.h @@ -57,11 +57,6 @@ typedef struct pv_u128_ { /** A key for a polyval hash, plus any precomputed key material. */ typedef struct polyval_key_t { pv_u128_ h; -#ifdef PV_USE_CTMUL64 - /** The elements of the key in bit-reversed form. - * (Used as an optimization.) */ - pv_u128_ hr; -#endif } polyval_key_t; /**