~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH harec] gen_const_array_at: avoid recomputation of the last offset

Details
Message ID
<20230923015033.28507-1-bgs@turminal.net>
DKIM signature
pass
Download raw message
Patch: +3 -7
In case of expandable arrays the offset of the last explicitly specified member
is used as a parameter to memcpy. Because the address was computed
earlier anyway, we can just reuse it.

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
---
 src/gen.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/gen.c b/src/gen.c
index daca666..8b3612f 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -1758,9 +1758,10 @@ gen_const_array_at(struct gen_context *ctx,
	const struct type *atype = type_dealias(NULL, expr->result);
	size_t msize = atype->array.members->size;
	struct gen_value item = mkgtemp(ctx, atype->array.members, "item.%d");
	struct qbe_value ptr;
	for (const struct array_constant *ac = aexpr; ac; ac = ac->next) {
		struct qbe_value offs = constl(n * msize);
		struct qbe_value ptr = mklval(ctx, &item);
		ptr = mklval(ctx, &item);
		pushi(ctx->current, &ptr, Q_ADD, &base, &offs, NULL);
		gen_expr_at(ctx, ac->value, item);
		++n;
@@ -1775,17 +1776,12 @@ gen_const_array_at(struct gen_context *ctx,
		return;
	}

	// last copied element
	struct qbe_value lsize = constl((n - 1) * msize);
	struct qbe_value last = mkqtmp(ctx, ctx->arch.ptr, ".%d");
	pushi(ctx->current, &last, Q_ADD, &base, &lsize, NULL);
	// start from the elements already copied
	struct qbe_value nsize = constl(n * msize);
	struct qbe_value next = mkqtmp(ctx, ctx->arch.ptr, ".%d");
	pushi(ctx->current, &next, Q_ADD, &base, &nsize, NULL);

	struct qbe_value qlen = constl((arr.length - n) * msize);
	pushi(ctx->current, NULL, Q_CALL, &ctx->rt.memcpy, &next, &last, &qlen, NULL);
	pushi(ctx->current, NULL, Q_CALL, &ctx->rt.memcpy, &next, &ptr, &qlen, NULL);
}

static struct qbe_data_item *gen_data_item(struct gen_context *,
-- 
2.38.4

[harec/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CVPWXGRTI3JX.8G1N9O0SEZXM@cirno2>
In-Reply-To
<20230923015033.28507-1-bgs@turminal.net> (view parent)
DKIM signature
missing
Download raw message
harec/patches: SUCCESS in 1m6s

[gen_const_array_at: avoid recomputation of the last offset][0] from [Bor Grošelj Simić][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/44959
[1]: bgs@turminal.net

✓ #1061652 SUCCESS harec/patches/netbsd.yml  https://builds.sr.ht/~sircmpwn/job/1061652
✓ #1061651 SUCCESS harec/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/1061651
✓ #1061650 SUCCESS harec/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/1061650
Details
Message ID
<CVRMDTKHYQF0.1EK503XZJ3KP7@monch>
In-Reply-To
<20230923015033.28507-1-bgs@turminal.net> (view parent)
DKIM signature
pass
Download raw message
thanks!

to git@git.sr.ht:~sircmpwn/harec
  6151bd6..a3687cb  master -> master
Reply to thread Export thread (mbox)