Граф коммитов

843 Коммитов

Автор SHA1 Сообщение Дата
akr bcc1796983 {Fixnum,Bignum}#bit_length is unified into Integer.
* numeric.c (rb_int_bit_length): {Fixnum,Bignum}#bit_length is
  unified into Integer.

* bignum.c (rb_big_bit_length): Don't define Bignum#bit_length.

* internal.h (rb_big_bit_length): Declared.

--This iine, and those below, will be ignored--

M    ChangeLog
M    bignum.c
M    internal.h
M    numeric.c


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 11:17:37 +00:00
akr 9368d7515b * numeric.c (int_abs): Integer#{abs,magnitude} moved from Fixnum and Bignum.
* internal.h (rb_big_abs): Declared.

* bignum.c (rb_big_abs): Don't define Bignum#{abs,magnitude}.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-26 10:59:27 +00:00
nobu 1ea1d2e4a7 numeric.c: int_round_zero_p
* bignum.c (rb_big_size): add wrapper function of BIGSIZE and
  rename the method funtion with _m suffix.
* numeric.c (int_round_zero_p): extracted from rb_int_round.
  optimize for Bignum, and convert VALUE returned by Numeric#size
  to long.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 05:12:01 +00:00
nobu 3b6c4dad0c bignum.c: rb_cstr_parse_inum
* bignum.c (rb_cstr_parse_inum): [EXPERIMENTAL] new function to
  parse integer in C-string with length.  the name and the
  arguments may be changed in the future.
* bignum.c (rb_str_to_inum): preserve encoding of the argument in
  error messages, and no longer needs to copy non-terminated
  strings.
* bignum.c (rb_str2big_{poweroftwo,normal,karatsuba,gmp}): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-08 17:05:12 +00:00
nobu 45c593d89e bignum.c: radix check functions
* bignum.c (valid_radix_p, invalid_radix): extracted functions to
  check radix.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-08 08:32:25 +00:00
nobu 57638377cc bignum.c: micro optimization
* bignum.c (rb_big_cmp): micro optimization of Fixnum comparison.
  as SIGNED_VALUE and Fixnum have same sign-bits and same order.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-20 10:09:14 +00:00
naruse a2b4c6d1b1 * bignum.c (rb_big_cmp): reduce the code.
* bignum.c (rb_big_eq): If normalized bignum is still bignum,
  it must be larger than fixnum.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-19 19:48:26 +00:00
mrkn 81f65a9e05 * bignum.c (Bignum#<=>): remove it because they are unified with
Integer#<=>.

* numeric.c (Integer#<=>, Fixnum#<=>): move <=> method from Fixnum to
  Integer.

* numeric.c (int_cmp): add this method for Integer#<=>.

* test/-ext-/integer/test_my_integer.rb (test_my_integer_cmp): add a
  test to examine Integer#<=> for unknown subclasses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-19 09:28:12 +00:00
mrkn 0d076fe4b3 * bignum.c (rb_big_to_f, Bignum#to_f): removed them because they are
unified with int_to_f and Integer#to_f.

* numeric.c (int_to_f): treat Bignum values directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 15:02:45 +00:00
mrkn 18d114eff2 * bignum.c (Bignum#eql?): remove its definition because it is unified
with Numeric#eql?.

* numeric.c (num_eql): treat Bignum values directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 13:11:09 +00:00
mrkn ad0b5ebc50 * bignum.c (rb_big_to_s, Bignum#to_s): remove its definition because
it is unified with Integer#to_s.

* numeric.c (int_to_s): treat Bignum values directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 12:57:40 +00:00
mrkn f8e79c84a9 * bignum.c (rb_big_hash): make it public function to be available in
other source files, and remove documentation comment for Bignum#hash.

* bignum.c (Bignum#hash): remove its definition because it is unified
  with Object#hash.

* include/ruby/intern.h (rb_big_hash): add a prototype declaration.

* hash.c (any_hash): treat Bignum values directly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 01:22:38 +00:00
mrkn aa1ea07d37 * bignum.c (Bignum#even?, Bignum#odd?): remove definitions
because they are unified with Integer#even? and Integer#odd?.

* numeric.c (Fixnum#zero?, Fixnum#even?, Fixnum#odd?): remove
  definitions because they are unified with Numeric#zero?,
  Integer#even?, and Integer#odd?.

* numeric.c (num_zero_p, int_even_p, int_odd_p): treat Fixnum and
  Bignum values directly.

* test/ruby/test_integer.rb (test_odd_p_even_p): remove meaningless
  test case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 17:11:42 +00:00
mrkn a3c9cda6d7 * bignum.c (rb_big_even_p, rb_big_odd_p): make them public functions
to be available in other source files.

* include/ruby/intern.h (rb_big_even_p, rb_big_odd_p): add prototype
  declarations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-17 17:07:29 +00:00
naruse 3d5a3a236d * 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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-14 10:14:48 +00:00
nobu 49079911ba bignum.c: micro optimization
* bignum.c (rb_big_uminus, bigsub_int): use BIGNUM_NEGATE.

* internal.h (BIGNUM_NEGATE): simplify negation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-15 05:15:33 +00:00
nobu 174be80027 use particlar macros
* bignum.c: use particlar macros for positive/negative conditions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-15 05:09:59 +00:00
naruse 1f57a334da * insns.def (opt_mult): Use int128_t for overflow detection.
* bignum.c (rb_uint128t2big): added for opt_mult.

* bignum.c (rb_uint128t2big): added for rb_uint128t2big..

* configure.in: define int128_t, uint128_t and related MACROs.
  Initially introduced by r41379 but reverted by r50749.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-05 04:31:27 +00:00
nobu 439224a590 RUBY_ASSERT
* error.c (rb_assert_failure): assertion with stack dump.
* ruby_assert.h (RUBY_ASSERT): new header for the assertion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-22 08:33:55 +00:00
nobu bb4d72c51f make local symbols static
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 15:07:41 +00:00
nobu 4191a6b90d preserve encodings in error messages
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-28 02:40:46 +00:00
nobu bbe805f09e internal.h: roomof
* internal.h (roomof): extract from type_roomof, and move from
  bignum.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-21 11:28:12 +00:00
nobu 61da10499f bignum.c: doc of rb_cstr_to_inum
* bignum.c (rb_cstr_to_inum): [DOC] add document of the function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-17 12:11:53 +00:00
hsbt d9a2b3480e * doc/contributors.rdoc: fix a typo. Patch by @davydovanton
[fix GH-872][ci skip]
* doc/syntax/methods.rdoc: ditto.
* ext/digest/sha2/sha2.c: ditto.
* ext/socket/ipsocket.c: ditto.
* ext/tk/*: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-04-15 01:37:47 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
akr 905b52217c * bignum.c (bary_mul_balance_with_mulfunc): Fix free work area
location.
  [ruby-dev:48723] [Bug #10464]
  [ruby-core:66044] [Bug #10465]
  Reported by Kohji Nishihama.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-01 08:13:30 +00:00
ngoto 9631e3e788 * bignum.c (absint_numwords_generic): set an array element after
definition of a variable to fix compile error with older version
  of fcc (Fujitsu C Compiler) 5.6 on Solaris 10 on Sparc.
  [Bug #10350] [ruby-dev:48608]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-09 14:36:35 +00:00
nobu aa3b506270 add some documents [ci skip]
* bignum.c (Init_Bignum): [DOC] Bignum::GMP_VERSION.

* complex.c (Init_Complex): [DOC] ignore an internal class.

* dir.c (Init_Dir): [DOC] File::FNM_SYSCASE.

* file.c (rb_file_exists_p): [DOC] File.exists? is deprecated.

* object.c (rb_mod_initialize_clone): [DOC] ignore implementation
  detail.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-28 11:28:55 +00:00
akr 95de2b0012 * internal.h (struct RBignum): Use size_t for len.
* include/ruby/intern.h (rb_big_new): Use size_t instead of long to
  specify the size of bignum.
  (rb_big_resize): Ditto.

* bignum.c: Follow above changes.

* rational.c: Follow above changes.

* marshal.c: Follow above changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-19 01:11:04 +00:00
akr a6024cdc1b * numeric.c (rb_num2long): Returns a long.
(rb_num2ulong): Returns a unsigned long.

* bignum.c (rb_big2long): Returns a long.
  (rb_big2ulong): Returns a unsigned long.

* include/ruby/intern.h: Follow above changes.

* include/ruby/ruby.h: Follow above changes.
  (rb_num2long_inline): No need to cast.
  (rb_num2ulong_inline): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-18 15:46:32 +00:00
akr 9aa67e267b * bignum.c (SIZEOF_BDIGIT): Renamed from SIZEOF_BDIGITS.
* internal.h: Ditto.

* marshal.c: Ditto.

* rational.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-13 03:48:17 +00:00
nobu 3008ea2872 bignum.c: adjust condtions
* bignum.c (maxpow{16,32,64,128}_{exp,num}): adjust preprocessor
  condtions to maxpow_in_bdigit_dbl().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:44 +00:00
nobu fc23374f06 [DOC] add links to `Object#hash`
add links to `Object#hash` to each #`hash` methods rdocs.
[Fixes GH-567]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:43 +00:00
nobu cc216f9aae adjust indent and style
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-27 07:10:14 +00:00
mame f67e09c7fd * bignum.c (bary_mul_precheck): fix a copy-paste error.
Coverity Scan found this bug.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-21 16:23:58 +00:00
akr 3c99764bcd * internal.h: Rename macro names: RBIGNUM_FOO to BIGNUM_FOO.
(BIGNUM_EMBED_LEN_NUMBITS): Renamed from RBIGNUM_EMBED_LEN_NUMBITS.
  (BIGNUM_EMBED_LEN_MAX): Renamed from RBIGNUM_EMBED_LEN_MAX.
  (BIGNUM_SIGN_BIT): Renamed from RBIGNUM_SIGN_BIT.
  (BIGNUM_SIGN): Renamed from RBIGNUM_SIGN.
  (BIGNUM_SET_SIGN): Renamed from RBIGNUM_SET_SIGN.
  (BIGNUM_POSITIVE_P): Renamed from RBIGNUM_POSITIVE_P.
  (BIGNUM_NEGATIVE_P): Renamed from RBIGNUM_NEGATIVE_P.
  (BIGNUM_EMBED_FLAG): Renamed from RBIGNUM_EMBED_FLAG.
  (BIGNUM_EMBED_LEN_MASK): Renamed from RBIGNUM_EMBED_LEN_MASK.
  (BIGNUM_EMBED_LEN_SHIFT): Renamed from RBIGNUM_EMBED_LEN_SHIFT.
  (BIGNUM_LEN): Renamed from RBIGNUM_LEN.
  (RBIGNUM_DIGITS): Renamed from RBIGNUM_DIGITS.
  (BIGNUM_LENINT): Renamed from RBIGNUM_LENINT.

* bignum.c: Follow the above change.

* gc.c: Ditto.

* marshal.c: Ditto.

* math.c: Ditto.

* numeric.c: Ditto.

* random.c: Ditto.

* rational.c: Ditto.

* sprintf.c: Ditto.

* ext/-test-/bignum/bigzero.c: Ditto.

* ext/-test-/bignum/intpack.c: Ditto.

* ext/bigdecimal/bigdecimal.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-15 21:17:34 +00:00
akr dfd26e3a47 * bignum.c (rb_big_cmp): Avoid bignum allocation for comparison
between bignum and fixnum.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-15 02:48:44 +00:00
akr 6f8b0e9bb0 * include/ruby/intern.h,
include/ruby/io.h,
  include/ruby/ruby.h,
  include/ruby/win32.h,
  include/ruby/backward/rubysig.h,
  bignum.c,
  gc.c,
  io.c,
  process.c,
  safe.c,
  struct.c,
  thread.c,
  ext/socket/rubysocket.h,
  ext/-test-/old_thread_select: Remove deprecated definitions
  [ruby-core:60581] [Feature #9502]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-14 15:16:31 +00:00
akr 2fee22f30d [DOC]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-11 16:40:41 +00:00
akr c1de2f4e3a * bignum.c (rb_big_cmp): Specialize a comparison to zero.
* ext/bigdecimal/bigdecimal.c (is_negative): Use rb_big_cmp instead of
  RBIGNUM_NEGATIVE_P.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-11 14:43:23 +00:00
akr bc65d709ab * bignum.c (bigxor_int): Apply BIGLO for long in a BDIGIT expression.
(bigor_int): Ditto.
  (bigand_int): Ditto.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-24 13:27:14 +00:00
akr d33541009f * include/ruby/defines.h: Don't use int128_t for Bignum.
It's not always faster.

* bignum.c: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-24 04:51:33 +00:00
nobu ef37d178bb bignum.c: suppress warning
* bignum.c (absint_numwords_generic): suppress false warning in
  rb_absint_numwords() by gcc 4.4.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-19 14:00:26 +00:00
nobu e146015272 bignum.c, math.c: RB_BIGNUM_TYPE_P
* bignum.c, math.c (RB_BIGNUM_TYPE_P): predicate macro like
  RB_FLOAT_TYPE_P.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-07 19:04:23 +00:00
nobu c26293dccf bignum.c, math.c: type predicates
* bignum.c, math.c: use type predicate macros instead of TYPE().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-07 19:04:18 +00:00
nobu a77ae1eced bignum.c: split rb_big_fdiv and big_fdiv
* bignum.c (rb_big_fdiv): split with big_fdiv by divider type.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-07 19:04:15 +00:00
akr b1b395911c * bignum.c (GMP_DIV_DIGITS): New macro.
(bary_divmod_gmp): New function.
  (rb_big_divrem_gmp): Ditto.
  (bary_divmod_branch): Ditto.
  (bary_divmod): Use bary_divmod_branch.
  (bigdivrem): Ditto.

* internal.h (rb_big_divrem_gmp): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 23:22:27 +00:00
akr 3b1ab2a6b7 * bignum.c (bary_divmod_normal): Reduce temporary array allocations.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 21:23:21 +00:00
akr 8745bc676e * bignum.c (rb_big_divrem_normal): Add GC guards.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 17:21:43 +00:00
akr 8f8bf8243d * bignum.c (rb_big_divrem_normal): New function.
* internal.h (rb_big_divrem_normal): Declared.

* ext/-test-/bignum/div.c: New file.

* test/-ext-/bignum/test_div.rb: New file.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 16:10:06 +00:00
akr cf3736a75a * bignum.c (bigdivrem_normal): Removed.
(bary_divmod_normal): New function.
  (bary_divmod): Use bary_divmod_normal.
  (bigdivrem): Use bary_divmod_normal.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 15:10:48 +00:00
akr 102a2c2e80 * bignum.c (bigdivrem): Useless declaration removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 14:03:29 +00:00
akr dd95c9b1cd * bignum.c (bigdivrem_normal): Add assertions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 11:23:05 +00:00
akr 2583689340 * bignum.c (GMP_STR2BIG_DIGITS): New macro.
(str2big_gmp): New function.
  (rb_cstr_to_inum): Use str2big_gmp for big bignums.
  (rb_str2big_gmp): New function.

* internal.h (rb_str2big_gmp): Declared.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-03 11:20:02 +00:00
akr 0b2413b471 * bignum.c (rb_str2big_poweroftwo): New function.
(rb_str2big_normal): Ditto.
  (rb_str2big_karatsuba): Ditto.

* internal.h (rb_str2big_poweroftwo): Declared.
  (rb_str2big_normal): Ditto.
  (rb_str2big_karatsuba): Ditto.

* ext/-test-/bignum/str2big.c: New file.

* test/-ext-/bignum/test_str2big.rb: New file.

* ext/-test-/bignum/depend: Add the dependency for str2big.c.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-03 03:50:15 +00:00
akr c048ad23b6 * bignum.c (str2big_scan_digits): Extracted from rb_cstr_to_inum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-03 03:03:32 +00:00
akr 0c3d124571 * bignum.c (bytes_2comp): Define it only for little endian
environment.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-02 22:41:07 +00:00
akr 1d7611ff48 * bignum.c (ISDIGIT): Unused macro removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-02 13:56:23 +00:00
akr 5f61a592e9 * bignum.c (str2big_poweroftwo): Extracted from rb_cstr_to_inum.
(str2big_normal): Ditto.
  (str2big_karatsuba): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-02 13:52:05 +00:00
akr 0effd06122 * bignum.c (Init_Bignum): Define Bignum::GMP_VERSION when GMP is used.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 22:04:35 +00:00
akr c48e169fb9 * bignum.c (big2str_generic): Reduce arguments.
(big2str_gmp): Ditto.
  (rb_big2str1): Follow the above change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 16:47:20 +00:00
akr b64c2c348f * bignum.c (GMP_BIG2STR_DIGITS): New constant.
(big2str_gmp): New function.
  (rb_big2str1): Use big2str_gmp for big bignums.

* internal.h (rb_big2str_gmp): Declared.

* ext/-test-/bignum/big2str.c (big2str_gmp): New method.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 14:34:53 +00:00
akr 4dd7a13a0a * bignum.c (bary_mul_gmp): Use mpz_init and mpz_clear instead of
mpz_inits and mpz_clears.
  Older GMP don't have them.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 13:38:49 +00:00
akr 7dd1604603 * bignum.c (big2str_base_poweroftwo): Renamed from
big2str_base_powerof2.
  (rb_big2str_poweroftwo): New function for test.
  (big2str_generic): Extracted from rb_big2str1.
  (rb_big2str_generic): New function for test.

* internal.h (rb_big2str_poweroftwo): Declared.
  (rb_big2str_generic): Ditto.

* ext/-test-/bignum/big2str.c: New file.

* test/-ext-/bignum/test_big2str.rb: New file.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 11:35:57 +00:00
akr 34004844cd * bignum.c (big2str_2bdigits): Renamed from big2str_orig.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 06:21:52 +00:00
akr 6fe40011a8 * bignum.c: Remove BITSPERDIG >= INT_MAX test. The static assertion,
SIZEOF_BDIGITS <= sizeof(BDIGIT) is enough.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42755 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 04:03:32 +00:00
akr c9b3571ceb * bignum.c (maxpow_in_bdigit): Removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 02:39:05 +00:00
akr 77f245e62e * numeric.c (rb_fix_bit_length): Moved from bignum.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 01:31:16 +00:00
akr a0a0b61b68 [DOC]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 01:00:15 +00:00
akr 7bb549d6b5 * internal.h (bit_length): Moved from bignum.c.
(nlz_int): Ditto.
  (nlz_long): Ditto.
  (nlz_long_long): Ditto.
  (nlz_int128): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-01 00:57:00 +00:00
akr 8bd7af6794 * bignum.c (bit_length): Renamed from bitsize.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-31 18:34:42 +00:00
akr 89744e75bd * bignum.c (rb_big_bit_length): New method.
(rb_fix_bit_length): Ditto.
  [ruby-core:56247] [Feature #8700]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-31 15:09:20 +00:00
akr 83a0709174 * bignum.c: Use GMP to accelerate big Bignum multiplication.
(bary_mul_gmp): New function.
  (bary_mul): Use bary_mul_gmp.
  (bigsq): Use different threshold with GMP.

* configure.in: Detect GMP.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-31 12:17:18 +00:00
akr 5a0e4a5871 * bignum.c (BARY_SHORT_MUL): Renamed from BARY_MUL1.
(bary_short_mul): Renamed from bary_mul1.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-24 16:51:23 +00:00
akr 364237623b * bignum.c (rb_big2str1): Make an expression more explicit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-18 01:07:50 +00:00
akr c106d19445 * bignum.c (rb_big2str1): Use power_level instead of bitsize(xn).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-17 18:21:46 +00:00
akr 908e7312c4 * bignum.c (BIGDIVREM_EXTRA_WORDS): Redefine to 1.
(bigdivrem_num_extra_words): Removed.
  (bigdivrem_normal): Simplefied.
  (big2str_karatsuba): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-17 15:48:44 +00:00
akr dcd4832d69 * bignum.c (bigdivrem_single1): Renamed from bigdivrem_single. Add
x_higher_bdigit argument.
  (bigdivrem_single): Just call bigdivrem_single1.
  (bigdivrem_restoring): Use bigdivrem_single1 to avoid memmove.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-16 01:11:18 +00:00
akr 9f6c62ad5f * bignum.c (bary_small_rshift): Specify the higher BDIGIT instead of
sign bit.
  (big_shift3): Follow the above change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-16 00:19:51 +00:00
akr d0b5d2016d * bignum.c (bary_mul_toom3): Reduce a branch.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-15 17:24:41 +00:00
akr 6df786c79f * bignum.c (bigdivrem_single): Use shift when y is a power of two.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-15 16:47:08 +00:00
akr 49e8387bae * bignum.c (bigdivrem_restoring): Use bigdivrem_single if non-topmost
BDIGITs of y are zero.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-15 16:16:08 +00:00
akr 7fc4142a02 * bignum.c (rb_big2str1): Truncate topmost zeros of x.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-15 15:36:00 +00:00
akr 02b6f663c5 * bignum.c (bary_divmod): Simplify an expression.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-15 15:03:35 +00:00
akr 942a3c9985 * bignum.c (bigdivrem_normal): Remove a local variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42567 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-15 15:01:38 +00:00
akr d94fc786a4 * bignum.c (big2str_karatsuba): Use bigdivrem_restoring directly to
reduce working buffer and memory copy.
  (rb_big2str1): Allocate working buffer for big2str_karatsuba here.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-15 14:25:19 +00:00
akr 38be07f833 * bignum.c (bigdivrem_restoring): xn argument removed.
(bigdivrem_normal): Follow the above change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-13 15:54:27 +00:00
akr f069f26bc2 * bignum.c (big_div_struct): Remove xn and j field. Add zn field.
(bigdivrem1): Follow the above change.
  (bigdivrem_restoring): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-13 15:21:42 +00:00
akr 26e69a89fa * bignum.c (big_div_struct): ynzero field removed.
(bigdivrem1): Follow the above change.
  (bigdivrem_restoring): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-13 14:43:10 +00:00
akr adaa5650cd * bignum.c (bigdivrem_restoring): Extracted from bigdivrem_normal.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-13 14:03:55 +00:00
akr 06ed1c781a * bignum.c (bitsize): Fix a conditional expression.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-10 18:26:28 +00:00
akr 180d461a22 * bignum.c (big_div_struct): Use size_t.
(bigdivrem1): Ditto.
  (bigdivrem_num_extra_words): Ditto.
  (bigdivrem_single): Ditto.
  (bigdivrem_normal): Ditto.
  (bary_divmod): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-09 19:55:24 +00:00
nobu ca3b9bbfe0 bignum.c: suppress warning
* bignum.c (rb_big_mul_karatsuba): suppress logical-op-parentheses
  warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-09 13:41:23 +00:00
akr fe6273975e * bignum.c (rb_big_odd_p): Check the bignum length.
(rb_big_even_p): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-07 11:08:03 +00:00
akr ff84827eb6 * bignum.c (dbl2big): A condition simplified.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-07 10:31:35 +00:00
akr d35596c61d * bignum.c (nlz16): Removed.
(nlz32): Ditto.
  (nlz64): Ditto.
  (nlz128): Ditto.
  (nlz_int): New function.
  (nlz_long): New function.
  (nlz_long_long): New function.
  (nlz_int128): New function.
  (nlz): Follow above changes.
  (bitsize): Follow above changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-06 22:43:01 +00:00
akr 25336fa7c1 * bignum.c (rb_big_realloc): Use VALGRIND_MAKE_MEM_UNDEFINED to
declare undefined memory area.
  (bignew_1): Ditto.

* internal.h (VALGRIND_MAKE_MEM_DEFINED): Moved from gc.c
  (VALGRIND_MAKE_MEM_UNDEFINED): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-06 03:26:34 +00:00
akr 2ae634f2f4 * bignum.c: Rename local variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-05 14:50:07 +00:00
akr 5a13ad0386 * bignum.c (BARY_TRUNC): New macro.
(bary_cmp): Use BARY_TRUNC.
  (bary_mul_toom3): Ditto.
  (bary_divmod): Ditto.
  (abs2twocomp): Ditto.
  (bigfixize): Ditto.
  (rb_cstr_to_inum): Ditto.
  (big2str_karatsuba): Ditto.
  (bigdivrem): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-03 16:58:30 +00:00
akr 092511bac7 * bignum.c (big2str_karatsuba): Don't allocate new temporary buffer
if the buffer is enough for current invocation.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-03 16:01:14 +00:00
nobu b3be3c29c4 bignum.c: suppress warnings
* bignum.c (power_cache_get_power): declare as inline before call to
  suppress warnings from gcc 4.2.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-03 15:41:31 +00:00
akr 606a03dc59 * bignum.c (bary2bdigitdbl): New function.
(bdigitdbl2bary): Ditto.
  (bary_mul_single): Use bdigitdbl2bary.
  (power_cache_get_power): Ditto.
  (bary_divmod): Use bary2bdigitdbl.
  (big2str_orig): Ditto.
  (bigdivrem): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-03 15:26:04 +00:00
akr f12ef626d1 * bignum.c: The branch condition of selecting multiplication
algorighms should check smaller argument because Karatsuba and Toom3
  is effective only if both arguments are big.
  (bary_mul_toom3_branch): Compare the smaller argument to
  TOOM3_MUL_DIGITS.
  (bary_mul): Compare the smaller argument to KARATSUBA_MUL_DIGITS.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-03 14:20:31 +00:00
akr f858cd8a38 * bignum.c (big2str_orig): Receive the number to stringize as
BDIGIT array and size.
  (big2str_karatsuba): Receive the number to stringize as BDIGIT array
  and size.  Use an temporary array of BDIGIT.
  (rb_big2str1): Follow the above change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-03 13:27:25 +00:00
akr 36c89c484b * bignum.c (MAX_BASE36_POWER_TABLE_ENTRIES): Renamed from
MAX_BIG2STR_TABLE_ENTRIES.
  (base36_power_cache): Renamed from big2str_power_cache.
  (base36_numdigits_cache): Renamed from big2str_numdigits_cache.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-03 04:32:33 +00:00
akr 04cf3fa346 * bignum.c (big2str_orig): Refactored.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 17:24:19 +00:00
akr 81f42c7576 * bignum.c (big2str_orig): Rename a local variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 16:42:40 +00:00
akr d0741fdf1c * bignum.c (bigadd_core): Removed.
(bigadd): Use bary_add instead of bigadd_core.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 16:22:47 +00:00
akr ebbaec9696 * bignum.c (rb_big2str1): Simplify power_level calculation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 15:55:07 +00:00
akr 54c3b1ba19 * bignum.c (power_cache_get_power): Appry bigtrunc to the result of
bigsq.
  (big2str_karatsuba): Fix number of leading zero characters.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 14:53:22 +00:00
nobu ba95b9787d bignum.c: suppress a warning
* bignum.c (rb_cstr_to_inum): remove set but unused variable.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 14:10:51 +00:00
akr bc7c0a63fd * bignum.c (big2str_karatsuba): Reduce power_level more than one at
recursion, if possible.
  (rb_big2str1): Follow the above change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 09:36:23 +00:00
akr 9e8f82e087 * bignum.c (bary_mul): Swap x and y for bary_mul1 if x is longer than y.
[ruby-dev:47565] [Bug #8719] Reported by Narihiro Nakamura.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42324 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-02 03:28:33 +00:00
akr 474dc1e816 * bignum.c (big2str_orig): Remove len argument.
(big2str_karatsuba): Ditto.
  (rb_big2str1): Follow above change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-01 22:49:12 +00:00
akr 9ebd675c47 * bignum.c (rb_big2str1): Remove a local variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-01 14:57:21 +00:00
akr 69263bb755 * bignum.c (rb_cstr_to_inum): Use power_cache_get_power.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-01 14:34:59 +00:00
akr d620b0b9cd * bignum.c (rb_big2str1): Raise an error for too big number.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-01 12:05:04 +00:00
akr 780a125faf * bignum.c (power_cache_get_power): Hide cached Bignum objects.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-01 11:48:42 +00:00
akr 0ade4f39fd * bignum.c (rb_big2str1): Remove non-trim mode.
(rb_big2str0): Non-trim mode implemented here.
  (big2str_find_n1): Change the result type to long again.
  (big2str_base_powerof2): Don't take arguments: len and trim.
  (rb_big2str): Follow above change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-01 10:19:23 +00:00
akr 93055423bd * bignum.c (big2str_alloc): New function to allocate the result string.
It is called after actual length is calculated.
  (big2str_struct): Add fields: negative, result and ptr.
  (big2str_orig): Write out the result via b2s->ptr.
  (big2str_orig): Ditto.
  (rb_big2str1): Don't allocate the result string at beginning.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-01 03:43:14 +00:00
akr 478bd3128c * bignum.c (big2str_orig): Use temporary buffer when trim mode.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 22:38:53 +00:00
akr 39a00c6710 * bignum.c (big2str_orig): Simplified because RBIGNUM_LEN(x) <= 2 now.
(big2str_struct): Two fields added: hbase2, hbase2_numdigits.
  (rb_big2str1): Initialize above fields.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 21:33:14 +00:00
akr eed6c15a21 * bignum.c (big2str_karatsuba): Fix a condition of power_level.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 16:48:08 +00:00
nobu 278b494ba7 * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 16:21:11 +00:00
akr 4f1b07e9eb * bignum.c (LOG2_KARATSUBA_BIG2STR_DIGITS): Removed.
(KARATSUBA_BIG2STR_DIGITS): Removed.
  (big2str_numdigits_cache): New variable.
  (power_cache_get_power): Merged with power_cache_get_power0.
  This function returns maxpow_in_bdigit_dbl(base)**(2**power_level).
  (rb_big2str1): use power_cache_get_power.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 16:20:26 +00:00
akr d28913b4b9 * bignum.c (big2str_find_n1): Change the return type to size_t.
(big2str_orig): Ditto.
  (big2str_karatsuba): Ditto.
  (rb_big2str1): Follow the above changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 15:01:55 +00:00
akr 9e84b33564 * bignum.c (power_cache_get_power): Change numdigits_ret to size_t *.
(big2str_orig): Change len argument to size_t.
  (big2str_karatsuba): Ditto.
  (rb_big2str1): Follow the above changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 14:21:54 +00:00
akr 621d2b3d6c * bignum.c (bary_cmp): Extracted from rb_big_cmp.
(power_cache_get_power): Change n1 argument (number of digits) to
  power_level which is just passed to power_cache_get_power0.
  (big2str_karatsuba): Ditto.
  (rb_big2str1): Calculate the initial power_level.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 13:42:22 +00:00
akr aba8c29a8b * bignum.c (MAX_BIG2STR_TABLE_ENTRIES): Use SIZEOF_SIZE_T.
(power_cache_get_power0): Add rb_bug call for too bit i argument.
  (power_cache_get_power): Simplified.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 10:58:58 +00:00
akr 6189859101 * bignum.c (big2str_struct): New structure.
(big2str_orig): Use big2str_struct.
  (big2str_karatsuba): Ditto.
  (rb_big2str1): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-31 03:20:35 +00:00
akr 16bf45bf38 * bignum.c (LOG2_KARATSUBA_BIG2STR_DIGITS): Renamed from
LOG2_KARATSUBA_DIGITS.
  (KARATSUBA_BIG2STR_DIGITS): Renamed from KARATSUBA_DIGITS.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-29 13:18:46 +00:00
akr 7a9aeb33db * bignum.c (bigdivrem): Specialized implementation added for
nx == 2 && ny == 2



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-28 15:14:20 +00:00
akr 37377b24d1 * bignum.c (absint_numwords_generic): The char_bit variable changed
to a static constant.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-28 03:51:13 +00:00
akr aecf007782 * bignum.c: Constify bary_* functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-28 03:12:36 +00:00
akr e5ff9d58ef * include/ruby/intern.h (rb_absint_size): Declaration moved from
internal.h to calculate required buffer size to pack integers.
  (rb_absint_numwords): Ditto.
  (rb_absint_singlebit_p): Ditto.
  [ruby-core:42813] [Feature #6065]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-28 02:14:58 +00:00
akr 5b89a56b4f * bignum.c (rb_big_size): Return the bignum "bytewise" size.
[ruby-core:55578] [Feature #8553]
  This is accepted by matz on DevelopersMeeting20130727Japan.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-27 15:39:01 +00:00
akr a84ea11986 * bignum.c: Move functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23 11:49:25 +00:00
akr ca3f5b533d * bignum.c (bary_divmod): Add special cases for x < y easily detected
and nx == 2 && ny == 2.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23 11:16:39 +00:00
akr 66cc0fa4ab * bignum.c (bary_mulsub_1xN): New function.
(bary_mul_toom3): Use bary_mulsub_1xN.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-22 22:16:45 +00:00
akr fdb991b9a0 * bignum.c (KARATSUBA_BALANCED): New macro.
(TOOM3_BALANCED): Ditto.
  (bary_mul_balance_with_mulfunc): Use KARATSUBA_BALANCED and
  TOOM3_BALANCED.
  (rb_big_mul_balance): Relax a condition.
  (rb_big_mul_karatsuba): Use KARATSUBA_BALANCED.
  (rb_big_mul_toom3): Use TOOM3_BALANCED.
  (bary_mul_karatsuba_branch): Use KARATSUBA_BALANCED.
  (bary_mul_toom3_branch): Use TOOM3_BALANCED.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-22 18:35:27 +00:00
akr 685e4c67bf * bignum.c (bigdivrem_mulsub): Extracted from bigdivrem1.
(bigdivrem1): Use bary_add.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-22 16:36:36 +00:00
akr d3845ef8db * bignum.c (bary_sq_fast): Refine expressions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-21 15:17:09 +00:00
akr 5cf931d65e * bignum.c (bary_mul): Use simple multiplication if yl is small.
(rb_cstr_to_inum): Invoke bigsq instead of bigmul0.
  (bigsq): Re-implemented.
  (bigmul0): Invoke bigsq if two arguments are identical.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-21 12:13:47 +00:00
akr a2116ef2cd * bignum.c (bary_mul_toom3): New function based on bigmul1_toom3.
(bary_mul_toom3_branch): Call bary_mul_toom3.
  (rb_big_mul_toom3): Ditto.
  (bigmul1_toom3): Removed.
  (big_real_len): Ditto.
  (big_split): Ditto.
  (big_split3): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-21 01:01:26 +00:00
akr abfb7b35a2 Update a comment for Toom3.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-20 13:32:11 +00:00
akr 2314c1bf47 * bignum.c (bary_sq_fast): Specialize the last iteration of the
outer loop.
  (bigfixize): A condition simplified.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-18 12:58:46 +00:00
akr 80afc9b2f3 * bignum.c (BDIGITS_ZERO): Defined.
(bary_pack): Use BDIGITS_ZERO.
  (bary_unpack): Ditto.
  (bary_mul_single): Ditto.
  (bary_mul_normal): Ditto.
  (bary_sq_fast): Ditto.
  (bary_mul_balance_with_mulfunc): Ditto.
  (bary_mul_precheck): Ditto.
  (bary_mul_toom3_branch): Ditto.
  (rb_cstr_to_inum): Ditto.
  (big_shift3): Ditto.
  (bigmul1_toom3): Ditto.
  (bary_divmod): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-18 04:00:49 +00:00
akr 15f7c7f9d4 * bignum.c: An static assertion for relation of SIZEOF_LONG and
SIZEOF_BDIGITS is added.
  (bary_mul_precheck): Reduce comparisons.
  (bary_mul): Invoke bary_sq_fast or bary_mul1 if the bignum size is
  small.
  (bigfixize): Resize the argument bignum here.
  (bignorm): Don't call bigtrunc after bigfixize.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-17 13:53:24 +00:00
akr deaec24790 * bignum.c (bigmul1_toom3): Use bigdivrem_single instead of bigdivrem.
(big_three): Removed.
  (Init_Bignum): Don't initialize big_three.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-16 15:17:21 +00:00
akr 6be7c95734 * bignum.c (bigsq): Renamed from bigsqr.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-16 11:23:03 +00:00
akr a08c5527ea * bignum.c (USHORT): Unused macro removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-16 10:44:27 +00:00
akr 4106413465 * bignum.c (big_shift3): Big shift width is not a problem for right
shift.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-16 10:08:25 +00:00
akr c0cce2938c * bignum.c (bary_mul_karatsuba): Avoid duplicate calculation when
squaring.
  ((bary_mul_toom3_branch): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-16 09:37:42 +00:00
akr a38f209a39 Fix spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 12:56:29 +00:00
akr 46360975a4 * include/ruby/intern.h (rb_big2str0): Deprecated.
* bignum.c (rb_big2str1): Renamed from rb_big2str0.
  (rb_big2str0): Deprecated wrapper for rb_big2str1.
  (rb_big2str): Invoke rb_big2str1 instead of rb_big2str0.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 05:42:22 +00:00
akr 1a42f3683f * bignum.c: Add static assertions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 04:50:49 +00:00
akr a5da8319b6 * bignum.c (maxpow_in_bdigit_dbl): Useless #if removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 02:26:24 +00:00
zzak b39b66f4aa * bignum.c (rb_big_coerce): [DOC] Add docs for Bignum#coerce
Based on patch by Juanito Fatas [Fixes GH-360]
  https://github.com/ruby/ruby/pull/360


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 02:13:13 +00:00
nobu e068834b5c bignum.c: suppress warnings
* bignum.c (big_shift2, rb_big_lshift, rb_big_rshift): cast explicitly
  to suppress warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 02:11:15 +00:00
akr 150b265502 * bignum.c (nlz16): Use __builtin_clz if possible.
(nlz32): Use __builtin_clz or __builtin_clzl if possible.
  (nlz64): Use __builtin_clzl or __builtin_clzll if possible.
  (nlz128): Use __builtin_clzll if possible.

* configure.in: Check __builtin_clz, __builtin_clzl and
  __builtin_clzll.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 01:49:32 +00:00
akr 508669b6da * bignum.c (power_cache_get_power): Use bitsize insteadof ceil_log2.
(ones): Removed.
  (next_pow2): Removed.
  (floor_log2): Removed.
  (ceil_log2): Removed.

* configure.in (__builtin_popcountl): Don't check.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 00:46:00 +00:00
akr 240f3056aa * configure.in: Check __builtin_popcountl, __builtin_bswap32 and
__builtin_bswap64.

* internal.h (swap32): Use the configure result for the condition to
  use __builtin_bswap32.
  (swap64): Use the configure result for the condition to use
  __builtin_bswap64.

* bignum.c (ones): Use the configure result for the condition to use
  __builtin_popcountl.
  (bary_unpack_internal): Use appropriate types for swap argument.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-14 14:28:33 +00:00
akr b0eacd027a * bignum.c (bary_subb): Support xn < yn.
(bigsub_core): Removed.
  (bigsub): Don't compare before subtraction.  Just subtract and
  get the two's complement if the subtraction causes a borrow.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-14 13:24:44 +00:00
akr 651f762c17 * bignum.c (DIGSPERLONG): Unused macro removed.
(DIGSPERLL): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-13 15:38:52 +00:00
akr 75a86e4733 * bignum.c (rb_big_aref): Less scan when the number is negative.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-13 15:36:18 +00:00
akr b9eeeac5c8 * bignum.c (big_shift): Avoid signed integer overflow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-13 15:19:48 +00:00
akr f9029004ee * bignum.c (bary_mul_precheck): Use bary_small_lshift or
bary_mul_normal if xl is 1.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-13 15:16:23 +00:00
akr de79b66f46 * bignum.c (big_shift3): New function.
big_lshift and big_rshift are merged.
  (big_shift2): New function.
  (big_lshift): Use big_shift3.
  (big_rshift): Ditto.
  (check_shiftdown): Removed.
  (rb_big_lshift): Use big_shift2 and big_shift3.
  (rb_big_rshift): Ditto.
  (big_lshift): Removed.
  (big_rshift): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-13 14:03:13 +00:00
akr 0001cf6bdc * bignum.c (bary_small_lshift): Use size_t instead of long.
(bary_small_rshift): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-13 06:53:12 +00:00
akr e31c9896d6 * bignum.c (bary_small_lshift): Functions moved to remove
declaration.
  (bary_small_rshift): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-13 06:36:40 +00:00
akr 725bc0c870 * bignum.c (biglsh_bang): Removed.
(bigrsh_bang): Ditto.
  (bigmul1_toom3): Use bary_small_lshift and bary_small_rshift.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-13 00:28:10 +00:00
akr 973d855391 * bignum.c: Don't use toom3 after once karatsuba is choosen.
(mulfunc_t): New type.
  (bary_mul_toom3_start): Renamed from bary_mul.
  (bary_mul_karatsuba_start): Renamed from bary_mul.
  (bary_mul_balance_with_mulfunc): Renamed from bary_mul_balance and
  new argument, mulfunc, is added.
  (rb_big_mul_balance): Invoke bary_mul_balance_with_mulfunc with
  bary_mul_toom3_start.
  (bary_mul_karatsuba): Invoke bary_mul_karatsuba_start instead of
  bary_mul.
  (bary_mul_precheck): Extracted from bary_mul.
  (bary_mul_karatsuba_branch): Extracted from bary_mul.
  (bary_mul_karatsuba_start): New function to call bary_mul_precheck
  and bary_mul_karatsuba_branch.
  (bary_mul_toom3_branch): Extracted from bary_mul.
  (bary_mul_toom3_start): New function to call bary_mul_precheck and
  bary_mul_toom3_branch.
  (bary_mul): Just call bary_mul_toom3_start.
  Arguments for work memory are removed.
  (rb_cstr_to_inum): Follow the bary_mul change.
  (bigmul0): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-11 03:06:02 +00:00
akr c0796c36b5 * bignum.c: Add a static assertion for RBIGNUM_EMBED_LEN_MAX.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-10 13:46:38 +00:00
akr 55e60d05dc * bignum.c (bary_2comp): Don't use bary_plus_one.
(bary_add_one): Replaced by the implementation of bary_plus_one.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-10 13:06:33 +00:00
nobu c37e6ab28d bignum.c: sizeof_bdigit_dbl
* bignum.c (sizeof_bdigit_dbl): check sizeof(BDIGIT_DBL).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-10 11:48:24 +00:00
akr 716c93bed1 * bignum.c (SIZEOF_BDIGIT_DBL): Add a ifdef guard for test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-10 11:10:05 +00:00
nobu cc47b02969 bignum.c: select by preprocessor conditions
* bignum.c (maxpow_in_bdigit_dbl, maxpow_in_bdigit): select by
  preprocessor conditions to reduce dead code and suppress warnings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-10 05:58:45 +00:00
akr 5ec8b6e78e * bignum.c (bary_mul): x*1 is x.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-09 15:43:48 +00:00
akr 55cbeefb2d * bignum.c (bary_mul_single): Invoke MEMZERO here.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-09 13:44:49 +00:00
akr 0c620c2ec3 * bignum.c (bary_mul1): No need to invoke MEMZERO at last.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-09 13:19:59 +00:00
akr fa343a796f * bignum.c (biglsh_bang): Don't shift a BDIGIT with BITSPERDIG bits.
(bigrsh_bang): Ditto.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 16:50:04 +00:00
akr fa1e85c933 * bignum.c (bigrsh_bang): Fix bignum digits overrun.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 16:19:18 +00:00
akr be2a1ad45b * bignum.c (biglsh_bang): Fix bignum digits under-run.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 15:48:09 +00:00
akr 1ffdd828b3 * bignum.c (bary_mul): Arguments for work memory added.
(bary_mul_balance): Ditto.
  (bary_mul_karatsuba): Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 13:44:34 +00:00
akr 6fdad008a2 * bignum.c (rb_big_sq_fast): New function for testing.
(rb_big_mul_toom3): Ditto.

* internal.h (rb_big_sq_fast): Declared.
  (rb_big_mul_toom3): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41832 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 13:05:57 +00:00
akr 85855a2242 * bignum.c (bary_mul_balance): Initialize a local variable to suppress
a warning.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 13:00:11 +00:00
akr ffe55cdc1e * bignum.c (bary_mul_balance): Reduce work memory.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-08 11:56:55 +00:00
akr a25f95f8b7 * bignum.c (bary_mul): Add a RB_GC_GUARD.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-07 23:04:25 +00:00
akr 1210743cad * bignum.c (bary_mul_karatsuba): Unreachable code removed. Remove
several branches.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-07 15:21:26 +00:00
akr 29634bca31 * internal.h (rb_big_mul_normal): Declared.
(rb_big_mul_balance): Ditto.
  (rb_big_mul_karatsuba): Ditto.

* bignum.c (rb_big_mul_normal): New function for tests.
  (rb_big_mul_balance): Ditto.
  (rb_big_mul_karatsuba): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-07 14:01:40 +00:00
akr d7c2f3f8a4 Useless comment removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-07 11:04:07 +00:00
akr 42d6020059 * bignum.c: Reorder functions to decrease forward reference.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-07 11:02:47 +00:00
akr 8dbf566094 * bignum.c: (bigsub_core): Use bary_sub.
(bary_sub): Returns a borrow flag.  Use bary_subb.
  (bary_subb): New function for actually calculating subtraction with
  borrow.
  (bary_sub_one): New function.
  (bigadd_core): Use bary_add.
  (bary_add): Returns a carry flag.  Use bary_addc.
  (bary_addc): New function for actually calculating addition with
  carry.
  (bary_add_one): New function.
  (bary_muladd_1xN): Extracted from bary_mul_normal.
  (bigmul1_normal): Removed.
  (bary_mul_karatsuba): New function.
  (bary_mul1): Invoke rb_thread_check_ints after bary_mul_normal.
  (bary_mul): Remove most and least significant zeros before actual
  multiplication.  Use bary_sq_fast, bary_mul_balance,
  bary_mul_karatsuba and bigmul1_toom3 as bigmul0.
  (bigmul1_balance): Removed.
  (bigmul1_karatsuba): Removed.
  (bigsqr_fast): Removed.
  (bary_sparse_p): Extracted from big_sparse_p.
  (big_sparse_p): Removed.
  (bigmul0): Use bary_mul.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-07 06:03:52 +00:00
akr b2cf5f36b9 * bignum.c (bary_sq_fast): Extracted from bigsqr_fast and
ensure not to access zds[2*xn].
  (bigsqr_fast): Allocate the result bignum with 2*xn words.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-07 01:22:55 +00:00
akr c97c78501f * bignum.c (BARY_MUL1): Renamed from BARY_MUL.
(bary_mul1): Renamed from bary_mul.
  (bary_mul): Renamed from bary_mul2.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-04 21:04:21 +00:00
akr c311134319 * bignum.c (bary_mul_balance): Extracted from bigmul1_balance and
use bary_mul2 and bary_add to decrease allocations.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-04 20:31:01 +00:00
nobu 4e681d978a bignum.c: constify
* bignum.c: constify maxpow tables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-04 14:41:26 +00:00
akr 313cdec1bc * bignum.c (maxpow_in_bdigit_dbl): Use tables if available.
(maxpow_in_bdigit): Ditto.
  (U16): New macro.
  (U32): Ditto.
  (U64): Ditto.
  (U128): Ditto.
  (maxpow16_exp): New table.
  (maxpow16_num): New table.
  (maxpow32_exp): New table.
  (maxpow32_num): New table.
  (maxpow64_exp): New table.
  (maxpow64_num): New table.
  (maxpow128_exp): New table.
  (maxpow128_num): New table.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-04 11:23:46 +00:00
akr fd8f2338e9 * bignum.c (rb_cstr_to_inum): Avoid temporary buffer allocation except
very big base non-power-of-2 numbers.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-04 09:38:11 +00:00
akr b2be623240 * internal.h (ruby_digit36_to_number_table): Declared.
* util.c (ruby_digit36_to_number_table): Moved from scan_digits.

* bignum.c (conv_digit): Use ruby_digit36_to_number_table.

* pack.c (hex2num): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-03 13:32:14 +00:00