From 83587d56e645f23c25b597c856b99578f642009f Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 23 Jun 2021 21:46:24 +0800 Subject: [PATCH] Update _sched_event to use signal ids --- src/cgen.c | 8 ++++++-- src/lower.c | 2 +- src/rt/rtkern.c | 36 ++++++++++++++++++++++-------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/cgen.c b/src/cgen.c index 763e6578..abbe2555 100644 --- a/src/cgen.c +++ b/src/cgen.c @@ -2207,8 +2207,11 @@ static void cgen_op_record_ref(int op, cgen_ctx_t *ctx) static void cgen_op_sched_event(int op, cgen_ctx_t *ctx) { + LLVMValueRef sigptr = cgen_get_arg(op, 0, ctx); + LLVMValueRef args[] = { - llvm_void_cast(cgen_get_arg(op, 0, ctx)), + LLVMBuildExtractValue(builder, sigptr, 0, "sid"), + LLVMBuildExtractValue(builder, sigptr, 0, "offset"), cgen_get_arg(op, 1, ctx), llvm_int32(vcode_get_subkind(op)), }; @@ -3852,7 +3855,8 @@ static LLVMValueRef cgen_support_fn(const char *name) } else if (strcmp(name, "_sched_event") == 0) { LLVMTypeRef args[] = { - llvm_void_ptr(), + LLVMInt32Type(), + LLVMInt32Type(), LLVMInt32Type(), LLVMInt32Type() }; diff --git a/src/lower.c b/src/lower.c index 05c40b62..a01c4a4a 100644 --- a/src/lower.c +++ b/src/lower.c @@ -2106,7 +2106,7 @@ static vcode_reg_t lower_param_ref(tree_t decl, expr_ctx_t ctx) } vcode_signal_t sig = obj & 0x7fffffff; - return emit_nets(sig); + return ctx == EXPR_LVALUE ? emit_nets(sig) : emit_resolved(sig); } else { vcode_reg_t reg = obj; diff --git a/src/rt/rtkern.c b/src/rt/rtkern.c index c3265cc8..6119a505 100644 --- a/src/rt/rtkern.c +++ b/src/rt/rtkern.c @@ -582,7 +582,7 @@ void _sched_waveform_s(uint32_t sid, uint32_t offset, uint64_t scalar, if (!rt_sched_driver(n, after, reject, values_copy)) deltaq_insert_driver(after, n, active_proc); - + #if 0 const netid_t nid = nids[0]; if (likely(nid != NETID_INVALID)) { @@ -601,7 +601,7 @@ DLLEXPORT void _sched_waveform(uint32_t sid, uint32_t offset, void *values, int32_t len, int64_t after, int64_t reject) { - RT_ASSERT(sid < n_nexus); + RT_ASSERT(sid < n_signals); rt_signal_t *s = &(signals[sid]); TRACE("_sched_waveform_s %s+%d value=%s len=%d after=%s reject=%s", @@ -645,8 +645,13 @@ void _sched_waveform(uint32_t sid, uint32_t offset, void *values, int32_t len, } DLLEXPORT -void _sched_event(void *_nids, int32_t n, int32_t flags) +void _sched_event(uint32_t sid, uint32_t offset, int32_t n, int32_t flags) { + RT_ASSERT(sid < n_signals); + rt_signal_t *s = &(signals[sid]); + + TRACE("_sched_event %s+d n=%d flags=%d proc %s", istr(e_path(s->enode)), + offset, n, flags, istr(e_path(active_proc->source))); #if 0 const int32_t *nids = _nids; @@ -803,7 +808,7 @@ void _init_nexus(uint32_t nid, const uint8_t *values) dummy->next = NULL; dummy->values = rt_alloc_value(n); memcpy(dummy->values->data, values, n->size * n->width); - + n->drivers[i].waveforms = dummy; } } @@ -1866,11 +1871,13 @@ static void rt_setup_scopes_recur(e_node_t e, unsigned *next_scope, r->usage = 0; r->context = context; - assert(e_nexuses(p) == 1); - assert(e_procs(e_nexus(p, 0)) == 1); - rt_nexus_t *n = &(nexus[e_pos(e_nexus(p, 0))]); - assert(n->n_drivers == 1); - n->drivers[0].proc = r; + const int nnexus = e_nexuses(p); + for (int j = 0; j < nnexus; j++) { + assert(e_procs(e_nexus(p, j)) == 1); + rt_nexus_t *n = &(nexus[e_pos(e_nexus(p, j))]); + assert(n->n_drivers == 1); + n->drivers[0].proc = r; + } } for (int i = 0; i < nsignals; i++) { @@ -1884,12 +1891,13 @@ static void rt_setup_scopes_recur(e_node_t e, unsigned *next_scope, r->n_nexus = e_nexuses(s); r->nexus = xmalloc_array(r->n_nexus, sizeof(rt_nexus_t*)); - assert(r->n_nexus == 1); - rt_nexus_t *n = &(nexus[e_pos(e_nexus(s, 0))]); - r->nexus[0] = n; + *total_mem += r->n_nexus * sizeof(rt_nexus_t*); + + for (int j = 0; j < r->n_nexus; j++) + r->nexus[j] = &(nexus[e_pos(e_nexus(s, j))]); context->signals[i].sig_id = sig_id; - context->signals[i].displaced = n->resolved; + context->signals[i].displaced = r->nexus[0]->resolved; } } @@ -2735,7 +2743,7 @@ static void rt_cleanup(e_node_t top) for (unsigned i = 0; i < n_nexus; i++) rt_cleanup_nexus(&(nexus[i])); - + free(nexus); nexus = NULL; -- 2.39.2