PALLENE_NBITS should be unsigned
While luaV_shift is doing a signed comparision, in pallene_shiftL and
pallene_shiftR we are doing an unsigned comparison. So we should not be
casting it to a signed integer.
Additionally, I am also moving the definition of PALLENE_LUAINTEGER_NBITS closer
to where it is used.
#define PALLENE_LIKELY(x) __builtin_expect(!!(x), 1)
#define PALLENE_UNLIKELY(x) __builtin_expect(!!(x), 0)
-#define PALLENE_LUAINTEGER_NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT)
-
-
const char *pallene_tag_name(int raw_tag);
void pallene_runtime_tag_check_error(
@@ -171,13 +168,16 @@ lua_Integer pallene_int_modi(
* instruction. In the dynamic case with unknown "y" this implementation is a
* little bit faster Lua because we put the most common case under a single
* level of branching. (~20% speedup) */
+
+#define PALLENE_NBITS (sizeof(lua_Integer) * CHAR_BIT)
+
static inline
lua_Integer pallene_shiftL(lua_Integer x, lua_Integer y)
{
- if (PALLENE_LIKELY(l_castS2U(y) < PALLENE_LUAINTEGER_NBITS)) {
+ if (PALLENE_LIKELY(l_castS2U(y) < PALLENE_NBITS)) {
return intop(<<, x, y);
} else {
- if (l_castS2U(-y) < PALLENE_LUAINTEGER_NBITS) {
+ if (l_castS2U(-y) < PALLENE_NBITS) {
return intop(>>, x, -y);
} else {
return 0;
@@ -187,10 +187,10 @@ lua_Integer pallene_shiftL(lua_Integer x, lua_Integer y)
static inline
lua_Integer pallene_shiftR(lua_Integer x, lua_Integer y)
{
- if (PALLENE_LIKELY(l_castS2U(y) < PALLENE_LUAINTEGER_NBITS)) {
+ if (PALLENE_LIKELY(l_castS2U(y) < PALLENE_NBITS)) {
return intop(>>, x, y);
} else {
- if (l_castS2U(-y) < PALLENE_LUAINTEGER_NBITS) {
+ if (l_castS2U(-y) < PALLENE_NBITS) {
return intop(<<, x, -y);
} else {
return 0;
