From: Ulya Trofimovich Date: Wed, 27 Feb 2019 10:44:15 +0000 (+0000) Subject: Moved hot functions to header to enable inlining. X-Git-Tag: 1.2~139 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47828ae1c96e64b53e3bf28ab402d8d7de90a00d;p=re2c Moved hot functions to header to enable inlining. --- diff --git a/re2c/src/dfa/determinization.h b/re2c/src/dfa/determinization.h index 6a363d46..465d5254 100644 --- a/re2c/src/dfa/determinization.h +++ b/re2c/src/dfa/determinization.h @@ -177,6 +177,34 @@ bool cmp_gtop_t::operator() (const nfa_state_t *x, const nfa_state_t *y) const return x->topord < y->topord; } +inline int32_t unpack_longest(int32_t packed) +{ + // take lower 30 bits and sign-extend + return static_cast(static_cast(packed) << 2u) >> 2u; +} + +inline int32_t unpack_leftmost(int32_t packed) +{ + // take higher 2 bits and sign-extend + return packed >> 30u; +} + +inline int32_t pack(int32_t longest, int32_t leftmost) +{ + // avoid signed overflows by using unsigned arithmetics + uint32_t u_longest = static_cast(longest); + uint32_t u_leftmost = static_cast(leftmost); + + // leftmost: higher 2 bits, longest: lower 30 bits + uint32_t u_packed = (u_longest & 0x3fffFFFF) | (u_leftmost << 30u); + int32_t packed = static_cast(u_packed); + + DASSERT(unpack_longest(packed) == longest + && unpack_leftmost(packed) == leftmost); + + return packed; +} + } // namespace re2c #endif // _RE2C_DFA_DETERMINIZATION_ diff --git a/re2c/src/dfa/posix_precedence.cc b/re2c/src/dfa/posix_precedence.cc index 66691f8c..d7a89e3d 100644 --- a/re2c/src/dfa/posix_precedence.cc +++ b/re2c/src/dfa/posix_precedence.cc @@ -98,32 +98,4 @@ int32_t precedence(determ_context_t &ctx, const clos_t &x, const clos_t &y return prec; } -int32_t unpack_longest(int32_t packed) -{ - // take lower 30 bits and sign-extend - return static_cast(static_cast(packed) << 2u) >> 2u; -} - -int32_t unpack_leftmost(int32_t packed) -{ - // take higher 2 bits and sign-extend - return packed >> 30u; -} - -int32_t pack(int32_t longest, int32_t leftmost) -{ - // avoid signed overflows by using unsigned arithmetics - uint32_t u_longest = static_cast(longest); - uint32_t u_leftmost = static_cast(leftmost); - - // leftmost: higher 2 bits, longest: lower 30 bits - uint32_t u_packed = (u_longest & 0x3fffFFFF) | (u_leftmost << 30u); - int32_t packed = static_cast(u_packed); - - DASSERT(unpack_longest(packed) == longest - && unpack_leftmost(packed) == leftmost); - - return packed; -} - } // namespace re2c