Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Make __rotl and __rotr functions portable
Browse files Browse the repository at this point in the history
GNU compiler doesn't have an intrinsic for these. Open code them
using the provided implementation.
  • Loading branch information
franksinankaya committed Jan 30, 2019
1 parent 42a8d7c commit 0aa6f2a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4434,7 +4434,15 @@ inline WCHAR *PAL_wcsstr(WCHAR *_S, const WCHAR *_P)
}
#endif

#if !__has_builtin(_rotl)
#if defined(_MSC_VER) || defined(__llvm__)
#define HAS_ROTL __has_builtin(_rotl)
#define HAS_ROTR __has_builtin(_rotr)
#else
#define HAS_ROTL 0
#define HAS_ROTR 0
#endif

#if !HAS_ROTL
/*++
Function:
_rotl
Expand All @@ -4452,14 +4460,14 @@ unsigned int __cdecl _rotl(unsigned int value, int shift)
retval = (value << shift) | (value >> (sizeof(int) * CHAR_BIT - shift));
return retval;
}
#endif // !__has_builtin(_rotl)
#endif // !HAS_ROTL

// On 64 bit unix, make the long an int.
#ifdef BIT64
#define _lrotl _rotl
#endif // BIT64

#if !__has_builtin(_rotr)
#if !HAS_ROTR

/*++
Function:
Expand All @@ -4479,7 +4487,7 @@ unsigned int __cdecl _rotr(unsigned int value, int shift)
return retval;
}

#endif // !__has_builtin(_rotr)
#endif // !HAS_ROTR

PALIMPORT int __cdecl abs(int);
// clang complains if this is declared with __int64
Expand Down

0 comments on commit 0aa6f2a

Please sign in to comment.