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

669 Коммитов

Автор SHA1 Сообщение Дата
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