1/*****************************************************************************\
2 Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3 This file is licensed under the Snes9x License.
4 For further information, consult the LICENSE file in the root directory.
5\*****************************************************************************/
6
7#ifndef _SAR_H_
8#define _SAR_H_
9
10#ifdef RIGHTSHIFT_IS_SAR
11#define SAR(b, n) ((b) >> (n))
12#else
13
14static inline int8 SAR (const int8 b, const int n)
15{
16#ifndef RIGHTSHIFT_int8_IS_SAR
17 if (b < 0)
18 return ((b >> n) | (-1 << (8 - n)));
19#endif
20 return (b >> n);
21}
22
23static inline int16 SAR (const int16 b, const int n)
24{
25#ifndef RIGHTSHIFT_int16_IS_SAR
26 if (b < 0)
27 return ((b >> n) | (-1 << (16 - n)));
28#endif
29 return (b >> n);
30}
31
32static inline int32 SAR (const int32 b, const int n)
33{
34#ifndef RIGHTSHIFT_int32_IS_SAR
35 if (b < 0)
36 return ((b >> n) | (-1 << (32 - n)));
37#endif
38 return (b >> n);
39}
40
41static inline int64 SAR (const int64 b, const int n)
42{
43#ifndef RIGHTSHIFT_int64_IS_SAR
44 if (b < 0)
45 return ((b >> n) | (-1 << (64 - n)));
46#endif
47 return (b >> n);
48}
49
50#endif
51
52#endif
53