twolevel.py 951 Bytes
Newer Older
Alan Marchiori's avatar
Alan Marchiori committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

from local import saturating_counter

class correlation_register():
    def __init__(self, bits=3):
        self.bits = bits
        self.mask = 2**self.bits - 1
        self.value = self.mask
        self.binfmt = "{{:0{:d}b}}".format(len(bin(self.mask)[2:])) # chop leading 0b prefix
        
    def learn(self, outcome):
        self.value = (self.value << 1) & (self.mask)
        if outcome == 'T':
            self.value |= 1
            
    def __str__(self):
        return self.binfmt.format(self.value)
    

class twolevel_predictor():
    def __init__(self, correlation_bits=3, pht_bits = 3):
        self.corr_bits = correlation_bits
        self.pht_bits = pht_bits
        self.corr_indexes = 2**self.corr_bits
        self.pht_indexes = 2**self.pht_bits
        
                
    def predict(self, pc, target, outcome, verbose):
        
        # TODO
        # finish me.
        
        return "T"