Skip to content

Commit b386c46

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 786edcc commit b386c46

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
@@ -6529,6 +6529,30 @@ PP(pp_unshift)
65296529
return NORMAL;
65306530
}
65316531

6532+
/* Some pp_reverse helpers for MSVC:*/
6533+
#ifdef _MSC_VER
6534+
# pragma intrinsic(_byteswap_ushort, _byteswap_ulong, _byteswap_uint64)
6535+
# define S_bswap16(_x) _byteswap_ushort(_x)
6536+
# define S_bswap32(_x) _byteswap_ulong(_x)
6537+
# define S_bswap64(_x) _byteswap_uint64(_x)
6538+
PERL_STATIC_FORCE_INLINE void *
6539+
S_memcpy(void *dest, const void *src,size_t count);
6540+
#else
6541+
# define S_bswap16(_x) _swab_16_(_x)
6542+
# define S_bswap32(_x) _swab_32_(_x)
6543+
# define S_bswap64(_x) _swab_64_(_x)
6544+
# define S_memcpy(_d,_s,_n) memcpy((_d),(_s),(_n))
6545+
#endif
6546+
/* this pragma can't be push/pop-ed vs whatever the cmd line to cl.exe was */
6547+
#ifdef _MSC_VER
6548+
# pragma intrinsic(memcpy)
6549+
void *
6550+
S_memcpy(void *dest, const void *src, size_t count)
6551+
{
6552+
return memcpy(dest, src, count);
6553+
}
6554+
#endif
6555+
65326556
PP_wrapped(pp_reverse, 0, 1)
65336557
{
65346558
dSP; dMARK;
@@ -6847,6 +6871,12 @@ PP_wrapped(pp_reverse, 0, 1)
68476871
RETURN;
68486872
}
68496873

6874+
/* Undefine some pp_reverse helpers */
6875+
#undef S_memcpy
6876+
#undef S_bswap16
6877+
#undef S_bswap32
6878+
#undef S_bswap64
6879+
68506880
PP_wrapped(pp_split,
68516881
( (PL_op->op_private & OPpSPLIT_ASSIGN)
68526882
&& (PL_op->op_flags & OPf_STACKED))

0 commit comments

Comments
 (0)