From 5fa680d47f36d2f54d436d47beee2cb7dcf986cb Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 9 Jul 2013 14:49:50 -0300 Subject: no need for type 'b_uint' (lua_Unsigned must have at least 32 bits) --- lbitlib.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/lbitlib.c b/lbitlib.c index 764d1d71..a76307b6 100644 --- a/lbitlib.c +++ b/lbitlib.c @@ -1,5 +1,5 @@ /* -** $Id: lbitlib.c,v 1.19 2013/04/16 18:39:37 roberto Exp roberto $ +** $Id: lbitlib.c,v 1.20 2013/06/21 17:27:24 roberto Exp roberto $ ** Standard library for bitwise operations ** See Copyright Notice in lua.h */ @@ -19,11 +19,8 @@ #endif -/* type with (at least) LUA_NBITS bits */ -typedef unsigned long b_uint; - -#define ALLONES (~(((~(b_uint)0) << (LUA_NBITS - 1)) << 1)) +#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) /* macro to trim extra bits */ @@ -35,9 +32,9 @@ typedef unsigned long b_uint; -static b_uint andaux (lua_State *L) { +static lua_Unsigned andaux (lua_State *L) { int i, n = lua_gettop(L); - b_uint r = ~(b_uint)0; + lua_Unsigned r = ~(lua_Unsigned)0; for (i = 1; i <= n; i++) r &= luaL_checkunsigned(L, i); return trim(r); @@ -45,14 +42,14 @@ static b_uint andaux (lua_State *L) { static int b_and (lua_State *L) { - b_uint r = andaux(L); + lua_Unsigned r = andaux(L); lua_pushunsigned(L, r); return 1; } static int b_test (lua_State *L) { - b_uint r = andaux(L); + lua_Unsigned r = andaux(L); lua_pushboolean(L, r != 0); return 1; } @@ -60,7 +57,7 @@ static int b_test (lua_State *L) { static int b_or (lua_State *L) { int i, n = lua_gettop(L); - b_uint r = 0; + lua_Unsigned r = 0; for (i = 1; i <= n; i++) r |= luaL_checkunsigned(L, i); lua_pushunsigned(L, trim(r)); @@ -70,7 +67,7 @@ static int b_or (lua_State *L) { static int b_xor (lua_State *L) { int i, n = lua_gettop(L); - b_uint r = 0; + lua_Unsigned r = 0; for (i = 1; i <= n; i++) r ^= luaL_checkunsigned(L, i); lua_pushunsigned(L, trim(r)); @@ -79,13 +76,13 @@ static int b_xor (lua_State *L) { static int b_not (lua_State *L) { - b_uint r = ~luaL_checkunsigned(L, 1); + lua_Unsigned r = ~luaL_checkunsigned(L, 1); lua_pushunsigned(L, trim(r)); return 1; } -static int b_shift (lua_State *L, b_uint r, int i) { +static int b_shift (lua_State *L, lua_Unsigned r, int i) { if (i < 0) { /* shift right? */ i = -i; r = trim(r); @@ -113,14 +110,14 @@ static int b_rshift (lua_State *L) { static int b_arshift (lua_State *L) { - b_uint r = luaL_checkunsigned(L, 1); + lua_Unsigned r = luaL_checkunsigned(L, 1); int i = luaL_checkint(L, 2); - if (i < 0 || !(r & ((b_uint)1 << (LUA_NBITS - 1)))) + if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) return b_shift(L, r, -i); else { /* arithmetic shift for 'negative' number */ if (i >= LUA_NBITS) r = ALLONES; else - r = trim((r >> i) | ~(trim(~(b_uint)0) >> i)); /* add signal bit */ + r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i)); /* add signal bit */ lua_pushunsigned(L, r); return 1; } @@ -128,7 +125,7 @@ static int b_arshift (lua_State *L) { static int b_rot (lua_State *L, int i) { - b_uint r = luaL_checkunsigned(L, 1); + lua_Unsigned r = luaL_checkunsigned(L, 1); i &= (LUA_NBITS - 1); /* i = i % NBITS */ r = trim(r); r = (r << i) | (r >> (LUA_NBITS - i)); @@ -167,7 +164,7 @@ static int fieldargs (lua_State *L, int farg, int *width) { static int b_extract (lua_State *L) { int w; - b_uint r = trim(luaL_checkunsigned(L, 1)); + lua_Unsigned r = trim(luaL_checkunsigned(L, 1)); int f = fieldargs(L, 2, &w); r = (r >> f) & mask(w); lua_pushunsigned(L, r); @@ -177,8 +174,8 @@ static int b_extract (lua_State *L) { static int b_replace (lua_State *L) { int w; - b_uint r = trim(luaL_checkunsigned(L, 1)); - b_uint v = luaL_checkunsigned(L, 2); + lua_Unsigned r = trim(luaL_checkunsigned(L, 1)); + lua_Unsigned v = luaL_checkunsigned(L, 2); int f = fieldargs(L, 3, &w); int m = mask(w); v &= m; /* erase bits outside given width */ -- cgit v1.2.3-55-g6feb