Skip to content

Commit 70c206c

Browse files
committed
2X unroll loop
From 37167 to 38621 lines per second on RP2040-GEEK.
1 parent 82ae872 commit 70c206c

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/hagl_line.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void hagl_draw_line(
5656
int16_t dy;
5757
int16_t sy;
5858
int16_t err;
59-
int16_t e2;
59+
int16_t err2;
6060

6161
dx = ABS(x1 - x0);
6262
sx = x0 < x1 ? 1 : -1;
@@ -67,18 +67,36 @@ void hagl_draw_line(
6767
while (1) {
6868
surface->put_pixel((void *)_surface, x0, y0, color);
6969

70-
if (x0 == x1 && y0 == y1) {
70+
if ((x0 == x1) && (y0 == y1)) {
7171
break;
72-
};
72+
}
73+
74+
err2 = err + err;
75+
76+
if (err2 > -dx) {
77+
err -= dy;
78+
x0 += sx;
79+
}
80+
81+
if (err2 < dy) {
82+
err += dx;
83+
y0 += sy;
84+
}
85+
86+
surface->put_pixel((void *)_surface, x0, y0, color);
87+
88+
if ((x0 == x1) && (y0 == y1)) {
89+
break;
90+
}
7391

74-
e2 = err + err;
92+
err2 = err + err;
7593

76-
if (e2 > -dx) {
94+
if (err2 > -dx) {
7795
err -= dy;
7896
x0 += sx;
7997
}
8098

81-
if (e2 < dy) {
99+
if (err2 < dy) {
82100
err += dx;
83101
y0 += sy;
84102
}

0 commit comments

Comments
 (0)