[Base] Move implementation out of header where appropriate, and qualify std namespace.
This commit is contained in:
parent
40cc8c52d7
commit
2048239f30
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2015 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "xenia/base/string_util.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "xenia/base/platform.h"
|
||||
#include "xenia/base/vec128.h"
|
||||
|
||||
namespace xe {
|
||||
namespace string_util {
|
||||
|
||||
inline std::string to_hex_string(uint32_t value) {
|
||||
char buffer[21];
|
||||
std::snprintf(buffer, sizeof(buffer), "%08" PRIX32, value);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
inline std::string to_hex_string(uint64_t value) {
|
||||
char buffer[21];
|
||||
std::snprintf(buffer, sizeof(buffer), "%016" PRIX64, value);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
inline std::string to_hex_string(const vec128_t& value) {
|
||||
char buffer[128];
|
||||
std::snprintf(buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]",
|
||||
value.u32[0], value.u32[1], value.u32[2], value.u32[3]);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
#if XE_ARCH_AMD64
|
||||
|
||||
// TODO(DrChat): This should not exist. Force the caller to use vec128.
|
||||
inline std::string to_hex_string(const __m128& value) {
|
||||
char buffer[128];
|
||||
float f[4];
|
||||
_mm_storeu_ps(f, value);
|
||||
std::snprintf(
|
||||
buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]",
|
||||
*reinterpret_cast<uint32_t*>(&f[0]), *reinterpret_cast<uint32_t*>(&f[1]),
|
||||
*reinterpret_cast<uint32_t*>(&f[2]), *reinterpret_cast<uint32_t*>(&f[3]));
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
inline std::string to_string(const __m128& value) {
|
||||
char buffer[128];
|
||||
float f[4];
|
||||
_mm_storeu_ps(f, value);
|
||||
std::snprintf(buffer, sizeof(buffer), "(%F, %F, %F, %F)", f[0], f[1], f[2], f[3]);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace string_util
|
||||
} // namespace xe
|
|
@ -22,17 +22,8 @@
|
|||
namespace xe {
|
||||
namespace string_util {
|
||||
|
||||
inline std::string to_hex_string(uint32_t value) {
|
||||
char buffer[21];
|
||||
snprintf(buffer, sizeof(buffer), "%08" PRIX32, value);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
inline std::string to_hex_string(uint64_t value) {
|
||||
char buffer[21];
|
||||
snprintf(buffer, sizeof(buffer), "%016" PRIX64, value);
|
||||
return std::string(buffer);
|
||||
}
|
||||
extern inline std::string to_hex_string(uint32_t value);
|
||||
extern inline std::string to_hex_string(uint64_t value);
|
||||
|
||||
inline std::string to_hex_string(float value) {
|
||||
union {
|
||||
|
@ -52,34 +43,13 @@ inline std::string to_hex_string(double value) {
|
|||
return to_hex_string(v.ui);
|
||||
}
|
||||
|
||||
inline std::string to_hex_string(const vec128_t& value) {
|
||||
char buffer[128];
|
||||
snprintf(buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]", value.u32[0],
|
||||
value.u32[1], value.u32[2], value.u32[3]);
|
||||
return std::string(buffer);
|
||||
}
|
||||
extern inline std::string to_hex_string(const vec128_t& value);
|
||||
|
||||
#if XE_ARCH_AMD64
|
||||
|
||||
// TODO(DrChat): This should not exist. Force the caller to use vec128.
|
||||
inline std::string to_hex_string(const __m128& value) {
|
||||
char buffer[128];
|
||||
float f[4];
|
||||
_mm_storeu_ps(f, value);
|
||||
snprintf(
|
||||
buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]",
|
||||
*reinterpret_cast<uint32_t*>(&f[0]), *reinterpret_cast<uint32_t*>(&f[1]),
|
||||
*reinterpret_cast<uint32_t*>(&f[2]), *reinterpret_cast<uint32_t*>(&f[3]));
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
inline std::string to_string(const __m128& value) {
|
||||
char buffer[128];
|
||||
float f[4];
|
||||
_mm_storeu_ps(f, value);
|
||||
snprintf(buffer, sizeof(buffer), "(%F, %F, %F, %F)", f[0], f[1], f[2], f[3]);
|
||||
return std::string(buffer);
|
||||
}
|
||||
extern inline std::string to_hex_string(const __m128& value);
|
||||
extern inline std::string to_string(const __m128& value);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/base/platform.h"
|
||||
#include "xenia/base/vec128.h"
|
||||
|
||||
namespace xe {
|
||||
|
||||
inline std::string to_string(const vec128_t& value) {
|
||||
char buffer[128];
|
||||
std::snprintf(buffer, sizeof(buffer), "(%g, %g, %g, %g)", value.x, value.y,
|
||||
value.z, value.w);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
} // namespace xe
|
|
@ -264,12 +264,7 @@ static inline vec128_t vec128b(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3,
|
|||
return v;
|
||||
}
|
||||
|
||||
inline std::string to_string(const vec128_t& value) {
|
||||
char buffer[128];
|
||||
snprintf(buffer, sizeof(buffer), "(%g, %g, %g, %g)", value.x, value.y,
|
||||
value.z, value.w);
|
||||
return std::string(buffer);
|
||||
}
|
||||
extern inline std::string to_string(const vec128_t& value);
|
||||
|
||||
} // namespace xe
|
||||
|
||||
|
|
Loading…
Reference in New Issue