// Not clipped
void draw_hline(unsigned x0, unsigned x1, unsigned y, u32 color_x4) {
if (x0 > x1) {
unsigned tmp = x0;
x0 = x1;
x1 = tmp;
}
u32 *dest = (u32*) get_framebuffer() + (y << 6) - (y << 2) + (x0 >> 2);
unsigned shift = (x0 & 3) << 3, mask, value;
// Small line
if ((x1 >> 2) == (x0 >> 2)) {
mask = 0xffffffffU << shift;
shift = 32 - ((x1 & 3) << 3);
mask &= 0xffffffffU >> shift;
*dest = (*dest & ~mask) | (color_x4 & mask);
return;
}
// First block of 4 pixels
if (x0 & 3) {
mask = ~(0xffffffffU << shift);
value = color_x4 << shift;
*dest = (*dest & mask) | value;
dest++;
x0 += 4 - (x0 & 3);
}
// Loop (could be unrolled)
unsigned count = (x1 - x0) >> 2;
while (count-- > 0)
*dest++ = color_x4;
// Last block
if (x1 & 3) {
shift = 32 - ((x1 & 3) << 3);
mask = ~(0xffffffffU >> shift);
value = color_x4 >> shift;
*dest = (*dest & mask) | value;
}
}