def testMakeDivide32(): numOfTests = 512 with open("input.csv",'w',newline='\n', encoding='utf-8') as csvFile,open("inputP.csv",'w',newline='\n', encoding='utf-8') as csvFileP: csvWriter = csv.writer(csvFile) csvWriterP = csv.writer(csvFileP) randomRange1 = [IEEE754.binaryToFloat32(randomNumberMaker("s")) for i in range(numOfTests)] randomRange2 = [IEEE754.binaryToFloat32(randomNumberMaker("s")) for i in range(numOfTests)] for i,j in zip(randomRange1,randomRange2): randomNumber1 = i randomNumber2 = j operation = '00' csvWriter.writerow((IEEE754.floatToBinary32(randomNumber1),IEEE754.floatToBinary32(randomNumber2),operation)) csvWriterP.writerow((randomNumber1,randomNumber2))
def testMakerSQRT64(): numOfTests = 32 with open("input.csv",'w',newline='\n', encoding='utf-8') as csvFile,open("inputP.csv",'w',newline='\n', encoding='utf-8') as csvFileP: csvWriter = csv.writer(csvFile) csvWriterP = csv.writer(csvFileP) randomRange = np.linspace(0,1.8 * 10**308,numOfTests,dtype=float) for i in randomRange: randomNumber = i operation = '11' csvWriter.writerow((IEEE754.floatToBinary32(randomNumber),operation)) csvWriterP.writerow(randomNumber)
def testVerifierSQRT64(): corrected = 0 all_tests = 0 with open("output.csv") as csvFile,open("inputP.csv") as csvFileP: csvReader = csv.reader(csvFile) csvReaderP = csv.reader(csvFileP) for row,rowP in zip(csvReader,csvReaderP): resHardWare = row[1] inp = rowP[0] resSoftWare = IEEE754.floatToBinary64(SQRT(float(inp))) if(check_answer(resHardWare,resSoftWare)): corrected += 1 else: print("err: %d"%(all_tests)) print("res hardware: %s"%resHardWare) print("res software: %s"%resSoftWare) print() all_tests += 1 print("Accuracy : %f\n%d corrects from %d tests"%(corrected / all_tests*100, corrected, all_tests))
def FPUTestVerifier(input_name): with open(input_name,mode="r") as csvFile: csvReader = csv.reader(csvFile) acc = 0 num = 0 for row in csvReader: num += 1 op = row[0] if(op=="00"): inpA,inpB,hardwareRes = row[1][32:],row[2][32:],row[3][32:] softwareRes = IEEE754.floatToBinary32(Divide(IEEE754.binaryToFloat32(inpA),IEEE754.binaryToFloat32(inpB))) if(check_answer(hardwareRes,softwareRes)): acc += 1 else: panic(num,inpA,inpB,hardwareRes,softwareRes) elif(op=="01"): inpA,hardwareRes = row[1][32:],row[2][32:] softwareRes = IEEE754.floatToBinary32(SQRT(IEEE754.binaryToFloat32(inpA))) if(check_answer(hardwareRes,softwareRes)): acc += 1 else: panic(num,inpA,None,hardwareRes,softwareRes) elif(op=="10"): inpA,inpB,hardwareRes = row[1],row[2],row[3] softwareRes = IEEE754.floatToBinary64(Divide(IEEE754.binaryToFloat64(inpA),IEEE754.binaryToFloat64(inpB))) if(check_answer(hardwareRes,softwareRes)): acc += 1 else: panic(num,inpA,inpB,hardwareRes,softwareRes) else: inpA,hardwareRes = row[1],row[2] softwareRes = IEEE754.floatToBinary64(SQRT(IEEE754.binaryToFloat64(inpA))) if(check_answer(hardwareRes,softwareRes)): acc += 1 else: panic(num,inpA,None,hardwareRes,softwareRes) print("accuracy : ", ((acc/num)*100), "%")