Skip to content

Commit

Permalink
inline.h: Use new C99 emulation
Browse files Browse the repository at this point in the history
We don't have to know explicitly if the platform is 64 or 32 bits, and
can derive the constants that were formerly hard-coded in.
  • Loading branch information
khwilliamson committed Dec 5, 2017
1 parent fba5a07 commit 2f6e257
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions inline.h
Expand Up @@ -387,24 +387,14 @@ S_is_utf8_invariant_string_loc(const U8* const s, STRLEN len, const U8 ** ep)
send = s + len;

#ifndef EBCDIC
/* Try to get the widest word on this platform */
# ifdef HAS_LONG_LONG
# define PERL_WORDCAST unsigned long long
# define PERL_WORDSIZE LONGLONGSIZE
# else
# define PERL_WORDCAST UV
# define PERL_WORDSIZE UVSIZE
# endif

# if PERL_WORDSIZE == 4
# define PERL_VARIANTS_WORD_MASK 0x80808080
# define PERL_WORD_BOUNDARY_MASK 0x3
# elif PERL_WORDSIZE == 8
# define PERL_VARIANTS_WORD_MASK UINT64_C(0x8080808080808080)
# define PERL_WORD_BOUNDARY_MASK 0x7
# else
# error Unexpected word size
# endif

/* This looks like 0x010101... */
#define PERL_COUNT_MULTIPLIER (~ (UINTMAX_C(0)) / 0xFF)

/* This looks like 0x808080... */
#define PERL_VARIANTS_WORD_MASK (PERL_COUNT_MULTIPLIER * 0x80)
#define PERL_WORDSIZE sizeof(PERL_COUNT_MULTIPLIER)
#define PERL_WORD_BOUNDARY_MASK (PERL_WORDSIZE - 1)

/* Process per-byte until reach word boundary. XXX This loop could be
* eliminated if we knew that this platform had fast unaligned reads */
Expand All @@ -421,7 +411,7 @@ S_is_utf8_invariant_string_loc(const U8* const s, STRLEN len, const U8 ** ep)

/* Process per-word as long as we have at least a full word left */
while (x + PERL_WORDSIZE <= send) {
if ((* (PERL_WORDCAST *) x) & PERL_VARIANTS_WORD_MASK) {
if ((* (uintmax_t *) x) & PERL_VARIANTS_WORD_MASK) {

/* Found a variant. Just return if caller doesn't want its exact
* position */
Expand Down

0 comments on commit 2f6e257

Please sign in to comment.