From e470a1da093aecacb397c78cb525c239a528ae4f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 9 Nov 2019 00:06:05 -0600 Subject: [PATCH] [ox/std] Add ox_inhibit_loop_to_libcall for memset and memcpy --- deps/ox/src/ox/std/memops.cpp | 8 ++++++-- deps/ox/src/ox/std/memops.hpp | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/deps/ox/src/ox/std/memops.cpp b/deps/ox/src/ox/std/memops.cpp index abde8da6..e24a3def 100644 --- a/deps/ox/src/ox/std/memops.cpp +++ b/deps/ox/src/ox/std/memops.cpp @@ -11,18 +11,22 @@ #ifndef OX_USE_STDLIB +#define ox_inhibit_loop_to_libcall __attribute__((__optimize__ ("-fno-tree-loop-distribute-patterns"))) + extern "C" { -void *memcpy(void *dest, const void *src, std::size_t size) { +void *ox_inhibit_loop_to_libcall memcpy(void *dest, const void *src, std::size_t size) { return ox_memcpy(dest, src, size); } -void *memset(void *ptr, int val, std::size_t size) { +void *ox_inhibit_loop_to_libcall memset(void *ptr, int val, std::size_t size) { return ox_memset(ptr, val, size); } } +#undef ox_inhibit_loop_to_libcall + #endif int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { diff --git a/deps/ox/src/ox/std/memops.hpp b/deps/ox/src/ox/std/memops.hpp index 5e4a5705..948e98be 100644 --- a/deps/ox/src/ox/std/memops.hpp +++ b/deps/ox/src/ox/std/memops.hpp @@ -28,9 +28,9 @@ constexpr void *ox_memcpy(void *dest, const void *src, std::size_t size) noexcep } constexpr void *ox_memset(void *ptr, int val, std::size_t size) noexcept { - auto buf = static_cast(ptr); + auto buf = reinterpret_cast(ptr); for (std::size_t i = 0; i < size; i++) { - buf[i] = val; + buf[i] = static_cast(val); } return ptr; }