op = random.randrange(0,13) #Range excluding division for the rest of the strips opcode=opcode_dict[op] opname = opcode_names[op] var1I= random.randrange(-100,100)#var1= r var2I=random.randrange(-100,100)#var2= r+5 #Check for div by zero and re-generate a new number if such is the case while (var2I==0 and op == 13): var2I=random.randrange(-100,100) var1FP=FP.custom_floating_point_creator (var1I,gf.D_wf,gf.D_we) var2FP=FP.custom_floating_point_creator (var2I,gf.D_wf,gf.D_we) var1H =gf.bin_to_hex_l(var1FP,64) var2H= gf.bin_to_hex_l(var2FP,64) d_wordH[r] = "Address %d:" %(r) + var1H d_wordH[r+(gf.DROWS/2)] = "Address %d:" %(r+(gf.DROWS/2)) + var2H if op== 0:#ADD answer = var1I+var2I answerFP=FP.custom_floating_point_creator (answer,gf.D_wf,gf.D_we) answerH= gf.bin_to_hex_l(answerFP,64) #Writing the same answer to both operand addresses, this way reading from and writing to every address is tested a_wordH[r] = "Address %d:" %(r) + answerH a_wordH[r+(gf.DROWS/2)] = "Address %d:" %(r+(gf.DROWS/2)) + answerH elif op== 1:#SUB answer = var1I-var2I
for r in range(0, gf.IROWS): #Write a row in a strip in a tile instruction_count = instruction_count + 1 #Pick a operation --alternative between add and multiply if op == 3: op = 0 else: op = 3 opcode = opcode_dict[op] opname = opcode_names[op] #The same data address is used to provide both operands and the result is saved back into the same location var1FP = FP.custom_floating_point_creator(var1I, gf.D_wf, gf.D_we) var1H = gf.bin_to_hex_l(var1FP, 64) d_wordH[r] = "Address %d:" % (r) + var1H if op == 0: #ADD answer = var1I + var1I answerFP = FP.custom_floating_point_creator( answer, gf.D_wf, gf.D_we) answerH = gf.bin_to_hex_l(answerFP, 64) #Writing the same answer to both operand addresses, this way reading from and writing to every address is tested a_wordH[r] = "Address %d:" % (r) + answerH elif op == 3: #MUL answer = var1I * var1I answerFP = FP.custom_floating_point_creator( answer, gf.D_wf, gf.D_we) answerH = gf.bin_to_hex_l(answerFP, 64)
sys.exit() #Inter-strip comms test print "Generating inter-strip communication test" NO_inter_strip=gf.STRIPS-1 #Number of instruction rows needed to test inter-strip communication opcode=cp for t in range(0,gf.TILES): for r in range(0,NO_inter_strip): #Create operands and write them to data files operands = range(gf.STRIPS) for s in range(0,gf.STRIPS): varI= random.randrange(-100,100) varFP=fp.custom_floating_point_creator (varI,gf.D_wf,gf.D_we) varH =gf.bin_to_hex_l(varFP,64) operands[s]=varH d_wordH = "Address %d:" %(r) + operands[s] zD[t][s].write(d_wordH+"\n") #Write answers to file #Shift operands along the correct number of times to put the answers into the correct strips for i in range(r+1): operands=[operands[-1]]+operands[:-1] for s in range(0,gf.STRIPS): a_wordH = "Address %d:" %(r) + operands[s] zA[t][s].write(a_wordH+"\n")
#Initialisation a = gf.initialise_files(gf.STRIPS,gf.TILES) zI =a[0] #Array of handles on instruction files: zI[tile][strip] zD =a[1] #Array of handles on data files: zD[tile][strip] zA =a[2] #Array of handles on answer files: zA[tile][strip] ######################################-TEST GENERATION-####################################### ###########Fill up data system ############### print "Generating data words for a %dx%d with %d words per strip: total number of data words being: "%(gf.STRIPS,gf.TILES,gf.DROWS),gf.DROWS*gf.STRIPS*gf.TILES for t in range(0, gf.TILES): for s in range(0,gf.STRIPS): for r in range(0,gf.DROWS): if t==0 and s==0 and (r == 3 or r== 4): #In Tile0Strip0Row 3&4, put data to cause an overflow on addition of the 2 d_wordH = gf.bin_to_hex_l("01111111000000000000000000000000",64) #0 11111110 00000000000000000000000 d_wordH = "Address %d:" %(r) + d_wordH zD[t][s].write(d_wordH+"\n") a_wordH = "xxx" if r == 3: a_wordH = FP.fp_infinity(gf.D_wf,gf.D_we,"0") # + Infinity a_wordH = gf.bin_to_hex_l(a_wordH,64) a_wordH = "Address %d:" %(r) + a_wordH zA[t][s].write(a_wordH+"\n") else: zA[t][s].write(d_wordH+"\n") print"HHHHHHHEEEEEEEEEEEEEERRRRRRRRRRRRRREEEEEEEEEEEEEEEE:" print "Data: ",d_wordH print "Answer: ",a_wordH
#Generate random values: var1= random.randrange(-10,10)#var1= r var2=random.randrange(-10,10)#var2= r+5 answer = var1*var2 #Just put a note in the answers if it's going to be a negative zero sign="" if answer==0: if (var1 <0 and var2>=0) or (var1 >=0 and var2<0): sign = "neg" var1=FP.custom_floating_point_creator (var1,gf.D_wf,gf.D_we) var2=FP.custom_floating_point_creator (var2,gf.D_wf,gf.D_we) answer=FP.custom_floating_point_creator (answer,gf.D_wf,gf.D_we) var1H =gf.bin_to_hex_l(var1,64) var2H= gf.bin_to_hex_l(var2,64) answerH= gf.bin_to_hex_l(answer,64) d_wordH[r] = "Address %d:" %(r) + var1H d_wordH[r+(gf.DROWS/2)] = "Address %d:" %(r+(gf.DROWS/2)) + var2H a_wordH[r] = "Address %d:" %(r) + answerH+sign a_wordH[r+(gf.DROWS/2)] = "Address %d:" %(r+(gf.DROWS/2)) + answerH+sign #Writing the same answer to both operand addresses, this way reading from and writing to every address are tested #Generate instruction opcode = mul addr0 = gf.int_to_bin(r,gf.DADDR_BITS) #Operand0 addr1 = gf.int_to_bin(r+(gf.DROWS/2),gf.DADDR_BITS) #Operand1 addr2 = gf.int_to_bin(r+(gf.DROWS/2),gf.DADDR_BITS) #Secondary address sel0 = gf.int_to_bin(s,3) #set sel's to the strip currently being written sel1 = gf.int_to_bin(s,3)
#Initialisation a = gf.initialise_files(gf.STRIPS,gf.TILES) zI =a[0] #Array of handles on instruction files: zI[tile][strip] zD =a[1] #Array of handles on data files: zD[tile][strip] zA =a[2] #Array of handles on answer files: zA[tile][strip] ######################################-TEST GENERATION-####################################### ###########Fill up data system ############### print "Generating data words for a %dx%d with %d words per strip: total number of data words being: "%(gf.STRIPS,gf.TILES,gf.DROWS),gf.DROWS*gf.STRIPS*gf.TILES for t in range(0, gf.TILES): for s in range(0,gf.STRIPS): for r in range(0,gf.DROWS): varI=random.randrange(0,100000) varFP=FP.custom_floating_point_creator (varI,gf.D_wf,gf.D_we) d_wordH = gf.bin_to_hex_l(varFP,64) d_wordH = "Address %d:" %(r) + d_wordH zD[t][s].write(d_wordH+"\n") zA[t][s].write(d_wordH+"\n") print "Generating nop instruction words for a %dx%d with %d instructions per strip: total number of instructions being: "%(gf.STRIPS,gf.TILES,gf.IROWS),gf.IROWS*gf.STRIPS*gf.TILES nop = "000010" for t in range(0, gf.TILES): for s in range(0,gf.STRIPS): for r in range(0,gf.IROWS): opcode = nop addr0 = gf.int_to_bin(r,gf.DADDR_BITS) addr1 = gf.int_to_bin(r,gf.DADDR_BITS) addr2 = gf.int_to_bin(r,gf.DADDR_BITS) sel0 = gf.int_to_bin(s,3) sel1 = gf.int_to_bin(s,3)
#----Row0----------------------------------# #--Strip0-----------------# opcode = add addr0 = gf.int_to_bin(0,gf.DADDR_BITS) addr1 = gf.int_to_bin(2,gf.DADDR_BITS) addr2 = gf.int_to_bin(r,gf.DADDR_BITS) sel0 = gf.int_to_bin(s,3) sel1 = gf.int_to_bin(s,3) selq = gf.int_to_bin(t,3) i_word = addr2+selq+opcode+sel1+sel0+addr1+addr0 i_wordH = gf.bin_to_hex(i_word) i_wordH = gf.formatH_for_roach(i_wordH) varFP=FP.custom_floating_point_creator (0,gf.D_wf,gf.D_we) d_wordH = gf.bin_to_hex_l(varFP,64) ansFP=FP.custom_floating_point_creator (11,gf.D_wf,gf.D_we) a_wordH = gf.bin_to_hex_l(ansFP,64) #Format final lines to be written to files i_wordH = i_word+":"+i_wordH d_wordH = "Address %d:" %(r) + d_wordH a_wordH = "Address %d:" %(r) + a_wordH #Write instruction and data words to file zI[t][s].write(i_wordH+"\n") zD[t][s].write(d_wordH+"\n") zA[t][s].write(a_wordH+"\n") print t,":",s,":",r
#Initialisation a = gf.initialise_files(gf.STRIPS,gf.TILES) zI =a[0] #Array of handles on instruction files: zI[tile][strip] zD =a[1] #Array of handles on data files: zD[tile][strip] zA =a[2] #Array of handles on answer files: zA[tile][strip] ######################################-TEST GENERATION-####################################### ###########Fill up data system ############### print "Generating data words for a %dx%d with %d words per strip: total number of data words being: "%(gf.STRIPS,gf.TILES,gf.DROWS),gf.DROWS*gf.STRIPS*gf.TILES for t in range(0, gf.TILES): for s in range(0,gf.STRIPS): for r in range(0,gf.DROWS): varI=random.randrange(0,100) varFP=FP.custom_floating_point_creator (varI,gf.D_wf,gf.D_we) d_wordH = gf.bin_to_hex_l(varFP,64) d_wordH = "Address %d:" %(r) + d_wordH zD[t][s].write(d_wordH+"\n") zA[t][s].write(d_wordH+"\n") print "Generating nop instruction words for a %dx%d with %d instructions per strip: total number of instructions being: "%(gf.STRIPS,gf.TILES,gf.IROWS),gf.IROWS*gf.STRIPS*gf.TILES nop = "000010" for t in range(0, gf.TILES): for s in range(0,gf.STRIPS): for r in range(0,gf.IROWS): opcode = nop addr0 = gf.int_to_bin(r,gf.DADDR_BITS) addr1 = gf.int_to_bin(r,gf.DADDR_BITS) addr2 = gf.int_to_bin(r,gf.DADDR_BITS) sel0 = gf.int_to_bin(s,gf.STRIP_Ad_bits) sel1 = gf.int_to_bin(s,gf.STRIP_Ad_bits)
#----Row0----------------------------------# #--Strip0-----------------# opcode = add addr0 = gf.int_to_bin(0, gf.DADDR_BITS) addr1 = gf.int_to_bin(2, gf.DADDR_BITS) addr2 = gf.int_to_bin(r, gf.DADDR_BITS) sel0 = gf.int_to_bin(s, 3) sel1 = gf.int_to_bin(s, 3) selq = gf.int_to_bin(t, 3) i_word = addr2 + selq + opcode + sel1 + sel0 + addr1 + addr0 i_wordH = gf.bin_to_hex(i_word) i_wordH = gf.formatH_for_roach(i_wordH) varFP = FP.custom_floating_point_creator(0, gf.D_wf, gf.D_we) d_wordH = gf.bin_to_hex_l(varFP, 64) ansFP = FP.custom_floating_point_creator(11, gf.D_wf, gf.D_we) a_wordH = gf.bin_to_hex_l(ansFP, 64) #Format final lines to be written to files i_wordH = i_word + ":" + i_wordH d_wordH = "Address %d:" % (r) + d_wordH a_wordH = "Address %d:" % (r) + a_wordH #Write instruction and data words to file zI[t][s].write(i_wordH + "\n") zD[t][s].write(d_wordH + "\n") zA[t][s].write(a_wordH + "\n") print t, ":", s, ":", r