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: Introduce jit_putobject #5179

Merged
merged 3 commits into from Nov 25, 2021
Merged

Conversation

jhawthorn
Copy link
Member

This extracts the logic previously inside gen_putobject to a more reusable helper method jit_putobject.

The motivation for this is that it both simplifies the implementation of other instructions, and other instructions can reuse the optimized behaviour for 32-bit special constants (most importantly opt_getinlinecache).

This commit also expands the optimization to use a mov directly to memory when we encounter a 32-bit immediate constant. Previously it covered fixnums and Qtrue/Qfalse, now it will cover any SPECIAL_CONST_P value which can be represented as a 32-bit immediate. Notably, this includes static symbols, and Qnil.

Sample disassembly

putobject with static symbol

:foo

Before:

  ; putobject
  55976964005d:  mov    eax, 0x84710c
  559769640062:  mov    qword ptr [rbx], rax

After:

  ; putobject
  55e4bb62105d:  mov    qword ptr [rbx], 0x84710c

getinlinecache

FOO = 123

def get_foo
  FOO
end

10.times { get_foo }

Before:

  ; opt_getinlinecache
  55bc6656b11a:  mov    eax, 0xf7
  55bc6656b11f:  mov    qword ptr [rbx], rax

After:

  ; opt_getinlinecache
  55ab1a1f111a:  mov    qword ptr [rbx], 0xf7

This extracts the logic previously inside gen_putobject to a more
reusable helper method jit_putobject.

The motivation for this is that it both simplifies the implementation of
other instructions, and other instructions can reuse the optimized
behaviour for 32-bit special constants (most importantly
opt_getinlinecache).

This commit also expands the optimization to use a mov directly to
memory when we encounter a 32-bit immediate constant. Previously it
covered fixnums and Qtrue/Qfalse, now it will cover any SPECIAL_CONST_P
value which can be represented as a 32-bit immediate. Notably, this
includes static symbols, and Qnil.
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.

Neat! :)

@jhawthorn jhawthorn merged commit b6f543d into ruby:master Nov 25, 2021
mrkn added a commit to mrkn/ruby that referenced this pull request Jan 17, 2024
Use imag.to_r when imag is not 0 or 0r.

Fixes [Bug ruby#5179]
mrkn added a commit to mrkn/ruby that referenced this pull request Feb 20, 2024
Use imag.to_r when imag is not 0 or 0r.

Fixes [Bug ruby#5179]
mrkn added a commit to mrkn/ruby that referenced this pull request Feb 22, 2024
Use imag.to_r when imag is not 0 or 0r.

Fixes [Bug ruby#5179]
mrkn added a commit to mrkn/ruby that referenced this pull request Feb 26, 2024
Use imag.to_r when imag is not 0 or 0r.

Fixes [Bug ruby#5179]
mrkn added a commit that referenced this pull request Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants