From ac6f08df231d6f4972de75461a2a835c54fe1270 Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 7 Mar 2017 03:35:47 +0000 Subject: Use ADD instead of MUL * On recent CPUs, 2-operand MUL's latency is 3 cycle but ADD is 1 cycle. * clang Optimizes `MUL rax,2` into `ADD rax,rax` but gcc7 doesn't. * LONG2FIX is compiled into `lea r14,[r15+r15*1+0x1]`; this is 1cycle and run in parallel if the branch prediction is correct. * Note that old (RB_POSFIXABLE(f) && RB_NEGFIXABLE(f)) is usually uses following instructions. * movabs rax,0x4000000000000000 * add rax,rdi * js It needs large immediate and Macro-Fusion is not applied. ADD and JO is much smaller though it is also Macro-Fusion unfriendly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index 50700b4c4a..0e15e58c12 100644 --- a/bignum.c +++ b/bignum.c @@ -4436,18 +4436,8 @@ rb_ull2inum(unsigned LONG_LONG n) VALUE rb_ll2inum(LONG_LONG n) { -#ifdef HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW - SIGNED_VALUE v; - if (__builtin_mul_overflow(n, 2, &v)) { - return rb_ll2big(n); - } - else { - return ((VALUE)v) | RUBY_FIXNUM_FLAG; - } -#else if (FIXABLE(n)) return LONG2FIX(n); return rb_ll2big(n); -#endif } #endif /* HAVE_LONG_LONG */ -- cgit v1.2.3