bench-rejected-impls/14_docking_data.rb
# This isn't even close to being a contender;
# the access pattern doesn't have enough locality for this,
# since the floating bits could be anywhere.
This isn't even close to being a contender;
the access pattern doesn't have enough locality for this,
since the floating bits could be anywhere.
This isn ' t even close to being a contender ; the access pattern doesn ' t have enough locality for this since the floating bits could be anywhere .
def run2_page_table(insts)
  mask_ones = nil
  mask_xs = nil
  pages = Hash.new { |h, k| h[k] = [] }
  addr_in_page_bits = 10
  page_index_bits = 36 - addr_in_page_bits
  addr_in_page_mask = (1 << addr_in_page_bits) - 1
  page_index_mask = ((1 << page_index_bits) - 1) << addr_in_page_bits
  insts.each { |inst, arg|
    case inst
    when :mask
      _, mask_ones, mask_xs = arg
    when :mem
      addr, val = arg
      addr |= mask_ones
      addr &= ~mask_xs
      n = 0
      while true
        dest = addr | n
        pages[dest & page_index_mask][dest & addr_in_page_mask] = val
        n = (n + ~mask_xs + 1) & mask_xs
        break if n == 0
      end
    else raise "bad #{inst} #{arg}"
    end
  }
  pages.sum { |_, v| v.compact.sum }
end
def run2_page_table ( insts ) mask_ones = nil mask_xs = nil pages = Hash . new { | h , k | h [ k ] = [ ] } addr_in_page_bits = 10 page_index_bits = 36 - addr_in_page_bits addr_in_page_mask = ( 1 << addr_in_page_bits ) - 1 page_index_mask = ( ( 1 << page_index_bits ) - 1 ) << addr_in_page_bits insts . each { | inst , arg | case inst when :mask _ , mask_ones , mask_xs = arg when :mem addr , val = arg addr |= mask_ones addr &= ~ mask_xs n = 0 while true dest = addr | n pages [ dest & page_index_mask ] [ dest & addr_in_page_mask ] = val n = ( n + ~ mask_xs + 1 ) & mask_xs break if n == 0 end else raise "bad #{inst} #{arg}" end } pages . sum { | _ , v | v . compact . sum } end
This isn't even close to being a contender;
the access pattern doesn't have enough locality for this,
since the floating bits could be anywhere.
This isn ' t even close to being a contender ; the access pattern doesn ' t have enough locality for this since the floating bits could be anywhere .
# Could shift page_index >> addr_in_page_bits so that it starts at 0, # but no point since pages are stored sparsely anyway.
insts
<not_specific>