Skip to content

Commit dd8309d

Browse files
committed
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. ;)
1 parent 4e9d64b commit dd8309d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pp.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6464,6 +6464,30 @@ PP(pp_unshift)
64646464
return NORMAL;
64656465
}
64666466

6467+
/* Some pp_reverse helpers for MSVC:*/
6468+
#ifdef _MSC_VER
6469+
# pragma intrinsic(_byteswap_ushort, _byteswap_ulong, _byteswap_uint64)
6470+
# define S_bswap16(_x) _byteswap_ushort(_x)
6471+
# define S_bswap32(_x) _byteswap_ulong(_x)
6472+
# define S_bswap64(_x) _byteswap_uint64(_x)
6473+
PERL_STATIC_FORCE_INLINE void *
6474+
S_memcpy(void *dest, const void *src,size_t count);
6475+
#else
6476+
# define S_bswap16(_x) _swab_16_(_x)
6477+
# define S_bswap32(_x) _swab_32_(_x)
6478+
# define S_bswap64(_x) _swab_64_(_x)
6479+
# define S_memcpy(_d,_s,_n) memcpy((_d),(_s),(_n))
6480+
#endif
6481+
/* this pragma can't be push/pop-ed vs whatever the cmd line to cl.exe was */
6482+
#ifdef _MSC_VER
6483+
# pragma intrinsic(memcpy)
6484+
void *
6485+
S_memcpy(void *dest, const void *src, size_t count)
6486+
{
6487+
return memcpy(dest, src, count);
6488+
}
6489+
#endif
6490+
64676491
PP_wrapped(pp_reverse, 0, 1)
64686492
{
64696493
dSP; dMARK;
@@ -6783,6 +6807,12 @@ PP_wrapped(pp_reverse, 0, 1)
67836807
RETURN;
67846808
}
67856809

6810+
/* Undefine some pp_reverse helpers */
6811+
#undef S_memcpy
6812+
#undef S_bswap16
6813+
#undef S_bswap32
6814+
#undef S_bswap64
6815+
67866816
PP_wrapped(pp_split,
67876817
( (PL_op->op_private & OPpSPLIT_ASSIGN)
67886818
&& (PL_op->op_flags & OPf_STACKED))

0 commit comments

Comments
 (0)