2 ** Math helper functions for assembler VM.
3 ** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h
18 /* -- Helper functions for generated machine code ------------------------- */
20 #if LJ_TARGET_X86ORX64
21 /* Wrapper functions to avoid linker issues on OSX. */
22 LJ_FUNCA
double lj_vm_sinh(double x
) { return sinh(x
); }
23 LJ_FUNCA
double lj_vm_cosh(double x
) { return cosh(x
); }
24 LJ_FUNCA
double lj_vm_tanh(double x
) { return tanh(x
); }
30 double lj_vm_log2(double a
)
32 return log(a
) * 1.4426950408889634074;
37 double lj_vm_exp2(double a
)
39 return exp(a
* 0.6931471805599453);
43 #if !(LJ_TARGET_ARM || LJ_TARGET_PPC)
44 int32_t LJ_FASTCALL
lj_vm_modi(int32_t a
, int32_t b
)
47 lua_assert(b
!= 0); /* This must be checked before using this function. */
48 ua
= a
< 0 ? (uint32_t)-a
: (uint32_t)a
;
49 ub
= b
< 0 ? (uint32_t)-b
: (uint32_t)b
;
51 if (y
!= 0 && (a
^b
) < 0) y
= y
- ub
;
52 if (((int32_t)y
^b
) < 0) y
= (uint32_t)-(int32_t)y
;
57 #if !LJ_TARGET_X86ORX64
59 static double lj_vm_powui(double x
, uint32_t k
)
63 for (; (k
& 1) == 0; k
>>= 1) x
*= x
;
78 double lj_vm_powi(double x
, int32_t k
)
81 return lj_vm_powui(x
, (uint32_t)k
);
87 return 1.0 / lj_vm_powui(x
, (uint32_t)-k
);
90 /* Computes fpm(x) for extended math functions. */
91 double lj_vm_foldfpm(double x
, int fpm
)
94 case IRFPM_FLOOR
: return lj_vm_floor(x
);
95 case IRFPM_CEIL
: return lj_vm_ceil(x
);
96 case IRFPM_TRUNC
: return lj_vm_trunc(x
);
97 case IRFPM_SQRT
: return sqrt(x
);
98 case IRFPM_EXP
: return exp(x
);
99 case IRFPM_EXP2
: return lj_vm_exp2(x
);
100 case IRFPM_LOG
: return log(x
);
101 case IRFPM_LOG2
: return lj_vm_log2(x
);
102 case IRFPM_LOG10
: return log10(x
);
103 case IRFPM_SIN
: return sin(x
);
104 case IRFPM_COS
: return cos(x
);
105 case IRFPM_TAN
: return tan(x
);
106 default: lua_assert(0);
113 int lj_vm_errno(void)