commit e2c2b7c

Devine Lu Linvega  ·  2025-12-31 00:24:19 +0000 UTC
parent 4ed3567
Removed multiplication from tight loop
1 files changed,  +18, -17
+18, -17
 1@@ -571,19 +571,18 @@ screen_draw_pixel(void)
 2 
 3 /* clang-format off */
 4 
 5-#define GET_SHIFT(n) const int qx = qfx - n * fx;
 6-#define PUT_PIXEL(n, op) { if(op | color) dst[n] = (dst[n] & layer_mask) | table[color]; }
 7-#define GET_COLOR(depth,ch1,ch2) const int color = depth ? (((ch1 >> qx) & 1) | ((ch2 >> qx) & 2)) : (ch1 >> qx) & 1;
 8-
 9-#define PUT_PIXELS(n,op,depth,ch1,ch2) {\
10-	{GET_SHIFT(0) GET_COLOR(depth,ch1,ch2) PUT_PIXEL(0,op)}\
11-	{GET_SHIFT(1) GET_COLOR(depth,ch1,ch2) PUT_PIXEL(1,op)}\
12-	{GET_SHIFT(2) GET_COLOR(depth,ch1,ch2) PUT_PIXEL(2,op)}\
13-	{GET_SHIFT(3) GET_COLOR(depth,ch1,ch2) PUT_PIXEL(3,op)}\
14-	{GET_SHIFT(4) GET_COLOR(depth,ch1,ch2) PUT_PIXEL(4,op)}\
15-	{GET_SHIFT(5) GET_COLOR(depth,ch1,ch2) PUT_PIXEL(5,op)}\
16-	{GET_SHIFT(6) GET_COLOR(depth,ch1,ch2) PUT_PIXEL(6,op)}\
17-	{GET_SHIFT(7) GET_COLOR(depth,ch1,ch2) PUT_PIXEL(7,op)}\
18+#define PUT_PIXEL(n, op) if(op | color) dst[n] = (dst[n] & layer_mask) | table[color]; 
19+#define GET_COLOR(depth, ch1, ch2, qx)  const int color = depth ? (((ch1 >> qx) & 1) | ((ch2 >> qx) & 2)) : (ch1 >> qx) & 1; 
20+
21+#define PUT_PIXELS(n,op,depth,ch1,ch2, qx) {\
22+	{GET_COLOR(depth, ch1, ch2, qx) PUT_PIXEL(0, op); qx -= fx; }\
23+	{GET_COLOR(depth, ch1, ch2, qx) PUT_PIXEL(1, op); qx -= fx; }\
24+	{GET_COLOR(depth, ch1, ch2, qx) PUT_PIXEL(2, op); qx -= fx; }\
25+	{GET_COLOR(depth, ch1, ch2, qx) PUT_PIXEL(3, op); qx -= fx; }\
26+	{GET_COLOR(depth, ch1, ch2, qx) PUT_PIXEL(4, op); qx -= fx; }\
27+	{GET_COLOR(depth, ch1, ch2, qx) PUT_PIXEL(5, op); qx -= fx; }\
28+	{GET_COLOR(depth, ch1, ch2, qx) PUT_PIXEL(6, op); qx -= fx; }\
29+	{GET_COLOR(depth, ch1, ch2, qx) PUT_PIXEL(7, op); qx -= fx; }\
30 }
31 
32 /* clang-format on */
33@@ -620,10 +619,11 @@ screen_draw_sprite(void)
34 				Uint8 *dst = &screen_layers[xmar + ymar * screen_wmar2];
35 				for(row = 0, qy = qfy; row < height; row++, dst += screen_wmar2, qy += fy) {
36 					const int ch1 = sprite[qy], ch2 = sprite[qy + 8] << 1;
37+					int qx = qfx;
38 					if(opaque)
39-						PUT_PIXELS(n, 1, 1, ch1, ch2)
40+						PUT_PIXELS(n, 1, 1, ch1, ch2, qx)
41 					else
42-						PUT_PIXELS(n, 0, 1, ch1, ch2)
43+						PUT_PIXELS(n, 0, 1, ch1, ch2, qx)
44 				}
45 			}
46 		}
47@@ -638,10 +638,11 @@ screen_draw_sprite(void)
48 				Uint8 *dst = &screen_layers[xmar + ymar * screen_wmar2];
49 				for(row = 0, qy = qfy; row < height; row++, dst += screen_wmar2, qy += fy) {
50 					const int ch1 = sprite[qy];
51+					int qx = qfx;
52 					if(opaque)
53-						PUT_PIXELS(n, 1, 0, ch1, 0)
54+						PUT_PIXELS(n, 1, 0, ch1, 0, qx)
55 					else
56-						PUT_PIXELS(n, 0, 0, ch1, 0)
57+						PUT_PIXELS(n, 0, 0, ch1, 0, qx)
58 				}
59 			}
60 		}