mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
3c07a36e95
Go 1.26 added SWAR optimizations to unicode/utf8 that use: const ptrSize = 4 << (^uintptr(0) >> 63) const hiBits = 0x8080808080808080 >> (64 - 8*ptrSize) This formula only distinguishes 32-bit and 64-bit architectures. On AVR (16-bit uintptr), ptrSize computes as 4, and hiBits becomes 0x80808080 (2155905152) which overflows the 16-bit uintptr type. Fix by providing a patched unicode/utf8 overlay for Go 1.26+ that uses a ptrSize formula handling all three sizes (16/32/64-bit): const ptrSize = 1 << (^uintptr(0)>>15&1 + ^uintptr(0)>>31&1 + ^uintptr(0)>>63&1) This evaluates to 2 on AVR, 4 on 32-bit, and 8 on 64-bit. The word() helper also gains a ptrSize==2 case for 16-bit loads.