diff options
author | Wojciech Kosior <kwojtus@protonmail.com> | 2020-09-05 18:21:53 +0200 |
---|---|---|
committer | Wojciech Kosior <kwojtus@protonmail.com> | 2020-09-05 18:21:53 +0200 |
commit | 8d92524d4c46493ad83ebd493dabd3f88e11037b (patch) | |
tree | 62973748aa831b2b64241d5a8b27565abdc707c8 | |
parent | 2c528314ebe29a1c94b6c03fd1b0e2668ee25dff (diff) | |
download | AGH-engineering-thesis-8d92524d4c46493ad83ebd493dabd3f88e11037b.tar.gz AGH-engineering-thesis-8d92524d4c46493ad83ebd493dabd3f88e11037b.zip |
add mul instruction together with bench
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | design/stack_machine.v | 7 | ||||
-rw-r--r-- | tclasm.tcl | 5 | ||||
-rwxr-xr-x | tests/stack_machine_mul/instructions.s.tcl | 38 | ||||
l--------- | tests/stack_machine_mul/test.v | 1 | ||||
-rw-r--r-- | tests/stack_machine_mul/words_to_verify.mem | 13 |
6 files changed, 66 insertions, 1 deletions
@@ -40,7 +40,8 @@ STACK_MACHINE_TESTS := \ swap \ add \ sub \ - div + div \ + mul # Add other tests here if You need TESTS := \ diff --git a/design/stack_machine.v b/design/stack_machine.v index 4313713..a6b2765 100644 --- a/design/stack_machine.v +++ b/design/stack_machine.v @@ -212,6 +212,10 @@ module stack_machine_new assign instr_udiv = !set_im && !use_im && stack_shrinks_by_1 && instruction[11:0] == 12'd2; + wire instr_mul; + assign instr_mul = !set_im && !use_im && stack_shrinks_by_1 && + instruction[11:0] == 12'd3; + reg halt; /* Set once a halt instruction is encountered */ assign finished = halt; @@ -505,6 +509,9 @@ module stack_machine_new if (instr_udiv && arithmetic_uncompleted) r1 <= div_quotient; + + if (instr_mul && arithmetic_uncompleted) + r1 <= r0 * r1; end // case: STEP_EXECUTING endcase // case (step) end // else: !if(RST_I) @@ -181,3 +181,8 @@ proc sub {} { proc div {} { puts 0011000000000010 } + + +proc mul {} { + puts 0011000000000011 +} diff --git a/tests/stack_machine_mul/instructions.s.tcl b/tests/stack_machine_mul/instructions.s.tcl new file mode 100755 index 0000000..fae5ec6 --- /dev/null +++ b/tests/stack_machine_mul/instructions.s.tcl @@ -0,0 +1,38 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### store 4 values to memory; load 2 of them back, multiply them and store the +### result; load another 2, multiply them and store the result; +### this is similar to addition and substraction tests + +set_sp 0 + +## store first 2 factors +const 483091365 +store h1EEE0 +const 74683203 +store h1EEE4 + +## store other 2 factors +const 8436 +store h1EEEC +const -14020 +store h1EEF0 + +## perform the first multiplication +load h1EEE0 +load h1EEE4 +# multiplying 483091365 by 74683203 should yield 36078810479842095 +# if we take lowest 32 bits of 36078810479842095 we get 2861683503 +mul +store h1EEE8 + +## perform the second multiplication +load h1EEEC +load h1EEF0 +# multiplying 8436 by -14020 should yield -118272720 (which fits in 32 bits) +mul +store h1EEF4 + +halt diff --git a/tests/stack_machine_mul/test.v b/tests/stack_machine_mul/test.v new file mode 120000 index 0000000..f5b6a59 --- /dev/null +++ b/tests/stack_machine_mul/test.v @@ -0,0 +1 @@ +../stack_machine_store/test.v
\ No newline at end of file diff --git a/tests/stack_machine_mul/words_to_verify.mem b/tests/stack_machine_mul/words_to_verify.mem new file mode 100644 index 0000000..ae4dbbc --- /dev/null +++ b/tests/stack_machine_mul/words_to_verify.mem @@ -0,0 +1,13 @@ +// address value + 1EEE0 1CCB63A5 // 483091365 in hex is 1CCB63A5 + + 1EEE4 4739343 // 74683203 in hex is 4739343 + + 1EEE8 AA91D32F // 2861683503 in hex is AA91D32F + + + 1EEEC 20F4 // 8436 in hex is 20F4 + + 1EEF0 FFFFC93C // -14020 in hex is FFFFC93C + + 1EEF4 F8F34D30 // -118272720 in hex is F8F34D30 |