From c87682b77f5770739a6912555e7c8790399b7fd6 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 4 Nov 2015 10:34:03 +0200 Subject: [PATCH] fix padding used to be that type and layout were hidden now type is gone and layout is an explicit instance, so 0 overhead --- lib/register/padding.rb | 6 ++---- test/register/test_padding.rb | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/register/padding.rb b/lib/register/padding.rb index ff8275df..ab04f5dd 100644 --- a/lib/register/padding.rb +++ b/lib/register/padding.rb @@ -2,10 +2,8 @@ module Padding # objects only come in lengths of multiple of 8 words - # but there is a constant overhead of 1 words for layout - # and as we would have to subtract 1 to make it work without overhead, we now have to add 7 def padded len - a = 32 * (1 + (len + 3)/32 ) + a = 32 * (1 + (len - 1)/32 ) #puts "#{a} for #{len}" a end @@ -15,7 +13,7 @@ module Padding end def padding_for length - pad = padded(length) - length - 4 # for header, layout + pad = padded(length) - length # for header, layout pad end end diff --git a/test/register/test_padding.rb b/test/register/test_padding.rb index 4f300af1..86cd96af 100644 --- a/test/register/test_padding.rb +++ b/test/register/test_padding.rb @@ -10,17 +10,17 @@ class TestPadding < MiniTest::Test @pad = Padded.new end def test_small - [6,20,27,28].each do |p| + [6,27,28,32].each do |p| assert_equal 32 , @pad.padded(p) , "Expecting 32 for #{p}" end end def test_medium - [29,40,57,60].each do |p| + [33,40,57,60,64].each do |p| assert_equal 64 , @pad.padded(p) , "Expecting 64 for #{p}" end end def test_large - [61,88].each do |p| + [65,88].each do |p| assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}" end end