add mem.h and memset32()

This commit is contained in:
Josh Holtrop 2020-10-20 15:08:12 -04:00
parent 79951bd0f1
commit b4b77dd52c
2 changed files with 17 additions and 5 deletions

View File

@ -1,5 +1,6 @@
#include "fb.h" #include "fb.h"
#include <stddef.h> #include <stddef.h>
#include "mem.h"
static uint32_t * fb; static uint32_t * fb;
static uint32_t fb_width; 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 * target = &fb[fb_pitch * y / 4u + x];
uint32_t pixel = build_pixel(r, g, b); uint32_t pixel = build_pixel(r, g, b);
/* TODO: use memset32() */
for (int row = 0; row < height; row++) for (int row = 0; row < height; row++)
{ {
for (int col = 0; col < width; col++) memset32(target, pixel, width);
{
target[col] = pixel;
}
target += fb_pitch / 4u; target += fb_pitch / 4u;
} }
} }

15
src/mem.h Normal file
View File

@ -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