Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YJIT: Add codegen for Float arithmetics #9774

Merged
merged 2 commits into from Jan 31, 2024
Merged

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Jan 31, 2024

This speeds up blurhash, matmul, and nbody.

--------  -----------  ----------  ----------  ----------  -------------  ------------
bench     before (ms)  stddev (%)  after (ms)  stddev (%)  after 1st itr  before/after
blurhash  240.8        0.4         233.7       0.4         1.03           1.03
matmul    1026.4       0.1         946.7       0.1         1.07           1.08
nbody     62.6         0.4         55.7        0.3         1.11           1.13
--------  -----------  ----------  ----------  ----------  -------------  ------------

@matzbot matzbot requested a review from a team January 31, 2024 01:43
Comment on lines +2488 to +2490
assert_equal '[2.0, 0.0, 1.0, 4.0]', %q{
[1.0 + 1.0, 1.0 - 1.0, 1.0 * 1.0, 8.0 / 2.0]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your test is perfectly good and valid, but I will point out in case you don't know: numbers having binary fractions are also guaranteed to be representable exactly using floating-point numbers :)

e.g. 1.50, 1.25, 1.125, 2.5 all have exact IEEE FP representations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't clever enough to figure out 1.125 is 2^0 + 2^(-3) right away, but thanks for a nice refresher 🙂

Copy link
Contributor

@maximecb maximecb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice first step in terms of adding FP support to YJIT 👌

Reading the code, I think it would be good to also add tests that mix fixnum and flonum, e.g. 1.5 * 2

@maximecb maximecb enabled auto-merge (squash) January 31, 2024 17:29
@maximecb maximecb merged commit 09427f5 into ruby:master Jan 31, 2024
97 checks passed
@k0kubun k0kubun deleted the yjit-float branch January 31, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants