From c805a49d304c344d69630a4282d21d753c70e1bd Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 22 Oct 2011 01:59:10 +0200 Subject: [PATCH] Separate/rename NUM/FLOAT <-> I64/U64 conversion functions. --- src/lj_asm.c | 8 ++++ src/lj_ircall.h | 92 ++++++++++++++++++++++++++++++---------------- src/lj_opt_split.c | 8 ++-- 3 files changed, 72 insertions(+), 36 deletions(-) diff --git a/src/lj_asm.c b/src/lj_asm.c index 4187a1d9..3d9a213b 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c @@ -1515,6 +1515,14 @@ static void asm_setup_regsp(ASMState *as) } #endif break; +#endif +#if LJ_NEED_FP64 + case IR_CONV: + if (irt_isfp((ir-1)->t)) { + ir->prev = REGSP_HINT(RID_FPRET); + continue; + } + /* fallthrough */ #endif case IR_CALLN: case IR_CALLXS: #if LJ_SOFTFP diff --git a/src/lj_ircall.h b/src/lj_ircall.h index 00209d4c..b1e0e446 100644 --- a/src/lj_ircall.h +++ b/src/lj_ircall.h @@ -58,6 +58,14 @@ typedef struct CCallInfo { #define IRCALLCOND_SOFTFP_FFI(x) NULL #endif +#define LJ_NEED_FP64 LJ_TARGET_PPC + +#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64) +#define IRCALLCOND_FP64_FFI(x) x +#else +#define IRCALLCOND_FP64_FFI(x) NULL +#endif + #if LJ_HASFFI #define IRCALLCOND_FFI(x) x #if LJ_32 @@ -130,21 +138,21 @@ typedef struct CCallInfo { _(SOFTFP, softfp_i2d, 1, N, NUM, 0) \ _(SOFTFP, softfp_d2i, 2, N, INT, 0) \ _(SOFTFP_FFI, softfp_ui2d, 1, N, NUM, 0) \ - _(SOFTFP_FFI, softfp_l2d, 2, N, NUM, 0) \ - _(SOFTFP_FFI, softfp_ul2d, 2, N, NUM, 0) \ _(SOFTFP_FFI, softfp_f2d, 1, N, NUM, 0) \ _(SOFTFP_FFI, softfp_d2ui, 2, N, INT, 0) \ - _(SOFTFP_FFI, softfp_d2l, 2, N, I64, 0) \ - _(SOFTFP_FFI, softfp_d2ul, 2, N, U64, 0) \ _(SOFTFP_FFI, softfp_d2f, 2, N, FLOAT, 0) \ _(SOFTFP_FFI, softfp_i2f, 1, N, FLOAT, 0) \ _(SOFTFP_FFI, softfp_ui2f, 1, N, FLOAT, 0) \ - _(SOFTFP_FFI, softfp_l2f, 2, N, FLOAT, 0) \ - _(SOFTFP_FFI, softfp_ul2f, 2, N, FLOAT, 0) \ _(SOFTFP_FFI, softfp_f2i, 1, N, INT, 0) \ _(SOFTFP_FFI, softfp_f2ui, 1, N, INT, 0) \ - _(SOFTFP_FFI, softfp_f2l, 1, N, I64, 0) \ - _(SOFTFP_FFI, softfp_f2ul, 1, N, U64, 0) \ + _(FP64_FFI, fp64_l2d, 2, N, NUM, 0) \ + _(FP64_FFI, fp64_ul2d, 2, N, NUM, 0) \ + _(FP64_FFI, fp64_l2f, 2, N, FLOAT, 0) \ + _(FP64_FFI, fp64_ul2f, 2, N, FLOAT, 0) \ + _(FP64_FFI, fp64_d2l, 2, N, I64, 0) \ + _(FP64_FFI, fp64_d2ul, 2, N, U64, 0) \ + _(FP64_FFI, fp64_f2l, 1, N, I64, 0) \ + _(FP64_FFI, fp64_f2ul, 1, N, U64, 0) \ _(FFI, lj_carith_divi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ _(FFI, lj_carith_divu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ _(FFI, lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ @@ -179,29 +187,29 @@ LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1]; #define softfp_div __aeabi_ddiv #define softfp_cmp __aeabi_cdcmple #define softfp_i2d __aeabi_i2d -#define softfp_ui2d __aeabi_ui2d -#define softfp_l2d __aeabi_l2d -#define softfp_ul2d __aeabi_ul2d -#define softfp_f2d __aeabi_f2d #define softfp_d2i __aeabi_d2iz +#define softfp_ui2d __aeabi_ui2d +#define softfp_f2d __aeabi_f2d #define softfp_d2ui __aeabi_d2uiz #define softfp_d2f __aeabi_d2f #define softfp_i2f __aeabi_i2f #define softfp_ui2f __aeabi_ui2f -#define softfp_l2f __aeabi_l2f -#define softfp_ul2f __aeabi_ul2f #define softfp_f2i __aeabi_f2iz #define softfp_f2ui __aeabi_f2uiz +#define fp64_l2d __aeabi_l2d +#define fp64_ul2d __aeabi_ul2d +#define fp64_l2f __aeabi_l2f +#define fp64_ul2f __aeabi_ul2f #if LJ_TARGET_OSX -#define softfp_d2l __fixdfdi -#define softfp_d2ul __fixunsdfdi -#define softfp_f2l __fixsfdi -#define softfp_f2ul __fixunssfdi +#define fp64_d2l __fixdfdi +#define fp64_d2ul __fixunsdfdi +#define fp64_f2l __fixsfdi +#define fp64_f2ul __fixunssfdi #else -#define softfp_d2l __aeabi_d2lz -#define softfp_d2ul __aeabi_d2ulz -#define softfp_f2l __aeabi_f2lz -#define softfp_f2ul __aeabi_f2ulz +#define fp64_d2l __aeabi_d2lz +#define fp64_d2ul __aeabi_d2ulz +#define fp64_f2l __aeabi_f2lz +#define fp64_f2ul __aeabi_f2ulz #endif #else #error "Missing soft-float definitions for target architecture" @@ -212,23 +220,43 @@ extern double softfp_mul(double a, double b); extern double softfp_div(double a, double b); extern void softfp_cmp(double a, double b); extern double softfp_i2d(int32_t a); -extern double softfp_ui2d(uint32_t a); -extern double softfp_l2d(int64_t a); -extern double softfp_ul2d(uint64_t a); -extern double softfp_f2d(float a); extern int32_t softfp_d2i(double a); +#if LJ_HASFFI +extern double softfp_ui2d(uint32_t a); +extern double softfp_f2d(float a); extern uint32_t softfp_d2ui(double a); -extern int64_t softfp_d2l(double a); -extern uint64_t softfp_d2ul(double a); extern float softfp_d2f(double a); extern float softfp_i2f(int32_t a); extern float softfp_ui2f(uint32_t a); -extern float softfp_l2f(int64_t a); -extern float softfp_ul2f(uint64_t a); extern int32_t softfp_f2i(float a); extern uint32_t softfp_f2ui(float a); -extern int64_t softfp_f2l(float a); -extern uint64_t softfp_f2ul(float a); +#endif +#endif + +#if LJ_HASFFI && LJ_NEED_FP64 +#ifdef __GNUC__ +#define fp64_l2d __floatdidf +#define fp64_ul2d __floatundidf +#define fp64_l2f __floatdisf +#define fp64_ul2f __floatundisf +#define fp64_d2l __fixdfdi +#define fp64_d2ul __fixunsdfdi +#define fp64_f2l __fixsfdi +#define fp64_f2ul __fixunssfdi +#else +#error "Missing fp64 helper definitions for this compiler" +#endif +#endif + +#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64) +extern double fp64_l2d(int64_t a); +extern double fp64_ul2d(uint64_t a); +extern float fp64_l2f(int64_t a); +extern float fp64_ul2f(uint64_t a); +extern int64_t fp64_d2l(double a); +extern uint64_t fp64_d2ul(double a); +extern int64_t fp64_f2l(float a); +extern uint64_t fp64_f2ul(float a); #endif #endif diff --git a/src/lj_opt_split.c b/src/lj_opt_split.c index 61275b03..bd785d65 100644 --- a/src/lj_opt_split.c +++ b/src/lj_opt_split.c @@ -338,7 +338,7 @@ static void split_ir(jit_State *J) #if LJ_32 && LJ_HASFFI if (st == IRT_I64 || st == IRT_U64) { hi = split_call_l(J, hisubst, oir, ir, - st == IRT_I64 ? IRCALL_softfp_l2d : IRCALL_softfp_ul2d); + st == IRT_I64 ? IRCALL_fp64_l2d : IRCALL_fp64_ul2d); break; } #endif @@ -435,10 +435,10 @@ static void split_ir(jit_State *J) #if LJ_SOFTFP if (st == IRT_NUM) { /* NUM to 64 bit int conv. */ hi = split_call_l(J, hisubst, oir, ir, - irt_isi64(ir->t) ? IRCALL_softfp_d2l : IRCALL_softfp_d2ul); + irt_isi64(ir->t) ? IRCALL_fp64_d2l : IRCALL_fp64_d2ul); } else if (st == IRT_FLOAT) { /* FLOAT to 64 bit int conv. */ nir->o = IR_CALLN; - nir->op2 = irt_isi64(ir->t) ? IRCALL_softfp_f2l : IRCALL_softfp_f2ul; + nir->op2 = irt_isi64(ir->t) ? IRCALL_fp64_f2l : IRCALL_fp64_f2ul; hi = split_emit(J, IRTI(IR_HIOP), nref, nref); } #else @@ -518,7 +518,7 @@ static void split_ir(jit_State *J) #if LJ_SOFTFP if (irt_isfloat(ir->t)) { split_call_l(J, hisubst, oir, ir, - st == IRT_I64 ? IRCALL_softfp_l2f : IRCALL_softfp_ul2f); + st == IRT_I64 ? IRCALL_fp64_l2f : IRCALL_fp64_ul2f); J->cur.nins--; /* Drop unused HIOP. */ } #else