From 572fade7ff3fb2b625a5479a9613c28f66c1185d Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Fri, 5 Feb 2021 23:55:42 -0800 Subject: [PATCH] [fb] Use rep stosl for screen fill This is mostly cleanup after fighting the double buffering bug - bring back rep stosl for screen fill, and move draw_pixel to be an inline function. --- src/drivers/fb/screen.cpp | 15 +++++---------- src/drivers/fb/screen.h | 6 +++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/drivers/fb/screen.cpp b/src/drivers/fb/screen.cpp index 3a95d7d..872e9ec 100644 --- a/src/drivers/fb/screen.cpp +++ b/src/drivers/fb/screen.cpp @@ -9,7 +9,8 @@ screen::screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanl m_resx(hres), m_resy(vres) { - m_back = reinterpret_cast(malloc(scanline*vres*sizeof(pixel_t))); + const size_t size = scanline * vres; + m_back = reinterpret_cast(malloc(size * sizeof(pixel_t))); } screen::pixel_t @@ -33,15 +34,9 @@ screen::color(uint8_t r, uint8_t g, uint8_t b) const void screen::fill(pixel_t color) { - const size_t len = m_resx * m_resy; - for (size_t i = 0; i < len; ++i) - m_back[i] = color; -} - -void -screen::draw_pixel(unsigned x, unsigned y, pixel_t color) -{ - m_back[x + y * m_resx] = color; + const size_t len = m_scanline * m_resy; + asm volatile ( "rep stosl" : : + "a"(color), "c"(len), "D"(m_back) ); } void diff --git a/src/drivers/fb/screen.h b/src/drivers/fb/screen.h index fbc9d82..b55903b 100644 --- a/src/drivers/fb/screen.h +++ b/src/drivers/fb/screen.h @@ -17,7 +17,11 @@ public: pixel_t color(uint8_t r, uint8_t g, uint8_t b) const; void fill(pixel_t color); - void draw_pixel(unsigned x, unsigned y, pixel_t color); + + inline void draw_pixel(unsigned x, unsigned y, pixel_t color) { + const size_t index = x + y * m_scanline; + m_back[index] = color; + } void update();