From fc65cd262266077dacb1d828fe375701181a5cfa Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 21 Oct 2022 19:32:25 +0100 Subject: [PATCH] Use static_alloc to allocate signals --- src/rt/model.c | 15 +++++---------- src/rt/structs.h | 9 ++++++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/rt/model.c b/src/rt/model.c index e21d26d5..5c608368 100644 --- a/src/rt/model.c +++ b/src/rt/model.c @@ -497,13 +497,6 @@ static void cleanup_signal(rt_model_t *m, rt_signal_t *s) } free(s->index); - - if (s->flags & NET_F_IMPLICIT) { - rt_implicit_t *imp = container_of(s, rt_implicit_t, signal); - free(imp); - } - else - free(s); } static void cleanup_scope(rt_model_t *m, rt_scope_t *scope) @@ -2669,9 +2662,11 @@ sig_shared_t *x_init_signal(int count, int size, const uint8_t *values, istr(tree_ident(where)), count, size, fmt_values(values, size * count), flags, offset); + rt_model_t *m = get_model(); + const size_t datasz = MAX(3 * count * size, 8); - rt_signal_t *s = xcalloc_flex(sizeof(rt_signal_t), 1, datasz); - setup_signal(get_model(), s, where, count, size, flags, offset); + rt_signal_t *s = static_alloc(m, sizeof(rt_signal_t) + datasz); + setup_signal(m, s, where, count, size, flags, offset); memcpy(s->shared.data, values, s->shared.size); @@ -3142,7 +3137,7 @@ sig_shared_t *x_implicit_signal(uint32_t count, uint32_t size, tree_t where, m->implicitq = workq_new(m); const size_t datasz = MAX(2 * count * size, 8); - rt_implicit_t *imp = xcalloc_flex(sizeof(rt_implicit_t), 1, datasz); + rt_implicit_t *imp = static_alloc(m, sizeof(rt_implicit_t) + datasz); setup_signal(m, &(imp->signal), where, count, size, NET_F_IMPLICIT, 0); imp->closure = *closure; diff --git a/src/rt/structs.h b/src/rt/structs.h index ee9d6cf3..8e9d4e8b 100644 --- a/src/rt/structs.h +++ b/src/rt/structs.h @@ -177,15 +177,16 @@ typedef struct _rt_nexus { rt_value_t forcing; uint32_t width; net_flags_t flags : 8; - uint8_t size; - uint8_t n_sources; - uint8_t __pad; + unsigned size : 8; + unsigned n_sources : 8; rt_source_t sources; rt_signal_t *signal; rt_source_t *outputs; void *resolved; } rt_nexus_t; +STATIC_ASSERT(sizeof(rt_nexus_t) <= 128); + // The code generator knows the layout of this struct typedef struct _sig_shared { uint32_t size; @@ -210,6 +211,8 @@ typedef struct _rt_signal { sig_shared_t shared; } rt_signal_t; +STATIC_ASSERT(sizeof(rt_signal_t) + 8 <= 192); + typedef enum { SCOPE_ROOT, SCOPE_INSTANCE, -- 2.39.2