MJIT: Refactor Compiler#cast_offset (#6967)
Subtract max value from offset when sign bit is set, without string operations.
This commit is contained in:
parent
502ca37dde
commit
1e989c49a8
Notes:
git
2022-12-21 05:29:07 +00:00
Merged-By: k0kubun <takashikkbn@gmail.com>
@ -817,9 +817,8 @@ class RubyVM::MJIT::Compiler
|
||||
|
||||
# Interpret unsigned long as signed long (VALUE -> OFFSET)
|
||||
def cast_offset(offset)
|
||||
bits = "%0#{8 * Fiddle::SIZEOF_VOIDP}d" % offset.to_s(2)
|
||||
if bits[0] == '1' # negative
|
||||
offset = -bits.chars.map { |i| i == '0' ? '1' : '0' }.join.to_i(2) - 1
|
||||
if offset >= 1 << 8 * Fiddle::SIZEOF_VOIDP - 1 # negative
|
||||
offset -= 1 << 8 * Fiddle::SIZEOF_VOIDP
|
||||
end
|
||||
offset
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user