From d6dc97dfc07bacd3b2e297419c90c4254f5bcb41 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Mon, 13 Jan 2025 15:34:44 +0000 Subject: [PATCH] Add prefetching on strings before hashing Turns out that the hotspots of nasm are mainly on string hashing when accessing memory. A simple performance improvement is to prefetch the first cacheline of a string to be hashed. Ran 50 tests on an i9-12900 building intel-ipsec-mb that heavily uses nasm and improved wall clock build times from 56.1 seconds to 53.2 seconds or around 5% speed improvement. Signed-off-by: Colin Ian King --- nasmlib/hashtbl.c | 4 ++++ nasmlib/strlist.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/nasmlib/hashtbl.c b/nasmlib/hashtbl.c index 95567eec..b53ed5b7 100644 --- a/nasmlib/hashtbl.c +++ b/nasmlib/hashtbl.c @@ -80,6 +80,8 @@ void **hash_findb(struct hash_table *head, const void *key, void **hash_find(struct hash_table *head, const char *key, struct hash_insert *insert) { + __builtin_prefetch(key); + return hash_findb(head, key, strlen(key)+1, insert); } @@ -124,6 +126,8 @@ void **hash_findib(struct hash_table *head, const void *key, size_t keylen, void **hash_findi(struct hash_table *head, const char *key, struct hash_insert *insert) { + __builtin_prefetch(key); + return hash_findib(head, key, strlen(key)+1, insert); } diff --git a/nasmlib/strlist.c b/nasmlib/strlist.c index 55cad656..ae6a3f2a 100644 --- a/nasmlib/strlist.c +++ b/nasmlib/strlist.c @@ -48,6 +48,8 @@ strlist_add(struct strlist *list, const char *str) struct hash_insert hi; size_t size; + __builtin_prefetch(str); + if (!list) return NULL;