diff --git a/riscv_isac/hazards.py b/riscv_isac/hazards.py deleted file mode 100644 index 2db3595..0000000 --- a/riscv_isac/hazards.py +++ /dev/null @@ -1,186 +0,0 @@ -## Coverpoint - [instr, ? : ? ..... instr]::[a=rd : ?consuming/not: ]::[RAW/WAW/WAR] - -''' -Combinations list - -Tester list - opcode list against which we check for other instructions (corresponding to queue[0]) -Test list - opcode list for which we check for potential hazards (corresponding to next n instructions) - -1. In-between instructions (non-consuming) -- Test list - have both rs1 and rs2 fields {arith_instr, branch_instr, rv64_arith} -- Test list - have only rs1 field (the other is immediate) {field_1, arithi_instr, rv64_arithi} -- Test list - Instructions have no rd fields (no WAW) {store_instr} - -''' -# Have both rs1, rs2 -arith_instr = ('mul','mulh','mulhsu','mulhu','div','divu','rem','remu','add','sub','sll','slt','sltu','xor','srl','sra','or','and') -branch_instr = ('beq','bne','blt','bge','bltu','bgeu') -rv64_arith = ('mulw','divw','divuw','remw','remuw','addw','subw','sllw','srlw','sraw') - -# Have only rs1 -field_1 = ('jalr','lb','lh','lw','ld','lbu','lhu','lwu') -arithi_instr = ('addi', 'slti', 'sltiu', 'xori', 'ori', 'andi', 'slli', 'srai', 'srli') -rv64_arithi = ('addiw','ssliw','srliw','sraiw') - -# No rs1, rs2 - only rd -misc_instr = ('lui', 'auipc', 'jal') - -# No rd - both rs1, rs2 -store_instr = ('sb', 'sh', 'sw', 'sd') - -## Combined string -instr_str = ", ".join(arith_instr + branch_instr + rv64_arith + field_1 + arithi_instr + rv64_arithi + misc_instr + store_instr) - -def raw (window_len, instr1, instr2): - ''' - Args: - window_len: size of window for evaluation (int) - gap: number of instructions in between (int) - instr1: tuple of intrcutions against which others are checked - instr2: tuple of intructions that are checked against a given instruction - - Return coverpoints like [(lui, auipc, jal):?:?:(sb, sh, sw, sd):?]::[a=rd:?:?:?:?]::[?:?:?:rs1==a or rs2==a:?] - ''' - gap = window_len - 2 - instr_str1 = ", ".join(instr1) - instr_str2 = ", ".join(instr2) - - opcode_list = "[(" + instr_str1 + ")" - for i in range(gap): - opcode_list += ":?" - opcode_list += ":("+ instr_str2 + ")" - opcode_list += "]" - - assign_list = "" - assign_list += '[a=rd' - for i in range (window_len - 1): - assign_list += ":?" - assign_list += "]" - - cond_list_rs = "" - cond_list_rs += "[?" - for i in range (gap): - cond_list_rs += ":?" - cond_list_rs += ":rs1==a or rs2==a" - cond_list_rs += "]" - - raw_str = opcode_list + "::" + assign_list + "::" + cond_list_rs - return raw_str - -def waw ( window_len, instr1, instr2 ): - ''' - Args: - window_len: size of window for evaluation (int) - gap: number of instructions in between (int) - instr1: tuple of intrcutions against which others are checked - instr2: tuple of intructions that are checked against a given instruction - - Return coverpoints like [(mul, mulh, mulhsu, mulhu, ):?:?:?:(sb, sh, sw, sd)]::[a=rd:?:?:?:?]::[?:?:?:?:rd==a] - - ''' - gap = window_len - 2 - instr_str1 = ", ".join(instr1) - instr_str2 = ", ".join(instr2) - opcode_list = "[(" + instr_str1 + ")" - for i in range(gap): - opcode_list += ":?" - opcode_list += ":("+ instr_str2 + ")" - opcode_list += "]" - - assign_list = "" - assign_list += '[a=rd' - for i in range (window_len - 1): - assign_list += ":?" - assign_list += "]" - - cond_list_rd = "" - cond_list_rd += "[?" - for i in range (gap): - cond_list_rd += ":?" - cond_list_rd += ":rd==a" - cond_list_rd += "]" - - waw_str = opcode_list + "::" + assign_list + "::" + cond_list_rd - - return waw_str - -def war ( window_len, instr1, instr2 ): - ''' - Args: - window_len: size of window for evaluation (int) - gap: number of instructions in between (int) - instr1: tuple of intrcutions against which others are checked - instr2: tuple of intructions that are checked against a given instruction - - Return coverpoints like [(mul, mulh, mulhsu, mulhu, ):?:?:?:(sb, sh, sw, sd)]::[a=rs1:?:?:?:?]::[?:?:?:?:rd==a or rd==b] - - ''' - gap = window_len - 2 - instr_str1 = ", ".join(instr1) - instr_str2 = ", ".join(instr2) - opcode_list = "[(" + instr_str1 + ")" - for i in range(gap): - opcode_list += ":?" - opcode_list += ":("+ instr_str2 + ")" - opcode_list += "]" - - assign_list = "" - assign_list += '[a=rs1 ; b=rs2' - for i in range (window_len - 1): - assign_list += ":?" - assign_list += "]" - - cond_list_rd = "" - cond_list_rd += "[?" - for i in range (gap): - cond_list_rd += ":?" - cond_list_rd += ":rd==a or rd==b" - cond_list_rd += "]" - - war_str = opcode_list + "::" + assign_list + "::" + cond_list_rd - - return war_str - -def consume_waw ( window_len, instr1, instr2): - ''' - Args: - window_len: size of window for evaluation (int) - gap: number of instructions in between (int) - instr1: tuple of intrcutions against which others are checked - instr2: tuple of intructions that are checked against a given instruction - - Return coverpoints like: [(mul, mulh, mulhsu, mulhu, ):?:?:?:(sb, sh, sw, sd)]::[a=rd:?:?:?:?]::[?:rs1==a || rs2==a:rs1==a || rs2==a:rs1==a || rs2==a:rd==a] - - ''' - gap = window_len - 2 - instr_str1 = ", ".join(instr1) - instr_str2 = ", ".join(instr2) - opcode_list = "[(" + instr_str1 + ")" - for i in range(gap): - opcode_list += ":?" - opcode_list += ":("+ instr_str2 + ")" - opcode_list += "]" - - assign_list = "" - assign_list += '[a=rd' - for i in range (window_len - 1): - assign_list += ":?" - assign_list += "]" - - cond_list_rd = "[?" - for i in range (gap): - cond_list_rd += ":rs1==a or rs2==a" - cond_list_rd += ":rd==a" - cond_list_rd += "]" - - waw = opcode_list + "::" + assign_list + "::" + cond_list_rd - - return waw - -print(war(3,misc_instr,store_instr)) - - - - - - diff --git a/riscv_isac/test_cross_coverage.py b/riscv_isac/test_cross_coverage.py deleted file mode 100644 index 4110c79..0000000 --- a/riscv_isac/test_cross_coverage.py +++ /dev/null @@ -1,183 +0,0 @@ -class temp(): - def __init__(self,instr_name, rd, rs1, rs2): - self.instr_name = instr_name - self.rd = rd - self.rs1 = rs1 - self.rs2 = rs2 - -class cross(): - - def __init__(self,label,coverpoint): - - self.label = label - self.coverpoint = coverpoint - self.result = 0 - - ## Extract relevant information from coverpt - self.data = self.coverpoint.split('::') - self.ops = [i for i in self.data[0][1:-1].split(':')] - self.assign_lst = [i for i in self.data[1][1:-1].split(':')] - self.cond_lst = [i for i in self.data[2][1:-1].split(':')] - - def process(self, queue, window_size): - - ''' - Check whether the coverpoint is a hit or not and update the metric - ''' - if(len(self.ops)>window_size or len(self.ops)>len(queue)): - return - - for index in range(len(self.ops)): - instr = queue[index] - instr_name = instr.instr_name - rd = int(instr.rd) - rs1 = int(instr.rs1) - rs2 = int(instr.rs2) - if(self.ops[index] != '?'): - check_lst = [i for i in self.ops[index][1:-1].split(', ')] - if (instr_name not in check_lst): - break - if(self.assign_lst[index] != '?'): - exec(self.assign_lst[index]) - if (self.cond_lst[index] != '?'): - if(eval(self.cond_lst[index])): - if(index==len(self.ops)-1): - self.result = self.result + 1 - else: - break - - def get_metric(self): - return self.result - -def cross_coverage(obj_dict, window_size, end=0): - ''' - Computes cross coverage for the current queue of instructions - - Arguments: - cross_cgf: CGF containing coverpoint nodes with their frequency of hits - window_size: maximum window length of instructions to check - end : end = 1 implies we have to evaluate the ending corner case - - Type: - cross_cgf: dictionary - window_size: int - end: int - - ''' - global cross_cover_queue - ## RAW, WAW, WAR - if(end): - while(len(cross_cover_queue)>1): - instr_name = cross_cover_queue[0].instr_name - for label,coverpt in obj_dict.keys(): - if(label==instr_name): - ## evaluate that coverpt - obj_dict[(label,coverpt)].process(cross_cover_queue, window_size) - cross_cover_queue.pop(0) - else: - instr_name = cross_cover_queue[0].instr_name - for label,coverpt in obj_dict.keys(): - if(label==instr_name): - ## evaluate that coverpt - obj_dict[(label,coverpt)].process(cross_cover_queue, window_size) - cross_cover_queue.pop(0) - - -def compute(cgf,window_size): - - obj_dict = {} ## (label,coverpoint): object - for cov_labels,value in cgf.items(): - if cov_labels != 'datasets': - if 'opcode' in value and 'cross_comb' in value and len(value['cross_comb'])!=0: - for coverpt in value['cross_comb'].keys(): - if(isinstance(coverpt,str)): - new_obj = cross(cov_labels,coverpt) - obj_dict[(cov_labels,coverpt)] = new_obj - ## raw, waw, war - global cross_cover_queue - cross_cover_queue = [] - i1 = temp("addi",1,2,3) - i2 = temp("slti",2,3,1) ## war(1), raw(1) - i3 = temp("andi",1,2,3) ## waw (1)-consume, raw(2), war(2) - i4 = temp("sub",7,8,9) ## nothing - i5 = temp("addi",10,11,13) - i6 = temp("andi",11,13,10) ## war(1), raw(1) - - lst = [i1,i2,i3,i4,i5,i6] - - for instrObj_temp in lst: - cross_cover_queue.append(instrObj_temp) - if(len(cross_cover_queue)>=window_size): - cross_coverage(obj_dict, window_size,0) - ## end pts - cross_coverage(obj_dict, window_size,1) - - for label,coverpt in obj_dict.keys(): - metric = obj_dict[(label,coverpt)].get_metric() - if(metric!=0): - cgf[label]['cross_comb'][coverpt] = metric - -cgf = { - "slti": { - "config": [ - "check ISA:=regex(.*E.*) ;def RVTEST_E = True" - ], - "opcode": { - "slti": 0 - }, - "cross_comb": { - '[(addi, andi, sub, add, slti):(addi, andi, sub, add, slti)]::[a=rd:?]::[?:rs1==a or rs2==a]':0, - '[(addi, andi, sub, add, slti):(addi, andi, sub, add, slti)]::[a=rs1 ; b=rs2:?]::[?:rd==a or rd==b]':0 - } - }, - "add": { - "config": [ - "check ISA:=regex(.*E.*) ;def RVTEST_E = True" - ], - "opcode": { - "add": 0 - }, - "cross_comb": { - '[(addi, andi, sub, add, slti):(addi, andi, sub, add, slti)]::[a=rs1 ; b=rs2:?]::[?:rd==a or rd==b]':0 - } - }, - "andi": { - "config": [ - "check ISA:=regex(.*E.*) ;def RVTEST_E = True" - ], - "opcode": { - "andi": 0 - }, - "cross_comb": { - '[(addi, andi, sub, add, slti):(addi, andi, sub, add, slti)]::[a=rs1 ; b=rs2:?]::[?:rd==a or rd==b]':0 - } - }, - "sub": { - "config": [ - "check ISA:=regex(.*E.*) ;def RVTEST_E = True" - ], - "opcode": { - "sub": 0 - }, - "cross_comb": { - '[(addi, andi, sub, add, slti):(addi, andi, sub, add, slti)]::[a=rs1 ; b=rs2:?]::[?:rd==a or rd==b]':0 - } - }, - "addi": { - "config": [ - "check ISA:=regex(.*E.*) ;def RVTEST_E = True" - ], - "opcode": { - "addi": 0 - }, - "cross_comb": { - '[(addi, andi, sub, add, slti):?:(addi, andi, sub, add, slti)]::[a=rs1 ; b=rs2:?:?]::[?:?:rd==a or rd==b]':0, - '[(addi, andi, sub, add, slti):(addi, andi, sub, add, slti)]::[a=rs1 ; b=rs2:?]::[?:rd==a or rd==b]':0, - '[(addi, andi, sub, add, slti):(addi, andi, sub, add, slti)]::[a=rd:?]::[?:rs1==a or rs2==a]':0, - '[(addi, andi, sub, add, slti):?:(addi, andi, sub, add, slti)]::[a=rd:?:?]::[?:rs1==a or rs2==a:rd==a]':0 - - } - } -} -compute(cgf,3) -print(cgf)