diff --git a/src/fb.c b/src/fb.c index 339336d..4618d9a 100644 --- a/src/fb.c +++ b/src/fb.c @@ -1,5 +1,6 @@ #include "fb.h" #include +#include "mem.h" static uint32_t * fb; static uint32_t fb_width; @@ -100,13 +101,9 @@ void fb_fill(int x, int y, int width, int height, uint8_t r, uint8_t g, uint8_t { uint32_t * target = &fb[fb_pitch * y / 4u + x]; uint32_t pixel = build_pixel(r, g, b); - /* TODO: use memset32() */ for (int row = 0; row < height; row++) { - for (int col = 0; col < width; col++) - { - target[col] = pixel; - } + memset32(target, pixel, width); target += fb_pitch / 4u; } } diff --git a/src/mem.h b/src/mem.h new file mode 100644 index 0000000..eaceeb2 --- /dev/null +++ b/src/mem.h @@ -0,0 +1,15 @@ +#ifndef MEM_H +#define MEM_H + +static inline void memset32(void * dest, uint32_t val, size_t count) +{ + uint32_t r0, r1; + __asm__ __volatile__ ( + "cld\n\t" + "rep stosl" + : "=&c" (r0), "=&D" (r1) + : "a" (val), "1" (dest), "0" (count) + : "memory"); +} + +#endif