From e1d569dd7c0e162d3a22843892cdb7d85f17f1df Mon Sep 17 00:00:00 2001 From: sephiroth99 Date: Tue, 22 Sep 2015 01:00:43 -0400 Subject: [PATCH] Fix usage of __m128. With GCC and clang, __m128 is not a struct, so there are no struct members to access the individual items in the vector. Use standard load/store function and some hackery to workaround this limitation. --- src/xenia/base/string_util.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/xenia/base/string_util.h b/src/xenia/base/string_util.h index 357d180c6..b279d3e17 100644 --- a/src/xenia/base/string_util.h +++ b/src/xenia/base/string_util.h @@ -60,9 +60,12 @@ inline std::string to_hex_string(const vec128_t& value) { inline std::string to_hex_string(const __m128& value) { char buffer[128]; - std::snprintf(buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]", - value.m128_u32[0], value.m128_u32[1], value.m128_u32[2], - value.m128_u32[3]); + float f[4]; + _mm_storeu_ps(f, value); + std::snprintf( + buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]", + *reinterpret_cast(&f[0]), *reinterpret_cast(&f[1]), + *reinterpret_cast(&f[2]), *reinterpret_cast(&f[3])); return std::string(buffer); } @@ -179,6 +182,8 @@ inline vec128_t from_string(const char* value, bool force_hex) { template <> inline __m128 from_string<__m128>(const char* value, bool force_hex) { __m128 v; + float f[4]; + uint32_t u; char* p = const_cast(value); bool hex_mode = force_hex; if (*p == '[') { @@ -193,22 +198,27 @@ inline __m128 from_string<__m128>(const char* value, bool force_hex) { ++p; } if (hex_mode) { - v.m128_u32[0] = std::strtoul(p, &p, 16); + u = std::strtoul(p, &p, 16); + f[0] = *reinterpret_cast(&u); while (*p == ' ' || *p == ',') ++p; - v.m128_u32[1] = std::strtoul(p, &p, 16); + u = std::strtoul(p, &p, 16); + f[1] = *reinterpret_cast(&u); while (*p == ' ' || *p == ',') ++p; - v.m128_u32[2] = std::strtoul(p, &p, 16); + u = std::strtoul(p, &p, 16); + f[2] = *reinterpret_cast(&u); while (*p == ' ' || *p == ',') ++p; - v.m128_u32[3] = std::strtoul(p, &p, 16); + u = std::strtoul(p, &p, 16); + f[3] = *reinterpret_cast(&u); } else { - v.m128_f32[0] = std::strtof(p, &p); + f[0] = std::strtof(p, &p); while (*p == ' ' || *p == ',') ++p; - v.m128_f32[1] = std::strtof(p, &p); + f[1] = std::strtof(p, &p); while (*p == ' ' || *p == ',') ++p; - v.m128_f32[2] = std::strtof(p, &p); + f[2] = std::strtof(p, &p); while (*p == ' ' || *p == ',') ++p; - v.m128_f32[3] = std::strtof(p, &p); + f[3] = std::strtof(p, &p); } + v = _mm_loadu_ps(f); return v; }