From 88a70c60e2422c2bce9246271dc083a9d02d2cdc Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Thu, 11 Apr 2024 23:59:19 -0500 Subject: how the fuck am i gonna finish this --- booth_multiplier.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'booth_multiplier.py') diff --git a/booth_multiplier.py b/booth_multiplier.py index dc32263..c17c2f8 100755 --- a/booth_multiplier.py +++ b/booth_multiplier.py @@ -1,7 +1,16 @@ #!/usr/bin/env python3 from tabulate import tabulate +import matplotlib import matplotlib.pyplot as plt +matplotlib.use("pgf") +matplotlib.rcParams.update({ + "pgf.texsystem": "pdflatex", + 'font.family': 'serif', + 'text.usetex': True, + 'pgf.rcfonts': False, +}) + with open('input.txt') as f: input_string = f.read().split('\n') @@ -60,6 +69,7 @@ def booth(multiplier, multiplicand, length): result = result >> 1 return (result, operations) +# TODO clean up def booth_mod(multiplier, multiplicand, length): operations = 0 multiplicand |= ((1 << length - 1) & multiplicand) << 1 # extend multiplicand sign to prevent overflow when mult/sub by 2 @@ -129,16 +139,24 @@ if __name__ == "__main__": opcount_table.append([bin(multiplicand), bin(multiplier), length, result_booth[1], result_mod_booth[1]]) debug(debug_results) - print(tabulate(result_table, result_headers)) + print(tabulate(result_table, result_headers, tablefmt="latex")) print(tabulate(opcount_table, opcount_headers)) + # output + with open("report/result_table.tex", 'w') as f: + f.write(tabulate(result_table, result_headers, tablefmt="latex_booktabs")) + + with open("report/speed_table.tex", "w") as f: + f.write(tabulate(opcount_table, opcount_headers, tablefmt="latex_booktabs")) + - # generate graph + + plt.title("Operations vs Operand Length") plt.plot(lengths, ops_booth, '^--m', label='booths algorithim') plt.plot(lengths, ops_mod_booth, 'v--c', label='modified booths algorithim') plt.gca().set_xlabel("Length of Operands") plt.gca().set_ylabel("Number of Additions and Subtractions") plt.legend(loc='upper left') - plt.show() + plt.savefig('report/performance.pgf') -- cgit v1.2.3