From 971877e3767a302d8293bd4fe89d82f3dd847971 Mon Sep 17 00:00:00 2001 From: Peter Breitenlohner Date: Tue, 16 Jun 2015 08:33:44 +0000 Subject: libs/luajit: Slight reorganization git-svn-id: svn://tug.org/texlive/trunk@37562 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/libs/luajit/ChangeLog | 6 +- .../libs/luajit/LuaJIT-2.0.4-PATCHES/ChangeLog | 8 + .../libs/luajit/LuaJIT-2.0.4-PATCHES/TL-Changes | 6 - .../source/libs/luajit/LuaJIT-2.0.4/src/lbitlib.c | 287 --------------------- Build/source/libs/luajit/Makefile.am | 4 +- Build/source/libs/luajit/Makefile.in | 62 ++--- Build/source/libs/luajit/lbitlib.c | 287 +++++++++++++++++++++ 7 files changed, 335 insertions(+), 325 deletions(-) delete mode 100644 Build/source/libs/luajit/LuaJIT-2.0.4-PATCHES/TL-Changes delete mode 100644 Build/source/libs/luajit/LuaJIT-2.0.4/src/lbitlib.c create mode 100644 Build/source/libs/luajit/lbitlib.c (limited to 'Build/source/libs') diff --git a/Build/source/libs/luajit/ChangeLog b/Build/source/libs/luajit/ChangeLog index 93745a1ddf5..9db21fe2c59 100644 --- a/Build/source/libs/luajit/ChangeLog +++ b/Build/source/libs/luajit/ChangeLog @@ -1,3 +1,7 @@ +2015-06-16 Peter Breitenlohner + + * lbitlib.c (new): Moved from LuaJIT-2.0.4/src/ to here. + 2015-06-12 Peter Breitenlohner Import LuaJIT-2.0.4. @@ -11,7 +15,7 @@ * Makefile.am, configure.ac: Build luajit as (possibly shared) Libtool library, install headers, library, and .pc file. - * luajiterror.test: Adapted. + * luajiterr.test: Adapted. 2014-09-20 Peter Breitenlohner diff --git a/Build/source/libs/luajit/LuaJIT-2.0.4-PATCHES/ChangeLog b/Build/source/libs/luajit/LuaJIT-2.0.4-PATCHES/ChangeLog index 30aa570e493..fb756444ba1 100644 --- a/Build/source/libs/luajit/LuaJIT-2.0.4-PATCHES/ChangeLog +++ b/Build/source/libs/luajit/LuaJIT-2.0.4-PATCHES/ChangeLog @@ -1,3 +1,11 @@ +2015-06-12 Peter Breitenlohner + + Import LuaJIT-2.0.4. + + * patch-01-LuaJITTeX: Adapted. + * patch-05-LuaJITTeX: Adapted. + * patch-06-ppc-darwin: Adapted. + 2015-01-19 Peter Breitenlohner * patch-06-ppc-darwin (new): Build fix for PPC OS X. diff --git a/Build/source/libs/luajit/LuaJIT-2.0.4-PATCHES/TL-Changes b/Build/source/libs/luajit/LuaJIT-2.0.4-PATCHES/TL-Changes deleted file mode 100644 index 5dc36ee546f..00000000000 --- a/Build/source/libs/luajit/LuaJIT-2.0.4-PATCHES/TL-Changes +++ /dev/null @@ -1,6 +0,0 @@ -Changes applied to the LuaJIT-2.0.3/ tree as obtained from: - http://luajit.org/download/LuaJIT-2.0.3.tar.gz - -Added: - src/lbitlib.c - diff --git a/Build/source/libs/luajit/LuaJIT-2.0.4/src/lbitlib.c b/Build/source/libs/luajit/LuaJIT-2.0.4/src/lbitlib.c deleted file mode 100644 index 5187bbff0dc..00000000000 --- a/Build/source/libs/luajit/LuaJIT-2.0.4/src/lbitlib.c +++ /dev/null @@ -1,287 +0,0 @@ -/* -** $Id: lbitlib.c,v 1.16 2011/06/20 16:35:23 roberto Exp $ -** Standard library for bitwise operations -** See Copyright Notice in lua.h -*/ - -#define lbitlib_c -#define LUA_LIB - -#include "lua.h" - -#include "lauxlib.h" -#include "lualib.h" - -#include "lj_obj.h" -#include "lj_state.h" - -/* http://lua-users.org/lists/lua-l/2011-01/msg01039.html */ -typedef unsigned int lua_Unsigned; -#define LUA_UNSIGNED unsigned LUA_INT32 - - -#if !defined(lua_unsigned2number) -/* on several machines, coercion from unsigned to double is slow, - so it may be worth to avoid */ -#define lua_unsigned2number(u) \ - (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)( unsigned int )(u)) -#endif - -#if !defined(lua_lock) -#define lua_lock(L) ((void) 0) -#define lua_unlock(L) ((void) 0) -#endif - - -LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) { - lua_Number n=0; - lua_lock(L); -/* printf("u=%d,%u,%x\n",u,u,u); - printf("INT_MAX=%d %u %x, (lua_Unsigned)INT_MAX=%d %u %x (unsigned int)INT_MAX=%d %u %x\n", - INT_MAX,INT_MAX,INT_MAX, - (lua_Unsigned)INT_MAX,(lua_Unsigned)INT_MAX,(lua_Unsigned)INT_MAX, - (unsigned int)INT_MAX,(unsigned int)INT_MAX,(unsigned int)INT_MAX); - printf("((u) <= (lua_Unsigned)INT_MAX) :%d\n",(((unsigned int)u) <= (lua_Unsigned)INT_MAX)); - printf("(lua_Number)(int)(u) =%d,%u,%x\n",(lua_Number)(int)(u),(lua_Number)(int)(u),(lua_Number)(int)(u)); - printf("(lua_Number)(u) =%f,%u,%x\n",(lua_Number)(u),(lua_Number)(u),(lua_Number)(u)); - printf("u=%d,%u,%x\n",u,u,u); -*/ - /*printf("n=%d,%u,%x u=%d,%u,%x\n",n,n,n,u,u,u); */ - n = lua_unsigned2number(u); -/* printf("n=%f \n",n); - printf("u=%d %u %x n=%d %u %x\n",u,u,u,n,n,n); - printf("n=%d %u %x\n",n,n,n); - printf("u=%d,%u,%x\n",u,u,u); -*/ -/* setintptrV(L->top, n); - incr_top(L); - setnumV(L->top, n); -*/ - setnumV(L->top, n); - if (LJ_UNLIKELY(tvisnan(L->top))) - setnanV(L->top); /* Canonicalize injected NaNs. */ - incr_top(L); - /*setnvalue(L->top, n); - api_incr_top(L); - */ - lua_unlock(L); -} - - - - - - -#define luaL_checkunsigned (lua_Unsigned) luaL_checkinteger -/*#define lua_pushunsigned lua_pushinteger*/ - - - -/* number of bits to consider in a number */ -#if !defined(LUA_NBITS) -#define LUA_NBITS 32 -#endif - - -#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) - -/* macro to trim extra bits */ -#define trim(x) ((x) & ALLONES) - - -/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ -#define mask(n) (~((ALLONES << 1) << ((n) - 1))) - - -typedef lua_Unsigned b_uint; - - - -static b_uint andaux (lua_State *L) { - int i, n = lua_gettop(L); - b_uint r = ~(b_uint)0; -/* printf("1 r=%d,%u,%x\n",r,r,r);*/ - for (i = 1; i <= n; i++) - r &= luaL_checkunsigned(L, i); -/* printf("2 r=%d,%u,%x\n",r,r,r); - printf("3 r=%d,%u,%x\n",trim(r),trim(r),trim(r)); -*/ - return trim(r); -} - - -static int b_and (lua_State *L) { - b_uint r = andaux(L); -/* printf("4 r=%d,%u,%x\n",r,r,r);*/ - lua_pushunsigned(L, r); - return 1; -} - - -static int b_test (lua_State *L) { - b_uint r = andaux(L); - lua_pushboolean(L, r != 0); - return 1; -} - - -static int b_or (lua_State *L) { - int i, n = lua_gettop(L); - b_uint r = 0; - for (i = 1; i <= n; i++) - r |= luaL_checkunsigned(L, i); - lua_pushunsigned(L, trim(r)); - return 1; -} - - -static int b_xor (lua_State *L) { - int i, n = lua_gettop(L); - b_uint r = 0; - for (i = 1; i <= n; i++) - r ^= luaL_checkunsigned(L, i); - lua_pushunsigned(L, trim(r)); - return 1; -} - - -static int b_not (lua_State *L) { - b_uint r = ~luaL_checkunsigned(L, 1); - lua_pushunsigned(L, trim(r)); - return 1; -} - - -static int b_shift (lua_State *L, b_uint r, int i) { - if (i < 0) { /* shift right? */ - i = -i; - r = trim(r); - if (i >= LUA_NBITS) r = 0; - else r >>= i; - } - else { /* shift left */ - if (i >= LUA_NBITS) r = 0; - else r <<= i; - r = trim(r); - } - lua_pushunsigned(L, r); - return 1; -} - - -static int b_lshift (lua_State *L) { - return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2)); -} - - -static int b_rshift (lua_State *L) { - return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2)); -} - - -static int b_arshift (lua_State *L) { - b_uint r = luaL_checkunsigned(L, 1); - int i = luaL_checkint(L, 2); - if (i < 0 || !(r & ((b_uint)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) | ~(~(b_uint)0 >> i)); /* add signal bit */ - lua_pushunsigned(L, r); - return 1; - } -} - - -static int b_rot (lua_State *L, int i) { - b_uint r = luaL_checkunsigned(L, 1); - i &= (LUA_NBITS - 1); /* i = i % NBITS */ - r = trim(r); - r = (r << i) | (r >> (LUA_NBITS - i)); - lua_pushunsigned(L, trim(r)); - return 1; -} - - -static int b_lrot (lua_State *L) { - return b_rot(L, luaL_checkint(L, 2)); -} - - -static int b_rrot (lua_State *L) { - return b_rot(L, -luaL_checkint(L, 2)); -} - - -/* -** get field and width arguments for field-manipulation functions, -** checking whether they are valid -*/ -static int fieldargs (lua_State *L, int farg, int *width) { - int f = luaL_checkint(L, farg); - int w = luaL_optint(L, farg + 1, 1); - luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); - luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); - if (f + w > LUA_NBITS) - luaL_error(L, "trying to access non-existent bits"); - *width = w; - return f; -} - - -static int b_extract (lua_State *L) { - int w; - b_uint r = luaL_checkunsigned(L, 1); - int f = fieldargs(L, 2, &w); - r = (r >> f) & mask(w); - lua_pushunsigned(L, r); - return 1; -} - - -static int b_replace (lua_State *L) { - int w; - b_uint r = luaL_checkunsigned(L, 1); - b_uint v = luaL_checkunsigned(L, 2); - int f = fieldargs(L, 3, &w); - int m = mask(w); - v &= m; /* erase bits outside given width */ - r = (r & ~(m << f)) | (v << f); - lua_pushunsigned(L, r); - return 1; -} - - -static const luaL_Reg bitlib[] = { - {"arshift", b_arshift}, - {"band", b_and}, - {"bnot", b_not}, - {"bor", b_or}, - {"bxor", b_xor}, - {"btest", b_test}, - {"extract", b_extract}, - {"lrotate", b_lrot}, - {"lshift", b_lshift}, - {"replace", b_replace}, - {"rrotate", b_rrot}, - {"rshift", b_rshift}, - {NULL, NULL} -}; - - - -/* http://lua-users.org/lists/lua-l/2011-01/msg01039.html */ - -/*LUAMOD_API int luaopen_bit32 (lua_State *L) {*/ -/* luaL_newlib(L, bitlib);*/ -/* return 1;*/ -/*} */ - -int luaopen_bit32 (lua_State *L) { - luaL_register(L, "bit32", bitlib); - return 1; -} - - - diff --git a/Build/source/libs/luajit/Makefile.am b/Build/source/libs/luajit/Makefile.am index c9ce9140986..1b3b6bd8386 100644 --- a/Build/source/libs/luajit/Makefile.am +++ b/Build/source/libs/luajit/Makefile.am @@ -25,9 +25,11 @@ lib_LTLIBRARIES = libtexluajit.la libtexluajit_la_LDFLAGS = -bindir @bindir@ -no-undefined -version-info $(LUAJIT_LT_VERSINFO) +dist_libtexluajit_la_SOURCES = \ + lbitlib.c + nodist_libtexluajit_la_SOURCES = \ $(ljlib_sources) \ - @LUAJIT_TREE@/src/lbitlib.c \ @LUAJIT_TREE@/src/lib_aux.c \ @LUAJIT_TREE@/src/lib_init.c \ @LUAJIT_TREE@/src/lj_alloc.c \ diff --git a/Build/source/libs/luajit/Makefile.in b/Build/source/libs/luajit/Makefile.in index a0c96569f5f..3a7bb22c1c8 100644 --- a/Build/source/libs/luajit/Makefile.in +++ b/Build/source/libs/luajit/Makefile.in @@ -148,18 +148,18 @@ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" \ "$(DESTDIR)$(luajitincludedir)" LTLIBRARIES = $(lib_LTLIBRARIES) @PEOBJ_TRUE@libtexluajit_la_DEPENDENCIES = lj_vm_obj.lo +dist_libtexluajit_la_OBJECTS = lbitlib.lo am__objects_1 = lib_base.lo lib_math.lo lib_bit.lo lib_string.lo \ lib_table.lo lib_io.lo lib_os.lo lib_package.lo lib_debug.lo \ lib_jit.lo lib_ffi.lo am__dirstamp = $(am__leading_dot)dirstamp @PEOBJ_FALSE@am__objects_2 = lj_vm_asm.lo nodist_libtexluajit_la_OBJECTS = $(am__objects_1) \ - @LUAJIT_TREE@/src/lbitlib.lo @LUAJIT_TREE@/src/lib_aux.lo \ - @LUAJIT_TREE@/src/lib_init.lo @LUAJIT_TREE@/src/lj_alloc.lo \ - @LUAJIT_TREE@/src/lj_api.lo @LUAJIT_TREE@/src/lj_asm.lo \ - @LUAJIT_TREE@/src/lj_bc.lo @LUAJIT_TREE@/src/lj_bcread.lo \ - @LUAJIT_TREE@/src/lj_bcwrite.lo @LUAJIT_TREE@/src/lj_carith.lo \ - @LUAJIT_TREE@/src/lj_ccall.lo \ + @LUAJIT_TREE@/src/lib_aux.lo @LUAJIT_TREE@/src/lib_init.lo \ + @LUAJIT_TREE@/src/lj_alloc.lo @LUAJIT_TREE@/src/lj_api.lo \ + @LUAJIT_TREE@/src/lj_asm.lo @LUAJIT_TREE@/src/lj_bc.lo \ + @LUAJIT_TREE@/src/lj_bcread.lo @LUAJIT_TREE@/src/lj_bcwrite.lo \ + @LUAJIT_TREE@/src/lj_carith.lo @LUAJIT_TREE@/src/lj_ccall.lo \ @LUAJIT_TREE@/src/lj_ccallback.lo \ @LUAJIT_TREE@/src/lj_cconv.lo @LUAJIT_TREE@/src/lj_cdata.lo \ @LUAJIT_TREE@/src/lj_char.lo @LUAJIT_TREE@/src/lj_clib.lo \ @@ -184,7 +184,8 @@ nodist_libtexluajit_la_OBJECTS = $(am__objects_1) \ @LUAJIT_TREE@/src/lj_tab.lo @LUAJIT_TREE@/src/lj_trace.lo \ @LUAJIT_TREE@/src/lj_udata.lo @LUAJIT_TREE@/src/lj_vmevent.lo \ @LUAJIT_TREE@/src/lj_vmmath.lo $(am__objects_2) -libtexluajit_la_OBJECTS = $(nodist_libtexluajit_la_OBJECTS) +libtexluajit_la_OBJECTS = $(dist_libtexluajit_la_OBJECTS) \ + $(nodist_libtexluajit_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent @@ -248,9 +249,10 @@ AM_V_CCAS = $(am__v_CCAS_@AM_V@) am__v_CCAS_ = $(am__v_CCAS_@AM_DEFAULT_V@) am__v_CCAS_0 = @echo " CCAS " $@; am__v_CCAS_1 = -SOURCES = $(nodist_libtexluajit_la_SOURCES) $(jittest_SOURCES) \ +SOURCES = $(dist_libtexluajit_la_SOURCES) \ + $(nodist_libtexluajit_la_SOURCES) $(jittest_SOURCES) \ $(nodist_luajittry_SOURCES) -DIST_SOURCES = $(jittest_SOURCES) +DIST_SOURCES = $(dist_libtexluajit_la_SOURCES) $(jittest_SOURCES) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ @@ -672,25 +674,27 @@ AM_CFLAGS = -Wall SUBDIRS = . native include lib_LTLIBRARIES = libtexluajit.la libtexluajit_la_LDFLAGS = -bindir @bindir@ -no-undefined -version-info $(LUAJIT_LT_VERSINFO) +dist_libtexluajit_la_SOURCES = \ + lbitlib.c + nodist_libtexluajit_la_SOURCES = $(ljlib_sources) \ - @LUAJIT_TREE@/src/lbitlib.c @LUAJIT_TREE@/src/lib_aux.c \ - @LUAJIT_TREE@/src/lib_init.c @LUAJIT_TREE@/src/lj_alloc.c \ - @LUAJIT_TREE@/src/lj_api.c @LUAJIT_TREE@/src/lj_asm.c \ - @LUAJIT_TREE@/src/lj_bc.c @LUAJIT_TREE@/src/lj_bcread.c \ - @LUAJIT_TREE@/src/lj_bcwrite.c @LUAJIT_TREE@/src/lj_carith.c \ - @LUAJIT_TREE@/src/lj_ccall.c @LUAJIT_TREE@/src/lj_ccallback.c \ - @LUAJIT_TREE@/src/lj_cconv.c @LUAJIT_TREE@/src/lj_cdata.c \ - @LUAJIT_TREE@/src/lj_char.c @LUAJIT_TREE@/src/lj_clib.c \ - @LUAJIT_TREE@/src/lj_cparse.c @LUAJIT_TREE@/src/lj_crecord.c \ - @LUAJIT_TREE@/src/lj_ctype.c @LUAJIT_TREE@/src/lj_debug.c \ - @LUAJIT_TREE@/src/lj_dispatch.c @LUAJIT_TREE@/src/lj_err.c \ - @LUAJIT_TREE@/src/lj_ffrecord.c @LUAJIT_TREE@/src/lj_func.c \ - @LUAJIT_TREE@/src/lj_gc.c @LUAJIT_TREE@/src/lj_gdbjit.c \ - @LUAJIT_TREE@/src/lj_ir.c @LUAJIT_TREE@/src/lj_lex.c \ - @LUAJIT_TREE@/src/lj_lib.c @LUAJIT_TREE@/src/lj_load.c \ - @LUAJIT_TREE@/src/lj_mcode.c @LUAJIT_TREE@/src/lj_meta.c \ - @LUAJIT_TREE@/src/lj_obj.c @LUAJIT_TREE@/src/lj_opt_dce.c \ - @LUAJIT_TREE@/src/lj_opt_fold.c \ + @LUAJIT_TREE@/src/lib_aux.c @LUAJIT_TREE@/src/lib_init.c \ + @LUAJIT_TREE@/src/lj_alloc.c @LUAJIT_TREE@/src/lj_api.c \ + @LUAJIT_TREE@/src/lj_asm.c @LUAJIT_TREE@/src/lj_bc.c \ + @LUAJIT_TREE@/src/lj_bcread.c @LUAJIT_TREE@/src/lj_bcwrite.c \ + @LUAJIT_TREE@/src/lj_carith.c @LUAJIT_TREE@/src/lj_ccall.c \ + @LUAJIT_TREE@/src/lj_ccallback.c @LUAJIT_TREE@/src/lj_cconv.c \ + @LUAJIT_TREE@/src/lj_cdata.c @LUAJIT_TREE@/src/lj_char.c \ + @LUAJIT_TREE@/src/lj_clib.c @LUAJIT_TREE@/src/lj_cparse.c \ + @LUAJIT_TREE@/src/lj_crecord.c @LUAJIT_TREE@/src/lj_ctype.c \ + @LUAJIT_TREE@/src/lj_debug.c @LUAJIT_TREE@/src/lj_dispatch.c \ + @LUAJIT_TREE@/src/lj_err.c @LUAJIT_TREE@/src/lj_ffrecord.c \ + @LUAJIT_TREE@/src/lj_func.c @LUAJIT_TREE@/src/lj_gc.c \ + @LUAJIT_TREE@/src/lj_gdbjit.c @LUAJIT_TREE@/src/lj_ir.c \ + @LUAJIT_TREE@/src/lj_lex.c @LUAJIT_TREE@/src/lj_lib.c \ + @LUAJIT_TREE@/src/lj_load.c @LUAJIT_TREE@/src/lj_mcode.c \ + @LUAJIT_TREE@/src/lj_meta.c @LUAJIT_TREE@/src/lj_obj.c \ + @LUAJIT_TREE@/src/lj_opt_dce.c @LUAJIT_TREE@/src/lj_opt_fold.c \ @LUAJIT_TREE@/src/lj_opt_loop.c @LUAJIT_TREE@/src/lj_opt_mem.c \ @LUAJIT_TREE@/src/lj_opt_narrow.c \ @LUAJIT_TREE@/src/lj_opt_sink.c \ @@ -843,8 +847,6 @@ clean-libLTLIBRARIES: @LUAJIT_TREE@/src/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) @LUAJIT_TREE@/src/$(DEPDIR) @: > @LUAJIT_TREE@/src/$(DEPDIR)/$(am__dirstamp) -@LUAJIT_TREE@/src/lbitlib.lo: @LUAJIT_TREE@/src/$(am__dirstamp) \ - @LUAJIT_TREE@/src/$(DEPDIR)/$(am__dirstamp) @LUAJIT_TREE@/src/lib_aux.lo: @LUAJIT_TREE@/src/$(am__dirstamp) \ @LUAJIT_TREE@/src/$(DEPDIR)/$(am__dirstamp) @LUAJIT_TREE@/src/lib_init.lo: @LUAJIT_TREE@/src/$(am__dirstamp) \ @@ -978,6 +980,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jittest-jittest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lbitlib.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib_base.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib_bit.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib_debug.Plo@am__quote@ @@ -989,7 +992,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib_package.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib_string.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib_table.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@@LUAJIT_TREE@/src/$(DEPDIR)/lbitlib.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@@LUAJIT_TREE@/src/$(DEPDIR)/lib_aux.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@@LUAJIT_TREE@/src/$(DEPDIR)/lib_init.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@@LUAJIT_TREE@/src/$(DEPDIR)/lj_alloc.Plo@am__quote@ diff --git a/Build/source/libs/luajit/lbitlib.c b/Build/source/libs/luajit/lbitlib.c new file mode 100644 index 00000000000..5187bbff0dc --- /dev/null +++ b/Build/source/libs/luajit/lbitlib.c @@ -0,0 +1,287 @@ +/* +** $Id: lbitlib.c,v 1.16 2011/06/20 16:35:23 roberto Exp $ +** Standard library for bitwise operations +** See Copyright Notice in lua.h +*/ + +#define lbitlib_c +#define LUA_LIB + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + +#include "lj_obj.h" +#include "lj_state.h" + +/* http://lua-users.org/lists/lua-l/2011-01/msg01039.html */ +typedef unsigned int lua_Unsigned; +#define LUA_UNSIGNED unsigned LUA_INT32 + + +#if !defined(lua_unsigned2number) +/* on several machines, coercion from unsigned to double is slow, + so it may be worth to avoid */ +#define lua_unsigned2number(u) \ + (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)( unsigned int )(u)) +#endif + +#if !defined(lua_lock) +#define lua_lock(L) ((void) 0) +#define lua_unlock(L) ((void) 0) +#endif + + +LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) { + lua_Number n=0; + lua_lock(L); +/* printf("u=%d,%u,%x\n",u,u,u); + printf("INT_MAX=%d %u %x, (lua_Unsigned)INT_MAX=%d %u %x (unsigned int)INT_MAX=%d %u %x\n", + INT_MAX,INT_MAX,INT_MAX, + (lua_Unsigned)INT_MAX,(lua_Unsigned)INT_MAX,(lua_Unsigned)INT_MAX, + (unsigned int)INT_MAX,(unsigned int)INT_MAX,(unsigned int)INT_MAX); + printf("((u) <= (lua_Unsigned)INT_MAX) :%d\n",(((unsigned int)u) <= (lua_Unsigned)INT_MAX)); + printf("(lua_Number)(int)(u) =%d,%u,%x\n",(lua_Number)(int)(u),(lua_Number)(int)(u),(lua_Number)(int)(u)); + printf("(lua_Number)(u) =%f,%u,%x\n",(lua_Number)(u),(lua_Number)(u),(lua_Number)(u)); + printf("u=%d,%u,%x\n",u,u,u); +*/ + /*printf("n=%d,%u,%x u=%d,%u,%x\n",n,n,n,u,u,u); */ + n = lua_unsigned2number(u); +/* printf("n=%f \n",n); + printf("u=%d %u %x n=%d %u %x\n",u,u,u,n,n,n); + printf("n=%d %u %x\n",n,n,n); + printf("u=%d,%u,%x\n",u,u,u); +*/ +/* setintptrV(L->top, n); + incr_top(L); + setnumV(L->top, n); +*/ + setnumV(L->top, n); + if (LJ_UNLIKELY(tvisnan(L->top))) + setnanV(L->top); /* Canonicalize injected NaNs. */ + incr_top(L); + /*setnvalue(L->top, n); + api_incr_top(L); + */ + lua_unlock(L); +} + + + + + + +#define luaL_checkunsigned (lua_Unsigned) luaL_checkinteger +/*#define lua_pushunsigned lua_pushinteger*/ + + + +/* number of bits to consider in a number */ +#if !defined(LUA_NBITS) +#define LUA_NBITS 32 +#endif + + +#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) + +/* macro to trim extra bits */ +#define trim(x) ((x) & ALLONES) + + +/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ +#define mask(n) (~((ALLONES << 1) << ((n) - 1))) + + +typedef lua_Unsigned b_uint; + + + +static b_uint andaux (lua_State *L) { + int i, n = lua_gettop(L); + b_uint r = ~(b_uint)0; +/* printf("1 r=%d,%u,%x\n",r,r,r);*/ + for (i = 1; i <= n; i++) + r &= luaL_checkunsigned(L, i); +/* printf("2 r=%d,%u,%x\n",r,r,r); + printf("3 r=%d,%u,%x\n",trim(r),trim(r),trim(r)); +*/ + return trim(r); +} + + +static int b_and (lua_State *L) { + b_uint r = andaux(L); +/* printf("4 r=%d,%u,%x\n",r,r,r);*/ + lua_pushunsigned(L, r); + return 1; +} + + +static int b_test (lua_State *L) { + b_uint r = andaux(L); + lua_pushboolean(L, r != 0); + return 1; +} + + +static int b_or (lua_State *L) { + int i, n = lua_gettop(L); + b_uint r = 0; + for (i = 1; i <= n; i++) + r |= luaL_checkunsigned(L, i); + lua_pushunsigned(L, trim(r)); + return 1; +} + + +static int b_xor (lua_State *L) { + int i, n = lua_gettop(L); + b_uint r = 0; + for (i = 1; i <= n; i++) + r ^= luaL_checkunsigned(L, i); + lua_pushunsigned(L, trim(r)); + return 1; +} + + +static int b_not (lua_State *L) { + b_uint r = ~luaL_checkunsigned(L, 1); + lua_pushunsigned(L, trim(r)); + return 1; +} + + +static int b_shift (lua_State *L, b_uint r, int i) { + if (i < 0) { /* shift right? */ + i = -i; + r = trim(r); + if (i >= LUA_NBITS) r = 0; + else r >>= i; + } + else { /* shift left */ + if (i >= LUA_NBITS) r = 0; + else r <<= i; + r = trim(r); + } + lua_pushunsigned(L, r); + return 1; +} + + +static int b_lshift (lua_State *L) { + return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkint(L, 2)); +} + + +static int b_rshift (lua_State *L) { + return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkint(L, 2)); +} + + +static int b_arshift (lua_State *L) { + b_uint r = luaL_checkunsigned(L, 1); + int i = luaL_checkint(L, 2); + if (i < 0 || !(r & ((b_uint)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) | ~(~(b_uint)0 >> i)); /* add signal bit */ + lua_pushunsigned(L, r); + return 1; + } +} + + +static int b_rot (lua_State *L, int i) { + b_uint r = luaL_checkunsigned(L, 1); + i &= (LUA_NBITS - 1); /* i = i % NBITS */ + r = trim(r); + r = (r << i) | (r >> (LUA_NBITS - i)); + lua_pushunsigned(L, trim(r)); + return 1; +} + + +static int b_lrot (lua_State *L) { + return b_rot(L, luaL_checkint(L, 2)); +} + + +static int b_rrot (lua_State *L) { + return b_rot(L, -luaL_checkint(L, 2)); +} + + +/* +** get field and width arguments for field-manipulation functions, +** checking whether they are valid +*/ +static int fieldargs (lua_State *L, int farg, int *width) { + int f = luaL_checkint(L, farg); + int w = luaL_optint(L, farg + 1, 1); + luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); + luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); + if (f + w > LUA_NBITS) + luaL_error(L, "trying to access non-existent bits"); + *width = w; + return f; +} + + +static int b_extract (lua_State *L) { + int w; + b_uint r = luaL_checkunsigned(L, 1); + int f = fieldargs(L, 2, &w); + r = (r >> f) & mask(w); + lua_pushunsigned(L, r); + return 1; +} + + +static int b_replace (lua_State *L) { + int w; + b_uint r = luaL_checkunsigned(L, 1); + b_uint v = luaL_checkunsigned(L, 2); + int f = fieldargs(L, 3, &w); + int m = mask(w); + v &= m; /* erase bits outside given width */ + r = (r & ~(m << f)) | (v << f); + lua_pushunsigned(L, r); + return 1; +} + + +static const luaL_Reg bitlib[] = { + {"arshift", b_arshift}, + {"band", b_and}, + {"bnot", b_not}, + {"bor", b_or}, + {"bxor", b_xor}, + {"btest", b_test}, + {"extract", b_extract}, + {"lrotate", b_lrot}, + {"lshift", b_lshift}, + {"replace", b_replace}, + {"rrotate", b_rrot}, + {"rshift", b_rshift}, + {NULL, NULL} +}; + + + +/* http://lua-users.org/lists/lua-l/2011-01/msg01039.html */ + +/*LUAMOD_API int luaopen_bit32 (lua_State *L) {*/ +/* luaL_newlib(L, bitlib);*/ +/* return 1;*/ +/*} */ + +int luaopen_bit32 (lua_State *L) { + luaL_register(L, "bit32", bitlib); + return 1; +} + + + -- cgit v1.2.3