From 3d5a3a236d99e7512955947be832b343b18b024c Mon Sep 17 00:00:00 2001 From: naruse Date: Mon, 14 Mar 2016 10:14:48 +0000 Subject: [PATCH] * bignum.c (big2str_2bdigits): reduce div instruction. Fix the code so that C compiler unify div instructions of `%` and `/`. Before: 4291b0: 48 89 f0 mov %rsi,%rax 4291b3: 31 d2 xor %edx,%edx 4291b5: 48 83 ef 01 sub $0x1,%rdi 4291b9: 48 f7 f1 div %rcx # <---- ! 4291bc: 41 0f b6 04 11 movzbl (%r9,%rdx,1),%eax 4291c1: 31 d2 xor %edx,%edx 4291c3: 41 88 04 38 mov %al,(%r8,%rdi,1) 4291c7: 48 63 4b 04 movslq 0x4(%rbx),%rcx 4291cb: 48 89 f0 mov %rsi,%rax 4291ce: 48 f7 f1 div %rcx # <---- ! 4291d1: 48 89 c6 mov %rax,%rsi 4291d4: 48 85 ff test %rdi,%rdi 4291d7: 75 d7 jne 4291b0 4291d9: 48 63 6b 10 movslq 0x10(%rbx),%rbp 4291dd: 48 01 6b 20 add %rbp,0x20(%rbx) 4291e1: 48 8b 44 24 48 mov 0x48(%rsp),%rax 4291e6: 64 48 33 04 25 28 00 xor %fs:0x28,%rax After: 4291b0: 48 63 73 04 movslq 0x4(%rbx),%rsi 4291b4: 31 d2 xor %edx,%edx 4291b6: 48 83 e9 01 sub $0x1,%rcx 4291ba: 48 f7 f6 div %rsi # <---- ! 4291bd: 41 0f b6 14 10 movzbl (%r8,%rdx,1),%edx 4291c2: 88 14 0f mov %dl,(%rdi,%rcx,1) 4291c5: 48 85 c9 test %rcx,%rcx 4291c8: 75 e6 jne 4291b0 4291ca: 48 63 6b 10 movslq 0x10(%rbx),%rbp 4291ce: 48 01 6b 20 add %rbp,0x20(%rbx) 4291d2: 48 8b 44 24 48 mov 0x48(%rsp),%rax 4291d7: 64 48 33 04 25 28 00 xor %fs:0x28,%rax git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ bignum.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5928f66580..a3f9fbdb1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Mar 14 19:05:39 2016 NARUSE, Yui + + * bignum.c (big2str_2bdigits): reduce div instruction. + Mon Mar 14 18:39:53 2016 Martin Duerst * include/ruby/oniguruma.h, enc/unicode.c: Adjusting flag assignments diff --git a/bignum.c b/bignum.c index 1f9dfb56aa..34c846a8f3 100644 --- a/bignum.c +++ b/bignum.c @@ -4615,8 +4615,9 @@ big2str_2bdigits(struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t tail p = buf; j = sizeof(buf); do { - p[--j] = ruby_digitmap[num % b2s->base]; + BDIGIT_DBL idx = num % b2s->base; num /= b2s->base; + p[--j] = ruby_digitmap[idx]; } while (num); len = sizeof(buf) - j; big2str_alloc(b2s, len + taillen); @@ -4626,8 +4627,9 @@ big2str_2bdigits(struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t tail p = b2s->ptr; j = b2s->hbase2_numdigits; do { - p[--j] = ruby_digitmap[num % b2s->base]; + BDIGIT_DBL idx = num % b2s->base; num /= b2s->base; + p[--j] = ruby_digitmap[idx]; } while (j); len = b2s->hbase2_numdigits; }