From e8fa27bcdb2872588e39b398f7857157fb249628 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Wed, 19 Jun 2024 12:39:21 +0200 Subject: [PATCH] drop imul rewriting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This was cute to do, but it is largely inconsequential, as shown by the rough timings below: benchmarking mul8_lea 3.9 ticks ± 0.88 (min: 3) benchmarking mul8_imul 3.3 ticks ± 0.27 (min: 3) benchmarking div8_udiv 6.5 ticks ± 0.52 (min: 6) benchmarking div8_shr 3.3 ticks ± 0.34 (min: 3) --- amd64/emit.c | 56 -------------------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/amd64/emit.c b/amd64/emit.c index bbc7def..00dd80f 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -360,54 +360,6 @@ Next: goto Next; } -static int -mulops(int depth, int *ops, int64_t k) -{ - static int tab[] = {9, 8, 5, 4, 3, 2, 1, 0}; - int *pm, m; - - while (depth && k>1) { - for (pm=tab; (m=*pm); pm++) - if (k % m == 0) { - *ops++ = m; - depth -= 1; - k /= m; - goto next; - } - return 0; - next:; - } - *ops = 1; - return k == 1; -} - -static int -emitmulk(Ref to, Ref r, int64_t k, Ins *i, Fn *fn, FILE *f) -{ - int ops[3], *pm, m; - char fmt[32]; - - if (k == 1 || !mulops(2, ops, k)) - return 0; - - for (pm=ops; (m=*pm) != 1; pm++) { - if (m == 4 || m == 2) { - if (!req(r, to)) - emitf("mov%k %1, %=", i, fn, f); - emitf("add%k %=, %=", i, fn, f); - if (m == 4) - emitf("add%k %=, %=", i, fn, f); - } else { - sprintf(fmt, "lea%%k (%s, %%1, %d), %%=", - (m & 1) ? "%1" : "", m & ~1); - emitf(fmt, i, fn, f); - } - r = to; - i->arg[1] = to; - } - return 1; -} - static void *negmask[4] = { [Ks] = (uint32_t[4]){ 0x80000000 }, [Kd] = (uint64_t[2]){ 0x8000000000000000 }, @@ -455,14 +407,6 @@ emitins(Ins i, Fn *fn, FILE *f) i.arg[0] = i.arg[1]; i.arg[1] = r; } - if (KBASE(i.cls) == 0) - if (rtype(i.arg[0]) == RCon) { - con = &fn->con[i.arg[0].val]; - val = con->bits.i; - if (con->type == CBits) - if (emitmulk(i.to, i.arg[1], val, &i, fn, f)) - break; - } if (KBASE(i.cls) == 0 /* only available for ints */ && rtype(i.arg[0]) == RCon && rtype(i.arg[1]) == RTmp) { -- 2.11.4.GIT