From d965fe5638465617263411b0e1eecfa7e9589c5c Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 30 Jun 2026 11:14:36 +1000 Subject: [PATCH] basic-handsum-decode: use our own memcpy --- snippet/basic-handsum-decode.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/snippet/basic-handsum-decode.c b/snippet/basic-handsum-decode.c index adc88f59..830d3758 100644 --- a/snippet/basic-handsum-decode.c +++ b/snippet/basic-handsum-decode.c @@ -42,7 +42,6 @@ #include #include #include -#include typedef struct basic_handsum_decode__pixel_buffer_type { uint32_t width; // Measured in pixels, not bytes. @@ -80,6 +79,17 @@ basic_handsum_decode__decode(basic_handsum_decode__pixel_buffer* dst, #ifdef BASIC_HANDSUM_DECODE_IMPLEMENTATION +// We implement memcpy ourselves, instead of using "#include ", so +// that we can compile this snippet with --target=wasm32. +static void // +basic_handsum_decode__memcpy(uint8_t* restrict dst, + const uint8_t* restrict src, + size_t n) { + while (n--) { + *dst++ = *src++; + } +} + static void // basic_handsum_decode__smooth_block_seams_16x16(uint8_t* b) { static const uint8_t smoothing_pairs_16x16[28][2] = { @@ -297,7 +307,7 @@ basic_handsum_decode__decode_block_q4(uint8_t* dst_ptr, for (size_t i = 0; i < 8; i++) { size_t di = i * dst_stride; size_t ti = i * 8; - memcpy(&dst_ptr[di], &tmp[ti], 8); + basic_handsum_decode__memcpy(&dst_ptr[di], &tmp[ti], 8); } return bit_offset; @@ -629,7 +639,8 @@ basic_handsum_decode__scale_horizontal( } for (int y = 0; y < 16; y++) { - memcpy(&pixbuf->bgra_pixels[4 * w * y], &dst[4 * w * y], 4 * w); + basic_handsum_decode__memcpy(&pixbuf->bgra_pixels[4 * w * y], + &dst[4 * w * y], 4 * w); } } @@ -686,7 +697,7 @@ basic_handsum_decode__scale_vertical( } } - memcpy(&pixbuf->bgra_pixels[0], &dst[0], 64 * h); + basic_handsum_decode__memcpy(&pixbuf->bgra_pixels[0], &dst[0], 64 * h); } static void //