drop imul rewriting
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)
This commit is contained in:
parent
7de34d3454
commit
e8fa27bcdb
1 changed files with 0 additions and 56 deletions
56
amd64/emit.c
56
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue