~mcf/cproc

fb00ba697821de4fb3d8d0dd44edfa5f4727d067 — Michael Forney 6 months ago 70fe9ef
expr: Use integer type for member access intermediate address calculation
M expr.c => expr.c +1 -2
@@ 907,12 907,11 @@ postfixexpr(struct scope *s, struct expr *r)
			if (tok.kind != TIDENT)
				error(&tok.loc, "expected identifier after '%s' operator", tokstr[op]);
			lvalue = op == TARROW || r->base->lvalue;
			r = exprconvert(r, mkpointertype(&typechar, QUALNONE));
			offset = 0;
			m = typemember(t, tok.lit, &offset);
			if (!m)
				error(&tok.loc, "struct/union has no member named '%s'", tok.lit);
			r = mkbinaryexpr(&tok.loc, TADD, r, mkconstexpr(&typeulong, offset));
			r = mkbinaryexpr(&tok.loc, TADD, exprconvert(r, &typeulong), mkconstexpr(&typeulong, offset));
			r = exprconvert(r, mkpointertype(m->type, tq | m->qual));
			r = mkunaryexpr(TMUL, r);
			r->lvalue = lvalue;

M test/bitfield-assignment-sign-extend.qbe => test/bitfield-assignment-sign-extend.qbe +12 -13
@@ 2,18 2,17 @@ export
function w $main() {
@start.1
@body.2
	%.1 =l mul 0, 1
	%.2 =l add $s, %.1
	%.3 =w shl 15, 0
	%.4 =w shl %.3, 28
	%.5 =w sar %.4, 28
	%.6 =w and %.3, 15
	%.7 =w loadw %.2
	%.8 =w and %.7, 18446744073709551600
	%.9 =w or %.6, %.8
	storew %.9, %.2
	%.10 =w neg 1
	%.11 =w cnew %.5, %.10
	ret %.11
	%.1 =l add $s, 0
	%.2 =w shl 15, 0
	%.3 =w shl %.2, 28
	%.4 =w sar %.3, 28
	%.5 =w and %.2, 15
	%.6 =w loadw %.1
	%.7 =w and %.6, 18446744073709551600
	%.8 =w or %.5, %.7
	storew %.8, %.1
	%.9 =w neg 1
	%.10 =w cnew %.4, %.9
	ret %.10
}
export data $s = align 4 { z 4 }

M test/bitfield-compound-assign.qbe => test/bitfield-compound-assign.qbe +13 -14
@@ 2,20 2,19 @@ export
function $f() {
@start.1
@body.2
	%.1 =l mul 0, 1
	%.2 =l add $s, %.1
	%.3 =w loadw %.2
	%.4 =w shl %.3, 19
	%.5 =w sar %.4, 23
	%.6 =w add %.5, 3
	%.7 =w shl %.6, 4
	%.8 =w shl %.7, 19
	%.9 =w sar %.8, 23
	%.10 =w and %.7, 8176
	%.11 =w loadw %.2
	%.12 =w and %.11, 18446744073709543439
	%.13 =w or %.10, %.12
	storew %.13, %.2
	%.1 =l add $s, 0
	%.2 =w loadw %.1
	%.3 =w shl %.2, 19
	%.4 =w sar %.3, 23
	%.5 =w add %.4, 3
	%.6 =w shl %.5, 4
	%.7 =w shl %.6, 19
	%.8 =w sar %.7, 23
	%.9 =w and %.6, 8176
	%.10 =w loadw %.1
	%.11 =w and %.10, 18446744073709543439
	%.12 =w or %.9, %.11
	storew %.12, %.1
	ret
}
export data $s = align 4 { z 4 }

M test/bitfield-integer-promotion.qbe => test/bitfield-integer-promotion.qbe +6 -7
@@ 3,12 3,11 @@ function w $main() {
@start.1
@body.2
	%.1 =w neg 1
	%.2 =l mul 0, 1
	%.3 =l add $s, %.2
	%.4 =w loadw %.3
	%.5 =w shl %.4, 30
	%.6 =w shr %.5, 30
	%.7 =w csgtw %.1, %.6
	ret %.7
	%.2 =l add $s, 0
	%.3 =w loadw %.2
	%.4 =w shl %.3, 30
	%.5 =w shr %.4, 30
	%.6 =w csgtw %.1, %.5
	ret %.6
}
export data $s = align 4 { z 4 }

M test/bitfield-load-signed.qbe => test/bitfield-load-signed.qbe +4 -5
@@ 2,11 2,10 @@ export
function $f() {
@start.1
@body.2
	%.1 =l mul 0, 1
	%.2 =l add $s, %.1
	%.3 =w loadw %.2
	%.4 =w shl %.3, 13
	%.5 =w sar %.4, 17
	%.1 =l add $s, 0
	%.2 =w loadw %.1
	%.3 =w shl %.2, 13
	%.4 =w sar %.3, 17
	ret
}
export data $s = align 4 { z 4 }

M test/bitfield-load-unsigned.qbe => test/bitfield-load-unsigned.qbe +4 -5
@@ 2,11 2,10 @@ export
function $f() {
@start.1
@body.2
	%.1 =l mul 0, 1
	%.2 =l add $s, %.1
	%.3 =w loadw %.2
	%.4 =w shl %.3, 13
	%.5 =w shr %.4, 17
	%.1 =l add $s, 0
	%.2 =w loadw %.1
	%.3 =w shl %.2, 13
	%.4 =w shr %.3, 17
	ret
}
export data $s = align 4 { z 4 }

M test/bitfield-short.qbe => test/bitfield-short.qbe +7 -8
@@ 3,12 3,11 @@ export
function w $main() {
@start.1
@body.2
	%.1 =l mul 0, 1
	%.2 =l add $s, %.1
	%.3 =w loadsh %.2
	%.4 =w shl %.3, 25
	%.5 =w sar %.4, 25
	%.6 =w extsh %.5
	%.7 =w csgtw %.6, 0
	ret %.7
	%.1 =l add $s, 0
	%.2 =w loadsh %.1
	%.3 =w shl %.2, 25
	%.4 =w sar %.3, 25
	%.5 =w extsh %.4
	%.6 =w csgtw %.5, 0
	ret %.6
}

M test/struct-flexible-array.qbe => test/struct-flexible-array.qbe +7 -8
@@ 6,12 6,11 @@ function w $f(l %.1) {
	storel %.1, %.2
@body.2
	%.3 =l loadl %.2
	%.4 =l mul 4, 1
	%.5 =l add %.3, %.4
	%.6 =l extsw 2
	%.7 =l mul %.6, 2
	%.8 =l add %.5, %.7
	%.9 =w loadsh %.8
	%.10 =w extsh %.9
	ret %.10
	%.4 =l add %.3, 4
	%.5 =l extsw 2
	%.6 =l mul %.5, 2
	%.7 =l add %.4, %.6
	%.8 =w loadsh %.7
	%.9 =w extsh %.8
	ret %.9
}

M test/struct-return-2.qbe => test/struct-return-2.qbe +3 -4
@@ 4,8 4,7 @@ function w $f() {
@start.1
@body.2
	%.1 =:.1 call $g()
	%.2 =l mul 4, 1
	%.3 =l add %.1, %.2
	%.4 =w loadw %.3
	ret %.4
	%.2 =l add %.1, 4
	%.3 =w loadw %.2
	ret %.3
}