Starting to cleanup includes a bit. Still a mess.

This commit is contained in:
Ben Vanik
2014-07-11 18:03:35 -07:00
parent f24b45a07c
commit 1d54342930
28 changed files with 245 additions and 245 deletions

17
src/poly/config.h Normal file
View File

@@ -0,0 +1,17 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef POLY_CONFIG_H_
#define POLY_CONFIG_H_
#if defined(DEBUG) || defined(_DEBUG)
#define XE_DEBUG 1
#endif // DEBUG
#endif // POLY_CONFIG_H_

View File

@@ -10,6 +10,8 @@
#ifndef POLY_POLY_CXX_COMPAT_H_
#define POLY_POLY_CXX_COMPAT_H_
#include <poly/config.h>
// C++11 thread local storage.
// http://en.cppreference.com/w/cpp/language/storage_duration
#if XE_COMPILER_MSVC

View File

@@ -15,6 +15,9 @@
#include <cstdint>
#include <cstring>
#include <poly/config.h>
#include <poly/platform.h>
namespace poly {
// lzcnt instruction, typed for integers of all sizes.
@@ -22,48 +25,48 @@ namespace poly {
// return value is the size of the input operand (8, 16, 32, or 64). If the most
// significant bit of value is one, the return value is zero.
#if XE_COMPILER_MSVC
uint8_t lzcnt(uint8_t v) { return static_cast<uint8_t>(__lzcnt16(v) - 8); }
uint8_t lzcnt(uint16_t v) { return static_cast<uint8_t>(__lzcnt16(v)); }
uint8_t lzcnt(uint32_t v) { return static_cast<uint8_t>(__lzcnt(v)); }
uint8_t lzcnt(uint64_t v) { return static_cast<uint8_t>(__lzcnt64(v)); }
inline uint8_t lzcnt(uint8_t v) { return static_cast<uint8_t>(__lzcnt16(v) - 8); }
inline uint8_t lzcnt(uint16_t v) { return static_cast<uint8_t>(__lzcnt16(v)); }
inline uint8_t lzcnt(uint32_t v) { return static_cast<uint8_t>(__lzcnt(v)); }
inline uint8_t lzcnt(uint64_t v) { return static_cast<uint8_t>(__lzcnt64(v)); }
#else
uint8_t lzcnt(uint8_t v) { return static_cast<uint8_t>(__builtin_clzs(v) - 8); }
uint8_t lzcnt(uint16_t v) { return static_cast<uint8_t>(__builtin_clzs(v)); }
uint8_t lzcnt(uint32_t v) { return static_cast<uint8_t>(__builtin_clz(v)); }
uint8_t lzcnt(uint64_t v) { return static_cast<uint8_t>(__builtin_clzll(v)); }
inline uint8_t lzcnt(uint8_t v) { return static_cast<uint8_t>(__builtin_clzs(v) - 8); }
inline uint8_t lzcnt(uint16_t v) { return static_cast<uint8_t>(__builtin_clzs(v)); }
inline uint8_t lzcnt(uint32_t v) { return static_cast<uint8_t>(__builtin_clz(v)); }
inline uint8_t lzcnt(uint64_t v) { return static_cast<uint8_t>(__builtin_clzll(v)); }
#endif // XE_COMPILER_MSVC
uint8_t lzcnt(int8_t v) { return lzcnt(static_cast<uint8_t>(v)); }
uint8_t lzcnt(int16_t v) { return lzcnt(static_cast<uint16_t>(v)); }
uint8_t lzcnt(int32_t v) { return lzcnt(static_cast<uint32_t>(v)); }
uint8_t lzcnt(int64_t v) { return lzcnt(static_cast<uint64_t>(v)); }
inline uint8_t lzcnt(int8_t v) { return lzcnt(static_cast<uint8_t>(v)); }
inline uint8_t lzcnt(int16_t v) { return lzcnt(static_cast<uint16_t>(v)); }
inline uint8_t lzcnt(int32_t v) { return lzcnt(static_cast<uint32_t>(v)); }
inline uint8_t lzcnt(int64_t v) { return lzcnt(static_cast<uint64_t>(v)); }
// BitScanForward (bsf).
// Search the value from least significant bit (LSB) to the most significant bit
// (MSB) for a set bit (1).
// Returns false if no bits are set and the output index is invalid.
#if XE_COMPILER_MSVC
bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) {
return _BitScanForward(out_first_set_index, v) != 0;
inline bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) {
return _BitScanForward(reinterpret_cast<DWORD*>(out_first_set_index), v) != 0;
}
bool bit_scan_forward(uint64_t v, uint32_t* out_first_set_index) {
return _BitScanForward64(out_first_set_index, v) != 0;
inline bool bit_scan_forward(uint64_t v, uint32_t* out_first_set_index) {
return _BitScanForward64(reinterpret_cast<DWORD*>(out_first_set_index), v) != 0;
}
#else
bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) {
inline bool bit_scan_forward(uint32_t v, uint32_t* out_first_set_index) {
int i = ffs(v);
*out_first_set_index = i;
return i != 0;
}
bool bit_scan_forward(uint64_t v, uint32_t* out_first_set_index) {
inline bool bit_scan_forward(uint64_t v, uint32_t* out_first_set_index) {
int i = ffsll(v);
*out_first_set_index = i;
return i != 0;
}
#endif // XE_COMPILER_MSVC
bool bit_scan_forward(int32_t v, uint32_t* out_first_set_index) {
inline bool bit_scan_forward(int32_t v, uint32_t* out_first_set_index) {
return bit_scan_forward(static_cast<uint32_t>(v), out_first_set_index);
}
bool bit_scan_forward(int64_t v, uint32_t* out_first_set_index) {
inline bool bit_scan_forward(int64_t v, uint32_t* out_first_set_index) {
return bit_scan_forward(static_cast<uint64_t>(v), out_first_set_index);
}
@@ -84,20 +87,28 @@ int32_t m128_i32(const __m128& v) {
return ret.i;
}
template <int N>
double m128_f64(const __m128& v) {
double m128_f64(const __m128d& v) {
double ret;
_mm_store_sd(&ret, _mm_shuffle_ps(v, v, _MM_SHUFFLE(N, N, N, N)));
_mm_store_sd(&ret, _mm_shuffle_pd(v, v, _MM_SHUFFLE2(N, N)));
return ret;
}
template <int N>
int64_t m128_i64(const __m128& v) {
double m128_f64(const __m128& v) {
return m128_f64<N>(_mm_castps_pd(v));
}
template <int N>
int64_t m128_i64(const __m128d& v) {
union {
double f;
int64_t i;
} ret;
_mm_store_sd(&ret.f, _mm_shuffle_ps(v, v, _MM_SHUFFLE(N, N, N, N)));
_mm_store_sd(&ret.f, _mm_shuffle_pd(v, v, _MM_SHUFFLE2(N, N)));
return ret.i;
}
template <int N>
int64_t m128_i64(const __m128& v) {
return m128_i64<N>(_mm_castps_pd(v));
}
} // namespace poly

163
src/poly/platform.h Normal file
View File

@@ -0,0 +1,163 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef POLY_PLATFORM_H_
#define POLY_PLATFORM_H_
// NOTE: ordering matters here as sometimes multiple flags are defined on
// certain platforms.
// Great resource on predefined macros: http://predef.sourceforge.net/preos.html
/*
XE_PLATFORM: IOS | OSX | XBOX360 | WINCE | WIN32 | ANDROID | NACL | UNIX
XE_LIKE: OSX | WIN32 | POSIX
XE_PROFILE: EMBEDDED | DESKTOP (+ _SIMULATOR)
XE_COMPILER: GNUC | MSVC | CLANG | INTEL | UNKNOWN
XE_CPU: 32BIT | 64BIT | BIGENDIAN | LITTLEENDIAN
*/
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
#if (defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED ) || \
(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE ) || \
(defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR)
#define XE_PLATFORM_IOS 1
#define XE_LIKE_OSX 1
#define XE_PROFILE_EMBEDDED 1
#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR
// EMBEDDED *and* SIMULATOR
#define XE_PROFILE_SIMULATOR 1
#endif
#elif defined(TARGET_OS_MAC) && TARGET_OS_MAC
#define XE_PLATFORM_OSX 1
#define XE_LIKE_OSX 1
#define XE_PROFILE_DESKTOP 1
#elif defined(_XBOX)
#define XE_PLATFORM_XBOX360 1
#define XE_LIKE_WIN32 1
#define XE_PROFILE_EMBEDDED 1
#elif defined(_WIN32_WCE)
#define XE_PLATFORM_WINCE 1
#define XE_LIKE_WIN32 1
#define XE_PROFILE_EMBEDDED 1
#elif defined(__CYGWIN__)
#define XE_PLATFORM_CYGWIN 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_DESKTOP 1
#elif defined(WIN32) || defined(_WIN32)
#define XE_PLATFORM_WIN32 1
#define XE_LIKE_WIN32 1
#define XE_PROFILE_DESKTOP 1
#elif defined(ANDROID)
#define XE_PLATFORM_ANDROID 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_EMBEDDED 1
#elif defined(__native_client__)
#define XE_PLATFORM_NACL 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_DESKTOP 1
#else
#define XE_PLATFORM_UNIX 1
#define XE_LIKE_POSIX 1
#define XE_PROFILE_DESKTOP 1
#endif
#if defined(__clang__)
#define XE_COMPILER_CLANG 1
#elif defined(__GNUC__)
#define XE_COMPILER_GNUC 1
#elif defined(_MSC_VER)
#define XE_COMPILER_MSVC 1
#elif defined(__MINGW32)
#define XE_COMPILER_MINGW32 1
#elif defined(__INTEL_COMPILER)
#define XE_COMPILER_INTEL 1
#else
#define XE_COMPILER_UNKNOWN 1
#endif
#if defined(__ia64__) || defined(_M_IA64) || \
defined(__ppc64__) || defined(__PPC64__) || \
defined(__arch64__) || \
defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) || \
defined(__LP64__) || defined(__LLP64) || \
defined(_WIN64) || \
(__WORDSIZE == 64)
#define XE_CPU_64BIT 1
#else
#define XE_CPU_32BIT 1
#endif // [64bit flags]
#if defined(__ppc__) || defined(__PPC__) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(_M_PPC) || defined(__PPC) || \
defined(__ppc64__) || defined(__PPC64__) || \
defined(__ARMEB__) || defined(__THUMBEB__) || \
defined(__AARCH64EB__) || \
defined(__BIG_ENDIAN) || defined(__BIG_ENDIAN__)
#define XE_CPU_BIGENDIAN 1
#else
#define XE_CPU_LITTLEENDIAN 1
#endif // [big endian flags]
#if XE_CPU_32BIT
#define XE_ALIGNMENT 8
#else
#define XE_ALIGNMENT 16
#endif // 32BIT
#if XE_PLATFORM_WINCE || XE_PLATFORM_WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <SDKDDKVer.h>
#include <windows.h>
#include <ObjBase.h>
#undef min
#undef max
#undef Yield
#endif // WINCE || WIN32
#if XE_PLATFORM_XBOX360
#include <xtl.h>
#include <xboxmath.h>
#endif // XBOX360
#if XE_COMPILER_MSVC
// Disable warning C4068: unknown pragma
#pragma warning(disable : 4068)
#endif // MSVC
#if XE_COMPILER_MSVC
#include <intrin.h>
#else
#include <x86intrin.h>
#endif // MSVC
#endif // POLY_PLATFORM_H_

View File

@@ -10,8 +10,10 @@
#ifndef POLY_POLY_H_
#define POLY_POLY_H_
#include <poly/config.h>
#include <poly/cxx_compat.h>
#include <poly/math.h>
#include <poly/platform.h>
#include <poly/threading.h>
namespace poly {} // namespace poly

View File

@@ -1,6 +1,7 @@
# Copyright 2014 Ben Vanik. All Rights Reserved.
{
'sources': [
'config.h',
'cxx_compat.h',
'math.h',
'poly-private.h',

View File

@@ -13,6 +13,8 @@
#include <chrono>
#include <cstdint>
#include <poly/config.h>
namespace poly {
namespace threading {

View File

@@ -9,6 +9,8 @@
#include <poly/threading.h>
#include <poly/platform.h>
namespace poly {
namespace threading {
@@ -22,7 +24,7 @@ void Sleep(std::chrono::microseconds duration) {
if (duration.count() < 100) {
SwitchToThread();
} else {
Sleep(duration.count() / 1000);
::Sleep(static_cast<DWORD>(duration.count() / 1000));
}
}