mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 08:47:35 +02:00
Added fast-sub
This commit is contained in:
parent
5d089b83eb
commit
bdd3edfe4f
3 changed files with 22 additions and 27 deletions
|
@ -263,7 +263,7 @@ 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 ptr, object x, object y);
|
||||
//object Cyc_fast_sub(void *data, object ptr, object x, object y);
|
||||
object Cyc_fast_sub(void *data, object ptr, 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,
|
||||
|
|
29
runtime.c
29
runtime.c
|
@ -2294,17 +2294,6 @@ void FUNC_APPLY(void *data, int argc, object clo, object cont, object n, ...) {
|
|||
return_closcall1(data, cont, result); \
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: need compiler to allocate a common type on the stack, and pass
|
||||
a pointer to it as ptr. This would allow us to have a function that can
|
||||
be inlined.
|
||||
|
||||
TODO: with above, will want compiler to replace suitable instances of +
|
||||
with something else to be compiled to this, such as Cyc:+.
|
||||
I think it is good enough to replace all calls to + with only 2 params.
|
||||
might be able to condense calls with more than 2 params down to multiple
|
||||
calls to Cyc:+, but lets do that afterwards
|
||||
*/
|
||||
object Cyc_fast_sum(void *data, object ptr, object x, object y) {
|
||||
// x is int (assume value types for integers)
|
||||
if (obj_is_int(x)){
|
||||
|
@ -2335,25 +2324,25 @@ object Cyc_fast_sum(void *data, object ptr, object x, object y) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*object Cyc_fast_sub(void *data, object ptr, object x, object y) {
|
||||
object Cyc_fast_sub(void *data, object ptr, 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));
|
||||
return 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);
|
||||
assign_double(ptr, (double)(obj_obj2int(x)) - double_value(y));
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
assign_double(ptr, (double)(obj_obj2int(y)) - double_value(x));
|
||||
return ptr;
|
||||
} 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);
|
||||
assign_double(ptr, double_value(x) - double_value(y));
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
// still here, raise an error
|
||||
|
@ -2363,7 +2352,7 @@ object Cyc_fast_sum(void *data, object ptr, object x, object y) {
|
|||
make_pair(c0, &s, &c1);
|
||||
Cyc_rt_raise(data, &c0);
|
||||
return NULL;
|
||||
}*/
|
||||
}
|
||||
|
||||
object Cyc_div_op(void *data, common_type * x, object y)
|
||||
{
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
Cyc-stdin
|
||||
Cyc-stderr
|
||||
Cyc-fast-plus
|
||||
Cyc-fast-sub
|
||||
+
|
||||
-
|
||||
*
|
||||
|
@ -182,6 +183,7 @@
|
|||
(Cyc-stdin 0 0)
|
||||
(Cyc-stderr 0 0)
|
||||
(Cyc-fast-plus 2 2)
|
||||
(Cyc-fast-sub 2 2)
|
||||
(- 1 #f)
|
||||
(/ 1 #f)
|
||||
(= 2 #f)
|
||||
|
@ -409,6 +411,7 @@
|
|||
((eq? p 'Cyc-stdin) "Cyc_stdin")
|
||||
((eq? p 'Cyc-stderr) "Cyc_stderr")
|
||||
((eq? p 'Cyc-fast-plus) "Cyc_fast_sum")
|
||||
((eq? p 'Cyc-fast-sub) "Cyc_fast_sub")
|
||||
((eq? p '+) "Cyc_sum")
|
||||
((eq? p '-) "Cyc_sub")
|
||||
((eq? p '*) "Cyc_mul")
|
||||
|
@ -531,6 +534,7 @@
|
|||
(define (prim/data-arg? p)
|
||||
(member p '(
|
||||
Cyc-fast-plus
|
||||
Cyc-fast-sub
|
||||
+
|
||||
-
|
||||
*
|
||||
|
@ -607,6 +611,7 @@
|
|||
(define (prim/c-var-pointer p)
|
||||
(cond
|
||||
((eq? p 'Cyc-fast-plus) "common_type")
|
||||
((eq? p 'Cyc-fast-sub) "common_type")
|
||||
(else #f)))
|
||||
|
||||
;; Determine if primitive assigns (allocates) a C variable
|
||||
|
@ -619,6 +624,7 @@
|
|||
((eq? p 'open-input-file) "port_type")
|
||||
((eq? p 'open-output-file) "port_type")
|
||||
((eq? p 'Cyc-fast-plus) "object")
|
||||
((eq? p 'Cyc-fast-sub) "object")
|
||||
((eq? p '+) "object")
|
||||
((eq? p '-) "object")
|
||||
((eq? p '*) "object")
|
||||
|
@ -674,6 +680,7 @@
|
|||
symbol->string number->string
|
||||
substring
|
||||
Cyc-fast-plus
|
||||
Cyc-fast-sub
|
||||
+ - * / apply
|
||||
= > < >= <=
|
||||
command-line-arguments
|
||||
|
@ -728,12 +735,11 @@
|
|||
(member exp '())))
|
||||
|
||||
(define (prim:inline-convert-prim-call prim-call)
|
||||
;(write `(prim:inline-convert-prim-call ,prim-call))
|
||||
;(newline)
|
||||
(cond
|
||||
((and (equal? (car prim-call) '+)
|
||||
(= (length prim-call) 3))
|
||||
(cons 'Cyc-fast-plus (cdr prim-call)))
|
||||
((and (equal? (car prim-call) '+) (= (length prim-call) 3))
|
||||
(cons 'Cyc-fast-plus (cdr prim-call)))
|
||||
((and (equal? (car prim-call) '-) (= (length prim-call) 3))
|
||||
(cons 'Cyc-fast-sub (cdr prim-call)))
|
||||
(else
|
||||
prim-call)))
|
||||
prim-call)))
|
||||
))
|
||||
|
|
Loading…
Add table
Reference in a new issue