Skip to content

Commit d6dc97d

Browse files
Colin Ian Kinghpax
authored andcommitted
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 <colin.i.king@intel.com>
1 parent 6f48f8f commit d6dc97d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

nasmlib/hashtbl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ void **hash_findb(struct hash_table *head, const void *key,
8080
void **hash_find(struct hash_table *head, const char *key,
8181
struct hash_insert *insert)
8282
{
83+
__builtin_prefetch(key);
84+
8385
return hash_findb(head, key, strlen(key)+1, insert);
8486
}
8587

@@ -124,6 +126,8 @@ void **hash_findib(struct hash_table *head, const void *key, size_t keylen,
124126
void **hash_findi(struct hash_table *head, const char *key,
125127
struct hash_insert *insert)
126128
{
129+
__builtin_prefetch(key);
130+
127131
return hash_findib(head, key, strlen(key)+1, insert);
128132
}
129133

nasmlib/strlist.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ strlist_add(struct strlist *list, const char *str)
4848
struct hash_insert hi;
4949
size_t size;
5050

51+
__builtin_prefetch(str);
52+
5153
if (!list)
5254
return NULL;
5355

0 commit comments

Comments
 (0)