From 227a2d91df59aed4aa4f54a575dd480b742bfe0a Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Wed, 11 Jan 2023 12:08:28 +0100 Subject: [PATCH] Allow duplicates in the mux output channel --- src/emu/mux.c | 4 ++++ test/unit/mux.c | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/emu/mux.c b/src/emu/mux.c index 1e7d37e..43f1492 100644 --- a/src/emu/mux.c +++ b/src/emu/mux.c @@ -144,6 +144,10 @@ mux_init(struct mux *mux, * input and select channel at the same time. */ chan_prop_set(output, CHAN_DIRTY_WRITE, 1); + /* Similarly, we may switch to an input channel that has the same value + * as the last output value, so we allow duplicates too */ + chan_prop_set(output, CHAN_DUPLICATES, 1); + memset(mux, 0, sizeof(struct mux_input)); mux->select = select; mux->output = output; diff --git a/test/unit/mux.c b/test/unit/mux.c index 862b995..112fffd 100644 --- a/test/unit/mux.c +++ b/test/unit/mux.c @@ -1,7 +1,7 @@ #include "emu/mux.h" #include "common.h" -#define N 6 +#define N 10 //static int //select_active_thread(struct mux *mux, @@ -164,6 +164,44 @@ test_mid_propagate(struct mux *mux, int key) check_output(mux, value_int64(new_value)); } +static void +test_duplicate_output(struct mux *mux, int key1, int key2) +{ + int new_value = 2000 + key1; + + struct mux_input *in1 = mux_find_input(mux, value_int64(key1)); + if (in1 == NULL) + die("mux_find_input failed to locate input1 %d\n", key1); + + struct mux_input *in2 = mux_find_input(mux, value_int64(key2)); + if (in2 == NULL) + die("mux_find_input failed to locate input2 %d\n", key2); + + if (chan_set(in1->chan, value_int64(new_value)) != 0) + die("chan_set failed\n"); + + if (chan_set(in2->chan, value_int64(new_value)) != 0) + die("chan_set failed\n"); + + /* Select input 1 */ + if (chan_set(mux->select, value_int64(key1)) != 0) + die("chan_set failed\n"); + + if (bay_propagate(mux->bay) != 0) + die("bay_propagate failed\n"); + + check_output(mux, value_int64(new_value)); + + /* Now switch to input 2, which has the same value */ + if (chan_set(mux->select, value_int64(key2)) != 0) + die("chan_set failed\n"); + + if (bay_propagate(mux->bay) != 0) + die("bay_propagate failed\n"); + + check_output(mux, value_int64(new_value)); +} + int main(void) @@ -212,6 +250,7 @@ main(void) test_select_and_input(&mux, 3); test_input_and_select(&mux, 4); test_mid_propagate(&mux, 5); + test_duplicate_output(&mux, 6, 7); err("OK\n");