~mcf/cproc

9cae1b50f1805393f00803b426a99a7bb448c84a — Michael Forney a month ago 0fb19da
qbe: Fix temporary type for < 8 byte aligned struct copies
2 files changed, 7 insertions(+), 5 deletions(-)

M qbe.c
M test/struct-copy.qbe
M qbe.c => qbe.c +4 -2
@@ 299,21 299,23 @@ static void
funccopy(struct func *f, struct value *dst, struct value *src, uint64_t size, int align)
{
	enum instkind load, store;
	int class;
	struct value *tmp, *inc;
	uint64_t off;

	class = 'w';
	switch (align) {
	case 1: load = ILOADUB, store = ISTOREB; break;
	case 2: load = ILOADUH, store = ISTOREH; break;
	case 4: load = ILOADW, store = ISTOREW; break;
	case 8: load = ILOADL, store = ISTOREL; break;
	case 8: load = ILOADL, store = ISTOREL, class = 'l'; break;
	default:
		fatal("internal error; invalid alignment %d", align);
	}
	inc = mkintconst(align);
	off = 0;
	for (;;) {
		tmp = funcinst(f, load, ptrclass, src, NULL);
		tmp = funcinst(f, load, class, src, NULL);
		funcinst(f, store, 0, tmp, dst);
		off += align;
		if (off >= size)

M test/struct-copy.qbe => test/struct-copy.qbe +3 -3
@@ 3,15 3,15 @@ function $f() {
@start.1
	%.1 =l alloc4 12
@body.2
	%.2 =l loadw $x
	%.2 =w loadw $x
	storew %.2, %.1
	%.3 =l add $x, 4
	%.4 =l add %.1, 4
	%.5 =l loadw %.3
	%.5 =w loadw %.3
	storew %.5, %.4
	%.6 =l add %.3, 4
	%.7 =l add %.4, 4
	%.8 =l loadw %.6
	%.8 =w loadw %.6
	storew %.8, %.7
	ret
}