diff options
| author | Mike Pall <mike> | 2011-06-03 17:12:46 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2011-06-03 17:15:44 +0200 |
| commit | eec28aa9fdf5f733a4f7d2628fc060eac66ab713 (patch) | |
| tree | d37d099e35e86df696d0b130cf98b098cd604d12 | |
| parent | 77bb8de93da29cc3b1a3fbc2f605f8b70841657b (diff) | |
| download | luajit-eec28aa9fdf5f733a4f7d2628fc060eac66ab713.tar.gz luajit-eec28aa9fdf5f733a4f7d2628fc060eac66ab713.tar.bz2 luajit-eec28aa9fdf5f733a4f7d2628fc060eac66ab713.zip | |
Move math helpers to lj_vmmath.c. Add missing log2/exp2 for Symbian.
| -rw-r--r-- | src/Makefile | 2 | ||||
| -rw-r--r-- | src/Makefile.dep | 26 | ||||
| -rw-r--r-- | src/buildvm_x64.h | 14 | ||||
| -rw-r--r-- | src/buildvm_x64win.h | 14 | ||||
| -rw-r--r-- | src/buildvm_x86.dasc | 16 | ||||
| -rw-r--r-- | src/buildvm_x86.h | 14 | ||||
| -rw-r--r-- | src/lib_math.c | 4 | ||||
| -rw-r--r-- | src/lj_asm_x86.h | 4 | ||||
| -rw-r--r-- | src/lj_ir.c | 66 | ||||
| -rw-r--r-- | src/lj_ircall.h | 4 | ||||
| -rw-r--r-- | src/lj_opt_split.c | 2 | ||||
| -rw-r--r-- | src/lj_vm.h | 15 | ||||
| -rw-r--r-- | src/lj_vmmath.c | 97 | ||||
| -rw-r--r-- | src/ljamalg.c | 1 |
14 files changed, 160 insertions, 119 deletions
diff --git a/src/Makefile b/src/Makefile index 03e45d2d..c99d8577 100644 --- a/src/Makefile +++ b/src/Makefile | |||
| @@ -359,7 +359,7 @@ LJLIB_C= $(LJLIB_O:.o=.c) | |||
| 359 | 359 | ||
| 360 | LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \ | 360 | LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \ |
| 361 | lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o \ | 361 | lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o \ |
| 362 | lj_state.o lj_dispatch.o lj_vmevent.o lj_api.o \ | 362 | lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_api.o \ |
| 363 | lj_lex.o lj_parse.o \ | 363 | lj_lex.o lj_parse.o \ |
| 364 | lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \ | 364 | lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \ |
| 365 | lj_opt_dce.o lj_opt_loop.o lj_opt_split.o \ | 365 | lj_opt_dce.o lj_opt_loop.o lj_opt_split.o \ |
diff --git a/src/Makefile.dep b/src/Makefile.dep index 8e0d7a1c..8bc891ad 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
| @@ -166,22 +166,24 @@ lj_udata.o: lj_udata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
| 166 | lj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 166 | lj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
| 167 | lj_str.h lj_tab.h lj_state.h lj_dispatch.h lj_bc.h lj_jit.h lj_ir.h \ | 167 | lj_str.h lj_tab.h lj_state.h lj_dispatch.h lj_bc.h lj_jit.h lj_ir.h \ |
| 168 | lj_vm.h lj_vmevent.h | 168 | lj_vm.h lj_vmevent.h |
| 169 | lj_vmmath.o: lj_vmmath.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | ||
| 170 | lj_ir.h lj_vm.h | ||
| 169 | ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \ | 171 | ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \ |
| 170 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h \ | 172 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h \ |
| 171 | lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h \ | 173 | lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h \ |
| 172 | lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c \ | 174 | lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c \ |
| 173 | lj_ff.h lj_ffdef.h lj_char.c lj_char.h lj_bc.c lj_bcdef.h lj_obj.c \ | 175 | lj_ff.h lj_ffdef.h lj_char.c lj_char.h lj_bc.c lj_bcdef.h lj_obj.c \ |
| 174 | lj_str.c lj_tab.c lj_func.c lj_udata.c lj_meta.c lj_state.c lj_lex.h \ | 176 | lj_str.c lj_tab.c lj_func.c lj_udata.c lj_meta.c lj_state.c lj_lex.h \ |
| 175 | lj_alloc.h lj_dispatch.c luajit.h lj_vmevent.c lj_vmevent.h lj_api.c \ | 177 | lj_alloc.h lj_dispatch.c luajit.h lj_vmevent.c lj_vmevent.h lj_vmmath.c \ |
| 176 | lj_parse.h lj_lex.c lualib.h lj_parse.c lj_ctype.c lj_cdata.c lj_cconv.h \ | 178 | lj_api.c lj_parse.h lj_lex.c lualib.h lj_parse.c lj_ctype.c lj_cdata.c \ |
| 177 | lj_cconv.c lj_ccall.c lj_ccall.h lj_carith.c lj_carith.h lj_clib.c \ | 179 | lj_cconv.h lj_cconv.c lj_ccall.c lj_ccall.h lj_carith.c lj_carith.h \ |
| 178 | lj_clib.h lj_cparse.c lj_cparse.h lj_lib.c lj_lib.h lj_ir.c lj_ircall.h \ | 180 | lj_clib.c lj_clib.h lj_cparse.c lj_cparse.h lj_lib.c lj_lib.h lj_ir.c \ |
| 179 | lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c \ | 181 | lj_ircall.h lj_iropt.h lj_opt_mem.c lj_opt_fold.c lj_folddef.h \ |
| 180 | lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_opt_split.c lj_mcode.c \ | 182 | lj_opt_narrow.c lj_opt_dce.c lj_opt_loop.c lj_snap.h lj_opt_split.c \ |
| 181 | lj_mcode.h lj_snap.c lj_target.h lj_target_*.h lj_record.c lj_record.h \ | 183 | lj_mcode.c lj_mcode.h lj_snap.c lj_target.h lj_target_*.h lj_record.c \ |
| 182 | lj_ffrecord.h lj_crecord.c lj_crecord.h lj_ffrecord.c lj_recdef.h \ | 184 | lj_record.h lj_ffrecord.h lj_crecord.c lj_crecord.h lj_ffrecord.c \ |
| 183 | lj_asm.c lj_asm.h lj_emit_*.h lj_asm_*.h lj_trace.c lj_gdbjit.h \ | 185 | lj_recdef.h lj_asm.c lj_asm.h lj_emit_*.h lj_asm_*.h lj_trace.c \ |
| 184 | lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c lj_libdef.h lib_math.c \ | 186 | lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c lib_base.c lj_libdef.h \ |
| 185 | lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c \ | 187 | lib_math.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c \ |
| 186 | lib_bit.c lib_jit.c lib_ffi.c lib_init.c | 188 | lib_debug.c lib_bit.c lib_jit.c lib_ffi.c lib_init.c |
| 187 | luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h | 189 | luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h |
diff --git a/src/buildvm_x64.h b/src/buildvm_x64.h index 918e514a..4a96493f 100644 --- a/src/buildvm_x64.h +++ b/src/buildvm_x64.h | |||
| @@ -879,7 +879,7 @@ enum { | |||
| 879 | GLOB_ff_math_log, | 879 | GLOB_ff_math_log, |
| 880 | GLOB_ff_math_log10, | 880 | GLOB_ff_math_log10, |
| 881 | GLOB_ff_math_exp, | 881 | GLOB_ff_math_exp, |
| 882 | GLOB_vm_exp, | 882 | GLOB_vm_exp_x87, |
| 883 | GLOB_ff_math_sin, | 883 | GLOB_ff_math_sin, |
| 884 | GLOB_ff_math_cos, | 884 | GLOB_ff_math_cos, |
| 885 | GLOB_ff_math_tan, | 885 | GLOB_ff_math_tan, |
| @@ -939,7 +939,7 @@ enum { | |||
| 939 | GLOB_vm_ceil_sse, | 939 | GLOB_vm_ceil_sse, |
| 940 | GLOB_vm_trunc_sse, | 940 | GLOB_vm_trunc_sse, |
| 941 | GLOB_vm_mod, | 941 | GLOB_vm_mod, |
| 942 | GLOB_vm_exp2, | 942 | GLOB_vm_exp2_x87, |
| 943 | GLOB_vm_exp2raw, | 943 | GLOB_vm_exp2raw, |
| 944 | GLOB_vm_pow_sse, | 944 | GLOB_vm_pow_sse, |
| 945 | GLOB_vm_powi_sse, | 945 | GLOB_vm_powi_sse, |
| @@ -1040,7 +1040,7 @@ static const char *const globnames[] = { | |||
| 1040 | "ff_math_log", | 1040 | "ff_math_log", |
| 1041 | "ff_math_log10", | 1041 | "ff_math_log10", |
| 1042 | "ff_math_exp", | 1042 | "ff_math_exp", |
| 1043 | "vm_exp", | 1043 | "vm_exp_x87", |
| 1044 | "ff_math_sin", | 1044 | "ff_math_sin", |
| 1045 | "ff_math_cos", | 1045 | "ff_math_cos", |
| 1046 | "ff_math_tan", | 1046 | "ff_math_tan", |
| @@ -1100,7 +1100,7 @@ static const char *const globnames[] = { | |||
| 1100 | "vm_ceil_sse", | 1100 | "vm_ceil_sse", |
| 1101 | "vm_trunc_sse", | 1101 | "vm_trunc_sse", |
| 1102 | "vm_mod", | 1102 | "vm_mod", |
| 1103 | "vm_exp2", | 1103 | "vm_exp2_x87", |
| 1104 | "vm_exp2raw", | 1104 | "vm_exp2raw", |
| 1105 | "vm_pow_sse", | 1105 | "vm_pow_sse", |
| 1106 | "vm_powi_sse", | 1106 | "vm_powi_sse", |
| @@ -1132,9 +1132,9 @@ static const char *const extnames[] = { | |||
| 1132 | "lj_tab_next", | 1132 | "lj_tab_next", |
| 1133 | "lj_tab_getinth@8", | 1133 | "lj_tab_getinth@8", |
| 1134 | "lj_ffh_coroutine_wrap_err@8", | 1134 | "lj_ffh_coroutine_wrap_err@8", |
| 1135 | "lj_wrapper_sinh", | 1135 | "lj_vm_sinh", |
| 1136 | "lj_wrapper_cosh", | 1136 | "lj_vm_cosh", |
| 1137 | "lj_wrapper_tanh", | 1137 | "lj_vm_tanh", |
| 1138 | "lj_str_new", | 1138 | "lj_str_new", |
| 1139 | "lj_tab_len@4", | 1139 | "lj_tab_len@4", |
| 1140 | "lj_gc_step@4", | 1140 | "lj_gc_step@4", |
diff --git a/src/buildvm_x64win.h b/src/buildvm_x64win.h index 59499a78..9dbad9a3 100644 --- a/src/buildvm_x64win.h +++ b/src/buildvm_x64win.h | |||
| @@ -876,7 +876,7 @@ enum { | |||
| 876 | GLOB_ff_math_log, | 876 | GLOB_ff_math_log, |
| 877 | GLOB_ff_math_log10, | 877 | GLOB_ff_math_log10, |
| 878 | GLOB_ff_math_exp, | 878 | GLOB_ff_math_exp, |
| 879 | GLOB_vm_exp, | 879 | GLOB_vm_exp_x87, |
| 880 | GLOB_ff_math_sin, | 880 | GLOB_ff_math_sin, |
| 881 | GLOB_ff_math_cos, | 881 | GLOB_ff_math_cos, |
| 882 | GLOB_ff_math_tan, | 882 | GLOB_ff_math_tan, |
| @@ -936,7 +936,7 @@ enum { | |||
| 936 | GLOB_vm_ceil_sse, | 936 | GLOB_vm_ceil_sse, |
| 937 | GLOB_vm_trunc_sse, | 937 | GLOB_vm_trunc_sse, |
| 938 | GLOB_vm_mod, | 938 | GLOB_vm_mod, |
| 939 | GLOB_vm_exp2, | 939 | GLOB_vm_exp2_x87, |
| 940 | GLOB_vm_exp2raw, | 940 | GLOB_vm_exp2raw, |
| 941 | GLOB_vm_pow_sse, | 941 | GLOB_vm_pow_sse, |
| 942 | GLOB_vm_powi_sse, | 942 | GLOB_vm_powi_sse, |
| @@ -1037,7 +1037,7 @@ static const char *const globnames[] = { | |||
| 1037 | "ff_math_log", | 1037 | "ff_math_log", |
| 1038 | "ff_math_log10", | 1038 | "ff_math_log10", |
| 1039 | "ff_math_exp", | 1039 | "ff_math_exp", |
| 1040 | "vm_exp", | 1040 | "vm_exp_x87", |
| 1041 | "ff_math_sin", | 1041 | "ff_math_sin", |
| 1042 | "ff_math_cos", | 1042 | "ff_math_cos", |
| 1043 | "ff_math_tan", | 1043 | "ff_math_tan", |
| @@ -1097,7 +1097,7 @@ static const char *const globnames[] = { | |||
| 1097 | "vm_ceil_sse", | 1097 | "vm_ceil_sse", |
| 1098 | "vm_trunc_sse", | 1098 | "vm_trunc_sse", |
| 1099 | "vm_mod", | 1099 | "vm_mod", |
| 1100 | "vm_exp2", | 1100 | "vm_exp2_x87", |
| 1101 | "vm_exp2raw", | 1101 | "vm_exp2raw", |
| 1102 | "vm_pow_sse", | 1102 | "vm_pow_sse", |
| 1103 | "vm_powi_sse", | 1103 | "vm_powi_sse", |
| @@ -1128,9 +1128,9 @@ static const char *const extnames[] = { | |||
| 1128 | "lj_tab_next", | 1128 | "lj_tab_next", |
| 1129 | "lj_tab_getinth@8", | 1129 | "lj_tab_getinth@8", |
| 1130 | "lj_ffh_coroutine_wrap_err@8", | 1130 | "lj_ffh_coroutine_wrap_err@8", |
| 1131 | "lj_wrapper_sinh", | 1131 | "lj_vm_sinh", |
| 1132 | "lj_wrapper_cosh", | 1132 | "lj_vm_cosh", |
| 1133 | "lj_wrapper_tanh", | 1133 | "lj_vm_tanh", |
| 1134 | "lj_str_new", | 1134 | "lj_str_new", |
| 1135 | "lj_tab_len@4", | 1135 | "lj_tab_len@4", |
| 1136 | "lj_gc_step@4", | 1136 | "lj_gc_step@4", |
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc index b8be39fb..6fde191d 100644 --- a/src/buildvm_x86.dasc +++ b/src/buildvm_x86.dasc | |||
| @@ -2028,7 +2028,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse) | |||
| 2028 | } | 2028 | } |
| 2029 | |.ffunc_n math_log, fldln2; fyl2x; jmp ->fff_resn | 2029 | |.ffunc_n math_log, fldln2; fyl2x; jmp ->fff_resn |
| 2030 | |.ffunc_n math_log10, fldlg2; fyl2x; jmp ->fff_resn | 2030 | |.ffunc_n math_log10, fldlg2; fyl2x; jmp ->fff_resn |
| 2031 | |.ffunc_n math_exp; call ->vm_exp; jmp ->fff_resn | 2031 | |.ffunc_n math_exp; call ->vm_exp_x87; jmp ->fff_resn |
| 2032 | | | 2032 | | |
| 2033 | |.ffunc_n math_sin; fsin; jmp ->fff_resn | 2033 | |.ffunc_n math_sin; fsin; jmp ->fff_resn |
| 2034 | |.ffunc_n math_cos; fcos; jmp ->fff_resn | 2034 | |.ffunc_n math_cos; fcos; jmp ->fff_resn |
| @@ -2055,7 +2055,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse) | |||
| 2055 | | .endif | 2055 | | .endif |
| 2056 | ||} | 2056 | ||} |
| 2057 | | mov RB, BASE | 2057 | | mov RB, BASE |
| 2058 | | call extern lj_wrapper_ .. func | 2058 | | call extern lj_vm_ .. func |
| 2059 | | mov BASE, RB | 2059 | | mov BASE, RB |
| 2060 | | .if X64 | 2060 | | .if X64 |
| 2061 | | jmp ->fff_resxmm0 | 2061 | | jmp ->fff_resxmm0 |
| @@ -3169,9 +3169,9 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse) | |||
| 3169 | |// FP exponentiation e^x and 2^x. Called by math.exp fast function and | 3169 | |// FP exponentiation e^x and 2^x. Called by math.exp fast function and |
| 3170 | |// from JIT code. Arg/ret on x87 stack. No int/xmm regs modified. | 3170 | |// from JIT code. Arg/ret on x87 stack. No int/xmm regs modified. |
| 3171 | |// Caveat: needs 3 slots on x87 stack! | 3171 | |// Caveat: needs 3 slots on x87 stack! |
| 3172 | |->vm_exp: | 3172 | |->vm_exp_x87: |
| 3173 | | fldl2e; fmulp st1 // e^x ==> 2^(x*log2(e)) | 3173 | | fldl2e; fmulp st1 // e^x ==> 2^(x*log2(e)) |
| 3174 | |->vm_exp2: | 3174 | |->vm_exp2_x87: |
| 3175 | | .if X64WIN | 3175 | | .if X64WIN |
| 3176 | | .define expscratch, dword [rsp+8] // Use scratch area. | 3176 | | .define expscratch, dword [rsp+8] // Use scratch area. |
| 3177 | | .elif X64 | 3177 | | .elif X64 |
| @@ -3444,11 +3444,11 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse) | |||
| 3444 | | cmp fpmop, 5; ja >2 | 3444 | | cmp fpmop, 5; ja >2 |
| 3445 | | .if X64WIN; pop rax; .endif | 3445 | | .if X64WIN; pop rax; .endif |
| 3446 | | je >1 | 3446 | | je >1 |
| 3447 | | call ->vm_exp | 3447 | | call ->vm_exp_x87 |
| 3448 | | .if X64WIN; push rax; .endif | 3448 | | .if X64WIN; push rax; .endif |
| 3449 | | jmp >7 | 3449 | | jmp >7 |
| 3450 | |1: | 3450 | |1: |
| 3451 | | call ->vm_exp2 | 3451 | | call ->vm_exp2_x87 |
| 3452 | | .if X64WIN; push rax; .endif | 3452 | | .if X64WIN; push rax; .endif |
| 3453 | | jmp >7 | 3453 | | jmp >7 |
| 3454 | |2: ; cmp fpmop, 7; je >1; ja >2 | 3454 | |2: ; cmp fpmop, 7; je >1; ja >2 |
| @@ -3487,7 +3487,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse) | |||
| 3487 | | fld qword [esp+4] | 3487 | | fld qword [esp+4] |
| 3488 | | ret | 3488 | | ret |
| 3489 | |2: ; fld qword [esp+4] | 3489 | |2: ; fld qword [esp+4] |
| 3490 | | cmp fpmop, 5; jb ->vm_exp; je ->vm_exp2 | 3490 | | cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87 |
| 3491 | |2: ; cmp fpmop, 7; je >1; ja >2 | 3491 | |2: ; cmp fpmop, 7; je >1; ja >2 |
| 3492 | | fldln2; fxch; fyl2x; ret | 3492 | | fldln2; fxch; fyl2x; ret |
| 3493 | |1: ; fld1; fxch; fyl2x; ret | 3493 | |1: ; fld1; fxch; fyl2x; ret |
| @@ -3505,7 +3505,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse) | |||
| 3505 | | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil | 3505 | | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil |
| 3506 | | cmp fpmop, 3; jb ->vm_trunc; ja >2 | 3506 | | cmp fpmop, 3; jb ->vm_trunc; ja >2 |
| 3507 | | fsqrt; ret | 3507 | | fsqrt; ret |
| 3508 | |2: ; cmp fpmop, 5; jb ->vm_exp; je ->vm_exp2 | 3508 | |2: ; cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87 |
| 3509 | | cmp fpmop, 7; je >1; ja >2 | 3509 | | cmp fpmop, 7; je >1; ja >2 |
| 3510 | | fldln2; fxch; fyl2x; ret | 3510 | | fldln2; fxch; fyl2x; ret |
| 3511 | |1: ; fld1; fxch; fyl2x; ret | 3511 | |1: ; fld1; fxch; fyl2x; ret |
diff --git a/src/buildvm_x86.h b/src/buildvm_x86.h index 1493381b..44f47339 100644 --- a/src/buildvm_x86.h +++ b/src/buildvm_x86.h | |||
| @@ -925,7 +925,7 @@ enum { | |||
| 925 | GLOB_ff_math_log, | 925 | GLOB_ff_math_log, |
| 926 | GLOB_ff_math_log10, | 926 | GLOB_ff_math_log10, |
| 927 | GLOB_ff_math_exp, | 927 | GLOB_ff_math_exp, |
| 928 | GLOB_vm_exp, | 928 | GLOB_vm_exp_x87, |
| 929 | GLOB_ff_math_sin, | 929 | GLOB_ff_math_sin, |
| 930 | GLOB_ff_math_cos, | 930 | GLOB_ff_math_cos, |
| 931 | GLOB_ff_math_tan, | 931 | GLOB_ff_math_tan, |
| @@ -985,7 +985,7 @@ enum { | |||
| 985 | GLOB_vm_ceil_sse, | 985 | GLOB_vm_ceil_sse, |
| 986 | GLOB_vm_trunc_sse, | 986 | GLOB_vm_trunc_sse, |
| 987 | GLOB_vm_mod, | 987 | GLOB_vm_mod, |
| 988 | GLOB_vm_exp2, | 988 | GLOB_vm_exp2_x87, |
| 989 | GLOB_vm_exp2raw, | 989 | GLOB_vm_exp2raw, |
| 990 | GLOB_vm_pow_sse, | 990 | GLOB_vm_pow_sse, |
| 991 | GLOB_vm_powi_sse, | 991 | GLOB_vm_powi_sse, |
| @@ -1086,7 +1086,7 @@ static const char *const globnames[] = { | |||
| 1086 | "ff_math_log", | 1086 | "ff_math_log", |
| 1087 | "ff_math_log10", | 1087 | "ff_math_log10", |
| 1088 | "ff_math_exp", | 1088 | "ff_math_exp", |
| 1089 | "vm_exp", | 1089 | "vm_exp_x87", |
| 1090 | "ff_math_sin", | 1090 | "ff_math_sin", |
| 1091 | "ff_math_cos", | 1091 | "ff_math_cos", |
| 1092 | "ff_math_tan", | 1092 | "ff_math_tan", |
| @@ -1146,7 +1146,7 @@ static const char *const globnames[] = { | |||
| 1146 | "vm_ceil_sse", | 1146 | "vm_ceil_sse", |
| 1147 | "vm_trunc_sse", | 1147 | "vm_trunc_sse", |
| 1148 | "vm_mod", | 1148 | "vm_mod", |
| 1149 | "vm_exp2", | 1149 | "vm_exp2_x87", |
| 1150 | "vm_exp2raw", | 1150 | "vm_exp2raw", |
| 1151 | "vm_pow_sse", | 1151 | "vm_pow_sse", |
| 1152 | "vm_powi_sse", | 1152 | "vm_powi_sse", |
| @@ -1177,9 +1177,9 @@ static const char *const extnames[] = { | |||
| 1177 | "lj_tab_next", | 1177 | "lj_tab_next", |
| 1178 | "lj_tab_getinth@8", | 1178 | "lj_tab_getinth@8", |
| 1179 | "lj_ffh_coroutine_wrap_err@8", | 1179 | "lj_ffh_coroutine_wrap_err@8", |
| 1180 | "lj_wrapper_sinh", | 1180 | "lj_vm_sinh", |
| 1181 | "lj_wrapper_cosh", | 1181 | "lj_vm_cosh", |
| 1182 | "lj_wrapper_tanh", | 1182 | "lj_vm_tanh", |
| 1183 | "lj_str_new", | 1183 | "lj_str_new", |
| 1184 | "lj_tab_len@4", | 1184 | "lj_tab_len@4", |
| 1185 | "lj_gc_step@4", | 1185 | "lj_gc_step@4", |
diff --git a/src/lib_math.c b/src/lib_math.c index 24501139..917b5e7b 100644 --- a/src/lib_math.c +++ b/src/lib_math.c | |||
| @@ -84,10 +84,6 @@ LJLIB_ASM_(math_max) LJLIB_REC(math_minmax IR_MAX) | |||
| 84 | LJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi) | 84 | LJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi) |
| 85 | LJLIB_PUSH(1e310) LJLIB_SET(huge) | 85 | LJLIB_PUSH(1e310) LJLIB_SET(huge) |
| 86 | 86 | ||
| 87 | LJ_FUNCA double lj_wrapper_sinh(double x) { return sinh(x); } | ||
| 88 | LJ_FUNCA double lj_wrapper_cosh(double x) { return cosh(x); } | ||
| 89 | LJ_FUNCA double lj_wrapper_tanh(double x) { return tanh(x); } | ||
| 90 | |||
| 91 | /* ------------------------------------------------------------------------ */ | 87 | /* ------------------------------------------------------------------------ */ |
| 92 | 88 | ||
| 93 | /* This implements a Tausworthe PRNG with period 2^223. Based on: | 89 | /* This implements a Tausworthe PRNG with period 2^223. Based on: |
diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h index b7712b36..c89bc521 100644 --- a/src/lj_asm_x86.h +++ b/src/lj_asm_x86.h | |||
| @@ -1591,8 +1591,8 @@ static void asm_fpmath(ASMState *as, IRIns *ir) | |||
| 1591 | } | 1591 | } |
| 1592 | emit_rmro(as, XO_FSTPq, XOg_FSTPq, RID_ESP, ofs); | 1592 | emit_rmro(as, XO_FSTPq, XOg_FSTPq, RID_ESP, ofs); |
| 1593 | switch (fpm) { /* st0 = lj_vm_*(st0) */ | 1593 | switch (fpm) { /* st0 = lj_vm_*(st0) */ |
| 1594 | case IRFPM_EXP: emit_call(as, lj_vm_exp); break; | 1594 | case IRFPM_EXP: emit_call(as, lj_vm_exp_x87); break; |
| 1595 | case IRFPM_EXP2: emit_call(as, lj_vm_exp2); break; | 1595 | case IRFPM_EXP2: emit_call(as, lj_vm_exp2_x87); break; |
| 1596 | case IRFPM_SIN: emit_x87op(as, XI_FSIN); break; | 1596 | case IRFPM_SIN: emit_x87op(as, XI_FSIN); break; |
| 1597 | case IRFPM_COS: emit_x87op(as, XI_FCOS); break; | 1597 | case IRFPM_COS: emit_x87op(as, XI_FCOS); break; |
| 1598 | case IRFPM_TAN: emit_x87op(as, XI_FPOP); emit_x87op(as, XI_FPTAN); break; | 1598 | case IRFPM_TAN: emit_x87op(as, XI_FPOP); emit_x87op(as, XI_FPTAN); break; |
diff --git a/src/lj_ir.c b/src/lj_ir.c index 749b7f12..8f22e085 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c | |||
| @@ -37,72 +37,6 @@ | |||
| 37 | /* Pass IR on to next optimization in chain (FOLD). */ | 37 | /* Pass IR on to next optimization in chain (FOLD). */ |
| 38 | #define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) | 38 | #define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) |
| 39 | 39 | ||
| 40 | /* -- Helper functions for generated machine code ------------------------- */ | ||
| 41 | |||
| 42 | #ifdef __ANDROID__ | ||
| 43 | /* Android doesn't have log2(). Oh well. */ | ||
| 44 | #define log2 lj_vm_log2 | ||
| 45 | static double lj_vm_log2(double a) | ||
| 46 | { | ||
| 47 | return log(a) * 1.4426950408889634074; | ||
| 48 | } | ||
| 49 | #endif | ||
| 50 | |||
| 51 | #if !LJ_TARGET_X86ORX64 | ||
| 52 | /* Unsigned x^k. */ | ||
| 53 | static double lj_vm_powui(double x, uint32_t k) | ||
| 54 | { | ||
| 55 | double y; | ||
| 56 | lua_assert(k != 0); | ||
| 57 | for (; (k & 1) == 0; k >>= 1) x *= x; | ||
| 58 | y = x; | ||
| 59 | if ((k >>= 1) != 0) { | ||
| 60 | for (;;) { | ||
| 61 | x *= x; | ||
| 62 | if (k == 1) break; | ||
| 63 | if (k & 1) y *= x; | ||
| 64 | k >>= 1; | ||
| 65 | } | ||
| 66 | y *= x; | ||
| 67 | } | ||
| 68 | return y; | ||
| 69 | } | ||
| 70 | |||
| 71 | /* Signed x^k. */ | ||
| 72 | static double lj_vm_powi(double x, int32_t k) | ||
| 73 | { | ||
| 74 | if (k > 1) | ||
| 75 | return lj_vm_powui(x, (uint32_t)k); | ||
| 76 | else if (k == 1) | ||
| 77 | return x; | ||
| 78 | else if (k == 0) | ||
| 79 | return 1; | ||
| 80 | else | ||
| 81 | return 1.0 / lj_vm_powui(x, (uint32_t)-k); | ||
| 82 | } | ||
| 83 | |||
| 84 | /* Computes fpm(x) for extended math functions. */ | ||
| 85 | double lj_vm_foldfpm(double x, int fpm) | ||
| 86 | { | ||
| 87 | switch (fpm) { | ||
| 88 | case IRFPM_FLOOR: return lj_vm_floor(x); | ||
| 89 | case IRFPM_CEIL: return lj_vm_ceil(x); | ||
| 90 | case IRFPM_TRUNC: return lj_vm_trunc(x); | ||
| 91 | case IRFPM_SQRT: return sqrt(x); | ||
| 92 | case IRFPM_EXP: return exp(x); | ||
| 93 | case IRFPM_EXP2: return exp2(x); | ||
| 94 | case IRFPM_LOG: return log(x); | ||
| 95 | case IRFPM_LOG2: return log2(x); | ||
| 96 | case IRFPM_LOG10: return log10(x); | ||
| 97 | case IRFPM_SIN: return sin(x); | ||
| 98 | case IRFPM_COS: return cos(x); | ||
| 99 | case IRFPM_TAN: return tan(x); | ||
| 100 | default: lua_assert(0); | ||
| 101 | } | ||
| 102 | return 0; | ||
| 103 | } | ||
| 104 | #endif | ||
| 105 | |||
| 106 | /* -- IR tables ----------------------------------------------------------- */ | 40 | /* -- IR tables ----------------------------------------------------------- */ |
| 107 | 41 | ||
| 108 | /* IR instruction modes. */ | 42 | /* IR instruction modes. */ |
diff --git a/src/lj_ircall.h b/src/lj_ircall.h index b83a0a81..1cbee91c 100644 --- a/src/lj_ircall.h +++ b/src/lj_ircall.h | |||
| @@ -91,9 +91,9 @@ typedef struct CCallInfo { | |||
| 91 | _(lj_vm_trunc, ARG1_FP, N, NUM, 0) \ | 91 | _(lj_vm_trunc, ARG1_FP, N, NUM, 0) \ |
| 92 | _(sqrt, ARG1_FP, N, NUM, 0) \ | 92 | _(sqrt, ARG1_FP, N, NUM, 0) \ |
| 93 | _(exp, ARG1_FP, N, NUM, 0) \ | 93 | _(exp, ARG1_FP, N, NUM, 0) \ |
| 94 | _(exp2, ARG1_FP, N, NUM, 0) \ | 94 | _(lj_vm_exp2, ARG1_FP, N, NUM, 0) \ |
| 95 | _(log, ARG1_FP, N, NUM, 0) \ | 95 | _(log, ARG1_FP, N, NUM, 0) \ |
| 96 | _(log2, ARG1_FP, N, NUM, 0) \ | 96 | _(lj_vm_log2, ARG1_FP, N, NUM, 0) \ |
| 97 | _(log10, ARG1_FP, N, NUM, 0) \ | 97 | _(log10, ARG1_FP, N, NUM, 0) \ |
| 98 | _(sin, ARG1_FP, N, NUM, 0) \ | 98 | _(sin, ARG1_FP, N, NUM, 0) \ |
| 99 | _(cos, ARG1_FP, N, NUM, 0) \ | 99 | _(cos, ARG1_FP, N, NUM, 0) \ |
diff --git a/src/lj_opt_split.c b/src/lj_opt_split.c index ea9b6fe3..0a1d87cb 100644 --- a/src/lj_opt_split.c +++ b/src/lj_opt_split.c | |||
| @@ -274,7 +274,7 @@ static void split_ir(jit_State *J) | |||
| 274 | IRIns *irm12 = IR(irm3->op1); | 274 | IRIns *irm12 = IR(irm3->op1); |
| 275 | IRIns *irl1 = IR(irm12->op1); | 275 | IRIns *irl1 = IR(irm12->op1); |
| 276 | if (irm12->op1 > J->loopref && irl1->o == IR_CALLN && | 276 | if (irm12->op1 > J->loopref && irl1->o == IR_CALLN && |
| 277 | irl1->op2 == IRCALL_log2) { | 277 | irl1->op2 == IRCALL_lj_vm_log2) { |
| 278 | IRRef tmp = irl1->op1; /* Recycle first two args from LOG2. */ | 278 | IRRef tmp = irl1->op1; /* Recycle first two args from LOG2. */ |
| 279 | IRRef arg3 = irm3->op2, arg4 = irm4->op2; | 279 | IRRef arg3 = irm3->op2, arg4 = irm4->op2; |
| 280 | J->cur.nins--; | 280 | J->cur.nins--; |
diff --git a/src/lj_vm.h b/src/lj_vm.h index 649280d0..3941dad9 100644 --- a/src/lj_vm.h +++ b/src/lj_vm.h | |||
| @@ -51,14 +51,25 @@ LJ_ASMF void lj_vm_exit_interp(void); | |||
| 51 | LJ_ASMF void lj_vm_floor_sse(void); | 51 | LJ_ASMF void lj_vm_floor_sse(void); |
| 52 | LJ_ASMF void lj_vm_ceil_sse(void); | 52 | LJ_ASMF void lj_vm_ceil_sse(void); |
| 53 | LJ_ASMF void lj_vm_trunc_sse(void); | 53 | LJ_ASMF void lj_vm_trunc_sse(void); |
| 54 | LJ_ASMF void lj_vm_exp(void); | 54 | LJ_ASMF void lj_vm_exp_x87(void); |
| 55 | LJ_ASMF void lj_vm_exp2(void); | 55 | LJ_ASMF void lj_vm_exp2_x87(void); |
| 56 | LJ_ASMF void lj_vm_pow_sse(void); | 56 | LJ_ASMF void lj_vm_pow_sse(void); |
| 57 | LJ_ASMF void lj_vm_powi_sse(void); | 57 | LJ_ASMF void lj_vm_powi_sse(void); |
| 58 | #else | 58 | #else |
| 59 | LJ_ASMF double lj_vm_floor(double); | 59 | LJ_ASMF double lj_vm_floor(double); |
| 60 | LJ_ASMF double lj_vm_ceil(double); | 60 | LJ_ASMF double lj_vm_ceil(double); |
| 61 | LJ_ASMF double lj_vm_trunc(double); | 61 | LJ_ASMF double lj_vm_trunc(double); |
| 62 | LJ_ASMF double lj_vm_powi(double, int32_t); | ||
| 63 | #if defined(__ANDROID__) || defined(__symbian__) | ||
| 64 | LJ_ASMF double lj_vm_log2(double); | ||
| 65 | #else | ||
| 66 | #define lj_vm_log2 log2 | ||
| 67 | #endif | ||
| 68 | #if defined(__symbian__) | ||
| 69 | LJ_ASMF double lj_vm_exp2(double); | ||
| 70 | #else | ||
| 71 | #define lj_vm_exp2 exp2 | ||
| 72 | #endif | ||
| 62 | #endif | 73 | #endif |
| 63 | #endif | 74 | #endif |
| 64 | 75 | ||
diff --git a/src/lj_vmmath.c b/src/lj_vmmath.c new file mode 100644 index 00000000..d357b4e3 --- /dev/null +++ b/src/lj_vmmath.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* | ||
| 2 | ** Math helper functions for assembler VM. | ||
| 3 | ** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h | ||
| 4 | */ | ||
| 5 | |||
| 6 | #define lj_vmmath_c | ||
| 7 | #define LUA_CORE | ||
| 8 | |||
| 9 | #include <math.h> | ||
| 10 | |||
| 11 | #include "lj_obj.h" | ||
| 12 | #if LJ_HASJIT | ||
| 13 | #include "lj_ir.h" | ||
| 14 | #endif | ||
| 15 | #include "lj_vm.h" | ||
| 16 | |||
| 17 | /* -- Helper functions for generated machine code ------------------------- */ | ||
| 18 | |||
| 19 | #if LJ_TARGET_X86ORX64 | ||
| 20 | /* Wrapper functions to avoid linker issues on OSX. */ | ||
| 21 | LJ_FUNCA double lj_vm_sinh(double x) { return sinh(x); } | ||
| 22 | LJ_FUNCA double lj_vm_cosh(double x) { return cosh(x); } | ||
| 23 | LJ_FUNCA double lj_vm_tanh(double x) { return tanh(x); } | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #if LJ_HASJIT | ||
| 27 | |||
| 28 | #if defined(__ANDROID__) || defined(__symbian__) | ||
| 29 | double lj_vm_log2(double a) | ||
| 30 | { | ||
| 31 | return log(a) * 1.4426950408889634074; | ||
| 32 | } | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #if defined(__symbian__) | ||
| 36 | double lj_vm_exp2(double a) | ||
| 37 | { | ||
| 38 | return exp(a * 0.6931471805599453); | ||
| 39 | } | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #if !LJ_TARGET_X86ORX64 | ||
| 43 | /* Unsigned x^k. */ | ||
| 44 | static double lj_vm_powui(double x, uint32_t k) | ||
| 45 | { | ||
| 46 | double y; | ||
| 47 | lua_assert(k != 0); | ||
| 48 | for (; (k & 1) == 0; k >>= 1) x *= x; | ||
| 49 | y = x; | ||
| 50 | if ((k >>= 1) != 0) { | ||
| 51 | for (;;) { | ||
| 52 | x *= x; | ||
| 53 | if (k == 1) break; | ||
| 54 | if (k & 1) y *= x; | ||
| 55 | k >>= 1; | ||
| 56 | } | ||
| 57 | y *= x; | ||
| 58 | } | ||
| 59 | return y; | ||
| 60 | } | ||
| 61 | |||
| 62 | /* Signed x^k. */ | ||
| 63 | double lj_vm_powi(double x, int32_t k) | ||
| 64 | { | ||
| 65 | if (k > 1) | ||
| 66 | return lj_vm_powui(x, (uint32_t)k); | ||
| 67 | else if (k == 1) | ||
| 68 | return x; | ||
| 69 | else if (k == 0) | ||
| 70 | return 1; | ||
| 71 | else | ||
| 72 | return 1.0 / lj_vm_powui(x, (uint32_t)-k); | ||
| 73 | } | ||
| 74 | |||
| 75 | /* Computes fpm(x) for extended math functions. */ | ||
| 76 | double lj_vm_foldfpm(double x, int fpm) | ||
| 77 | { | ||
| 78 | switch (fpm) { | ||
| 79 | case IRFPM_FLOOR: return lj_vm_floor(x); | ||
| 80 | case IRFPM_CEIL: return lj_vm_ceil(x); | ||
| 81 | case IRFPM_TRUNC: return lj_vm_trunc(x); | ||
| 82 | case IRFPM_SQRT: return sqrt(x); | ||
| 83 | case IRFPM_EXP: return exp(x); | ||
| 84 | case IRFPM_EXP2: return lj_vm_exp2(x); | ||
| 85 | case IRFPM_LOG: return log(x); | ||
| 86 | case IRFPM_LOG2: return lj_vm_log2(x); | ||
| 87 | case IRFPM_LOG10: return log10(x); | ||
| 88 | case IRFPM_SIN: return sin(x); | ||
| 89 | case IRFPM_COS: return cos(x); | ||
| 90 | case IRFPM_TAN: return tan(x); | ||
| 91 | default: lua_assert(0); | ||
| 92 | } | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #endif | ||
diff --git a/src/ljamalg.c b/src/ljamalg.c index 5d90c002..3d1f3938 100644 --- a/src/ljamalg.c +++ b/src/ljamalg.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include "lj_state.c" | 41 | #include "lj_state.c" |
| 42 | #include "lj_dispatch.c" | 42 | #include "lj_dispatch.c" |
| 43 | #include "lj_vmevent.c" | 43 | #include "lj_vmevent.c" |
| 44 | #include "lj_vmmath.c" | ||
| 44 | #include "lj_api.c" | 45 | #include "lj_api.c" |
| 45 | #include "lj_lex.c" | 46 | #include "lj_lex.c" |
| 46 | #include "lj_parse.c" | 47 | #include "lj_parse.c" |
