__builtin_expect function isn't available in gcc below version 3

"'Richard Beckmann' via lua-l" <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <sSLnQBY7lONKV23ehalZ-Yi_pu6B5Rb1Ezh7cWuRXkcWnefwhkoYzLuPWZNivcQiNHJktDLinMfbDw7fhtKNKuyu2PGFPHxK3-EXhOdfEYw=@protonmail.com>
Dear Lua team

When compiling Lua 5.4.7 for Haiku targeting x86 32 bit using gcc 2 I encounter that '__builtin_expect' function isn't available. Btw, this specific x86 32 bit target of Haiku uses gcc version 2. This issue is also affecting Lua 5.4.8 and Lua 5.5.0.

I checked out the gcc 2.95 manual at https://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html and the gcc 3.0 manual at https://gcc.gnu.org/onlinedocs/gcc-3.0/gcc_5.html. I recognize that `__builtin_expect` is in the gcc 3.0 manual but not in the gcc 2.95 manual. From there I conclude that `__builtin_expect` is only available since gcc version 3.

Based on this conclusion, one of the Haiku developers Begasus and I created a patch. In the patchset of the Lua 5.4.7 compilation for Haiku at https://github.com/haikuports/haikuports/blob/master/dev-lang/lua/patches/lua-5.4.7.patchset
the patch is as follows.
```
diff --git a/src/luaconf.h b/src/luaconf.h
index 024aa7f..9e24be9 100644
--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -701,7 +701,7 @@
*/
#if !defined(luai_likely)

-#if defined(__GNUC__) && !defined(LUA_NOBUILTIN)
+#if defined(__GNUC__) && ((__GNUC__) >= 3) && !defined(LUA_NOBUILTIN)
#define luai_likely(x) (__builtin_expect(((x) != 0), 1))
#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0))
#else
--
2.45.2
```

In this patch `((__GNUC__) >= 3)` is added to `defined(__GNUC__)` because only gcc 3 and above have support for `__builtin_expect`.

Sincerely,

Richard Beckmann
Sent with Proton Mail secure email.

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/sSLnQBY7lONKV23ehalZ-Yi_pu6B5Rb1Ezh7cWuRXkcWnefwhkoYzLuPWZNivcQiNHJktDLinMfbDw7fhtKNKuyu2PGFPHxK3-EXhOdfEYw%3D%40protonmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.