示例#1
0
    def display_addr_refs(self, refs, table_width):

        table = Table(num_cols=len(REF_COL_NAMES),
                      width=table_width,
                      alignment='right')
        table.header[:] = REF_COL_NAMES

        for ref in refs:

            if ref.tag is not None:
                ref_tag = ref.tag
            else:
                ref_tag = 'n/a'

            if ref.index is not None:
                ref_index = ref.index
            else:
                ref_index = 'n/a'

            if ref.offset is not None:
                ref_offset = ref.offset
            else:
                ref_offset = 'n/a'

            # Display data for each address as a row in the table
            table.rows.append(
                (ref.word_addr,
                 BinaryAddress.prettify(ref.bin_addr, MIN_BITS_PER_GROUP),
                 BinaryAddress.prettify(ref_tag, MIN_BITS_PER_GROUP),
                 BinaryAddress.prettify(ref_index, MIN_BITS_PER_GROUP),
                 BinaryAddress.prettify(ref_offset,
                                        MIN_BITS_PER_GROUP), ref.cache_status))

        print(table)
示例#2
0
 def __init__(self, word_addr, num_addr_bits, num_offset_bits,
              num_index_bits, num_tag_bits):
     self.word_addr = WordAddress(word_addr)
     self.bin_addr = BinaryAddress(word_addr=self.word_addr,
                                   num_addr_bits=num_addr_bits)
     self.offset = self.bin_addr.get_offset(num_offset_bits)
     self.index = self.bin_addr.get_index(num_offset_bits, num_index_bits)
     self.tag = self.bin_addr.get_tag(num_tag_bits)
     self.cache_status = None
示例#3
0
class Reference(object):
    def __init__(self, word_addr, num_addr_bits, num_offset_bits,
                 num_index_bits, num_tag_bits):
        self.word_addr = WordAddress(word_addr)
        self.bin_addr = BinaryAddress(word_addr=self.word_addr,
                                      num_addr_bits=num_addr_bits)
        self.offset = self.bin_addr.get_offset(num_offset_bits)
        self.index = self.bin_addr.get_index(num_offset_bits, num_index_bits)
        self.tag = self.bin_addr.get_tag(num_tag_bits)
        self.cache_status = None

    def __str__(self):
        return str(OrderedDict(sorted(self.__dict__.items())))

    __repr__ = __str__

    # Return a lightweight entry to store in the cache
    def get_cache_entry(self, num_words_per_block):
        return {
            'tag': self.tag,
            'data': self.word_addr.get_consecutive_words(num_words_per_block)
        }
def test_get_offset_0_bit():
    """get_offset should return None if no bits are allocated to an offset"""
    nose.assert_is_none(
        BinaryAddress('10110100').get_offset(num_offset_bits=0))
def test_get_bin_addr_unpadded():
    """get_bin_addr should return unpadded binary address of word address"""
    nose.assert_equal(BinaryAddress(word_addr=WordAddress(180)), '10110100')
def test_get_offset_2_bit():
    """get_offset should return correct 2 offset bits for an address"""
    nose.assert_equal(
        BinaryAddress('11111101').get_offset(num_offset_bits=2), '01')
def test_get_index_0_bit():
    """get_index should return None if no bits are allocated to an index"""
    nose.assert_is_none(
        BinaryAddress('11111111').get_index(num_offset_bits=1,
                                            num_index_bits=0))
def test_get_index_2_bit():
    """get_index should return correct 2 index bits for an address"""
    nose.assert_equal(
        BinaryAddress('11111101').get_index(num_offset_bits=1,
                                            num_index_bits=2), '10')
def test_get_tag_0_bit():
    """get_tag should return None if no bits are allocated to a tag"""
    nose.assert_is_none(BinaryAddress('10110100').get_tag(num_tag_bits=0))
def test_get_tag_5_bit():
    """get_tag should return correct 5 tag bits for an address"""
    nose.assert_equal(
        BinaryAddress('10110100').get_tag(num_tag_bits=5), '10110')
def test_prettify_bin_addr_5_bit():
    """prettify_bin_addr should prettify 5-bit string into groups of 3"""
    nose.assert_equal(BinaryAddress.prettify('10110', min_bits_per_group=3),
                      '10110')
def test_get_bin_addr_padded():
    """get_bin_addr should return padded binary address of word address"""
    nose.assert_equal(
        BinaryAddress(word_addr=WordAddress(44), num_addr_bits=8), '00101100')