ruby-changes:42028
From: naruse <ko1@a...>
Date: Mon, 14 Mar 2016 19:14:54 +0900 (JST)
Subject: [ruby-changes:42028] naruse:r54102 (trunk): * bignum.c (big2str_2bdigits): reduce div instruction.
naruse 2016-03-14 19:14:48 +0900 (Mon, 14 Mar 2016) New Revision: 54102 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54102 Log: * 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 <big2str_2bdigits+0x50> 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 <big2str_2bdigits+0x50> 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 Modified files: trunk/ChangeLog trunk/bignum.c Index: bignum.c =================================================================== --- bignum.c (revision 54101) +++ bignum.c (revision 54102) @@ -4615,8 +4615,9 @@ big2str_2bdigits(struct big2str_struct * https://github.com/ruby/ruby/blob/trunk/bignum.c#L4615 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 * https://github.com/ruby/ruby/blob/trunk/bignum.c#L4627 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; } Index: ChangeLog =================================================================== --- ChangeLog (revision 54101) +++ ChangeLog (revision 54102) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Mar 14 19:05:39 2016 NARUSE, Yui <naruse@r...> + + * bignum.c (big2str_2bdigits): reduce div instruction. + Mon Mar 14 18:39:53 2016 Martin Duerst <duerst@i...> * include/ruby/oniguruma.h, enc/unicode.c: Adjusting flag assignments -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/