Skip to content

Commit b4697f0

Browse files
author
H. Peter Anvin
committed
Conditionalize __builtin_prefetch() on it existing!!
You have to check that something that isn't standard C actually exists before trying to use it... Cc: Colin Ian King <colin.i.king@intel.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1 parent d6dc97d commit b4697f0

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ dnl Some rather useful gcc extensions...
278278
dnl
279279
PA_HAVE_FUNC(__builtin_constant_p, (0))
280280
PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2))
281+
PA_HAVE_FUNC(__builtin_prefetch, (NULL))
281282

282283
dnl
283284
dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)

include/compiler.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,20 @@ static inline void *mempset(void *dst, int c, size_t n)
320320
* Hints to the compiler that a particular branch of code is more or
321321
* less likely to be taken.
322322
*/
323-
#if HAVE___BUILTIN_EXPECT
323+
#ifdef HAVE___BUILTIN_EXPECT
324324
# define likely(x) __builtin_expect(bool(x), true)
325325
# define unlikely(x) __builtin_expect(bool(x), false)
326326
#else
327327
# define likely(x) bool(x)
328328
# define unlikely(x) bool(x)
329329
#endif
330330

331+
#ifdef HAVE___BUILTIN_PREFETCH
332+
# define prefetch(x) __builtin_prefetch(x)
333+
#else
334+
# define prefetch(x) ((void)(x))
335+
#endif
336+
331337
/*
332338
* Attributes
333339
*/

nasmlib/hashtbl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ 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);
83+
prefetch(key);
8484

8585
return hash_findb(head, key, strlen(key)+1, insert);
8686
}
@@ -126,7 +126,7 @@ void **hash_findib(struct hash_table *head, const void *key, size_t keylen,
126126
void **hash_findi(struct hash_table *head, const char *key,
127127
struct hash_insert *insert)
128128
{
129-
__builtin_prefetch(key);
129+
prefetch(key);
130130

131131
return hash_findib(head, key, strlen(key)+1, insert);
132132
}

nasmlib/strlist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ strlist_add(struct strlist *list, const char *str)
4848
struct hash_insert hi;
4949
size_t size;
5050

51-
__builtin_prefetch(str);
51+
prefetch(str);
5252

5353
if (!list)
5454
return NULL;

0 commit comments

Comments
 (0)