From dd8309d23d7193f614a9c35def5da5bc2fed9300 Mon Sep 17 00:00:00 2001 From: Richard Leach Date: Sun, 26 Oct 2025 17:04:24 +0000 Subject: [PATCH] Add MSVC support for chunk-at-a-time string reversal The heavy lifting for this commit was done by bulk88 in GH#23374. Any deficiencies in transcription are down to richardleach. ;) --- pp.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pp.c b/pp.c index 36709a13c1..5d3ecdfc45 100644 --- a/pp.c +++ b/pp.c @@ -6464,6 +6464,30 @@ PP(pp_unshift) return NORMAL; } +/* Some pp_reverse helpers for MSVC:*/ +#ifdef _MSC_VER +# pragma intrinsic(_byteswap_ushort, _byteswap_ulong, _byteswap_uint64) +# define S_bswap16(_x) _byteswap_ushort(_x) +# define S_bswap32(_x) _byteswap_ulong(_x) +# define S_bswap64(_x) _byteswap_uint64(_x) +PERL_STATIC_FORCE_INLINE void * + S_memcpy(void *dest, const void *src,size_t count); +#else +# define S_bswap16(_x) _swab_16_(_x) +# define S_bswap32(_x) _swab_32_(_x) +# define S_bswap64(_x) _swab_64_(_x) +# define S_memcpy(_d,_s,_n) memcpy((_d),(_s),(_n)) +#endif +/* this pragma can't be push/pop-ed vs whatever the cmd line to cl.exe was */ +#ifdef _MSC_VER +# pragma intrinsic(memcpy) +void * +S_memcpy(void *dest, const void *src, size_t count) +{ + return memcpy(dest, src, count); +} +#endif + PP_wrapped(pp_reverse, 0, 1) { dSP; dMARK; @@ -6783,6 +6807,12 @@ PP_wrapped(pp_reverse, 0, 1) RETURN; } +/* Undefine some pp_reverse helpers */ +#undef S_memcpy +#undef S_bswap16 +#undef S_bswap32 +#undef S_bswap64 + PP_wrapped(pp_split, ( (PL_op->op_private & OPpSPLIT_ASSIGN) && (PL_op->op_flags & OPf_STACKED))