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. ;)
This commit is contained in:
Richard Leach 2025-10-26 17:04:24 +00:00
parent 4e9d64bf17
commit dd8309d23d

30
pp.c
View File

@ -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))