summaryrefslogtreecommitdiff
path: root/booth_multiplier.py
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@gmail.com>2024-04-11 23:59:19 -0500
committerBrett Weiland <brett_weiland@gmail.com>2024-04-11 23:59:19 -0500
commit88a70c60e2422c2bce9246271dc083a9d02d2cdc (patch)
tree8662035eda8df000aab330ece228638515befd46 /booth_multiplier.py
parent3f1369e4f9e48ff0dd19fe6f500364845d437b0c (diff)
how the fuck am i gonna finish this
Diffstat (limited to 'booth_multiplier.py')
-rwxr-xr-xbooth_multiplier.py24
1 files changed, 21 insertions, 3 deletions
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')