commit 35eb6c4

Devine Lu Linvega  ·  2026-01-11 19:07:06 +0000 UTC
parent fa4d32b
Tried to remove branching inside of sprite tight loop
1 files changed,  +9, -12
+9, -12
 1@@ -602,33 +602,30 @@ screen_deo_sprite(void)
 2 	const int ctrl = dev[0x2f];
 3 	const int blend = ctrl & 0xf;
 4 	const int opaque_mask = opaque_lut[blend];
 5-	const int flipx = ctrl & 0x10, dx = flipx ? -rDY : rDY;
 6-	const int flipy = ctrl & 0x20, dy = flipy ? -rDX : rDX;
 7+	const int flipx = ctrl & 0x10, flipy = ctrl & 0x20;
 8+	const int dx = flipx ? -rDY : rDY, dy = flipy ? -rDX : rDX;
 9 	const int layer_mask = (ctrl & 0x40) ? 0x3 : 0xc;
10 	const Uint8 *table = (ctrl & 0x40) ? blend_lut[blend][1] : blend_lut[blend][0];
11 	const int is_2bpp = (ctrl & 0x80) != 0;
12 	const int addr_incr = rMA << (is_2bpp ? 2 : 1);
13 	const int stride = screen_wmar2;
14-	const int qfy = flipy ? 7 : 0;
15-	const int src_stride = flipy ? -1 : 1;
16+	const int row_start = flipx ? 0 : 7;
17+	const int src_delta = flipy ? -1 : 1;
18+	const int row_delta = flipx ? 1 : -1;
19 	for(i = 0; i <= rML; i++, x += dx, y += dy, rA += addr_incr) {
20 		const Uint16 x0 = x + 8, y0 = y + 8;
21 		if(x0 + 8 >= stride || y0 + 8 >= screen_hmar2) continue;
22 		Uint8 *dst = screen_layers + y0 * stride + x0;
23-		const Uint8 *src = &ram[rA + qfy];
24-		for(j = 0; j < 8; j++, dst += stride, src += src_stride) {
25+		const Uint8 *src = &ram[rA + (flipy ? 7 : 0)];
26+		for(j = 0; j < 8; j++, dst += stride, src += src_delta) {
27 			const int ch1 = *src, ch2 = is_2bpp ? (src[8] << 1) : 0;
28-			int bit = flipx ? 0x01 : 0x80;
29 			Uint8 *d = dst;
30-			for(int px = 0; px < 8; px++, d++) {
31+			for(int px = 0, row = row_start; px < 8; px++, d++, row += row_delta) {
32+				const int bit = 1 << row;
33 				const int color = ((ch1 & bit) ? 1 : 0) | ((ch2 & (bit << 1)) ? 2 : 0);
34 				const Uint8 mask = (color | opaque_mask) ? 0xff : 0x00;
35 				const Uint8 next = (*d & layer_mask) | table[color];
36 				*d = (*d & ~mask) | (next & mask);
37-				if(flipx)
38-					bit <<= 1;
39-				else
40-					bit >>= 1;
41 			}
42 		}
43 	}