1 #ifndef PICO_PORT_INCLUDED
2 #define PICO_PORT_INCLUDED
4 // provide size_t, uintptr_t
6 #if !(defined(_MSC_VER) && _MSC_VER < 1800)
9 #include "pico_types.h"
11 #ifdef USE_LIBRETRO_VFS
12 #include "file_stream_transforms.h"
15 #if defined(__GNUC__) && defined(__i386__)
16 #define REGPARM(x) __attribute__((regparm(x)))
22 #define NOINLINE __attribute__((noinline))
23 #define ALIGNED(n) __attribute__((aligned(n)))
24 #define unlikely(x) __builtin_expect((x), 0)
25 #define likely(x) __builtin_expect(!!(x), 1)
29 #define unlikely(x) (x)
34 #define snprintf _snprintf
35 #define strcasecmp _stricmp
36 #define strncasecmp _strnicmp
37 #define strdup _strdup
41 // There's no standard way to determine endianess at compile time. Try using
42 // some well known non-standard macros for detection.
43 #if defined __BYTE_ORDER__
44 #define CPU_IS_LE __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
45 #elif defined __BYTE_ORDER
46 #define CPU_IS_LE __BYTE_ORDER == __LITTLE_ENDIAN
47 #elif defined __BIG_ENDIAN__ || defined _M_PPC // Windows on PPC was big endian
49 #elif defined __LITTLE_ENDIAN__ || defined _WIN32 // all other Windows is LE
52 #warning "can't detect byte order, assume little endian"
55 // NB mixed endian integer platforms are not supported.
58 // address/offset operations
59 #define MEM_BE2(a) ((a)^1) // addr/offs of u8 in u16, or u16 in u32
60 #define MEM_BE4(a) ((a)^3) // addr/offs of u8 in u32
61 #define MEM_LE2(a) (a)
62 #define MEM_LE4(a) (a)
64 #define CPU_BE2(v) ((u32)((u64)(v)<<16)|((u32)(v)>>16))
65 #define CPU_BE4(v) (((u32)(v)>>24)|(((v)>>8)&0x00ff00)| \
66 (((v)<<8)&0xff0000)|(u32)((v)<<24))
67 #define CPU_LE2(v) (v) // swap of 2*u16 in u32
68 #define CPU_LE4(v) (v) // swap of 4*u8 in u32
70 // address/offset operations
71 #define MEM_BE2(a) (a)
72 #define MEM_BE4(a) (a)
73 #define MEM_LE2(a) ((a)^1)
74 #define MEM_LE4(a) ((a)^3)
76 #define CPU_BE2(v) (v)
77 #define CPU_BE4(v) (v)
78 #define CPU_LE2(v) ((u32)((u64)(v)<<16)|((u32)(v)>>16))
79 #define CPU_LE4(v) (((u32)(v)>>24)|(((v)>>8)&0x00ff00)| \
80 (((v)<<8)&0xff0000)|(u32)((v)<<24))
83 #endif // PICO_PORT_INCLUDED