@@ -135,6 +135,61 @@ DEFINE_SSE_FILLRECT(4, Uint32)
135135/* *INDENT-ON* */ /* clang-format on */
136136#endif /* __SSE__ */
137137
138+ #if defined(__loongarch_sx )
139+
140+ #define LSX_BEGIN __m128i c128 = __lsx_vreplgr2vr_w(color);
141+
142+ #define LSX_WORK \
143+ for (i = n / 64; i--;) { \
144+ __lsx_vst(c128, p, 0); \
145+ __lsx_vst(c128, p, 16); \
146+ __lsx_vst(c128, p, 32); \
147+ __lsx_vst(c128, p, 48); \
148+ p += 64; \
149+ }
150+
151+ #define DEFINE_LSX_FILLRECT (bpp , type ) \
152+ static void \
153+ SDL_FillRect##bpp##LSX(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
154+ { \
155+ int i, n; \
156+ Uint8 *p = NULL; \
157+ \
158+ LSX_BEGIN; \
159+ \
160+ while (h--) { \
161+ n = w * bpp; \
162+ p = pixels; \
163+ \
164+ if (n > 63) { \
165+ int adjust = 16 - ((uintptr_t)p & 15); \
166+ if (adjust < 16) { \
167+ n -= adjust; \
168+ adjust /= bpp; \
169+ while (adjust--) { \
170+ *((type *)p) = (type)color; \
171+ p += bpp; \
172+ } \
173+ } \
174+ LSX_WORK; \
175+ } \
176+ if (n & 63) { \
177+ int remainder = (n & 63); \
178+ remainder /= bpp; \
179+ while (remainder--) { \
180+ *((type *)p) = (type)color; \
181+ p += bpp; \
182+ } \
183+ } \
184+ pixels += pitch; \
185+ } \
186+ \
187+ }
188+
189+ DEFINE_LSX_FILLRECT (4 , Uint32 )
190+
191+ #endif
192+
138193static void SDL_FillRect1 (Uint8 * pixels , int pitch , Uint32 color , int w , int h )
139194{
140195 int n ;
@@ -423,6 +478,13 @@ int SDL_FillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
423478 break ;
424479 }
425480#endif
481+
482+ #ifdef __loongarch_sx
483+ if (SDL_HasLSX ()) {
484+ fill_function = SDL_FillRect4LSX ;
485+ break ;
486+ }
487+ #endif
426488 fill_function = SDL_FillRect4 ;
427489 break ;
428490 }
0 commit comments