2018-12-03 12:26:02 +01:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
2009-11-30 09:14:38 +01:00
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
#ifndef _SAR_H_
|
|
|
|
#define _SAR_H_
|
|
|
|
|
|
|
|
#ifdef RIGHTSHIFT_IS_SAR
|
2010-01-27 23:08:56 +01:00
|
|
|
#define SAR(b, n) ((b) >> (n))
|
2008-08-06 03:09:59 +02:00
|
|
|
#else
|
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
static inline int8 SAR (const int8 b, const int n)
|
|
|
|
{
|
2008-08-06 03:09:59 +02:00
|
|
|
#ifndef RIGHTSHIFT_int8_IS_SAR
|
2010-01-27 23:08:56 +01:00
|
|
|
if (b < 0)
|
|
|
|
return ((b >> n) | (-1 << (8 - n)));
|
2008-08-06 03:09:59 +02:00
|
|
|
#endif
|
2010-01-27 23:08:56 +01:00
|
|
|
return (b >> n);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
static inline int16 SAR (const int16 b, const int n)
|
|
|
|
{
|
2008-08-06 03:09:59 +02:00
|
|
|
#ifndef RIGHTSHIFT_int16_IS_SAR
|
2010-01-27 23:08:56 +01:00
|
|
|
if (b < 0)
|
|
|
|
return ((b >> n) | (-1 << (16 - n)));
|
2008-08-06 03:09:59 +02:00
|
|
|
#endif
|
2010-01-27 23:08:56 +01:00
|
|
|
return (b >> n);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
static inline int32 SAR (const int32 b, const int n)
|
|
|
|
{
|
2008-08-06 03:09:59 +02:00
|
|
|
#ifndef RIGHTSHIFT_int32_IS_SAR
|
2010-01-27 23:08:56 +01:00
|
|
|
if (b < 0)
|
|
|
|
return ((b >> n) | (-1 << (32 - n)));
|
2008-08-06 03:09:59 +02:00
|
|
|
#endif
|
2010-01-27 23:08:56 +01:00
|
|
|
return (b >> n);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2010-01-27 23:08:56 +01:00
|
|
|
static inline int64 SAR (const int64 b, const int n)
|
|
|
|
{
|
2008-08-06 03:09:59 +02:00
|
|
|
#ifndef RIGHTSHIFT_int64_IS_SAR
|
2010-01-27 23:08:56 +01:00
|
|
|
if (b < 0)
|
|
|
|
return ((b >> n) | (-1 << (64 - n)));
|
2008-08-06 03:09:59 +02:00
|
|
|
#endif
|
2010-01-27 23:08:56 +01:00
|
|
|
return (b >> n);
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|