From 3e037950bf89ab864c15f4623747fb5301e4cc09 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 14 Oct 2016 00:33:20 -0400 Subject: [PATCH] Testing Cyc_fast_sum and Cyc_fast_sub --- include/cyclone/runtime.h | 2 ++ runtime.c | 60 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index cd4c559c..b93ac289 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -262,6 +262,8 @@ object Cyc_sum(void *data, object cont, int argc, object n, ...); object Cyc_sub(void *data, object cont, int argc, object n, ...); object Cyc_mul(void *data, object cont, int argc, object n, ...); object Cyc_div(void *data, object cont, int argc, object n, ...); +object Cyc_fast_sum(void *data, object cont, int argc, object x, object y); +object Cyc_fast_sub(void *data, object cont, int argc, object x, object y); object Cyc_bit_unset(void *data, object n1, object n2); object Cyc_bit_set(void *data, object n1, object n2); object Cyc_num_op_va_list(void *data, int argc, diff --git a/runtime.c b/runtime.c index 19c319fc..8d93c9ee 100644 --- a/runtime.c +++ b/runtime.c @@ -2289,6 +2289,66 @@ void FUNC_APPLY(void *data, int argc, object clo, object cont, object n, ...) { return_closcall1(data, cont, result); \ } +object Cyc_fast_sum(void *data, object cont, int argc, object x, object y) { + // x is int (assume value types for integers) + if (obj_is_int(x)){ + if (obj_is_int(y)){ + int z = obj_obj2int(x) + obj_obj2int(y); + _return_closcall1(data, cont, obj_int2obj(z)); + } else if (is_object_type(y) && type_of(y) == double_tag) { + make_double(d, (double)(obj_obj2int(x)) + double_value(y)); + _return_closcall1(data, cont, &d); + } + } + // x is double + if (is_object_type(x) && type_of(x) == double_tag) { + if (obj_is_int(y)){ + make_double(d, (double)(obj_obj2int(y)) + double_value(x)); + _return_closcall1(data, cont, &d); + } else if (is_object_type(y) && type_of(y) == double_tag) { + make_double(d, double_value(x) + double_value(y)); + _return_closcall1(data, cont, &d); + } + } + // still here, raise an error + make_string(s, "Bad argument type"); + make_pair(c2, y, NULL); + make_pair(c1, x, &c2); + make_pair(c0, &s, &c1); + Cyc_rt_raise(data, &c0); + return NULL; +} + +object Cyc_fast_sub(void *data, object cont, int argc, object x, object y) { + // x is int (assume value types for integers) + if (obj_is_int(x)){ + if (obj_is_int(y)){ + int z = obj_obj2int(x) - obj_obj2int(y); + _return_closcall1(data, cont, obj_int2obj(z)); + } else if (is_object_type(y) && type_of(y) == double_tag) { + make_double(d, (double)(obj_obj2int(x)) - double_value(y)); + _return_closcall1(data, cont, &d); + } + } + // x is double + if (is_object_type(x) && type_of(x) == double_tag) { + if (obj_is_int(y)){ + make_double(d, (double)(obj_obj2int(y)) - double_value(x)); + _return_closcall1(data, cont, &d); + } else if (is_object_type(y) && type_of(y) == double_tag) { + make_double(d, double_value(x) - double_value(y)); + _return_closcall1(data, cont, &d); + } + } + // still here, raise an error + make_string(s, "Bad argument type"); + make_pair(c2, y, NULL); + make_pair(c1, x, &c2); + make_pair(c0, &s, &c1); + Cyc_rt_raise(data, &c0); + return NULL; +} + object Cyc_div_op(void *data, common_type * x, object y) { int tx = type_of(x), ty = (obj_is_int(y) ? -1 : type_of(y));