aboutsummaryrefslogtreecommitdiff
path: root/src/lj_vmmath.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_vmmath.c')
-rw-r--r--src/lj_vmmath.c56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/lj_vmmath.c b/src/lj_vmmath.c
index 50a2cbba..2a41bcaa 100644
--- a/src/lj_vmmath.c
+++ b/src/lj_vmmath.c
@@ -13,16 +13,29 @@
13#include "lj_ir.h" 13#include "lj_ir.h"
14#include "lj_vm.h" 14#include "lj_vm.h"
15 15
16/* -- Helper functions for generated machine code ------------------------- */ 16/* -- Wrapper functions --------------------------------------------------- */
17 17
18#if LJ_TARGET_X86ORX64 18#if LJ_TARGET_X86 && __ELF__ && __PIC__
19/* Wrapper functions to avoid linker issues on OSX. */ 19/* Wrapper functions to deal with the ELF/x86 PIC disaster. */
20LJ_FUNCA double lj_vm_sinh(double x) { return sinh(x); } 20LJ_FUNCA double lj_wrap_log(double x) { return log(x); }
21LJ_FUNCA double lj_vm_cosh(double x) { return cosh(x); } 21LJ_FUNCA double lj_wrap_log10(double x) { return log10(x); }
22LJ_FUNCA double lj_vm_tanh(double x) { return tanh(x); } 22LJ_FUNCA double lj_wrap_exp(double x) { return exp(x); }
23LJ_FUNCA double lj_wrap_sin(double x) { return sin(x); }
24LJ_FUNCA double lj_wrap_cos(double x) { return cos(x); }
25LJ_FUNCA double lj_wrap_tan(double x) { return tan(x); }
26LJ_FUNCA double lj_wrap_asin(double x) { return asin(x); }
27LJ_FUNCA double lj_wrap_acos(double x) { return acos(x); }
28LJ_FUNCA double lj_wrap_atan(double x) { return atan(x); }
29LJ_FUNCA double lj_wrap_sinh(double x) { return sinh(x); }
30LJ_FUNCA double lj_wrap_cosh(double x) { return cosh(x); }
31LJ_FUNCA double lj_wrap_tanh(double x) { return tanh(x); }
32LJ_FUNCA double lj_wrap_atan2(double x, double y) { return atan2(x, y); }
33LJ_FUNCA double lj_wrap_pow(double x, double y) { return pow(x, y); }
34LJ_FUNCA double lj_wrap_fmod(double x, double y) { return fmod(x, y); }
23#endif 35#endif
24 36
25#if !LJ_TARGET_X86ORX64 37/* -- Helper functions for generated machine code ------------------------- */
38
26double lj_vm_foldarith(double x, double y, int op) 39double lj_vm_foldarith(double x, double y, int op)
27{ 40{
28 switch (op) { 41 switch (op) {
@@ -43,6 +56,19 @@ double lj_vm_foldarith(double x, double y, int op)
43 default: return x; 56 default: return x;
44 } 57 }
45} 58}
59
60#if (LJ_HASJIT && !(LJ_TARGET_ARM || LJ_TARGET_ARM64 || LJ_TARGET_PPC)) || LJ_TARGET_MIPS
61int32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b)
62{
63 uint32_t y, ua, ub;
64 lua_assert(b != 0); /* This must be checked before using this function. */
65 ua = a < 0 ? (uint32_t)-a : (uint32_t)a;
66 ub = b < 0 ? (uint32_t)-b : (uint32_t)b;
67 y = ua % ub;
68 if (y != 0 && (a^b) < 0) y = y - ub;
69 if (((int32_t)y^b) < 0) y = (uint32_t)-(int32_t)y;
70 return (int32_t)y;
71}
46#endif 72#endif
47 73
48#if LJ_HASJIT 74#if LJ_HASJIT
@@ -61,20 +87,6 @@ double lj_vm_exp2(double a)
61} 87}
62#endif 88#endif
63 89
64#if !(LJ_TARGET_ARM || LJ_TARGET_PPC)
65int32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b)
66{
67 uint32_t y, ua, ub;
68 lua_assert(b != 0); /* This must be checked before using this function. */
69 ua = a < 0 ? (uint32_t)-a : (uint32_t)a;
70 ub = b < 0 ? (uint32_t)-b : (uint32_t)b;
71 y = ua % ub;
72 if (y != 0 && (a^b) < 0) y = y - ub;
73 if (((int32_t)y^b) < 0) y = (uint32_t)-(int32_t)y;
74 return (int32_t)y;
75}
76#endif
77
78#if !LJ_TARGET_X86ORX64 90#if !LJ_TARGET_X86ORX64
79/* Unsigned x^k. */ 91/* Unsigned x^k. */
80static double lj_vm_powui(double x, uint32_t k) 92static double lj_vm_powui(double x, uint32_t k)
@@ -107,6 +119,7 @@ double lj_vm_powi(double x, int32_t k)
107 else 119 else
108 return 1.0 / lj_vm_powui(x, (uint32_t)-k); 120 return 1.0 / lj_vm_powui(x, (uint32_t)-k);
109} 121}
122#endif
110 123
111/* Computes fpm(x) for extended math functions. */ 124/* Computes fpm(x) for extended math functions. */
112double lj_vm_foldfpm(double x, int fpm) 125double lj_vm_foldfpm(double x, int fpm)
@@ -128,7 +141,6 @@ double lj_vm_foldfpm(double x, int fpm)
128 } 141 }
129 return 0; 142 return 0;
130} 143}
131#endif
132 144
133#if LJ_HASFFI 145#if LJ_HASFFI
134int lj_vm_errno(void) 146int lj_vm_errno(void)