-
Notifications
You must be signed in to change notification settings - Fork 463
/
sar.h
52 lines (44 loc) · 1.12 KB
/
sar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*****************************************************************************\
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.
\*****************************************************************************/
#ifndef _SAR_H_
#define _SAR_H_
#ifdef RIGHTSHIFT_IS_SAR
#define SAR(b, n) ((b) >> (n))
#else
static inline int8 SAR (const int8 b, const int n)
{
#ifndef RIGHTSHIFT_int8_IS_SAR
if (b < 0)
return ((b >> n) | (-1 << (8 - n)));
#endif
return (b >> n);
}
static inline int16 SAR (const int16 b, const int n)
{
#ifndef RIGHTSHIFT_int16_IS_SAR
if (b < 0)
return ((b >> n) | (-1 << (16 - n)));
#endif
return (b >> n);
}
static inline int32 SAR (const int32 b, const int n)
{
#ifndef RIGHTSHIFT_int32_IS_SAR
if (b < 0)
return ((b >> n) | (-1 << (32 - n)));
#endif
return (b >> n);
}
static inline int64 SAR (const int64 b, const int n)
{
#ifndef RIGHTSHIFT_int64_IS_SAR
if (b < 0)
return ((b >> n) | (-1 << (64 - n)));
#endif
return (b >> n);
}
#endif
#endif