From: Jérémie Astor Date: Sun, 6 Sep 2020 23:25:19 +0000 (+0200) Subject: :art: Use computed gotos instead of ugop X-Git-Tag: nightly~1367 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=9673ea251f8f1311a1cdcfcd57029925c9ff9935;p=gwion.git :art: Use computed gotos instead of ugop --- diff --git a/src/lib/ugen.c b/src/lib/ugen.c index 73d8f79b..63f3584d 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -12,11 +12,6 @@ #include "driver.h" #include "gwi.h" -ANN static inline void ugop_add (const UGen u, const m_float f) { u->in += f; } -ANN static inline void ugop_sub (const UGen u, const m_float f) { u->in -= f; } -ANN static inline void ugop_mul (const UGen u, const m_float f) { u->in *= f; } -ANN static inline void ugop_div (const UGen u, const m_float f) { u->in /= f; } - static TICK(dac_tick) { m_float* out = ((VM*)u->module.gen.data)->bbq->out; uint i = 0; @@ -45,7 +40,22 @@ ANN void compute_mono(const UGen u) { for(uint i = 1; i < size; ++i) { const UGen w = (UGen)vector_at(vec, i); COMPUTE(w) - u->op(u, w->out); + static const void* dispatch[] = { &&add, &&sub, &&mul, &&div }; + do { + goto *dispatch[u->op]; + add: + u->in += w->out; + break; + sub: + u->in -= w->out; + break; + mul: + u->in *= w->out; + break; + div: + u->in *= w->out; + break; + }while(0); } } } @@ -76,7 +86,7 @@ describe_compute(multi, trig, {u->module.gen.trig->compute(u->module.gen.trig);} ANEW static UGen new_UGen(MemPool p) { const UGen u = mp_calloc(p, UGen); - u->op = ugop_add; + u->op = 0; u->compute = gen_compute_mono; return u; } @@ -246,18 +256,10 @@ static MFUN(ugen_channel) { } static MFUN(ugen_get_op) { - const f_ugop f = UGEN(o)->op; - if(f == ugop_add) - *(m_uint*)RETURN = 1; - else if(f == ugop_sub) - *(m_uint*)RETURN = 2; - else if(f == ugop_mul) - *(m_uint*)RETURN = 3; - else if(f == ugop_div) - *(m_uint*)RETURN = 4; -} - -ANN static void set_op(const UGen u, const f_ugop f) { + *(m_uint*)RETURN = UGEN(o)->op; +} + +ANN static void set_op(const UGen u, const uint f) { if(u->multi) { for(uint i = u->connect.multi->n_chan + 1; --i;) UGEN(u->connect.multi->channel[i-1])->op = f; @@ -267,14 +269,8 @@ ANN static void set_op(const UGen u, const f_ugop f) { static MFUN(ugen_set_op) { const m_int i = *(m_int*)MEM(SZ_INT); - if(i == 1) - set_op(UGEN(o), ugop_add); - else if(i == 2) - set_op(UGEN(o), ugop_sub); - else if(i == 3) - set_op(UGEN(o), ugop_mul); - else if(i == 4) - set_op(UGEN(o), ugop_div); + if(i >= 1 && i <= 4) + set_op(UGEN(o), i-1); *(m_int*)RETURN = i; }