From 0c04b7e03bd5db2df407edc9e9d46946848ca4f8 Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 19 Jul 2021 04:27:45 +0300 Subject: [PATCH] move vec_add slow case to .c file --- obj/subMakefile | 2 +- src/utils/mut.c | 10 ++++++++++ src/utils/mut.h | 16 ++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/utils/mut.c diff --git a/obj/subMakefile b/obj/subMakefile index 57f4db65..75504b32 100644 --- a/obj/subMakefile +++ b/obj/subMakefile @@ -42,7 +42,7 @@ base: load.o main.o rtwrap.o vm.o ns.o nfns.o @echo $< | cut -c 11- @$(CMD) $@.d -c $< -utils: utf.o hash.o file.o +utils: utf.o hash.o file.o mut.o %.o: ../../src/utils/%.c @echo $< | cut -c 11- @$(CMD) $@.d -c $< diff --git a/src/utils/mut.c b/src/utils/mut.c new file mode 100644 index 00000000..50b3ad9c --- /dev/null +++ b/src/utils/mut.c @@ -0,0 +1,10 @@ +#include "../core.h" +#include "mut.h" +NOINLINE B vec_addR(B w, B x) { + usz wia = a(w)->ia; + MAKE_MUT(r, wia+1); mut_to(r, el_or(TI(w,elType), selfElType(x))); + mut_copyG(r, 0, w, 0, wia); + mut_setG(r, wia, x); + dec(w); + return mut_fv(r); +} \ No newline at end of file diff --git a/src/utils/mut.h b/src/utils/mut.h index 1b403406..f971b621 100644 --- a/src/utils/mut.h +++ b/src/utils/mut.h @@ -38,10 +38,10 @@ static void mut_to(Mut* m, u8 n) { } #endif switch(n) { default: UD; - case el_i32: { I32Arr* t= toI32Arr(taga(m->val)); m->val = (Arr*)t; m->ai32 = t->a; return; } - case el_f64: { F64Arr* t= toF64Arr(taga(m->val)); m->val = (Arr*)t; m->af64 = t->a; return; } - case el_c32: { C32Arr* t= toC32Arr(taga(m->val)); m->val = (Arr*)t; m->ac32 = t->a; return; } - case el_B : { HArr* t= toHArr (taga(m->val)); m->val = (Arr*)t; m->aB = t->a; return; } + case el_i32: { I32Arr* t=toI32Arr(taga(m->val)); m->val=(Arr*)t; m->ai32=t->a; return; } + case el_f64: { F64Arr* t=toF64Arr(taga(m->val)); m->val=(Arr*)t; m->af64=t->a; return; } + case el_c32: { C32Arr* t=toC32Arr(taga(m->val)); m->val=(Arr*)t; m->ac32=t->a; return; } + case el_B : { HArr* t=toHArr (taga(m->val)); m->val=(Arr*)t; m->aB =t->a; return; } } } } @@ -403,12 +403,8 @@ static inline bool inplace_add(B w, B x) { // fails if fills wouldn't be correct } return false; } +B vec_addR(B w, B x); static B vec_add(B w, B x) { // consumes both; fills may be wrong if (inplace_add(w, x)) return w; - usz wia = a(w)->ia; - MAKE_MUT(r, wia+1); mut_to(r, el_or(TI(w,elType), selfElType(x))); - mut_copy(r, 0, w, 0, wia); - mut_set(r, wia, x); - dec(w); - return mut_fv(r); + return vec_addR(w, x); }