From 9adc0e5bad01f34f6cf6b6d53019ead30ba49945 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Mon, 14 Sep 2020 17:21:55 +0200 Subject: add ability to make non-aligned loads/stores and loads/stores of 1 or 2 bytes together with test bench --- tests/stack_machine_unaligned/Makefile | 1 + tests/stack_machine_unaligned/instructions.s.tcl | 125 ++++++++++++++++++++++ tests/stack_machine_unaligned/test.v | 1 + tests/stack_machine_unaligned/words_to_verify.mem | 19 ++++ 4 files changed, 146 insertions(+) create mode 120000 tests/stack_machine_unaligned/Makefile create mode 100644 tests/stack_machine_unaligned/instructions.s.tcl create mode 120000 tests/stack_machine_unaligned/test.v create mode 100644 tests/stack_machine_unaligned/words_to_verify.mem (limited to 'tests') diff --git a/tests/stack_machine_unaligned/Makefile b/tests/stack_machine_unaligned/Makefile new file mode 120000 index 0000000..2c3c770 --- /dev/null +++ b/tests/stack_machine_unaligned/Makefile @@ -0,0 +1 @@ +../stack_machine_store/Makefile \ No newline at end of file diff --git a/tests/stack_machine_unaligned/instructions.s.tcl b/tests/stack_machine_unaligned/instructions.s.tcl new file mode 100644 index 0000000..9f2a0a8 --- /dev/null +++ b/tests/stack_machine_unaligned/instructions.s.tcl @@ -0,0 +1,125 @@ +### make memory reads and writes of bytes, words and dwords at both +### aligned and unaligned locations + +## set up stack +set_sp 0 + +## store value h9A785634 at h100 writing 1 byte at a time + +# write first 2 bytes using storeb +const h34 +storeb h000100 + +# try putting some garbage in higher 3 bytes of our constant - it should +# not get written anyway +const h9ABA9E56 +storeb h000101 + +# write another 2 bytes using storeb+ +const 2 +const h78 +storeb+ h100 + +const 3 +const h9A +storeb+ h100 + + +## test single-byte loads + +# sign-extend read value h9A (as hFFFFFF9A) and store it at h104 +loadbsx h00103 +store h00104 + +# sign-extend read value h78 (as h00000078) and store it at h108 +const 2 +loadbsx+ h00100 +store h00108 + +# zero-extend read value h9A (as h0000009A) and store it at h10C +const 3 +loadbzx+ h00100 +store h0010C + +# zero-extend read value h78 (as h00000078) and store it at h110 +loadbzx h00102 +store h00110 + + +## store values hD4C32B1A and h8877FFEE at h200 and h204 +## writing 2 bytes at a time + +# make aligned writes at h200 and h206 +# only byte 1A matters - higher one will be overwritten later +const h481A +storew h00200 + +# only byte 88 matters - lower one will be overwritten later +const 6 +const h8805 +storew+ h00200 + +# make unaligned writes at h203, h201 and h205 +const hEED4 +storew h00203 + +const 1 +const hC32B +storew+ h00200 + +# only bytes 77FF matter - higher ones won't be written anyway +const h71F577FF +storew h00205 + + +## test 2-word loads + +# sign-extend read value h2B1A (as h00002B1A) and store it at h208 +const 0 +loadwsx+ h00200 +store h00208 + +# sign-extend read value hC32B (as hFFFFC32B) and store it at h20C +loadwsx h00201 +store h0020C + +# zero-extend read value hD4C3 (as h0000D4C3) and store it at h210 +loadwzx h00202 +store h00210 + +# zero-extend read value h77FF (as h000077FF) and store it at h214 +const 5 +loadwzx+ h00200 +store h00214 + + +## test unaligned 4-byte memory writes + +# write values h92837400, hBECD0001 and h000044AF at h300, h304 and h308 +const 0 +const 0 +const 0 +storeb h300 +storeb h305 +storew h30A + +const h01928374 +store h301 + +const 6 +const h44AFBECD +store+ h300 + + +## test unaligned 4-byte memory reads + +# read value hCD000192 and write it at h30C +load h303 +store h30C + +# read value h0044AFBE and write it at h310 +const 7 +load+ h300 +store h310 + +halt diff --git a/tests/stack_machine_unaligned/test.v b/tests/stack_machine_unaligned/test.v new file mode 120000 index 0000000..f5b6a59 --- /dev/null +++ b/tests/stack_machine_unaligned/test.v @@ -0,0 +1 @@ +../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_unaligned/words_to_verify.mem b/tests/stack_machine_unaligned/words_to_verify.mem new file mode 100644 index 0000000..a426aa7 --- /dev/null +++ b/tests/stack_machine_unaligned/words_to_verify.mem @@ -0,0 +1,19 @@ +// address value + 100 9A785634 + 104 FFFFFF9A + 108 00000078 + 10C 0000009A + 110 00000078 + + 200 D4C32B1A + 204 8877FFEE + 208 00002B1A + 20C FFFFC32B + 210 0000D4C3 + 214 000077FF + + 300 92837400 + 304 BECD0001 + 308 000044AF + 30C CD000192 + 310 0044AFBE -- cgit v1.2.3