MJIT: Refactor BitField dereference byte and bitmask (#6955)
Prefer Array#unpack1 and Enumerable#sum. I think the bitmask formula ``2 ** @width - 1`` would be clearer, but not faster for such small integers.
This commit is contained in:
parent
6e3bc67103
commit
632beec01f
Notes:
git
2022-12-17 21:07:09 +00:00
Merged-By: k0kubun <takashikkbn@gmail.com>
@ -282,12 +282,12 @@ module RubyVM::MJIT
|
|||||||
|
|
||||||
# Dereference
|
# Dereference
|
||||||
def *
|
def *
|
||||||
byte = Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_CHAR].unpack('c').first
|
byte = Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_CHAR].unpack1('c')
|
||||||
if @width == 1
|
if @width == 1
|
||||||
bit = (1 & (byte >> @offset))
|
bit = (1 & (byte >> @offset))
|
||||||
bit == 1
|
bit == 1
|
||||||
elsif @width <= 8 && @offset == 0
|
elsif @width <= 8 && @offset == 0
|
||||||
bitmask = @width.times.map { |i| 1 << i }.sum
|
bitmask = @width.times.sum { |i| 1 << i }
|
||||||
byte & bitmask
|
byte & bitmask
|
||||||
else
|
else
|
||||||
raise NotImplementedError.new("not-implemented bit field access: width=#{@width} offset=#{@offset}")
|
raise NotImplementedError.new("not-implemented bit field access: width=#{@width} offset=#{@offset}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user