84205879 [olympic] Cleanup ItemMaker, remove unnecessary copy ebf3a696 [ox/std] Add String constructor that takes a StringLiteral dfd27afd [ox/std] Add implicit String constructor for str literals 6bfe1842 [ox/std] Remove unnecessary copying from HashMap::expand 700d7016 [nostalgia] Update for Ox changes 92232383 [ox] Cleanup 3b8d13dc [nostalgia,olympic] Fixes for Ox update a20d7fd9 [ox] Cleanup 2c0e0227 [ox/std] Add assert to AnyPtr::Wrap::copyTo to ensure sufficiently large buff e3c74637 [turbine] Make applicationData return const& 41e08d67 [turbine] Make keyEventHandler nodiscard 50f3479d [ox/std] Make AnyPtr constexpr 1616ca70 [turbine] Replace WrapPtr with ox::AnyPtr 3fa247e3 [ox/std] Add AnyPtr 27f1df8f [nostalgia,olympic] Further reduce use of applicationData a4f0c7cd [nostalgia/core/studio] Remove applicationData usages git-subtree-dir: deps/nostalgia git-subtree-split: 84205879d46610dfe08098d1265c0398f2215d3d
99 lines
2.4 KiB
C++
99 lines
2.4 KiB
C++
/*
|
|
* Copyright 2015 - 2022 gary@drinkingtea.net
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "defines.hpp"
|
|
#include "types.hpp"
|
|
#include "memops.hpp"
|
|
|
|
#ifndef OX_USE_STDLIB
|
|
|
|
#define ox_inhibit_loop_to_libcall __attribute__((__optimize__("-fno-tree-loop-distribute-patterns")))
|
|
|
|
extern "C" {
|
|
|
|
void *ox_inhibit_loop_to_libcall memcpy(void *dest, const void *src, std::size_t size) {
|
|
return ox::memcpy(dest, src, size);
|
|
}
|
|
|
|
void *ox_inhibit_loop_to_libcall memmove(void *dest, const void *src, std::size_t size) {
|
|
return ox::memcpy(dest, src, size);
|
|
}
|
|
|
|
void *ox_inhibit_loop_to_libcall memset(void *ptr, int val, std::size_t size) {
|
|
return ox::memset(ptr, val, size);
|
|
}
|
|
|
|
|
|
int ox_inhibit_loop_to_libcall memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept {
|
|
int retval = 0;
|
|
auto block1 = reinterpret_cast<const uint8_t*>(ptr1);
|
|
auto block2 = reinterpret_cast<const uint8_t*>(ptr2);
|
|
for (std::size_t i = 0; i < size; i++) {
|
|
if (block1[i] < block2[i]) {
|
|
retval = -1;
|
|
break;
|
|
} else if (block1[i] > block2[i]) {
|
|
retval = 1;
|
|
break;
|
|
}
|
|
}
|
|
return retval;
|
|
}
|
|
|
|
}
|
|
|
|
#undef ox_inhibit_loop_to_libcall
|
|
|
|
#endif
|
|
|
|
namespace ox {
|
|
|
|
void *memmove(void *dest, const void *src, std::size_t size) noexcept {
|
|
if constexpr(!ox::defines::UseStdLib) {
|
|
auto srcBuf = static_cast<const char*>(src);
|
|
auto dstBuf = static_cast<char*>(dest);
|
|
for (std::size_t i = 0; i < size; ++i) {
|
|
dstBuf[i] = static_cast<char>(srcBuf[i]);
|
|
}
|
|
return dest;
|
|
} else {
|
|
return ::memmove(dest, src, size);
|
|
}
|
|
}
|
|
|
|
void *memset(void *ptr, int val, std::size_t size) noexcept {
|
|
if constexpr(!ox::defines::UseStdLib) {
|
|
auto buf = static_cast<uint8_t*>(ptr);
|
|
for (std::size_t i = 0; i < size; ++i) {
|
|
buf[i] = static_cast<uint8_t>(val);
|
|
}
|
|
return ptr;
|
|
} else {
|
|
return ::memset(ptr, val, size);
|
|
}
|
|
}
|
|
|
|
void *memcpy(void *dest, const void *src, std::size_t size) noexcept {
|
|
if constexpr(!ox::defines::UseStdLib) {
|
|
auto srcBuf = static_cast<const char*>(src);
|
|
auto dstBuf = static_cast<char*>(dest);
|
|
for (std::size_t i = 0; i < size; ++i) {
|
|
dstBuf[i] = static_cast<char>(srcBuf[i]);
|
|
}
|
|
return dest;
|
|
} else {
|
|
return ::memcpy(dest, src, size);
|
|
}
|
|
}
|
|
|
|
int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept {
|
|
return ::memcmp(ptr1, ptr2, size);
|
|
}
|
|
|
|
}
|