Skip to content

Commit 3ba70e2

Browse files
committed
Add "width == stride" optimization for 8/16/32-bpp vc_rectfill
1 parent af72c42 commit 3ba70e2

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

kos/src/libvideo/codec/codecs.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,17 @@ rectfill8(byte_t *__restrict line, video_coord_t x, size_t stride,
247247
line += x;
248248
codec_assert(size_x > 0);
249249
codec_assert(size_y > 0);
250-
do {
251-
memset(line, (uint8_t)pixel, size_x);
252-
line += stride;
253-
} while (--size_y);
250+
#ifndef __OPTIMIZE_SIZE__
251+
if (stride == size_x) {
252+
memset(line, (uint8_t)pixel, size_x * size_y);
253+
} else
254+
#endif /* !__OPTIMIZE_SIZE__ */
255+
{
256+
do {
257+
memset(line, (uint8_t)pixel, size_x);
258+
line += stride;
259+
} while (--size_y);
260+
}
254261
}
255262

256263
PRIVATE NONNULL((1, 4)) void CC
@@ -469,10 +476,17 @@ rectfill16(byte_t *__restrict line, video_coord_t x, size_t stride,
469476
codec_assert(!(stride & 1));
470477
codec_assert(!((uintptr_t)line & 1));
471478
#endif /* !__ARCH_HAVE_UNALIGNED_MEMORY_ACCESS */
472-
do {
473-
memsetw(line, (uint16_t)pixel, size_x);
474-
line += stride;
475-
} while (--size_y);
479+
#ifndef __OPTIMIZE_SIZE__
480+
if (stride == (size_x << 1)) {
481+
memsetw(line, (uint16_t)pixel, size_x * size_y);
482+
} else
483+
#endif /* !__OPTIMIZE_SIZE__ */
484+
{
485+
do {
486+
memsetw(line, (uint16_t)pixel, size_x);
487+
line += stride;
488+
} while (--size_y);
489+
}
476490
}
477491

478492
#ifdef __ARCH_HAVE_UNALIGNED_MEMORY_ACCESS
@@ -1219,10 +1233,17 @@ rectfill32(byte_t *__restrict line, video_coord_t x, size_t stride,
12191233
codec_assert(!(stride & 3));
12201234
codec_assert(!((uintptr_t)line & 3));
12211235
#endif /* !__ARCH_HAVE_UNALIGNED_MEMORY_ACCESS */
1222-
do {
1223-
memsetl(line, (uint32_t)pixel, size_x);
1224-
line += stride;
1225-
} while (--size_y);
1236+
#ifndef __OPTIMIZE_SIZE__
1237+
if (stride == (size_x << 2)) {
1238+
memsetl(line, (uint32_t)pixel, size_x * size_y);
1239+
} else
1240+
#endif /* !__OPTIMIZE_SIZE__ */
1241+
{
1242+
do {
1243+
memsetl(line, (uint32_t)pixel, size_x);
1244+
line += stride;
1245+
} while (--size_y);
1246+
}
12261247
}
12271248

12281249
PRIVATE NONNULL((1, 4)) void CC

0 commit comments

Comments
 (0)