2007-03-14 20:24:57 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
2015-09-19 13:50:57 +00:00
|
|
|
* FILE: lib/sdk/crt/stdlib/rot.c
|
2007-03-14 20:24:57 +00:00
|
|
|
* PURPOSE: Performs a bitwise rotation
|
|
|
|
* PROGRAMER: Ariadne
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* 03/04/99: Created
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-02-03 22:36:49 +00:00
|
|
|
#ifdef __clang__
|
2021-04-09 12:59:33 +00:00
|
|
|
# define _rotl __function_rotl
|
|
|
|
# define _rotr __function_rotr
|
|
|
|
# define _lrotl __function_lrotl
|
|
|
|
# define _lrotr __function_lrotr
|
2019-02-03 22:36:49 +00:00
|
|
|
#elif defined(_MSC_VER)
|
2021-04-09 12:59:33 +00:00
|
|
|
# pragma function(_rotr, _rotl, _rotr, _lrotl, _lrotr)
|
2011-02-10 11:35:05 +00:00
|
|
|
#endif
|
|
|
|
|
2020-11-09 11:54:06 +00:00
|
|
|
#if defined (__clang__) && !defined(_MSC_VER)
|
2021-04-09 12:59:33 +00:00
|
|
|
# ifdef _M_IX86
|
|
|
|
unsigned int _rotr( unsigned int value, int shift ) __asm__("__rotr");
|
|
|
|
unsigned long _lrotr(unsigned long value, int shift) __asm__("__lrotr");
|
|
|
|
unsigned int _rotl( unsigned int value, int shift ) __asm__("__rotl");
|
|
|
|
unsigned long _lrotl( unsigned long value, int shift ) __asm__("__lrotl");
|
|
|
|
# else
|
|
|
|
unsigned int _rotr( unsigned int value, int shift ) __asm__("_rotr");
|
|
|
|
unsigned long _lrotr(unsigned long value, int shift) __asm__("_lrotr");
|
|
|
|
unsigned int _rotl( unsigned int value, int shift ) __asm__("_rotl");
|
|
|
|
unsigned long _lrotl( unsigned long value, int shift ) __asm__("_lrotl");
|
|
|
|
# endif
|
2021-04-09 13:12:13 +00:00
|
|
|
#else
|
|
|
|
unsigned int _rotr( unsigned int value, int shift );
|
|
|
|
unsigned long _lrotr(unsigned long value, int shift);
|
|
|
|
unsigned int _rotl( unsigned int value, int shift );
|
|
|
|
unsigned long _lrotl( unsigned long value, int shift );
|
2020-11-09 11:54:06 +00:00
|
|
|
#endif
|
2007-03-14 20:24:57 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
unsigned int _rotl( unsigned int value, int shift )
|
|
|
|
{
|
|
|
|
int max_bits = sizeof(unsigned int)<<3;
|
|
|
|
if ( shift < 0 )
|
|
|
|
return _rotr(value,-shift);
|
|
|
|
|
|
|
|
if ( shift > max_bits )
|
|
|
|
shift = shift % max_bits;
|
|
|
|
return (value << shift) | (value >> (max_bits-shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
unsigned int _rotr( unsigned int value, int shift )
|
|
|
|
{
|
|
|
|
int max_bits = sizeof(unsigned int)<<3;
|
|
|
|
if ( shift < 0 )
|
|
|
|
return _rotl(value,-shift);
|
|
|
|
|
2017-10-28 08:28:27 +00:00
|
|
|
if ( shift > max_bits )
|
2007-03-14 20:24:57 +00:00
|
|
|
shift = shift % max_bits;
|
|
|
|
return (value >> shift) | (value << (max_bits-shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
unsigned long _lrotl( unsigned long value, int shift )
|
|
|
|
{
|
|
|
|
int max_bits = sizeof(unsigned long)<<3;
|
|
|
|
if ( shift < 0 )
|
|
|
|
return _lrotr(value,-shift);
|
|
|
|
|
|
|
|
if ( shift > max_bits )
|
|
|
|
shift = shift % max_bits;
|
|
|
|
return (value << shift) | (value >> (max_bits-shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
unsigned long _lrotr( unsigned long value, int shift )
|
|
|
|
{
|
|
|
|
int max_bits = sizeof(unsigned long)<<3;
|
|
|
|
if ( shift < 0 )
|
|
|
|
return _lrotl(value,-shift);
|
|
|
|
|
|
|
|
if ( shift > max_bits )
|
|
|
|
shift = shift % max_bits;
|
|
|
|
return (value >> shift) | (value << (max_bits-shift));
|
|
|
|
}
|