From 537e8bc975ca87060e42a6d9bf729f7f8d743eb6 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 26 Nov 2019 15:37:52 -0500 Subject: [PATCH] Experimenting with unsafe prims --- include/cyclone/runtime.h | 2 ++ scheme/cyclone/cgen.sld | 4 +++- scheme/cyclone/primitives.sld | 13 ++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 6f6223f3..2bdb4acc 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -486,6 +486,8 @@ object Cyc_is_immutable(object obj); /**@{*/ object Cyc_vector_length(void *data, object v); object Cyc_vector_ref(void *d, object v, object k); +#define Cyc_vector_ref_unsafe(d, v, k) \ + ((vector) v)->elements[unbox_number(k)] object Cyc_vector_set(void *d, object v, object k, object obj); object Cyc_make_vector(void *data, object cont, int argc, object len, ...); /**@}*/ diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index 5c97f435..7c408971 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -41,6 +41,7 @@ (begin (define *cgen:track-call-history* #t) +(define *cgen:use-unsafe-prims* #f) (define *optimize-well-known-lambdas* #f) (define (emit line) @@ -745,7 +746,7 @@ ((closure)" (cgen:mangle-global p) ")->fn)") - (prim->c-func p use-alloca?))) + (prim->c-func p use-alloca? *cgen:use-unsafe-prims*))) ;; Following closure defs are only used for prim:cont? to ;; create a new closure for the continuation, if needed. ;; @@ -1855,6 +1856,7 @@ flag-set?) (set! *global-syms* (append globals (lib:idb:ids import-db))) (set! *cgen:track-call-history* (flag-set? 'track-call-history)) + (set! *cgen:use-unsafe-prims* (flag-set? 'use-unsafe-prims)) (set! num-lambdas (+ (adb:max-lambda-id) 1)) (set! cgen:mangle-global (lambda (ident) diff --git a/scheme/cyclone/primitives.sld b/scheme/cyclone/primitives.sld index d4577799..87164ad2 100644 --- a/scheme/cyclone/primitives.sld +++ b/scheme/cyclone/primitives.sld @@ -492,7 +492,7 @@ ;; TODO: get rid of this function and replace this with the same type of pre-alloc that ;; we do for fast numeric operations. That will allow us to prevent out-of-order ;; execution for these as part of Cyc-seq - (define (prim->c-func p use-alloca?) + (define (prim->c-func p use-alloca? emit-unsafe) (cond (use-alloca? ;; Special case, when this flag is set the compiler is requesting a @@ -507,11 +507,11 @@ ;((eq? p 'Cyc-fast-list-4) "alloca_list_4") ;((eq? p 'cell) "alloca_cell") (else - (_prim->c-func p)))) + (_prim->c-func p emit-unsafe)))) (else - (_prim->c-func p)))) + (_prim->c-func p emit-unsafe)))) - (define (_prim->c-func p) + (define (_prim->c-func p emit-unsafe) (cond ((eq? p 'Cyc-global-vars) "Cyc_get_global_variables") ((eq? p 'Cyc-get-cvar) "Cyc_get_cvar") @@ -619,7 +619,10 @@ ((eq? p 'make-vector) "Cyc_make_vector") ((eq? p 'list->vector) "Cyc_list2vector") ((eq? p 'vector-length) "Cyc_vector_length") - ((eq? p 'vector-ref) "Cyc_vector_ref") + ((eq? p 'vector-ref) + (if emit-unsafe + "Cyc_vector_ref_unsafe" + "Cyc_vector_ref")) ((eq? p 'vector-set!) "Cyc_vector_set") ((eq? p 'string-append) "Cyc_string_append") ((eq? p 'string-cmp) "Cyc_string_cmp")