summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorAbrar Habib <86024593+dddictionary@users.noreply.github.com>2025-12-09 07:41:09 -0500
committerGitHub <noreply@github.com>2025-12-09 12:41:09 +0000
commitedca81a1bb72a9dc54a37766d2c80790dec13884 (patch)
treec22b14dab1b2c68fdef59a84b7ea2eb157e379c1 /test/ruby
parent5ae2bd240f0adea46358f0a95bc26276d9f0cc31 (diff)
ZJIT: Add codegen for FixnumDiv (#15452)
Fixes https://github.com/Shopify/ruby/issues/902 This pull request adds code generation for dividing fixnums. Testing confirms the normal case, flooring, and side-exiting on division by zero.
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_zjit.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index 03d2461fa0..cc5143aee5 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -960,6 +960,37 @@ class TestZJIT < Test::Unit::TestCase
}, call_threshold: 2, insns: [:opt_mult]
end
+ def test_fixnum_div
+ assert_compiles '12', %q{
+ C = 48
+ def test(n) = C / n
+ test(4)
+ test(4)
+ }, call_threshold: 2, insns: [:opt_div]
+ end
+
+ def test_fixnum_floor
+ assert_compiles '0', %q{
+ C = 3
+ def test(n) = C / n
+ test(4)
+ test(4)
+ }, call_threshold: 2, insns: [:opt_div]
+ end
+
+ def test_fixnum_div_zero
+ assert_runs '"divided by 0"', %q{
+ def test(n)
+ n / 0
+ rescue ZeroDivisionError => e
+ e.message
+ end
+
+ test(0)
+ test(0)
+ }, call_threshold: 2, insns: [:opt_div]
+ end
+
def test_opt_not
assert_compiles('[true, true, false]', <<~RUBY, insns: [:opt_not])
def test(obj) = !obj