mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-02-17 17:19:35 +08:00
Introduce cold function attribute
Attribute to deemphasize certain code paths. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
6feef84f25
commit
6686fc627e
@ -87,7 +87,7 @@ void nasm_error(int severity, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
no_return nasm_fatal(int flags, const char *fmt, ...)
|
fatal_func nasm_fatal(int flags, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ no_return nasm_fatal(int flags, const char *fmt, ...)
|
|||||||
abort(); /* We should never get here */
|
abort(); /* We should never get here */
|
||||||
}
|
}
|
||||||
|
|
||||||
no_return nasm_panic(int flags, const char *fmt, ...)
|
fatal_func nasm_panic(int flags, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -105,12 +105,12 @@ no_return nasm_panic(int flags, const char *fmt, ...)
|
|||||||
abort(); /* We should never get here */
|
abort(); /* We should never get here */
|
||||||
}
|
}
|
||||||
|
|
||||||
no_return nasm_panic_from_macro(const char *file, int line)
|
fatal_func nasm_panic_from_macro(const char *file, int line)
|
||||||
{
|
{
|
||||||
nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", file, line);
|
nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
no_return nasm_assert_failed(const char *file, int line, const char *msg)
|
fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
|
||||||
{
|
{
|
||||||
nasm_panic(0, "assertion %s failed at %s:%d", msg, file, line);
|
nasm_panic(0, "assertion %s failed at %s:%d", msg, file, line);
|
||||||
}
|
}
|
||||||
|
@ -223,6 +223,7 @@ PA_FUNC_ATTRIBUTE(alloc_size, (1))
|
|||||||
PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
|
PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
|
||||||
PA_FUNC_ATTRIBUTE(const)
|
PA_FUNC_ATTRIBUTE(const)
|
||||||
PA_FUNC_ATTRIBUTE(pure)
|
PA_FUNC_ATTRIBUTE(pure)
|
||||||
|
PA_FUNC_ATTRIBUTE(cold)
|
||||||
PA_FUNC_ATTRIBUTE_ERROR
|
PA_FUNC_ATTRIBUTE_ERROR
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
|
@ -285,6 +285,22 @@ size_t strnlen(const char *s, size_t maxlen);
|
|||||||
# define no_return void
|
# define no_return void
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* How to tell the compiler that a function is unlikely to be executed.
|
||||||
|
* This differs from unlikely() in that it is applied to a function call,
|
||||||
|
* not a boolean condition.
|
||||||
|
*/
|
||||||
|
#ifndef HAVE_FUNC_ATTRIBUTE_COLD
|
||||||
|
# define unlikely_func __attribute__((cold))
|
||||||
|
#else
|
||||||
|
# define unlikely_func
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A fatal function is both unlikely and no_return
|
||||||
|
*/
|
||||||
|
#define fatal_func no_return unlikely_func
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* How to tell the compiler that a function takes a printf-like string
|
* How to tell the compiler that a function takes a printf-like string
|
||||||
*/
|
*/
|
||||||
|
@ -44,9 +44,9 @@
|
|||||||
* An error reporting function should look like this.
|
* An error reporting function should look like this.
|
||||||
*/
|
*/
|
||||||
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
|
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
|
||||||
no_return printf_func(2, 3) nasm_fatal(int flags, const char *fmt, ...);
|
fatal_func printf_func(2, 3) nasm_fatal(int flags, const char *fmt, ...);
|
||||||
no_return printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...);
|
fatal_func printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...);
|
||||||
no_return nasm_panic_from_macro(const char *file, int line);
|
fatal_func nasm_panic_from_macro(const char *file, int line);
|
||||||
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);
|
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);
|
||||||
|
|
||||||
typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
|
typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
|
||||||
|
@ -111,7 +111,7 @@ void nasm_write(const void *, size_t, FILE *);
|
|||||||
/*
|
/*
|
||||||
* NASM assert failure
|
* NASM assert failure
|
||||||
*/
|
*/
|
||||||
no_return nasm_assert_failed(const char *, int, const char *);
|
fatal_func nasm_assert_failed(const char *, int, const char *);
|
||||||
#define nasm_assert(x) \
|
#define nasm_assert(x) \
|
||||||
do { \
|
do { \
|
||||||
if (unlikely(!(x))) \
|
if (unlikely(!(x))) \
|
||||||
|
Loading…
Reference in New Issue
Block a user