]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
Add new trunc insn for rounding float values towards zero.
authorKlaus Treichel <ktreichel@web.de>
Fri, 6 Aug 2010 09:30:02 +0000 (11:30 +0200)
committerKlaus Treichel <ktreichel@web.de>
Fri, 6 Aug 2010 09:30:02 +0000 (11:30 +0200)
ChangeLog
config/jit-opcodes.ops
dpas/dpas-builtin.c
include/jit/jit-insn.h
jit/jit-insn.c
jit/jit-interp.c
tests/math.pas

index d88218452123e1da64a72f0941e58e75e202c34c..55fac5a745a58e9627073547756e4d9a14755657 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,9 +3,21 @@
        * configure.ac: Add checks for the rint, round and trunc c library
        functions.
 
+       * config/jit-opcodes.ops: (ftrunc, dtrunc, nftrunc): Add opcode
+       definitions for the new trunc instruction.
+
+       * dpas/dpas-builtin.c: Add new Trunc builtin.
+
+       * include/jit/jit-insn.c (jit_insn_trunc): Add prototype.
+
        * include/jit/jit-intrinsic.h (jit_float32_trunc, jit_float64_trunc,
        jit_nfloat_trunc): Add prototypes.
 
+       * jit/jit-insn.c (jit_insn_trunc): Add new float rounding function.
+
+       * jit/jit-interp.c (_jit_run_function): Add support for the new
+       trunc opcodes.
+
        * jit/jit-intrinsic.c: Nove float rounding intrinsics to one block
        and refine conmments.
        (jit_float32_rint): Use rintf or rint if available.
@@ -20,6 +32,8 @@
        * jit/jit-symbol.c: Add the new intrinsics jit_float32_trunc,
        jit_float64_trunc and jit_nfloat_trunc to the symbol table.
 
+       * tests/math.pas: Add tests for the new trunc insn.
+
 2010-08-04  Klaus Treichel  <ktreichel@web.de>
 
        * include/jit/Makefile.am: Don't include jit-arch.h in the
index c156443bbbfeee0a7a87216a971dd3e5ce9f81f6..4cec16f4ba588ea8de70ec5522560f85664d8383 100644 (file)
@@ -342,6 +342,7 @@ opcodes(JIT_OP_, "jit_opcode_info_t const jit_opcodes[JIT_OP_NUM_OPCODES]")
        op_def("fsqrt") { op_values(float32, float32) }
        op_def("ftan") { op_values(float32, float32) }
        op_def("ftanh") { op_values(float32, float32) }
+       op_def("ftrunc") { op_values(float32, float32) }
        op_def("dacos") { op_values(float64, float64) }
        op_def("dasin") { op_values(float64, float64) }
        op_def("datan") { op_values(float64, float64) }
@@ -361,6 +362,7 @@ opcodes(JIT_OP_, "jit_opcode_info_t const jit_opcodes[JIT_OP_NUM_OPCODES]")
        op_def("dsqrt") { op_values(float64, float64) }
        op_def("dtan") { op_values(float64, float64) }
        op_def("dtanh") { op_values(float64, float64) }
+       op_def("dtrunc") { op_values(float64, float64) }
        op_def("nfacos") { op_values(nfloat, nfloat) }
        op_def("nfasin") { op_values(nfloat, nfloat) }
        op_def("nfatan") { op_values(nfloat, nfloat) }
@@ -380,6 +382,7 @@ opcodes(JIT_OP_, "jit_opcode_info_t const jit_opcodes[JIT_OP_NUM_OPCODES]")
        op_def("nfsqrt") { op_values(nfloat, nfloat) }
        op_def("nftan") { op_values(nfloat, nfloat) }
        op_def("nftanh") { op_values(nfloat, nfloat) }
+       op_def("nftrunc") { op_values(nfloat, nfloat) }
        /*
         * Absolute, minimum, maximum, and sign.
         */
index e43414d4d34620a7179f8cebb866e4cb795821b6..0a03c526301b666963c11a40fd2f27f49e2a5c7c 100644 (file)
@@ -498,6 +498,7 @@ dpas_math_unary(sinh, jit_insn_sinh)
 dpas_math_unary(sqrt, jit_insn_sqrt)
 dpas_math_unary(tan, jit_insn_tan)
 dpas_math_unary(tanh, jit_insn_tanh)
+dpas_math_unary(trunc, jit_insn_trunc)
 dpas_math_unary(abs, jit_insn_abs)
 dpas_math_binary(min, jit_insn_min)
 dpas_math_binary(max, jit_insn_max)
@@ -535,13 +536,14 @@ dpas_math_test(finite, jit_insn_is_finite)
 #define        DPAS_BUILTIN_SQRT                       24
 #define        DPAS_BUILTIN_TAN                        25
 #define        DPAS_BUILTIN_TANH                       26
-#define        DPAS_BUILTIN_ABS                        27
-#define        DPAS_BUILTIN_MIN                        28
-#define        DPAS_BUILTIN_MAX                        29
-#define        DPAS_BUILTIN_SIGN                       30
-#define        DPAS_BUILTIN_ISNAN                      31
-#define        DPAS_BUILTIN_ISINF                      32
-#define        DPAS_BUILTIN_FINITE                     33
+#define        DPAS_BUILTIN_TRUNC                      27
+#define        DPAS_BUILTIN_ABS                        28
+#define        DPAS_BUILTIN_MIN                        29
+#define        DPAS_BUILTIN_MAX                        30
+#define        DPAS_BUILTIN_SIGN                       31
+#define        DPAS_BUILTIN_ISNAN                      32
+#define        DPAS_BUILTIN_ISINF                      33
+#define        DPAS_BUILTIN_FINITE                     34
 
 /*
  * Table that defines the builtins.
@@ -581,6 +583,7 @@ static dpas_builtin const builtins[] = {
        {"Sqrt",                DPAS_BUILTIN_SQRT,              dpas_sqrt,        1},
        {"Tan",                 DPAS_BUILTIN_TAN,               dpas_tan,         1},
        {"Tanh",                DPAS_BUILTIN_TANH,              dpas_tanh,        1},
+       {"Trunc",               DPAS_BUILTIN_TRUNC,             dpas_trunc,       1},
        {"Abs",                 DPAS_BUILTIN_ABS,               dpas_abs,         1},
        {"Min",                 DPAS_BUILTIN_MIN,               dpas_min,         2},
        {"Max",                 DPAS_BUILTIN_MAX,               dpas_max,         2},
index e2631ebe178a9a1c9262628b031268cca641ee59..f3427475c1692f9d1906aa8497e33f9543f9c262 100644 (file)
@@ -189,6 +189,8 @@ jit_value_t jit_insn_tan
        (jit_function_t func, jit_value_t value1) JIT_NOTHROW;
 jit_value_t jit_insn_tanh
        (jit_function_t func, jit_value_t value1) JIT_NOTHROW;
+jit_value_t jit_insn_trunc
+       (jit_function_t func, jit_value_t value1) JIT_NOTHROW;
 jit_value_t jit_insn_is_nan
        (jit_function_t func, jit_value_t value1) JIT_NOTHROW;
 jit_value_t jit_insn_is_finite
index b1dd2e2a37ddd6c59d679a3943014a555cb32c7c..5780d7bbddf32b4eddc6ab813d5d59b2337dfde0 100644 (file)
@@ -3249,6 +3249,24 @@ jit_value_t jit_insn_tanh(jit_function_t func, jit_value_t value1)
        return apply_unary_arith(func, &tanh_descr, value1, 0, 1, 0);
 }
 
+jit_value_t jit_insn_trunc(jit_function_t func, jit_value_t value1)
+{
+       static jit_opcode_descr const trunc_descr = {
+               0, 0, 0, 0,
+               JIT_OP_FTRUNC,
+               JIT_OP_DTRUNC,
+               JIT_OP_NFTRUNC,
+               jit_no_intrinsic,
+               jit_no_intrinsic,
+               jit_no_intrinsic,
+               jit_no_intrinsic,
+               jit_intrinsic(jit_float32_trunc, descr_f_f),
+               jit_intrinsic(jit_float64_trunc, descr_d_d),
+               jit_intrinsic(jit_nfloat_trunc, descr_D_D)
+       };
+       return apply_unary_arith(func, &trunc_descr, value1, 0, 1, 0);
+}
+
 /*@
  * @deftypefun jit_value_t jit_insn_is_nan (jit_function_t @var{func}, jit_value_t @var{value1})
  * @deftypefunx jit_value_t jit_insn_is_finite (jit_function_t @var{func}, jit_value_t @var{value1})
index 16f5267466eca8e06ca0ee8776770cc38127ea12..bf484e42f8447aabb0865495a9ffbb1d656535b9 100644 (file)
@@ -2786,6 +2786,14 @@ restart_tail:
                }
                VMBREAK;
 
+               VMCASE(JIT_OP_FTRUNC):
+               {
+                       /* Compute 32-bit float "trunc" */
+                       VM_R0_FLOAT32 = jit_float32_trunc(VM_R1_FLOAT32);
+                       VM_MODIFY_PC(1);
+               }
+               VMBREAK;
+
                VMCASE(JIT_OP_DACOS):
                {
                        /* Compute 64-bit float "acos" */
@@ -2938,6 +2946,14 @@ restart_tail:
                }
                VMBREAK;
 
+               VMCASE(JIT_OP_DTRUNC):
+               {
+                       /* Compute 64-bit float "trunc" */
+                       VM_R0_FLOAT64 = jit_float64_trunc(VM_R1_FLOAT64);
+                       VM_MODIFY_PC(1);
+               }
+               VMBREAK;
+
                VMCASE(JIT_OP_NFACOS):
                {
                        /* Compute native float "acos" */
@@ -3090,6 +3106,14 @@ restart_tail:
                }
                VMBREAK;
 
+               VMCASE(JIT_OP_NFTRUNC):
+               {
+                       /* Compute native float "trunc" */
+                       VM_R0_NFLOAT = jit_nfloat_trunc(VM_R1_NFLOAT);
+                       VM_MODIFY_PC(1);
+               }
+               VMBREAK;
+
                /******************************************************************
                 * Absolute, minimum, maximum, and sign.
                 ******************************************************************/
index 135e8108011e6ac8f7ff75a5a08246ef2abf46d2..8f4fcee03ac23bca5c3763f6df017c4a288d65cc 100644 (file)
@@ -300,6 +300,9 @@ begin
        runf("math_f_rint_2.5", Rint(ShortReal(2.5)), ShortReal(2.0), 0.00001);
        runf("math_f_round_1.5", Round(ShortReal(1.5)), ShortReal(2.0), 0.00001);
        runf("math_f_round_2.5", Round(ShortReal(2.5)), ShortReal(3.0), 0.00001);
+       runf("math_f_trunc_1.5", Trunc(ShortReal(1.5)), ShortReal(1.0), 0.00001);
+       runf("math_f_trunc_2.5", Trunc(ShortReal(2.5)), ShortReal(2.0), 0.00001);
+       runf("math_f_trunc_m1.5", Trunc(ShortReal(-1.5)), ShortReal(-1.0), 0.00001);
 
        { real versions }
        rund("math_d_abs_1.5", Abs(Real(1.5)), Real(1.5), 0.00001);
@@ -325,6 +328,9 @@ begin
        rund("math_d_rint_2.5", Rint(Real(2.5)), Real(2.0), 0.00001);
        rund("math_d_round_1.5", Round(Real(1.5)), Real(2.0), 0.00001);
        rund("math_d_round_2.5", Round(Real(2.5)), Real(3.0), 0.00001);
+       rund("math_d_trunc_1.5", Trunc(Real(1.5)), Real(1.0), 0.00001);
+       rund("math_d_trunc_2.5", Trunc(Real(2.5)), Real(2.0), 0.00001);
+       rund("math_d_trunc_m1.5", Trunc(Real(-1.5)), Real(-1.0), 0.00001);
 
        { long real versions }
        runn("math_n_abs_1.5", Abs(LongReal(1.5)), LongReal(1.5), 0.00001);
@@ -350,6 +356,9 @@ begin
        runn("math_n_rint_2.5", Rint(LongReal(2.5)), LongReal(2.0), 0.00001);
        runn("math_n_round_1.5", Round(LongReal(1.5)), LongReal(2.0), 0.00001);
        runn("math_n_round_2.5", Round(LongReal(2.5)), LongReal(3.0), 0.00001);
+       runn("math_n_trunc_1.5", Trunc(LongReal(1.5)), LongReal(1.0), 0.00001);
+       runn("math_n_trunc_2.5", Trunc(LongReal(2.5)), LongReal(2.0), 0.00001);
+       runn("math_n_trunc_m1.5", Trunc(LongReal(-1.5)), LongReal(-1.0), 0.00001);
 
 end;