immunio 0.15.4 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +0 -27
- data/ext/immunio/Rakefile +9 -0
- data/lib/immunio/plugins/active_record.rb +1 -1
- data/lib/immunio/plugins/active_record_relation.rb +1 -1
- data/lib/immunio/plugins/environment_reporter.rb +20 -0
- data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
- data/lib/immunio/version.rb +1 -1
- data/lib/immunio/vm.rb +1 -2
- data/lua-hooks/Makefile +97 -0
- data/lua-hooks/ext/all.c +41 -52
- data/lua-hooks/ext/all.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
- data/lua-hooks/ext/libinjection/lualib.c +2 -2
- data/lua-hooks/ext/lpeg/lpcap.c +2 -2
- data/lua-hooks/ext/lpeg/lpcap.o +0 -0
- data/lua-hooks/ext/lpeg/lpcode.c +2 -2
- data/lua-hooks/ext/lpeg/lpcode.h +1 -1
- data/lua-hooks/ext/lpeg/lpcode.o +0 -0
- data/lua-hooks/ext/lpeg/lpprint.o +0 -0
- data/lua-hooks/ext/lpeg/lptree.c +2 -2
- data/lua-hooks/ext/lpeg/lptypes.h +1 -1
- data/lua-hooks/ext/lpeg/lpvm.c +2 -2
- data/lua-hooks/ext/lpeg/lpvm.o +0 -0
- data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
- data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
- data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
- data/lua-hooks/ext/luajit/Makefile +159 -0
- data/lua-hooks/ext/luajit/README +16 -0
- data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
- data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
- data/lua-hooks/ext/luajit/doc/changes.html +804 -0
- data/lua-hooks/ext/luajit/doc/contact.html +104 -0
- data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
- data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
- data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
- data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
- data/lua-hooks/ext/luajit/doc/faq.html +186 -0
- data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
- data/lua-hooks/ext/luajit/doc/install.html +659 -0
- data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
- data/lua-hooks/ext/luajit/doc/running.html +309 -0
- data/lua-hooks/ext/luajit/doc/status.html +118 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
- data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
- data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
- data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
- data/lua-hooks/ext/luajit/src/Makefile +697 -0
- data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
- data/lua-hooks/ext/luajit/src/host/README +4 -0
- data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
- data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
- data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
- data/lua-hooks/ext/luajit/src/host/minilua +0 -0
- data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
- data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
- data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
- data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
- data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
- data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
- data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
- data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
- data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
- data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
- data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
- data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
- data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
- data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
- data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
- data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
- data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
- data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
- data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
- data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
- data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
- data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
- data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
- data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
- data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
- data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
- data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
- data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
- data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
- data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
- data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
- data/lua-hooks/ext/luajit/src/lj.supp +26 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
- data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
- data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
- data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
- data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
- data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
- data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
- data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
- data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
- data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
- data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
- data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
- data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
- data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
- data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
- data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
- data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
- data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
- data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
- data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
- data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
- data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
- data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
- data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
- data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
- data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
- data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
- data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
- data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
- data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
- data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
- data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
- data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
- data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
- data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
- data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
- data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
- data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
- data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
- data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
- data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
- data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
- data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
- data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
- data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
- data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
- data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
- data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
- data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
- data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
- data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
- data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
- data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
- data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
- data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
- data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
- data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
- data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
- data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
- data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
- data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
- data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
- data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
- data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
- data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
- data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
- data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
- data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
- data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
- data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
- data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
- data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
- data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
- data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
- data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
- data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
- data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
- data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
- data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
- data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
- data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
- data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
- data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
- data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
- data/lua-hooks/ext/luajit/src/luajit +0 -0
- data/lua-hooks/ext/luajit/src/luajit.c +570 -0
- data/lua-hooks/ext/luajit/src/luajit.h +79 -0
- data/lua-hooks/ext/luajit/src/luajit.o +0 -0
- data/lua-hooks/ext/luajit/src/lualib.h +43 -0
- data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
- data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
- data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
- data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
- data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
- data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
- data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
- data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
- data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
- data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
- data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
- data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
- data/lua-hooks/lib/boot.lua +37 -2
- metadata +372 -69
- data/lua-hooks/ext/bitop/README +0 -22
- data/lua-hooks/ext/bitop/bit.c +0 -189
- data/lua-hooks/ext/extconf.rb +0 -38
- data/lua-hooks/ext/lua/COPYRIGHT +0 -34
- data/lua-hooks/ext/lua/lapi.c +0 -1087
- data/lua-hooks/ext/lua/lapi.h +0 -16
- data/lua-hooks/ext/lua/lauxlib.c +0 -652
- data/lua-hooks/ext/lua/lbaselib.c +0 -659
- data/lua-hooks/ext/lua/lcode.c +0 -831
- data/lua-hooks/ext/lua/lcode.h +0 -76
- data/lua-hooks/ext/lua/ldblib.c +0 -398
- data/lua-hooks/ext/lua/ldebug.c +0 -638
- data/lua-hooks/ext/lua/ldebug.h +0 -33
- data/lua-hooks/ext/lua/ldo.c +0 -519
- data/lua-hooks/ext/lua/ldo.h +0 -57
- data/lua-hooks/ext/lua/ldump.c +0 -164
- data/lua-hooks/ext/lua/lfunc.c +0 -174
- data/lua-hooks/ext/lua/lfunc.h +0 -34
- data/lua-hooks/ext/lua/lgc.c +0 -710
- data/lua-hooks/ext/lua/lgc.h +0 -110
- data/lua-hooks/ext/lua/linit.c +0 -38
- data/lua-hooks/ext/lua/liolib.c +0 -556
- data/lua-hooks/ext/lua/llex.c +0 -463
- data/lua-hooks/ext/lua/llex.h +0 -81
- data/lua-hooks/ext/lua/llimits.h +0 -128
- data/lua-hooks/ext/lua/lmathlib.c +0 -263
- data/lua-hooks/ext/lua/lmem.c +0 -86
- data/lua-hooks/ext/lua/lmem.h +0 -49
- data/lua-hooks/ext/lua/loadlib.c +0 -705
- data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
- data/lua-hooks/ext/lua/lobject.c +0 -214
- data/lua-hooks/ext/lua/lobject.h +0 -381
- data/lua-hooks/ext/lua/lopcodes.c +0 -102
- data/lua-hooks/ext/lua/lopcodes.h +0 -268
- data/lua-hooks/ext/lua/loslib.c +0 -243
- data/lua-hooks/ext/lua/lparser.c +0 -1339
- data/lua-hooks/ext/lua/lparser.h +0 -82
- data/lua-hooks/ext/lua/lstate.c +0 -214
- data/lua-hooks/ext/lua/lstate.h +0 -169
- data/lua-hooks/ext/lua/lstring.c +0 -111
- data/lua-hooks/ext/lua/lstring.h +0 -31
- data/lua-hooks/ext/lua/lstrlib.c +0 -871
- data/lua-hooks/ext/lua/ltable.c +0 -588
- data/lua-hooks/ext/lua/ltable.h +0 -40
- data/lua-hooks/ext/lua/ltablib.c +0 -287
- data/lua-hooks/ext/lua/ltm.c +0 -75
- data/lua-hooks/ext/lua/ltm.h +0 -54
- data/lua-hooks/ext/lua/lua.c +0 -392
- data/lua-hooks/ext/lua/lua.def +0 -131
- data/lua-hooks/ext/lua/lua.rc +0 -28
- data/lua-hooks/ext/lua/lua_dll.rc +0 -26
- data/lua-hooks/ext/lua/luac.c +0 -200
- data/lua-hooks/ext/lua/luac.rc +0 -1
- data/lua-hooks/ext/lua/luaconf.h +0 -763
- data/lua-hooks/ext/lua/luaconf.h.in +0 -724
- data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
- data/lua-hooks/ext/lua/lualib.h +0 -53
- data/lua-hooks/ext/lua/lundump.c +0 -227
- data/lua-hooks/ext/lua/lundump.h +0 -36
- data/lua-hooks/ext/lua/lvm.c +0 -767
- data/lua-hooks/ext/lua/lvm.h +0 -36
- data/lua-hooks/ext/lua/lzio.c +0 -82
- data/lua-hooks/ext/lua/lzio.h +0 -67
- data/lua-hooks/ext/lua/print.c +0 -227
Binary file
|
Binary file
|
@@ -0,0 +1,652 @@
|
|
1
|
+
/*
|
2
|
+
** NARROW: Narrowing of numbers to integers (double to int32_t).
|
3
|
+
** STRIPOV: Stripping of overflow checks.
|
4
|
+
** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#define lj_opt_narrow_c
|
8
|
+
#define LUA_CORE
|
9
|
+
|
10
|
+
#include "lj_obj.h"
|
11
|
+
|
12
|
+
#if LJ_HASJIT
|
13
|
+
|
14
|
+
#include "lj_bc.h"
|
15
|
+
#include "lj_ir.h"
|
16
|
+
#include "lj_jit.h"
|
17
|
+
#include "lj_iropt.h"
|
18
|
+
#include "lj_trace.h"
|
19
|
+
#include "lj_vm.h"
|
20
|
+
#include "lj_strscan.h"
|
21
|
+
|
22
|
+
/* Rationale for narrowing optimizations:
|
23
|
+
**
|
24
|
+
** Lua has only a single number type and this is a FP double by default.
|
25
|
+
** Narrowing doubles to integers does not pay off for the interpreter on a
|
26
|
+
** current-generation x86/x64 machine. Most FP operations need the same
|
27
|
+
** amount of execution resources as their integer counterparts, except
|
28
|
+
** with slightly longer latencies. Longer latencies are a non-issue for
|
29
|
+
** the interpreter, since they are usually hidden by other overhead.
|
30
|
+
**
|
31
|
+
** The total CPU execution bandwidth is the sum of the bandwidth of the FP
|
32
|
+
** and the integer units, because they execute in parallel. The FP units
|
33
|
+
** have an equal or higher bandwidth than the integer units. Not using
|
34
|
+
** them means losing execution bandwidth. Moving work away from them to
|
35
|
+
** the already quite busy integer units is a losing proposition.
|
36
|
+
**
|
37
|
+
** The situation for JIT-compiled code is a bit different: the higher code
|
38
|
+
** density makes the extra latencies much more visible. Tight loops expose
|
39
|
+
** the latencies for updating the induction variables. Array indexing
|
40
|
+
** requires narrowing conversions with high latencies and additional
|
41
|
+
** guards (to check that the index is really an integer). And many common
|
42
|
+
** optimizations only work on integers.
|
43
|
+
**
|
44
|
+
** One solution would be speculative, eager narrowing of all number loads.
|
45
|
+
** This causes many problems, like losing -0 or the need to resolve type
|
46
|
+
** mismatches between traces. It also effectively forces the integer type
|
47
|
+
** to have overflow-checking semantics. This impedes many basic
|
48
|
+
** optimizations and requires adding overflow checks to all integer
|
49
|
+
** arithmetic operations (whereas FP arithmetics can do without).
|
50
|
+
**
|
51
|
+
** Always replacing an FP op with an integer op plus an overflow check is
|
52
|
+
** counter-productive on a current-generation super-scalar CPU. Although
|
53
|
+
** the overflow check branches are highly predictable, they will clog the
|
54
|
+
** execution port for the branch unit and tie up reorder buffers. This is
|
55
|
+
** turning a pure data-flow dependency into a different data-flow
|
56
|
+
** dependency (with slightly lower latency) *plus* a control dependency.
|
57
|
+
** In general, you don't want to do this since latencies due to data-flow
|
58
|
+
** dependencies can be well hidden by out-of-order execution.
|
59
|
+
**
|
60
|
+
** A better solution is to keep all numbers as FP values and only narrow
|
61
|
+
** when it's beneficial to do so. LuaJIT uses predictive narrowing for
|
62
|
+
** induction variables and demand-driven narrowing for index expressions,
|
63
|
+
** integer arguments and bit operations. Additionally it can eliminate or
|
64
|
+
** hoist most of the resulting overflow checks. Regular arithmetic
|
65
|
+
** computations are never narrowed to integers.
|
66
|
+
**
|
67
|
+
** The integer type in the IR has convenient wrap-around semantics and
|
68
|
+
** ignores overflow. Extra operations have been added for
|
69
|
+
** overflow-checking arithmetic (ADDOV/SUBOV) instead of an extra type.
|
70
|
+
** Apart from reducing overall complexity of the compiler, this also
|
71
|
+
** nicely solves the problem where you want to apply algebraic
|
72
|
+
** simplifications to ADD, but not to ADDOV. And the x86/x64 assembler can
|
73
|
+
** use lea instead of an add for integer ADD, but not for ADDOV (lea does
|
74
|
+
** not affect the flags, but it helps to avoid register moves).
|
75
|
+
**
|
76
|
+
**
|
77
|
+
** All of the above has to be reconsidered for architectures with slow FP
|
78
|
+
** operations or without a hardware FPU. The dual-number mode of LuaJIT
|
79
|
+
** addresses this issue. Arithmetic operations are performed on integers
|
80
|
+
** as far as possible and overflow checks are added as needed.
|
81
|
+
**
|
82
|
+
** This implies that narrowing for integer arguments and bit operations
|
83
|
+
** should also strip overflow checks, e.g. replace ADDOV with ADD. The
|
84
|
+
** original overflow guards are weak and can be eliminated by DCE, if
|
85
|
+
** there's no other use.
|
86
|
+
**
|
87
|
+
** A slight twist is that it's usually beneficial to use overflow-checked
|
88
|
+
** integer arithmetics if all inputs are already integers. This is the only
|
89
|
+
** change that affects the single-number mode, too.
|
90
|
+
*/
|
91
|
+
|
92
|
+
/* Some local macros to save typing. Undef'd at the end. */
|
93
|
+
#define IR(ref) (&J->cur.ir[(ref)])
|
94
|
+
#define fins (&J->fold.ins)
|
95
|
+
|
96
|
+
/* Pass IR on to next optimization in chain (FOLD). */
|
97
|
+
#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
|
98
|
+
|
99
|
+
#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))
|
100
|
+
|
101
|
+
/* -- Elimination of narrowing type conversions --------------------------- */
|
102
|
+
|
103
|
+
/* Narrowing of index expressions and bit operations is demand-driven. The
|
104
|
+
** trace recorder emits a narrowing type conversion (CONV.int.num or TOBIT)
|
105
|
+
** in all of these cases (e.g. array indexing or string indexing). FOLD
|
106
|
+
** already takes care of eliminating simple redundant conversions like
|
107
|
+
** CONV.int.num(CONV.num.int(x)) ==> x.
|
108
|
+
**
|
109
|
+
** But the surrounding code is FP-heavy and arithmetic operations are
|
110
|
+
** performed on FP numbers (for the single-number mode). Consider a common
|
111
|
+
** example such as 'x=t[i+1]', with 'i' already an integer (due to induction
|
112
|
+
** variable narrowing). The index expression would be recorded as
|
113
|
+
** CONV.int.num(ADD(CONV.num.int(i), 1))
|
114
|
+
** which is clearly suboptimal.
|
115
|
+
**
|
116
|
+
** One can do better by recursively backpropagating the narrowing type
|
117
|
+
** conversion across FP arithmetic operations. This turns FP ops into
|
118
|
+
** their corresponding integer counterparts. Depending on the semantics of
|
119
|
+
** the conversion they also need to check for overflow. Currently only ADD
|
120
|
+
** and SUB are supported.
|
121
|
+
**
|
122
|
+
** The above example can be rewritten as
|
123
|
+
** ADDOV(CONV.int.num(CONV.num.int(i)), 1)
|
124
|
+
** and then into ADDOV(i, 1) after folding of the conversions. The original
|
125
|
+
** FP ops remain in the IR and are eliminated by DCE since all references to
|
126
|
+
** them are gone.
|
127
|
+
**
|
128
|
+
** [In dual-number mode the trace recorder already emits ADDOV etc., but
|
129
|
+
** this can be further reduced. See below.]
|
130
|
+
**
|
131
|
+
** Special care has to be taken to avoid narrowing across an operation
|
132
|
+
** which is potentially operating on non-integral operands. One obvious
|
133
|
+
** case is when an expression contains a non-integral constant, but ends
|
134
|
+
** up as an integer index at runtime (like t[x+1.5] with x=0.5).
|
135
|
+
**
|
136
|
+
** Operations with two non-constant operands illustrate a similar problem
|
137
|
+
** (like t[a+b] with a=1.5 and b=2.5). Backpropagation has to stop there,
|
138
|
+
** unless it can be proven that either operand is integral (e.g. by CSEing
|
139
|
+
** a previous conversion). As a not-so-obvious corollary this logic also
|
140
|
+
** applies for a whole expression tree (e.g. t[(a+1)+(b+1)]).
|
141
|
+
**
|
142
|
+
** Correctness of the transformation is guaranteed by avoiding to expand
|
143
|
+
** the tree by adding more conversions than the one we would need to emit
|
144
|
+
** if not backpropagating. TOBIT employs a more optimistic rule, because
|
145
|
+
** the conversion has special semantics, designed to make the life of the
|
146
|
+
** compiler writer easier. ;-)
|
147
|
+
**
|
148
|
+
** Using on-the-fly backpropagation of an expression tree doesn't work
|
149
|
+
** because it's unknown whether the transform is correct until the end.
|
150
|
+
** This either requires IR rollback and cache invalidation for every
|
151
|
+
** subtree or a two-pass algorithm. The former didn't work out too well,
|
152
|
+
** so the code now combines a recursive collector with a stack-based
|
153
|
+
** emitter.
|
154
|
+
**
|
155
|
+
** [A recursive backpropagation algorithm with backtracking, employing
|
156
|
+
** skip-list lookup and round-robin caching, emitting stack operations
|
157
|
+
** on-the-fly for a stack-based interpreter -- and all of that in a meager
|
158
|
+
** kilobyte? Yep, compilers are a great treasure chest. Throw away your
|
159
|
+
** textbooks and read the codebase of a compiler today!]
|
160
|
+
**
|
161
|
+
** There's another optimization opportunity for array indexing: it's
|
162
|
+
** always accompanied by an array bounds-check. The outermost overflow
|
163
|
+
** check may be delegated to the ABC operation. This works because ABC is
|
164
|
+
** an unsigned comparison and wrap-around due to overflow creates negative
|
165
|
+
** numbers.
|
166
|
+
**
|
167
|
+
** But this optimization is only valid for constants that cannot overflow
|
168
|
+
** an int32_t into the range of valid array indexes [0..2^27+1). A check
|
169
|
+
** for +-2^30 is safe since -2^31 - 2^30 wraps to 2^30 and 2^31-1 + 2^30
|
170
|
+
** wraps to -2^30-1.
|
171
|
+
**
|
172
|
+
** It's also good enough in practice, since e.g. t[i+1] or t[i-10] are
|
173
|
+
** quite common. So the above example finally ends up as ADD(i, 1)!
|
174
|
+
**
|
175
|
+
** Later on, the assembler is able to fuse the whole array reference and
|
176
|
+
** the ADD into the memory operands of loads and other instructions. This
|
177
|
+
** is why LuaJIT is able to generate very pretty (and fast) machine code
|
178
|
+
** for array indexing. And that, my dear, concludes another story about
|
179
|
+
** one of the hidden secrets of LuaJIT ...
|
180
|
+
*/
|
181
|
+
|
182
|
+
/* Maximum backpropagation depth and maximum stack size. */
|
183
|
+
#define NARROW_MAX_BACKPROP 100
|
184
|
+
#define NARROW_MAX_STACK 256
|
185
|
+
|
186
|
+
/* The stack machine has a 32 bit instruction format: [IROpT | IRRef1]
|
187
|
+
** The lower 16 bits hold a reference (or 0). The upper 16 bits hold
|
188
|
+
** the IR opcode + type or one of the following special opcodes:
|
189
|
+
*/
|
190
|
+
enum {
|
191
|
+
NARROW_REF, /* Push ref. */
|
192
|
+
NARROW_CONV, /* Push conversion of ref. */
|
193
|
+
NARROW_SEXT, /* Push sign-extension of ref. */
|
194
|
+
NARROW_INT /* Push KINT ref. The next code holds an int32_t. */
|
195
|
+
};
|
196
|
+
|
197
|
+
typedef uint32_t NarrowIns;
|
198
|
+
|
199
|
+
#define NARROWINS(op, ref) (((op) << 16) + (ref))
|
200
|
+
#define narrow_op(ins) ((IROpT)((ins) >> 16))
|
201
|
+
#define narrow_ref(ins) ((IRRef1)(ins))
|
202
|
+
|
203
|
+
/* Context used for narrowing of type conversions. */
|
204
|
+
typedef struct NarrowConv {
|
205
|
+
jit_State *J; /* JIT compiler state. */
|
206
|
+
NarrowIns *sp; /* Current stack pointer. */
|
207
|
+
NarrowIns *maxsp; /* Maximum stack pointer minus redzone. */
|
208
|
+
IRRef mode; /* Conversion mode (IRCONV_*). */
|
209
|
+
IRType t; /* Destination type: IRT_INT or IRT_I64. */
|
210
|
+
NarrowIns stack[NARROW_MAX_STACK]; /* Stack holding stack-machine code. */
|
211
|
+
} NarrowConv;
|
212
|
+
|
213
|
+
/* Lookup a reference in the backpropagation cache. */
|
214
|
+
static BPropEntry *narrow_bpc_get(jit_State *J, IRRef1 key, IRRef mode)
|
215
|
+
{
|
216
|
+
ptrdiff_t i;
|
217
|
+
for (i = 0; i < BPROP_SLOTS; i++) {
|
218
|
+
BPropEntry *bp = &J->bpropcache[i];
|
219
|
+
/* Stronger checks are ok, too. */
|
220
|
+
if (bp->key == key && bp->mode >= mode &&
|
221
|
+
((bp->mode ^ mode) & IRCONV_MODEMASK) == 0)
|
222
|
+
return bp;
|
223
|
+
}
|
224
|
+
return NULL;
|
225
|
+
}
|
226
|
+
|
227
|
+
/* Add an entry to the backpropagation cache. */
|
228
|
+
static void narrow_bpc_set(jit_State *J, IRRef1 key, IRRef1 val, IRRef mode)
|
229
|
+
{
|
230
|
+
uint32_t slot = J->bpropslot;
|
231
|
+
BPropEntry *bp = &J->bpropcache[slot];
|
232
|
+
J->bpropslot = (slot + 1) & (BPROP_SLOTS-1);
|
233
|
+
bp->key = key;
|
234
|
+
bp->val = val;
|
235
|
+
bp->mode = mode;
|
236
|
+
}
|
237
|
+
|
238
|
+
/* Backpropagate overflow stripping. */
|
239
|
+
static void narrow_stripov_backprop(NarrowConv *nc, IRRef ref, int depth)
|
240
|
+
{
|
241
|
+
jit_State *J = nc->J;
|
242
|
+
IRIns *ir = IR(ref);
|
243
|
+
if (ir->o == IR_ADDOV || ir->o == IR_SUBOV ||
|
244
|
+
(ir->o == IR_MULOV && (nc->mode & IRCONV_CONVMASK) == IRCONV_ANY)) {
|
245
|
+
BPropEntry *bp = narrow_bpc_get(nc->J, ref, IRCONV_TOBIT);
|
246
|
+
if (bp) {
|
247
|
+
ref = bp->val;
|
248
|
+
} else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {
|
249
|
+
NarrowIns *savesp = nc->sp;
|
250
|
+
narrow_stripov_backprop(nc, ir->op1, depth);
|
251
|
+
if (nc->sp < nc->maxsp) {
|
252
|
+
narrow_stripov_backprop(nc, ir->op2, depth);
|
253
|
+
if (nc->sp < nc->maxsp) {
|
254
|
+
*nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref);
|
255
|
+
return;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
nc->sp = savesp; /* Path too deep, need to backtrack. */
|
259
|
+
}
|
260
|
+
}
|
261
|
+
*nc->sp++ = NARROWINS(NARROW_REF, ref);
|
262
|
+
}
|
263
|
+
|
264
|
+
/* Backpropagate narrowing conversion. Return number of needed conversions. */
|
265
|
+
static int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth)
|
266
|
+
{
|
267
|
+
jit_State *J = nc->J;
|
268
|
+
IRIns *ir = IR(ref);
|
269
|
+
IRRef cref;
|
270
|
+
|
271
|
+
if (nc->sp >= nc->maxsp) return 10; /* Path too deep. */
|
272
|
+
|
273
|
+
/* Check the easy cases first. */
|
274
|
+
if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) {
|
275
|
+
if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY)
|
276
|
+
narrow_stripov_backprop(nc, ir->op1, depth+1);
|
277
|
+
else
|
278
|
+
*nc->sp++ = NARROWINS(NARROW_REF, ir->op1); /* Undo conversion. */
|
279
|
+
if (nc->t == IRT_I64)
|
280
|
+
*nc->sp++ = NARROWINS(NARROW_SEXT, 0); /* Sign-extend integer. */
|
281
|
+
return 0;
|
282
|
+
} else if (ir->o == IR_KNUM) { /* Narrow FP constant. */
|
283
|
+
lua_Number n = ir_knum(ir)->n;
|
284
|
+
if ((nc->mode & IRCONV_CONVMASK) == IRCONV_TOBIT) {
|
285
|
+
/* Allows a wider range of constants. */
|
286
|
+
int64_t k64 = (int64_t)n;
|
287
|
+
if (n == (lua_Number)k64) { /* Only if const doesn't lose precision. */
|
288
|
+
*nc->sp++ = NARROWINS(NARROW_INT, 0);
|
289
|
+
*nc->sp++ = (NarrowIns)k64; /* But always truncate to 32 bits. */
|
290
|
+
return 0;
|
291
|
+
}
|
292
|
+
} else {
|
293
|
+
int32_t k = lj_num2int(n);
|
294
|
+
/* Only if constant is a small integer. */
|
295
|
+
if (checki16(k) && n == (lua_Number)k) {
|
296
|
+
*nc->sp++ = NARROWINS(NARROW_INT, 0);
|
297
|
+
*nc->sp++ = (NarrowIns)k;
|
298
|
+
return 0;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
return 10; /* Never narrow other FP constants (this is rare). */
|
302
|
+
}
|
303
|
+
|
304
|
+
/* Try to CSE the conversion. Stronger checks are ok, too. */
|
305
|
+
cref = J->chain[fins->o];
|
306
|
+
while (cref > ref) {
|
307
|
+
IRIns *cr = IR(cref);
|
308
|
+
if (cr->op1 == ref &&
|
309
|
+
(fins->o == IR_TOBIT ||
|
310
|
+
((cr->op2 & IRCONV_MODEMASK) == (nc->mode & IRCONV_MODEMASK) &&
|
311
|
+
irt_isguard(cr->t) >= irt_isguard(fins->t)))) {
|
312
|
+
*nc->sp++ = NARROWINS(NARROW_REF, cref);
|
313
|
+
return 0; /* Already there, no additional conversion needed. */
|
314
|
+
}
|
315
|
+
cref = cr->prev;
|
316
|
+
}
|
317
|
+
|
318
|
+
/* Backpropagate across ADD/SUB. */
|
319
|
+
if (ir->o == IR_ADD || ir->o == IR_SUB) {
|
320
|
+
/* Try cache lookup first. */
|
321
|
+
IRRef mode = nc->mode;
|
322
|
+
BPropEntry *bp;
|
323
|
+
/* Inner conversions need a stronger check. */
|
324
|
+
if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX && depth > 0)
|
325
|
+
mode += IRCONV_CHECK-IRCONV_INDEX;
|
326
|
+
bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode);
|
327
|
+
if (bp) {
|
328
|
+
*nc->sp++ = NARROWINS(NARROW_REF, bp->val);
|
329
|
+
return 0;
|
330
|
+
} else if (nc->t == IRT_I64) {
|
331
|
+
/* Try sign-extending from an existing (checked) conversion to int. */
|
332
|
+
mode = (IRT_INT<<5)|IRT_NUM|IRCONV_INDEX;
|
333
|
+
bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode);
|
334
|
+
if (bp) {
|
335
|
+
*nc->sp++ = NARROWINS(NARROW_REF, bp->val);
|
336
|
+
*nc->sp++ = NARROWINS(NARROW_SEXT, 0);
|
337
|
+
return 0;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {
|
341
|
+
NarrowIns *savesp = nc->sp;
|
342
|
+
int count = narrow_conv_backprop(nc, ir->op1, depth);
|
343
|
+
count += narrow_conv_backprop(nc, ir->op2, depth);
|
344
|
+
if (count <= 1) { /* Limit total number of conversions. */
|
345
|
+
*nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref);
|
346
|
+
return count;
|
347
|
+
}
|
348
|
+
nc->sp = savesp; /* Too many conversions, need to backtrack. */
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
/* Otherwise add a conversion. */
|
353
|
+
*nc->sp++ = NARROWINS(NARROW_CONV, ref);
|
354
|
+
return 1;
|
355
|
+
}
|
356
|
+
|
357
|
+
/* Emit the conversions collected during backpropagation. */
|
358
|
+
static IRRef narrow_conv_emit(jit_State *J, NarrowConv *nc)
|
359
|
+
{
|
360
|
+
/* The fins fields must be saved now -- emitir() overwrites them. */
|
361
|
+
IROpT guardot = irt_isguard(fins->t) ? IRTG(IR_ADDOV-IR_ADD, 0) : 0;
|
362
|
+
IROpT convot = fins->ot;
|
363
|
+
IRRef1 convop2 = fins->op2;
|
364
|
+
NarrowIns *next = nc->stack; /* List of instructions from backpropagation. */
|
365
|
+
NarrowIns *last = nc->sp;
|
366
|
+
NarrowIns *sp = nc->stack; /* Recycle the stack to store operands. */
|
367
|
+
while (next < last) { /* Simple stack machine to process the ins. list. */
|
368
|
+
NarrowIns ref = *next++;
|
369
|
+
IROpT op = narrow_op(ref);
|
370
|
+
if (op == NARROW_REF) {
|
371
|
+
*sp++ = ref;
|
372
|
+
} else if (op == NARROW_CONV) {
|
373
|
+
*sp++ = emitir_raw(convot, ref, convop2); /* Raw emit avoids a loop. */
|
374
|
+
} else if (op == NARROW_SEXT) {
|
375
|
+
lua_assert(sp >= nc->stack+1);
|
376
|
+
sp[-1] = emitir(IRT(IR_CONV, IRT_I64), sp[-1],
|
377
|
+
(IRT_I64<<5)|IRT_INT|IRCONV_SEXT);
|
378
|
+
} else if (op == NARROW_INT) {
|
379
|
+
lua_assert(next < last);
|
380
|
+
*sp++ = nc->t == IRT_I64 ?
|
381
|
+
lj_ir_kint64(J, (int64_t)(int32_t)*next++) :
|
382
|
+
lj_ir_kint(J, *next++);
|
383
|
+
} else { /* Regular IROpT. Pops two operands and pushes one result. */
|
384
|
+
IRRef mode = nc->mode;
|
385
|
+
lua_assert(sp >= nc->stack+2);
|
386
|
+
sp--;
|
387
|
+
/* Omit some overflow checks for array indexing. See comments above. */
|
388
|
+
if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX) {
|
389
|
+
if (next == last && irref_isk(narrow_ref(sp[0])) &&
|
390
|
+
(uint32_t)IR(narrow_ref(sp[0]))->i + 0x40000000u < 0x80000000u)
|
391
|
+
guardot = 0;
|
392
|
+
else /* Otherwise cache a stronger check. */
|
393
|
+
mode += IRCONV_CHECK-IRCONV_INDEX;
|
394
|
+
}
|
395
|
+
sp[-1] = emitir(op+guardot, sp[-1], sp[0]);
|
396
|
+
/* Add to cache. */
|
397
|
+
if (narrow_ref(ref))
|
398
|
+
narrow_bpc_set(J, narrow_ref(ref), narrow_ref(sp[-1]), mode);
|
399
|
+
}
|
400
|
+
}
|
401
|
+
lua_assert(sp == nc->stack+1);
|
402
|
+
return nc->stack[0];
|
403
|
+
}
|
404
|
+
|
405
|
+
/* Narrow a type conversion of an arithmetic operation. */
|
406
|
+
TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J)
|
407
|
+
{
|
408
|
+
if ((J->flags & JIT_F_OPT_NARROW)) {
|
409
|
+
NarrowConv nc;
|
410
|
+
nc.J = J;
|
411
|
+
nc.sp = nc.stack;
|
412
|
+
nc.maxsp = &nc.stack[NARROW_MAX_STACK-4];
|
413
|
+
nc.t = irt_type(fins->t);
|
414
|
+
if (fins->o == IR_TOBIT) {
|
415
|
+
nc.mode = IRCONV_TOBIT; /* Used only in the backpropagation cache. */
|
416
|
+
} else {
|
417
|
+
nc.mode = fins->op2;
|
418
|
+
}
|
419
|
+
if (narrow_conv_backprop(&nc, fins->op1, 0) <= 1)
|
420
|
+
return narrow_conv_emit(J, &nc);
|
421
|
+
}
|
422
|
+
return NEXTFOLD;
|
423
|
+
}
|
424
|
+
|
425
|
+
/* -- Narrowing of implicit conversions ----------------------------------- */
|
426
|
+
|
427
|
+
/* Recursively strip overflow checks. */
|
428
|
+
static TRef narrow_stripov(jit_State *J, TRef tr, int lastop, IRRef mode)
|
429
|
+
{
|
430
|
+
IRRef ref = tref_ref(tr);
|
431
|
+
IRIns *ir = IR(ref);
|
432
|
+
int op = ir->o;
|
433
|
+
if (op >= IR_ADDOV && op <= lastop) {
|
434
|
+
BPropEntry *bp = narrow_bpc_get(J, ref, mode);
|
435
|
+
if (bp) {
|
436
|
+
return TREF(bp->val, irt_t(IR(bp->val)->t));
|
437
|
+
} else {
|
438
|
+
IRRef op1 = ir->op1, op2 = ir->op2; /* The IR may be reallocated. */
|
439
|
+
op1 = narrow_stripov(J, op1, lastop, mode);
|
440
|
+
op2 = narrow_stripov(J, op2, lastop, mode);
|
441
|
+
tr = emitir(IRT(op - IR_ADDOV + IR_ADD,
|
442
|
+
((mode & IRCONV_DSTMASK) >> IRCONV_DSH)), op1, op2);
|
443
|
+
narrow_bpc_set(J, ref, tref_ref(tr), mode);
|
444
|
+
}
|
445
|
+
} else if (LJ_64 && (mode & IRCONV_SEXT) && !irt_is64(ir->t)) {
|
446
|
+
tr = emitir(IRT(IR_CONV, IRT_INTP), tr, mode);
|
447
|
+
}
|
448
|
+
return tr;
|
449
|
+
}
|
450
|
+
|
451
|
+
/* Narrow array index. */
|
452
|
+
TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef tr)
|
453
|
+
{
|
454
|
+
IRIns *ir;
|
455
|
+
lua_assert(tref_isnumber(tr));
|
456
|
+
if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */
|
457
|
+
return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_INDEX);
|
458
|
+
/* Omit some overflow checks for array indexing. See comments above. */
|
459
|
+
ir = IR(tref_ref(tr));
|
460
|
+
if ((ir->o == IR_ADDOV || ir->o == IR_SUBOV) && irref_isk(ir->op2) &&
|
461
|
+
(uint32_t)IR(ir->op2)->i + 0x40000000u < 0x80000000u)
|
462
|
+
return emitir(IRTI(ir->o - IR_ADDOV + IR_ADD), ir->op1, ir->op2);
|
463
|
+
return tr;
|
464
|
+
}
|
465
|
+
|
466
|
+
/* Narrow conversion to integer operand (overflow undefined). */
|
467
|
+
TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr)
|
468
|
+
{
|
469
|
+
if (tref_isstr(tr))
|
470
|
+
tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);
|
471
|
+
if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */
|
472
|
+
return emitir(IRTI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_ANY);
|
473
|
+
if (!tref_isinteger(tr))
|
474
|
+
lj_trace_err(J, LJ_TRERR_BADTYPE);
|
475
|
+
/*
|
476
|
+
** Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV.
|
477
|
+
** Use IRCONV_TOBIT for the cache entries, since the semantics are the same.
|
478
|
+
*/
|
479
|
+
return narrow_stripov(J, tr, IR_MULOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT);
|
480
|
+
}
|
481
|
+
|
482
|
+
/* Narrow conversion to bitop operand (overflow wrapped). */
|
483
|
+
TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr)
|
484
|
+
{
|
485
|
+
if (tref_isstr(tr))
|
486
|
+
tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);
|
487
|
+
if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */
|
488
|
+
return emitir(IRTI(IR_TOBIT), tr, lj_ir_knum_tobit(J));
|
489
|
+
if (!tref_isinteger(tr))
|
490
|
+
lj_trace_err(J, LJ_TRERR_BADTYPE);
|
491
|
+
/*
|
492
|
+
** Wrapped overflow semantics allow stripping of ADDOV and SUBOV.
|
493
|
+
** MULOV cannot be stripped due to precision widening.
|
494
|
+
*/
|
495
|
+
return narrow_stripov(J, tr, IR_SUBOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT);
|
496
|
+
}
|
497
|
+
|
498
|
+
#if LJ_HASFFI
|
499
|
+
/* Narrow C array index (overflow undefined). */
|
500
|
+
TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef tr)
|
501
|
+
{
|
502
|
+
lua_assert(tref_isnumber(tr));
|
503
|
+
if (tref_isnum(tr))
|
504
|
+
return emitir(IRT(IR_CONV, IRT_INTP), tr, (IRT_INTP<<5)|IRT_NUM|IRCONV_ANY);
|
505
|
+
/* Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV. */
|
506
|
+
return narrow_stripov(J, tr, IR_MULOV,
|
507
|
+
LJ_64 ? ((IRT_INTP<<5)|IRT_INT|IRCONV_SEXT) :
|
508
|
+
((IRT_INTP<<5)|IRT_INT|IRCONV_TOBIT));
|
509
|
+
}
|
510
|
+
#endif
|
511
|
+
|
512
|
+
/* -- Narrowing of arithmetic operators ----------------------------------- */
|
513
|
+
|
514
|
+
/* Check whether a number fits into an int32_t (-0 is ok, too). */
|
515
|
+
static int numisint(lua_Number n)
|
516
|
+
{
|
517
|
+
return (n == (lua_Number)lj_num2int(n));
|
518
|
+
}
|
519
|
+
|
520
|
+
/* Narrowing of arithmetic operations. */
|
521
|
+
TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,
|
522
|
+
TValue *vb, TValue *vc, IROp op)
|
523
|
+
{
|
524
|
+
if (tref_isstr(rb)) {
|
525
|
+
rb = emitir(IRTG(IR_STRTO, IRT_NUM), rb, 0);
|
526
|
+
lj_strscan_num(strV(vb), vb);
|
527
|
+
}
|
528
|
+
if (tref_isstr(rc)) {
|
529
|
+
rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0);
|
530
|
+
lj_strscan_num(strV(vc), vc);
|
531
|
+
}
|
532
|
+
/* Must not narrow MUL in non-DUALNUM variant, because it loses -0. */
|
533
|
+
if ((op >= IR_ADD && op <= (LJ_DUALNUM ? IR_MUL : IR_SUB)) &&
|
534
|
+
tref_isinteger(rb) && tref_isinteger(rc) &&
|
535
|
+
numisint(lj_vm_foldarith(numberVnum(vb), numberVnum(vc),
|
536
|
+
(int)op - (int)IR_ADD)))
|
537
|
+
return emitir(IRTGI((int)op - (int)IR_ADD + (int)IR_ADDOV), rb, rc);
|
538
|
+
if (!tref_isnum(rb)) rb = emitir(IRTN(IR_CONV), rb, IRCONV_NUM_INT);
|
539
|
+
if (!tref_isnum(rc)) rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);
|
540
|
+
return emitir(IRTN(op), rb, rc);
|
541
|
+
}
|
542
|
+
|
543
|
+
/* Narrowing of unary minus operator. */
|
544
|
+
TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc)
|
545
|
+
{
|
546
|
+
if (tref_isstr(rc)) {
|
547
|
+
rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0);
|
548
|
+
lj_strscan_num(strV(vc), vc);
|
549
|
+
}
|
550
|
+
if (tref_isinteger(rc)) {
|
551
|
+
if ((uint32_t)numberVint(vc) != 0x80000000u)
|
552
|
+
return emitir(IRTGI(IR_SUBOV), lj_ir_kint(J, 0), rc);
|
553
|
+
rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);
|
554
|
+
}
|
555
|
+
return emitir(IRTN(IR_NEG), rc, lj_ir_knum_neg(J));
|
556
|
+
}
|
557
|
+
|
558
|
+
/* Narrowing of modulo operator. */
|
559
|
+
TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vc)
|
560
|
+
{
|
561
|
+
TRef tmp;
|
562
|
+
if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc))
|
563
|
+
lj_trace_err(J, LJ_TRERR_BADTYPE);
|
564
|
+
if ((LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) &&
|
565
|
+
tref_isinteger(rb) && tref_isinteger(rc) &&
|
566
|
+
(tvisint(vc) ? intV(vc) != 0 : !tviszero(vc))) {
|
567
|
+
emitir(IRTGI(IR_NE), rc, lj_ir_kint(J, 0));
|
568
|
+
return emitir(IRTI(IR_MOD), rb, rc);
|
569
|
+
}
|
570
|
+
/* b % c ==> b - floor(b/c)*c */
|
571
|
+
rb = lj_ir_tonum(J, rb);
|
572
|
+
rc = lj_ir_tonum(J, rc);
|
573
|
+
tmp = emitir(IRTN(IR_DIV), rb, rc);
|
574
|
+
tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_FLOOR);
|
575
|
+
tmp = emitir(IRTN(IR_MUL), tmp, rc);
|
576
|
+
return emitir(IRTN(IR_SUB), rb, tmp);
|
577
|
+
}
|
578
|
+
|
579
|
+
/* Narrowing of power operator or math.pow. */
|
580
|
+
TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vc)
|
581
|
+
{
|
582
|
+
if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc))
|
583
|
+
lj_trace_err(J, LJ_TRERR_BADTYPE);
|
584
|
+
/* Narrowing must be unconditional to preserve (-x)^i semantics. */
|
585
|
+
if (tvisint(vc) || numisint(numV(vc))) {
|
586
|
+
int checkrange = 0;
|
587
|
+
/* Split pow is faster for bigger exponents. But do this only for (+k)^i. */
|
588
|
+
if (tref_isk(rb) && (int32_t)ir_knum(IR(tref_ref(rb)))->u32.hi >= 0) {
|
589
|
+
int32_t k = numberVint(vc);
|
590
|
+
if (!(k >= -65536 && k <= 65536)) goto split_pow;
|
591
|
+
checkrange = 1;
|
592
|
+
}
|
593
|
+
if (!tref_isinteger(rc)) {
|
594
|
+
if (tref_isstr(rc))
|
595
|
+
rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0);
|
596
|
+
/* Guarded conversion to integer! */
|
597
|
+
rc = emitir(IRTGI(IR_CONV), rc, IRCONV_INT_NUM|IRCONV_CHECK);
|
598
|
+
}
|
599
|
+
if (checkrange && !tref_isk(rc)) { /* Range guard: -65536 <= i <= 65536 */
|
600
|
+
TRef tmp = emitir(IRTI(IR_ADD), rc, lj_ir_kint(J, 65536));
|
601
|
+
emitir(IRTGI(IR_ULE), tmp, lj_ir_kint(J, 2*65536));
|
602
|
+
}
|
603
|
+
return emitir(IRTN(IR_POW), rb, rc);
|
604
|
+
}
|
605
|
+
split_pow:
|
606
|
+
/* FOLD covers most cases, but some are easier to do here. */
|
607
|
+
if (tref_isk(rb) && tvispone(ir_knum(IR(tref_ref(rb)))))
|
608
|
+
return rb; /* 1 ^ x ==> 1 */
|
609
|
+
rc = lj_ir_tonum(J, rc);
|
610
|
+
if (tref_isk(rc) && ir_knum(IR(tref_ref(rc)))->n == 0.5)
|
611
|
+
return emitir(IRTN(IR_FPMATH), rb, IRFPM_SQRT); /* x ^ 0.5 ==> sqrt(x) */
|
612
|
+
/* Split up b^c into exp2(c*log2(b)). Assembler may rejoin later. */
|
613
|
+
rb = emitir(IRTN(IR_FPMATH), rb, IRFPM_LOG2);
|
614
|
+
rc = emitir(IRTN(IR_MUL), rb, rc);
|
615
|
+
return emitir(IRTN(IR_FPMATH), rc, IRFPM_EXP2);
|
616
|
+
}
|
617
|
+
|
618
|
+
/* -- Predictive narrowing of induction variables ------------------------- */
|
619
|
+
|
620
|
+
/* Narrow a single runtime value. */
|
621
|
+
static int narrow_forl(jit_State *J, cTValue *o)
|
622
|
+
{
|
623
|
+
if (tvisint(o)) return 1;
|
624
|
+
if (LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) return numisint(numV(o));
|
625
|
+
return 0;
|
626
|
+
}
|
627
|
+
|
628
|
+
/* Narrow the FORL index type by looking at the runtime values. */
|
629
|
+
IRType lj_opt_narrow_forl(jit_State *J, cTValue *tv)
|
630
|
+
{
|
631
|
+
lua_assert(tvisnumber(&tv[FORL_IDX]) &&
|
632
|
+
tvisnumber(&tv[FORL_STOP]) &&
|
633
|
+
tvisnumber(&tv[FORL_STEP]));
|
634
|
+
/* Narrow only if the runtime values of start/stop/step are all integers. */
|
635
|
+
if (narrow_forl(J, &tv[FORL_IDX]) &&
|
636
|
+
narrow_forl(J, &tv[FORL_STOP]) &&
|
637
|
+
narrow_forl(J, &tv[FORL_STEP])) {
|
638
|
+
/* And if the loop index can't possibly overflow. */
|
639
|
+
lua_Number step = numberVnum(&tv[FORL_STEP]);
|
640
|
+
lua_Number sum = numberVnum(&tv[FORL_STOP]) + step;
|
641
|
+
if (0 <= step ? (sum <= 2147483647.0) : (sum >= -2147483648.0))
|
642
|
+
return IRT_INT;
|
643
|
+
}
|
644
|
+
return IRT_NUM;
|
645
|
+
}
|
646
|
+
|
647
|
+
#undef IR
|
648
|
+
#undef fins
|
649
|
+
#undef emitir
|
650
|
+
#undef emitir_raw
|
651
|
+
|
652
|
+
#endif
|