2016-12-06 11:38:09 +02:00
|
|
|
# Helper functions to pad memory.
|
|
|
|
#
|
|
|
|
# Meory is always in lines, chunks of 8 words / 32 bytes
|
2015-06-04 08:22:38 +03:00
|
|
|
module Padding
|
|
|
|
|
2015-11-15 20:42:07 +02:00
|
|
|
# objects only come in lengths of multiple of 8 words / 32 bytes
|
|
|
|
# and there is a "hidden" 1 word that is used for debug/check memory corruption
|
2016-12-31 20:08:33 +02:00
|
|
|
def self.padded( len )
|
2015-11-15 20:42:07 +02:00
|
|
|
a = 32 * (1 + (len + 3)/32 )
|
2015-06-04 08:22:38 +03:00
|
|
|
#puts "#{a} for #{len}"
|
|
|
|
a
|
|
|
|
end
|
|
|
|
|
2016-12-31 20:08:33 +02:00
|
|
|
def self.padded_words( words )
|
2015-06-04 08:22:38 +03:00
|
|
|
padded(words*4) # 4 == word length, a constant waiting for a home
|
|
|
|
end
|
|
|
|
|
2016-12-31 20:08:33 +02:00
|
|
|
def self.padding_for( length )
|
2016-02-25 11:50:10 -08:00
|
|
|
pad = padded(length) - length # for header, type
|
2015-06-04 08:22:38 +03:00
|
|
|
pad
|
|
|
|
end
|
|
|
|
end
|