aboutgitcodebugslistschat
path: root/siphash.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-09-28 11:21:01 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-09-30 12:40:51 +0200
commit04b10a8d907d8ceb09e3adb4885c02f546841bbc (patch)
tree4b2b473f9f690165a1b40d10d9d99248c5bdc3ba /siphash.c
parentceae8422c1ca997b80436e9b574f48146e92d12c (diff)
downloadpasst-04b10a8d907d8ceb09e3adb4885c02f546841bbc.tar
passt-04b10a8d907d8ceb09e3adb4885c02f546841bbc.tar.gz
passt-04b10a8d907d8ceb09e3adb4885c02f546841bbc.tar.bz2
passt-04b10a8d907d8ceb09e3adb4885c02f546841bbc.tar.lz
passt-04b10a8d907d8ceb09e3adb4885c02f546841bbc.tar.xz
passt-04b10a8d907d8ceb09e3adb4885c02f546841bbc.tar.zst
passt-04b10a8d907d8ceb09e3adb4885c02f546841bbc.zip
siphash, checksum: Move TBAA explanation to checksum.c
A number of checksum and hash functions require workarounds for the odd behaviour of Type-Baased Alias Analysis. We have a detailed comment about this on siphash_8b() and other functions reference that. Move the main comment to csume_16b() instead, because we're going to reorganise things in siphash.c. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'siphash.c')
-rw-r--r--siphash.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/siphash.c b/siphash.c
index 91bcc5d..d2b068c 100644
--- a/siphash.c
+++ b/siphash.c
@@ -24,17 +24,8 @@
*
* Return: the 64-bit hash output
*/
-/* Type-Based Alias Analysis (TBAA) optimisation in gcc 11 and 12 (-flto -O2)
- * makes these functions essentially useless by allowing reordering of stores of
- * input data across function calls. Not even declaring @in as char pointer is
- * enough: disable gcc's interpretation of strict aliasing altogether. See also:
- *
- * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106706
- * https://stackoverflow.com/questions/2958633/gcc-strict-aliasing-and-horror-stories
- * https://lore.kernel.org/all/alpine.LFD.2.00.0901121128080.6528__33422.5328093909$1232291247$gmane$org@localhost.localdomain/
- */
/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing")))
+__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
/* cppcheck-suppress unusedFunction */
uint64_t siphash_8b(const uint8_t *in, const uint64_t *k)
{
@@ -53,7 +44,7 @@ uint64_t siphash_8b(const uint8_t *in, const uint64_t *k)
* Return: the 64-bit hash output
*/
/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See siphash_8b() */
+__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
/* cppcheck-suppress unusedFunction */
uint64_t siphash_12b(const uint8_t *in, const uint64_t *k)
{
@@ -73,7 +64,7 @@ uint64_t siphash_12b(const uint8_t *in, const uint64_t *k)
* Return: the 64-bit hash output
*/
/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See siphash_8b() */
+__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
uint64_t siphash_20b(const uint8_t *in, const uint64_t *k)
{
struct siphash_state state = SIPHASH_INIT(k);
@@ -94,7 +85,7 @@ uint64_t siphash_20b(const uint8_t *in, const uint64_t *k)
* Return: the 64-bit hash output
*/
/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See siphash_8b() */
+__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
/* cppcheck-suppress unusedFunction */
uint64_t siphash_32b(const uint8_t *in, const uint64_t *k)
{
@@ -116,7 +107,7 @@ uint64_t siphash_32b(const uint8_t *in, const uint64_t *k)
* Return: the 64-bit hash output
*/
/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See siphash_8b() */
+__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
uint64_t siphash_36b(const uint8_t *in, const uint64_t *k)
{
struct siphash_state state = SIPHASH_INIT(k);