From 4130a31a0070ad9703f8d146ee437313d6060d4f Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 26 Feb 2007 12:56:08 +0100 Subject: [PATCH] Stack bugfixes --- ships/Stack.ship | 26 +++++++++++++++----------- tests/stack/stack-test.fleet | 7 +++++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ships/Stack.ship b/ships/Stack.ship index 58d5e12..a3bb7ef 100644 --- a/ships/Stack.ship +++ b/ships/Stack.ship @@ -37,21 +37,25 @@ process any new {\tt pop} operations. reg [(`DATAWIDTH-1):0] mem [4:0]; reg [5:0] depth; + reg skip; + initial depth = 0; always @(posedge clk) begin - if (depth < 32) begin - `onread(push_r, push_a) - pop_d = push_d; - mem[depth] <= push_d; - depth = depth + 1; - end - end + skip = 0; if (depth > 0) begin - `onwrite(pop_r, pop_d) - depth = depth - 1; - if (depth > 0) begin - pop_d = mem[depth]; + `onwrite(pop_r, pop_a) + if (depth > 1) begin + pop_d <= mem[depth-2]; end + depth <= depth - 1; + skip = 1; + end + end + if (!skip && depth < 32) begin + `onread(push_r, push_a) + pop_d <= push_d; + mem[depth] <= push_d; + depth <= depth + 1; end end end diff --git a/tests/stack/stack-test.fleet b/tests/stack/stack-test.fleet index 835ffc0..8cd24b1 100644 --- a/tests/stack/stack-test.fleet +++ b/tests/stack/stack-test.fleet @@ -7,15 +7,18 @@ #expect 1 #expect 0 +debug.in: [*] take, deliver; stack.push: [5] take, deliver; notify stack.pop; +stack.pop: wait; [*] take, sendto debug.in; + 0: sendto stack.push; 1: sendto stack.push; 2: sendto stack.push; 3: sendto stack.push; 4: sendto stack.push; -stack.pop: wait; [*] take, sendto debug.in; -debug.in: [*] take, deliver; + + -- 1.7.10.4