From 5eeaec9f267e0f5e0f44dec877e2ef2bc22f0007 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 23 Feb 2024 15:48:00 +0000 Subject: [PATCH] Avoid calling memcpy when updating single-element signals --- src/rt/model.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/rt/model.c b/src/rt/model.c index 4f585f35..828876a7 100644 --- a/src/rt/model.c +++ b/src/rt/model.c @@ -2079,14 +2079,21 @@ static void propagate_nexus(rt_model_t *m, rt_nexus_t *n, const void *resolved) // Must only be called once per cycle assert(n->last_event != m->now || n->event_delta != m->iteration); - const size_t valuesz = n->size * n->width; + unsigned char *eff = nexus_effective(n); + unsigned char *last = nexus_last_value(n); // LAST_VALUE is the same as the initial value when there have // been no events on the signal otherwise only update it when // there is an event - void *eff = nexus_effective(n); - memcpy(nexus_last_value(n), eff, valuesz); - memcpy(eff, resolved, valuesz); + if (n->size == 1 && n->width == 1) { + *last = *eff; + *eff = *(unsigned char *)resolved; + } + else { + const size_t valuesz = n->size * n->width; + memcpy(last, eff, valuesz); + memcpy(eff, resolved, valuesz); + } } static int nexus_rank(rt_nexus_t *n) -- 2.39.2