summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-05 17:23:32 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-05 17:23:32 +0000
commiteb79191f16dea9547ded38413b38f4de3fa78569 (patch)
tree180d91f941c8e4b7958bc7193bf1b12a7d63432e /include
parent756914e57ed6c818155961e43d502132a401cc20 (diff)
Introduce "COLDFUNC" function attribute.
* include/ruby/defines.h: introduce "COLDFUNC" function attribute on several compilers for called unlikely functions. Apply to rb_memerror, rb_warn and rb_bug. A patch form methodmissing <lourens@bearmetal.eu>. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r--include/ruby/defines.h10
-rw-r--r--include/ruby/intern.h2
-rw-r--r--include/ruby/ruby.h4
3 files changed, 13 insertions, 3 deletions
diff --git a/include/ruby/defines.h b/include/ruby/defines.h
index fb80813f05..cbf5537790 100644
--- a/include/ruby/defines.h
+++ b/include/ruby/defines.h
@@ -89,6 +89,16 @@ extern "C" {
#define RB_UNLIKELY(x) (x)
#endif /* __GNUC__ >= 3 */
+/*
+ cold attribute for code layout improvements
+ RUBY_FUNC_ATTRIBUTE not used because MSVC does not like nested func macros
+ */
+#if defined(__clang__) || GCC_VERSION_SINCE(4, 3, 0)
+#define COLDFUNC __attribute__((cold))
+#else
+#define COLDFUNC
+#endif
+
#ifdef __GNUC__
#if defined __MINGW_PRINTF_FORMAT
#define PRINTF_ARGS(decl, string_index, first_to_check) \
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index d60f370a6d..e8d49b820a 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -479,7 +479,7 @@ VALUE rb_file_directory_p(VALUE,VALUE);
VALUE rb_str_encode_ospath(VALUE);
int rb_is_absolute_path(const char *);
/* gc.c */
-NORETURN(void rb_memerror(void));
+COLDFUNC NORETURN(void rb_memerror(void));
PUREFUNC(int rb_during_gc(void));
void rb_gc_mark_locations(const VALUE*, const VALUE*);
void rb_mark_tbl(struct st_table*);
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 89298196f9..9e9423e810 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1901,7 +1901,7 @@ enum rb_io_wait_readwrite {RB_IO_WAIT_READABLE, RB_IO_WAIT_WRITABLE};
PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2);
-PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2);
+COLDFUNC PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2);
NORETURN(void rb_bug_errno(const char*, int));
NORETURN(void rb_sys_fail(const char*));
NORETURN(void rb_sys_fail_str(VALUE));
@@ -1925,7 +1925,7 @@ PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);
PRINTF_ARGS(void rb_compile_warning(const char *, int, const char*, ...), 3, 4);
PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
/* reports always */
-PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
+COLDFUNC PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4);
#define RUBY_BLOCK_CALL_FUNC_TAKES_BLOCKARG 1