From: "George Spelvin" <linux@horizon.com>
To: linux@horizon.com, torvalds@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de
Subject: Re: [patch 2/7] lib/hashmod: Add modulo based hash mechanism
Date: 29 Apr 2016 23:04:31 -0400 [thread overview]
Message-ID: <20160430030431.20266.qmail@ns.horizon.com> (raw)
In-Reply-To: <CA+55aFzcKdp3o=JTS=jESD4sXK2Ee+Z_=aG1vGf4Y0EvZQSbVw@mail.gmail.com>
> Not doing it for 64-bit constants makes no sense if it just uses the
> trivial Booth's algorithm version.
AFAICT, gcc 5 *does* optimize 64-bit multiplies by constants.
Does the belief that it doesn't date back to some really old
version?
There's still a threshold where it just punts to the multiplier.
Some examples, x86-64 (gcc 6.0.1) and aarch64 (gcc 5.3.1).
Note the difference in the multiply-by-12345 routine.
return x*9;
mul9:
leaq (%rdi,%rdi,8), %rax
ret
mul9:
add x0, x0, x0, lsl 3
ret
return x*10;
mul10:
leaq (%rdi,%rdi,4), %rax
addq %rax, %rax
ret
mul10:
lsl x1, x0, 3
add x0, x1, x0, lsl 1
ret
return x*127;
mul127:
movq %rdi, %rax
salq $7, %rax
subq %rdi, %rax
ret
mul127:
lsl x1, x0, 7
sub x0, x1, x0
ret
return x*12345;
mul12345:
imulq $12345, %rdi, %rax
ret
mul12345:
lsl x1, x0, 3
sub x1, x1, x0
lsl x1, x1, 1
sub x1, x1, x0
lsl x1, x1, 3
sub x1, x1, x0
lsl x1, x1, 3
sub x0, x1, x0
lsl x1, x0, 4
sub x0, x1, x0
ret
uint64_t y = (x << 9) - (x << 3) + x;
return x + (x << 14) - (y << 3);
mul12345_manual:
movq %rdi, %rdx
salq $14, %rax
salq $9, %rdx
addq %rdi, %rax
addq %rdi, %rdx
salq $3, %rdi
subq %rdi, %rdx
salq $3, %rdx
subq %rdx, %rax
ret
mul12345_manual:
lsl x2, x0, 9
lsl x1, x0, 14
add x2, x2, x0
add x1, x1, x0
sub x0, x2, x0, lsl 3
sub x0, x1, x0, lsl 3
ret
return x*2654435769:
mul2654435769:
movl $2654435769, %eax
imulq %rdi, %rax
ret
mul2654435769:
mov x1, 31161
movk x1, 0x9e37, lsl 16
mul x0, x0, x1
ret
The problem with variant code paths like mul12345_manual is that the
infrastructure required to determine which to use is many times larger
than the code itself. :-(
next prev parent reply other threads:[~2016-04-30 3:04 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-29 2:57 George Spelvin
2016-04-29 3:16 ` Linus Torvalds
2016-04-29 4:12 ` George Spelvin
2016-04-29 23:31 ` George Spelvin
2016-04-30 0:05 ` Linus Torvalds
2016-04-30 0:32 ` George Spelvin
2016-04-30 1:12 ` Linus Torvalds
2016-04-30 3:04 ` George Spelvin [this message]
[not found] <CA+55aFxBWfAHQNAdBbdVr+z8ror4GVteyce3D3=vwDWxhu5KqQ@mail.gmail.com>
2016-04-30 20:52 ` George Spelvin
2016-05-01 8:35 ` Thomas Gleixner
2016-05-01 9:43 ` George Spelvin
2016-05-01 16:51 ` Linus Torvalds
2016-05-14 3:54 ` George Spelvin
2016-05-14 18:35 ` Linus Torvalds
2016-05-02 7:11 ` Thomas Gleixner
-- strict thread matches above, loose matches on Subject: below --
2016-04-28 16:42 [patch 0/7] futex: Add support for process private hashing Thomas Gleixner
2016-04-28 16:42 ` [patch 2/7] lib/hashmod: Add modulo based hash mechanism Thomas Gleixner
2016-04-28 18:32 ` Linus Torvalds
2016-04-28 23:26 ` Thomas Gleixner
2016-04-29 2:25 ` Linus Torvalds
2016-04-30 13:02 ` Thomas Gleixner
2016-04-30 16:45 ` Eric Dumazet
2016-04-30 17:12 ` Linus Torvalds
2016-04-30 17:37 ` Eric Dumazet
2016-06-12 12:18 ` Sandy Harris
2016-04-29 21:10 ` Linus Torvalds
2016-04-29 23:51 ` Linus Torvalds
2016-04-30 1:34 ` Rik van Riel
2016-05-02 9:39 ` Torvald Riegel
2016-04-30 15:22 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160430030431.20266.qmail@ns.horizon.com \
--to=linux@horizon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®