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

832 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans aaab3b1de9 Fix integer/float remainder with infinity argument of opposite sign
Previously, the result was incorrect:

4.remainder(-Float::INFINITY)
Before: => NaN
After: => 4

4.2.remainder(-Float::INFINITY)
Before: => NaN
After: => 4.2

Fixes [Bug #6120]
2021-03-12 07:35:18 -08:00
S.H efd19badf4
Improve performance some Numeric methods [Feature #17632] (#4190) 2021-02-19 11:11:19 -08:00
S.H fad7908a5d
Improve performance Float#positive? and Float#negative? [Feature #17614] (#4160) 2021-02-08 20:29:42 -08:00
S-H-GAMELINKS 25d506a318 Move rb_big_isqrt declaration 2021-01-31 09:23:51 +09:00
Takashi Kokubun 9d1475c621
Fix JIT link failures
forgotten in https://github.com/ruby/ruby/pull/4018
2021-01-18 14:52:33 -08:00
S.H daec5f9edc
Improve performance some Float methods [Feature #17498] (#4018) 2021-01-01 18:39:07 -08:00
Takashi Kokubun dbb4f19969
Allow inlining Integer#-@ and #~
```
$ benchmark-driver -v --rbenv 'before --jit;after --jit' benchmark/mjit_integer.yml --filter '(comp|uminus)'
before --jit: ruby 3.0.0dev (2020-12-23T05:41:44Z master 0dd4896175) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-12-23T06:25:41Z master 8887d78992) +JIT [x86_64-linux]
last_commit=Allow inlining Integer#-@ and #~
Calculating -------------------------------------
                     before --jit  after --jit
        mjit_comp(1)      44.006M      70.417M i/s -     40.000M times in 0.908967s 0.568042s
      mjit_uminus(1)      44.333M      68.422M i/s -     40.000M times in 0.902255s 0.584603s

Comparison:
                     mjit_comp(1)
         after --jit:  70417331.4 i/s
        before --jit:  44005980.4 i/s - 1.60x  slower

                   mjit_uminus(1)
         after --jit:  68422468.8 i/s
        before --jit:  44333371.0 i/s - 1.54x  slower
```
2020-12-22 22:32:19 -08:00
Alan Wu c59b9a8c0c Move docs for Integer#bit_length [ci skip] 2020-12-14 20:01:55 -05:00
S-H-GAMELINKS 52bca75cde Remove unused function declarations 2020-12-12 14:12:40 +09:00
Kenta Murata fad3023e94
Fix ArithmeticSequence#last and ArithmeticSequence#each for non-integer sequences (#3870)
[Bug #17218]
[ruby-core:100312]
2020-12-09 18:48:59 +09:00
S-H-GAMELINKS 8cbd5f218b rename 2020-11-20 11:47:47 +09:00
S-H-GAMELINKS c11c25baef fix code 2020-11-20 11:47:47 +09:00
S-H-GAMELINKS d79cdcb113 add flo_prev_or_next func 2020-11-20 11:47:47 +09:00
Kenta Murata f754b42285
numeric.c, range.c: prohibit zero step
* numeric.c: prohibit zero step in Numeric#step

* range.c: prohibit zero step in Range#step

* Fix ruby-spec

[Feature #15573]
2020-10-23 15:26:51 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Nobuyoshi Nakada dd77796f1c
Hoisted out ensure_cmp which checks the comparison succeeded 2020-10-02 21:30:07 +09:00
Nobuyoshi Nakada 89ca842dcc
Ensure that the comparison succeeded [Bug #17205] 2020-10-02 11:02:45 +09:00
Peter Zhu f7bd9f0750 Fix unsigned int overflow in error message for chr
The error message has an integer overflow because it treats an unsigned int as a signed int.

Before:
```
> 3_000_000_000.chr
-1294967296 out of char range (RangeError)
```

After:
```
> 3_000_000_000.chr
3000000000 out of char range (RangeError)
```

Redmine ticket: https://bugs.ruby-lang.org/issues/17186
2020-09-30 00:31:59 +09:00
S-H-GAMELINKS 9db5d63ece [DOC] Use oracle url instead of sun url
[ci skip]
2020-08-05 08:04:58 +09:00
Kazuhiro NISHIYAMA 946cd6c534
Use https instead of http 2020-07-28 19:51:54 +09:00
卜部昌平 802bcd3ec8 fix MJIT link error 2020-07-13 08:56:18 +09:00
卜部昌平 9721f477c7 inline Primitive.cexpr!
We can obtain the verbatim source code of Primitive.cexpr!.  Why not
paste that content into the JITed program.
2020-07-13 08:56:18 +09:00
卜部昌平 de3e931df7 add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return.  When a
function does not end with a return statement, such compilers can issue
warnings.  We would better tell them about reachabilities.
2020-06-29 11:05:41 +09:00
卜部昌平 03354feb6a fix_pow: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 250189f54f int_pow: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 bf19820bb3 flo_to_s: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
Takashi Kokubun 0703e01471
Mark some Integer methods as inline (#3264) 2020-06-27 10:07:47 -07:00
Takashi Kokubun 95b0fed371
Make Integer#zero? a separated method and builtin (#3226)
A prerequisite to fix https://bugs.ruby-lang.org/issues/15589 with JIT.
This commit alone doesn't make a significant difference yet, but I thought
this commit should be committed independently.

This method override was discussed in [Misc #16961].
2020-06-20 14:55:09 -07:00
S.H eaf76be087
Remove unused else if statements in int_even_p func (#3220)
* remove else if & rb_funcall

* fix int_even_p impl

* fix rb_int_odd_p implementation
2020-06-16 10:13:54 -07:00
S.H 84160dc29b
Add static modifier for rb_int_ceil & rb_int_floor (#3217) 2020-06-16 17:47:59 +09:00
Yusuke Endoh 42abad2464 numeric.c: optimize `float ** 2` case by fastpath
It would be a relatively frequent case.  It is still slower than
`float * float` because `*` has a dedicated VM instruction (opt_mult),
though.
2020-05-12 02:14:27 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Nobuyoshi Nakada 5d430c1b34
Added more NORETURN declarations 2020-05-11 00:40:14 +09:00
Yusuke Endoh 1a4f33e84e numeric.c: Remove unreachable code
b cannot be <= 0 here.  Found by Coverity Scan
2020-04-09 09:14:02 +09:00
Nobuyoshi Nakada 11d5a8318d
Suppress C4244 "possible loss of data" warnings 2020-04-08 18:03:46 +09:00
Nobuyoshi Nakada e474c189da
Suppress -Wswitch warnings 2020-04-08 15:13:37 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada 5b287481be
Removed non-RUBY_INTEGER_UNIFICATION code 2020-03-21 16:59:55 +09:00
Jeremy Evans ecef163cf9 Remove Float::ROUNDS
Fixes [Bug #16044]
2020-03-09 06:39:42 -07:00
Nobuyoshi Nakada 1ddc719a56
Check the encoding of `half:` option 2020-01-27 16:12:15 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
卜部昌平 0958e19ffb add several __has_something macro
With these macros implemented we can write codes just like we can assume
the compiler being clang.  MSC_VERSION_SINCE is defined to implement
those macros, but turned out to be handy for other places.  The -fdeclspec
compiler flag is necessary for clang to properly handle __has_declspec().
2019-12-26 20:45:12 +09:00
卜部昌平 0e8219f591 make functions static
These functions are used from within a compilation unit so we can
make them static, for better binary size.  This changeset reduces
the size of generated ruby binary from 26,590,128 bytes to
26,584,472 bytes on my macihne.
2019-11-19 12:36:19 +09:00
NARUSE, Yui 6aa80d5583 Use FIX2LONG instead of FIX2INT like 26843cbcd0 2019-11-07 18:53:51 +09:00
NARUSE, Yui 26843cbcd0 Use FIX2LONG to avoid unexpected exception
Though it won't happen in the real world in this context, FIX2INT may
raise an exception and it cause to generate extra code.
2019-11-07 18:50:35 +09:00
Nobuyoshi Nakada 59648af296
Suppress keyword argument warning from #step
* numeric.c (num_step): pass the extracted argument from keyword
  argument, not the last argument itself which should have been
  warned already.
2019-09-30 01:17:55 +09:00
Nobuyoshi Nakada 5decf66ab3
Inspect dynamic symbol as well as static symbol 2019-08-25 11:39:20 +09:00
Nobuyoshi Nakada d69ffa4d93
Expanded f_quo 2019-08-10 14:38:30 +09:00
Nobuyoshi Nakada e89d9f3deb
Deprecate Float::ROUNDS, which should not be a constant
[Bug #16044]
2019-08-07 00:02:45 +09:00
Nobuyoshi Nakada 4ea5c5610a
Predefine some IDs 2019-08-03 10:18:39 +09:00
Nobuyoshi Nakada f9a0492b76
Expanded f_ceil 2019-08-02 11:26:58 +09:00
Nobuyoshi Nakada a036a8a038
Adjust styles and indents 2019-07-19 06:35:15 +09:00
Yusuke Endoh 36f2d9bac2 numeric.c (fix_cmp): remove a unreachable return statement 2019-07-14 22:46:34 +09:00
git 9987296b8b * expand tabs. 2019-07-14 17:16:35 +09:00
Yusuke Endoh 934e6b2aeb Prefer `rb_error_arity` to `rb_check_arity` when it can be used 2019-07-14 17:16:19 +09:00
Yusuke Endoh 65e63af377 Make opt_aref instruction support Integer#[]
only when its receiver and the argument are both Integers.

Since 6bedbf4625, Integer#[] has supported a range extraction.
This means that Integer#[] now accepts multiple arguments, which made
the method very slow unfortunately.

This change fixes the performance issue by adding a special handling for
its traditional use case: `num[idx]` where both `num` and `idx` are
Integers.
2019-06-01 13:15:43 +09:00
Hiroshi SHIBATA b72623012d
Update broken URL in Float documentation.
[Misc #15775][ruby-core:92332]
2019-05-04 06:23:25 +09:00
git 555d1dda71 * expand tabs. 2019-04-28 23:42:46 +09:00
Yusuke Endoh 6bedbf4625 numeric.c: Extend Integer#[] to support range arguments
````
0b01001101[2, 4]  #=> 0b0011
0b01001100[2..5]  #=> 0b0011
0b01001100[2...6] #=> 0b0011
    ^^^^
````

[Feature #8842]
2019-04-28 23:40:57 +09:00
nobu e5f01dab9d numeric.c: fix infinite loop
* numeric.c (int_pow): fix infinite loop in the case of y equal 1
  and power of x does not overflow.
  [ruby-core:91734] [Bug #15651]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-11 01:37:16 +00:00
mrkn 6f6cf042d2 enumerator.c: fix arith_seq_first for Infinity
* enumerator.c (arith_seq_first): fix for Float::INFINITY.

* test/ruby/test_arithmetic_sequence.rb: add tests.

* numeric.c (ruby_float_step_size): export for internal use.

* internal.h: add prototype declaration of ruby_float_step_size.

[ruby-core:90937][Bug #15518]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-30 06:05:57 +00:00
svn 4bcfccddca * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-24 05:30:45 +00:00
mrkn 161ece4795 numeric.c: Fix negative step with float components
* numeric.c (ruby_float_step): fix negative step with float components.

* test/ruby/test_numeric.c (test_step_bug15537): add tests.

* test/ruby/test_range.c (test_step_bug15537): add tests.

[Bug #15537] [ruby-core:91101]

From: shuujii (Shuji KOBAYASHI) <shuujii@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-24 05:30:42 +00:00
mrkn fc9e0302ea complex.c: optimize zero check for Float
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09 07:05:37 +00:00
mrkn 673ff731c1 complex.c: Optimize Complex#* and Complex#**
Optimize f_mul for the core numeric class components.
This change improves the computation time of Complex#* and Complex#**.

```
$ make benchmark ITEM=complex_float_ COMPARE_RUBY=/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby
generating known_errors.inc
known_errors.inc unchanged
/Users/mrkn/src/github.com/ruby/ruby/revision.h unchanged
/Users/mrkn/.rbenv/shims/ruby --disable=gems -rrubygems -I/Users/mrkn/src/github.com/ruby/ruby/benchmark/lib /Users/mrkn/src/github.com/ruby/ruby/benchmark/benchmark-driver/exe/benchmark-driver \
                    --executables="compare-ruby::/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby -I.ext/common --disable-gem" \
                    --executables="built-ruby::./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common  -r/Users/mrkn/src/github.com/ruby/ruby/prelude --disable-gem" \
                    $(find /Users/mrkn/src/github.com/ruby/ruby/benchmark -maxdepth 1 -name '*complex_float_*.yml' -o -name '*complex_float_*.rb' | sort)
Calculating -------------------------------------
                     compare-ruby  built-ruby
   complex_float_add       6.558M     13.012M i/s -      1.000M times in 0.152480s 0.076850s
   complex_float_div     576.821k    567.969k i/s -      1.000M times in 1.733640s 1.760660s
   complex_float_mul       1.690M      2.628M i/s -      1.000M times in 0.591786s 0.380579s
   complex_float_new       1.350M      1.268M i/s -      1.000M times in 0.740669s 0.788762s
 complex_float_power       1.571M      1.835M i/s -      1.000M times in 0.636507s 0.544909s
   complex_float_sub       8.635M      8.779M i/s -      1.000M times in 0.115814s 0.113906s

Comparison:
                complex_float_add
          built-ruby:  13012361.7 i/s
        compare-ruby:   6558237.1 i/s - 1.98x  slower

                complex_float_div
        compare-ruby:    576821.0 i/s
          built-ruby:    567968.8 i/s - 1.02x  slower

                complex_float_mul
          built-ruby:   2627575.4 i/s
        compare-ruby:   1689800.0 i/s - 1.55x  slower

                complex_float_new
        compare-ruby:   1350130.8 i/s
          built-ruby:   1267809.6 i/s - 1.06x  slower

              complex_float_power
          built-ruby:   1835168.8 i/s
        compare-ruby:   1571074.6 i/s - 1.17x  slower

                complex_float_sub
          built-ruby:   8779168.8 i/s
        compare-ruby:   8634534.7 i/s - 1.02x  slower
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-03 06:19:17 +00:00
mrkn 5f90845420 complex.c: Optimize Complex#+ for some conditions
Optimize f_add defined in complex.c for some specific conditions.
It makes Complex#+ about 1.4x faster than r66678.

Compared to r66678:

```
mrkn-mbp15-late2016:complex-optim-o3 mrkn$ make benchmark ITEM=complex_float_ COMPARE_RUBY=/Users/mrkn/.rbenv/versions/trunk-o3/bin/ruby
/Users/mrkn/src/github.com/ruby/ruby/revision.h unchanged
/Users/mrkn/.rbenv/shims/ruby --disable=gems -rrubygems -I/Users/mrkn/src/github.com/ruby/ruby/benchmark/lib /Users/mrkn/src/github.com/ruby/ruby/benchmark/benchmark-driver/exe/benchmark-driver \
                    --executables="compare-ruby::/Users/mrkn/.rbenv/versions/trunk-o3/bin/ruby -I.ext/common --disable-gem" \
                    --executables="built-ruby::./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common  -r/Users/mrkn/src/github.com/ruby/ruby/prelude --disable-gem" \
                    $(find /Users/mrkn/src/github.com/ruby/ruby/benchmark -maxdepth 1 -name '*complex_float_*.yml' -o -name '*complex_float_*.rb' | sort)
Calculating -------------------------------------
                     compare-ruby  built-ruby
   complex_float_add       9.132M     12.864M i/s -      1.000M times in 0.109511s 0.077734s
   complex_float_div     600.723k    627.878k i/s -      1.000M times in 1.664662s 1.592666s
   complex_float_mul       2.320M      2.347M i/s -      1.000M times in 0.431039s 0.426113s
   complex_float_new       1.473M      1.489M i/s -      1.000M times in 0.678791s 0.671750s
 complex_float_power       1.690M      1.722M i/s -      1.000M times in 0.591863s 0.580775s
   complex_float_sub       8.870M      9.516M i/s -      1.000M times in 0.112740s 0.105091s

Comparison:
                complex_float_add
          built-ruby:  12864383.7 i/s
        compare-ruby:   9131502.8 i/s - 1.41x  slower

                complex_float_div
          built-ruby:    627878.0 i/s
        compare-ruby:    600722.5 i/s - 1.05x  slower

                complex_float_mul
          built-ruby:   2346795.3 i/s
        compare-ruby:   2319975.7 i/s - 1.01x  slower

                complex_float_new
          built-ruby:   1488649.1 i/s
        compare-ruby:   1473207.5 i/s - 1.01x  slower

              complex_float_power
          built-ruby:   1721837.2 i/s
        compare-ruby:   1689580.2 i/s - 1.02x  slower

                complex_float_sub
          built-ruby:   9515562.7 i/s
        compare-ruby:   8869966.3 i/s - 1.07x  slower
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 12:20:05 +00:00
nobu dc8afd385d complex.c: rb_complex_new_polar
* complex.c (rb_complex_new_polar): renamed with _new to clarify
  that it creates a new instance, but is not an instance method.

* complex.c (rb_complex_polar): deprecated.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12 11:06:47 +00:00
nobu 34cc6fef83 Make some internal functions static
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16 06:52:00 +00:00
shyouhei a9723e96f5 numeric.c: avoid division by zero
Forgot to add in r65751.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16 04:05:53 +00:00
shyouhei 3a083985a4 avoid division by zero
* cvt(): use signbit() instead of 1/d < 0
* w_float(): ditto
* ruby_float_step_size(): unit==0 check shall be prior to divisions
* arith_seq_float_step_size(): ditto
* rb_big_divide(): same as r65642
* fix_divide(): ditto
* rb_big_fdiv_double(): ditto
* fix_fdiv_double(): ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16 01:52:39 +00:00
nobu d6cd22dbc5 Export rb_flo_div_flo for MJIT
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-12 07:14:43 +00:00
shyouhei 68261c06b5 numeric.c: fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-12 04:09:24 +00:00
shyouhei 00b8b11858 vm_insnhelper.c: avoid division by zero
same as r65642.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-12 03:26:39 +00:00
shyouhei b8540e0a9d numeric.c: avoid division by zero
In C, division by zero is undefined, even if the expression is double
(cf: ISO/IEC 9899:1990 section 6.3.5).  OTOH we have tests about such
operations and results, means we expect no exceptional situation shall
occur.  We need to carefully reroute the situation, and generate what
is needed.

See also: https://travis-ci.org/ruby/ruby/jobs/452680646#L2943

PS: Recently (last two decades), C have Annex. F document. It
normatively specifies that the division operator is IEEE 754's
division operator (cf: ISO/IEC 9899:1999 section F.3).  If we could
move to such newer version this could be no problem.  But that is not
possible today.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-09 09:14:23 +00:00
nobu 3e063ca7ae complex.c: rb_dbl_complex_polar_pi
* complex.c (rb_dbl_complex_polar_pi): suffixed with _pi to
  clarify that `ang` is not radian, but multiplied by PI.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04 00:22:13 +00:00
nobu b4bbfe4bb9 complex.c: small optimization of Complex#**
* complex.c (rb_complex_pow): calculate power of a Fixnum without
  allocating intermediate Complex objects, and avoid unexpected
  NaNs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 02:49:18 +00:00
nobu 603f95a0ed Fix Rational of Float
[ruby-core:89239] [Bug #15189]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-02 16:42:21 +00:00
svn 4add701ad4 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-29 00:45:44 +00:00
nobu 36c4713e31 rational.c: may be float
* rational.c (f_muldiv): Integer#** can return Rational with Float
  right now.  [ruby-core:89212] [Bug #15175]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-29 00:45:41 +00:00
mrkn 98fa0ab4d9 [DOC] Modify descriptions for ArithmeticSequence
[ci-skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-12 08:51:34 +00:00
kazu 77bc5e4f18 Remove needless comment [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-10 12:36:30 +00:00
mrkn f15069338d enumerator.c: Introduce Enumerator::ArithmeticSequence
This commit introduces new core class Enumerator::ArithmeticSequence.
Enumerator::ArithmeticSequence is a subclass of Enumerator, and
represents a number generator of an arithmetic sequence.

After this commit, Numeric#step and Range#step without blocks
returned an ArithmeticSequence object instead of an Enumerator.

This class introduces the following incompatibilities:

- You can create a zero-step ArithmeticSequence,
  and its size is not ArgumentError, but Infinity.
- You can create a negative-step ArithmeticSequence from a range.

[ruby-core:82816] [Feature #13904]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-06 09:08:28 +00:00
nobu 97e05dad7f UNREACHABLE_RETURN
* include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end
  of non-void functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24 05:38:07 +00:00
nobu 4fedad85ef refine Integer#** and Float#**
* complex.c (rb_dbl_complex_polar): utility function, which
  returns more precise value in right angle cases.

* bignum.c (rb_big_pow): use rb_dbl_complex_polar().

* numeric.c (rb_float_pow, fix_pow): create a Complex by polar
  form.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-17 02:37:32 +00:00
nobu f12cc0e6f7 refine Integer#**
* numeric.c (fix_pow): calculate the denominator, exponent of
  self.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-17 01:07:27 +00:00
nobu c9db11ea60 bignum.c: get rid of redefined method
* bignum.c (int_pow_tmp3): get rid of redefined Integer#> on
  internal calculations, as well as the GMP version.

* bignum.c (rb_int_powm): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-14 07:09:02 +00:00
mame 7f95eed19e Introduce endless range [Feature#12912]
Typical usages:
```
p ary[1..]          # drop the first element; identical to ary[1..-1]
(1..).each {|n|...} # iterate forever from 1; identical to 1.step{...}
```

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-19 15:18:50 +00:00
nobu 23228b6e31 Remove outdated example from Numeric documentation
Since 2.5, Numeric instances can be cloned and duplicated.

[Fix GH-1850]

From: Miguel Landaeta <miguel@miguel.cc>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-07 13:03:35 +00:00
nobu b9d01e2257 [DOC] obsolete classes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:16:43 +00:00
k0kubun 288b44328d Export some missing symbols for MJIT
tool/ruby_vm/views/_insn_name_info.erb: on Linux, rb_vm_insn_name_offset
was needed to compile with --jit-debug (Usually --jit-debug requires
more symbols than the situation without --jit-debug because -O2 skips
some functions to compile).

vm.c: when running transform_mjit_header.rb with --jit-wait,
rb_source_location_cstr was repoted to be missing.

string.c: ditto, for rb_str_eql
numeric.c: ditto, for rb_float_eql

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-08 13:54:37 +00:00
k0kubun ed935aa5be mjit_compile.c: merge initial JIT compiler
which has been developed by Takashi Kokubun <takashikkbn@gmail> as
YARV-MJIT. Many of its bugs are fixed by wanabe <s.wanabe@gmail.com>.

This JIT compiler is designed to be a safe migration path to introduce
JIT compiler to MRI. So this commit does not include any bytecode
changes or dynamic instruction modifications, which are done in original
MJIT.

This commit even strips off some aggressive optimizations from
YARV-MJIT, and thus it's slower than YARV-MJIT too. But it's still
fairly faster than Ruby 2.5 in some benchmarks (attached below).

Note that this JIT compiler passes `make test`, `make test-all`, `make
test-spec` without JIT, and even with JIT. Not only it's perfectly safe
with JIT disabled because it does not replace VM instructions unlike
MJIT, but also with JIT enabled it stably runs Ruby applications
including Rails applications.

I'm expecting this version as just "initial" JIT compiler. I have many
optimization ideas which are skipped for initial merging, and you may
easily replace this JIT compiler with a faster one by just replacing
mjit_compile.c. `mjit_compile` interface is designed for the purpose.

common.mk: update dependencies for mjit_compile.c.

internal.h: declare `rb_vm_insn_addr2insn` for MJIT.

vm.c: exclude some definitions if `-DMJIT_HEADER` is provided to
compiler. This avoids to include some functions which take a long time
to compile, e.g. vm_exec_core. Some of the purpose is achieved in
transform_mjit_header.rb (see `IGNORED_FUNCTIONS`) but others are
manually resolved for now. Load mjit_helper.h for MJIT header.
mjit_helper.h: New. This is a file used only by JIT-ed code. I'll
refactor `mjit_call_cfunc` later.
vm_eval.c: add some #ifdef switches to skip compiling some functions
like Init_vm_eval.

win32/mkexports.rb: export thread/ec functions, which are used by MJIT.

include/ruby/defines.h: add MJIT_FUNC_EXPORTED macro alis to clarify
that a function is exported only for MJIT.

array.c: export a function used by MJIT.
bignum.c: ditto.
class.c: ditto.
compile.c: ditto.
error.c: ditto.
gc.c: ditto.
hash.c: ditto.
iseq.c: ditto.
numeric.c: ditto.
object.c: ditto.
proc.c: ditto.
re.c: ditto.
st.c: ditto.
string.c: ditto.
thread.c: ditto.
variable.c: ditto.
vm_backtrace.c: ditto.
vm_insnhelper.c: ditto.
vm_method.c: ditto.

I would like to improve maintainability of function exports, but I
believe this way is acceptable as initial merging if we clarify the
new exports are for MJIT (so that we can use them as TODO list to fix)
and add unit tests to detect unresolved symbols.
I'll add unit tests of JIT compilations in succeeding commits.

Author: Takashi Kokubun <takashikkbn@gmail.com>
Contributor: wanabe <s.wanabe@gmail.com>

Part of [Feature #14235]

---

* Known issues
  * Code generated by gcc is faster than clang. The benchmark may be worse
    in macOS. Following benchmark result is provided by gcc w/ Linux.
  * Performance is decreased when Google Chrome is running
  * JIT can work on MinGW, but it doesn't improve performance at least
    in short running benchmark.
  * Currently it doesn't perform well with Rails. We'll try to fix this
    before release.

---

* Benchmark reslts

Benchmarked with:
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores

- 2.0.0-p0: Ruby 2.0.0-p0
- r62186: Ruby trunk (early 2.6.0), before MJIT changes
- JIT off: On this commit, but without `--jit` option
- JIT on: On this commit, and with `--jit` option

** Optcarrot fps

Benchmark: https://github.com/mame/optcarrot

|         |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:--------|:--------|:--------|:--------|:--------|
|fps      |37.32    |51.46    |51.31    |58.88    |
|vs 2.0.0 |1.00x    |1.38x    |1.37x    |1.58x    |

** MJIT benchmarks

Benchmark: https://github.com/benchmark-driver/mjit-benchmarks
(Original: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch/MJIT-benchmarks)

|           |2.0.0-p0 |r62186   |JIT off  |JIT on   |
|:----------|:--------|:--------|:--------|:--------|
|aread      |1.00     |1.09     |1.07     |2.19     |
|aref       |1.00     |1.13     |1.11     |2.22     |
|aset       |1.00     |1.50     |1.45     |2.64     |
|awrite     |1.00     |1.17     |1.13     |2.20     |
|call       |1.00     |1.29     |1.26     |2.02     |
|const2     |1.00     |1.10     |1.10     |2.19     |
|const      |1.00     |1.11     |1.10     |2.19     |
|fannk      |1.00     |1.04     |1.02     |1.00     |
|fib        |1.00     |1.32     |1.31     |1.84     |
|ivread     |1.00     |1.13     |1.12     |2.43     |
|ivwrite    |1.00     |1.23     |1.21     |2.40     |
|mandelbrot |1.00     |1.13     |1.16     |1.28     |
|meteor     |1.00     |2.97     |2.92     |3.17     |
|nbody      |1.00     |1.17     |1.15     |1.49     |
|nest-ntimes|1.00     |1.22     |1.20     |1.39     |
|nest-while |1.00     |1.10     |1.10     |1.37     |
|norm       |1.00     |1.18     |1.16     |1.24     |
|nsvb       |1.00     |1.16     |1.16     |1.17     |
|red-black  |1.00     |1.02     |0.99     |1.12     |
|sieve      |1.00     |1.30     |1.28     |1.62     |
|trees      |1.00     |1.14     |1.13     |1.19     |
|while      |1.00     |1.12     |1.11     |2.41     |

** Discourse's script/bench.rb

Benchmark: https://github.com/discourse/discourse/blob/v1.8.7/script/bench.rb

NOTE: Rails performance was somehow a little degraded with JIT for now.
We should fix this.
(At least I know opt_aref is performing badly in JIT and I have an idea
 to fix it. Please wait for the fix.)

*** JIT off
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 17
  75: 18
  90: 22
  99: 29
home_admin:
  50: 21
  75: 21
  90: 27
  99: 40
topic_admin:
  50: 17
  75: 18
  90: 22
  99: 32
categories:
  50: 35
  75: 41
  90: 43
  99: 77
home:
  50: 39
  75: 46
  90: 49
  99: 95
topic:
  50: 46
  75: 52
  90: 56
  99: 101

*** JIT on
Your Results: (note for timings- percentile is first, duration is second in millisecs)

categories_admin:
  50: 19
  75: 21
  90: 25
  99: 33
home_admin:
  50: 24
  75: 26
  90: 30
  99: 35
topic_admin:
  50: 19
  75: 20
  90: 25
  99: 30
categories:
  50: 40
  75: 44
  90: 48
  99: 76
home:
  50: 42
  75: 48
  90: 51
  99: 89
topic:
  50: 49
  75: 55
  90: 58
  99: 99

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 11:22:28 +00:00
kazu ef83b306e2 Fix duplicated HAVE_NAN
And remove redundant `HAVE_*` macros,
and use `USE_RB_*` macros instead.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-27 04:14:26 +00:00
shyouhei 782236e3bd add missing/nan.c
instead of scattering #ifdef HAVE_NANF here and there define our
own nan() unless defined elsewhere.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-20 03:16:59 +00:00
shyouhei 3ca0948f68 INFINITY is float. That of double is HUGE_VAL.
It seems HUGE_VAL is already used. Why not eliminate INTINITY.
NAN is also float. That of double is called nan(). This is also
fixed.

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19 01:45:36 +00:00
shyouhei 193b85a9e0 num_funcall_op_1_recursion marked as NORETURN
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61916 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 09:44:39 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
marcandre 907508b25f Integer#{any|all|no}_bits: Fix coercion. Add specs [#12753]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-17 18:19:41 +00:00
stomar df15754bd7 numeric.c: [DOC] grammar fixes
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-14 10:25:57 +00:00
naruse 0da34dbb26 Integer#allbits?, Integer#anybits?, Integer#nobits? [Feature #12753]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12 09:12:14 +00:00