mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-05-04 03:23:56 +00:00
Some checks are pending
CI / clang-format (push) Waiting to run
CI / ${{ matrix.name }} (false, --toolchain $GITHUB_WORKSPACE/CMake/i586-pc-msdosdjgpp.cmake, false, true, false, Ninja, DOS, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, --toolchain /usr/local/vitasdk/share/vita.toolchain.cmake, false, false, Ninja, Vita, ubuntu-latest, true, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.26100.0, false, false, Visual Studio 17 2022, true, Xbox One, windows-latest, amd64, false, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake, false, devkitpro/devkitarm:latest, false, Ninja, true, Nintendo 3DS, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake, false, devkitpro/devkita64:latest, false, Ninja, Nintendo Switch, true, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, emcmake, false, false, true, Ninja, Emscripten, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, false, Ninja, true, MSVC (arm64), windows-latest, amd64_arm64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, true, Ninja, true, MSVC (x86), windows-latest, amd64_x86, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, false, Ninja, true, MSVC (x64), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, true, false, Ninja, true, MSVC (x64 Debug), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, -DCMAKE_SYSTEM_NAME=iOS, false, false, Xcode, true, iOS, macos-15, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, false, false, Ninja, Android, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, true, false, Ninja, macOS, macos-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, false, Ninja, true, mingw-w64-x86_64, mingw64, msys2 mingw64, windows-latest, msys2 {0}, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux (Debug), ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux, ubuntu-latest, true) (push) Waiting to run
CI / FreeBSD (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (aarch64, ubuntu-22.04-arm) (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (x86_64, ubuntu-latest) (push) Waiting to run
CI / C++ (push) Waiting to run
CI / Release (push) Blocked by required conditions
Docker / Publish web port (push) Waiting to run
Co-authored-by: Anonymous Maarten <anonymous.maarten@gmail.com>
110 lines
2.7 KiB
C
110 lines
2.7 KiB
C
/*
|
|
* Non-atomic 64-bit __atomic_*_8 stubs for DJGPP / DOS.
|
|
*
|
|
* DOS is single-threaded so real atomics are unnecessary. GCC emits calls to
|
|
* these helper functions when targeting i486 (or when __i586__ is undefined)
|
|
* because the ISA lacks a native 64-bit atomic instruction. Normally libatomic
|
|
* provides them, but DJGPP doesn't ship libatomic.
|
|
*
|
|
* Every function simply performs a plain (non-atomic) load/store/exchange/CAS
|
|
* which is perfectly safe in a single-threaded environment.
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
uint64_t __atomic_load_8(const volatile void *ptr, int memorder)
|
|
{
|
|
(void)memorder;
|
|
uint64_t val;
|
|
memcpy(&val, (const void *)ptr, sizeof(val));
|
|
return val;
|
|
}
|
|
|
|
void __atomic_store_8(volatile void *ptr, uint64_t val, int memorder)
|
|
{
|
|
(void)memorder;
|
|
memcpy((void *)ptr, &val, sizeof(val));
|
|
}
|
|
|
|
uint64_t __atomic_exchange_8(volatile void *ptr, uint64_t val, int memorder)
|
|
{
|
|
(void)memorder;
|
|
uint64_t old;
|
|
memcpy(&old, (void *)ptr, sizeof(old));
|
|
memcpy((void *)ptr, &val, sizeof(val));
|
|
return old;
|
|
}
|
|
|
|
int __atomic_compare_exchange_8(
|
|
volatile void *ptr,
|
|
void *expected,
|
|
uint64_t desired,
|
|
int success_memorder,
|
|
int failure_memorder
|
|
)
|
|
{
|
|
(void)success_memorder;
|
|
(void)failure_memorder;
|
|
uint64_t current;
|
|
memcpy(¤t, (void *)ptr, sizeof(current));
|
|
uint64_t exp;
|
|
memcpy(&exp, expected, sizeof(exp));
|
|
if (current == exp) {
|
|
memcpy((void *)ptr, &desired, sizeof(desired));
|
|
return 1;
|
|
}
|
|
memcpy(expected, ¤t, sizeof(current));
|
|
return 0;
|
|
}
|
|
|
|
uint64_t __atomic_fetch_add_8(volatile void *ptr, uint64_t val, int memorder)
|
|
{
|
|
(void)memorder;
|
|
uint64_t old;
|
|
memcpy(&old, (void *)ptr, sizeof(old));
|
|
uint64_t new_val = old + val;
|
|
memcpy((void *)ptr, &new_val, sizeof(new_val));
|
|
return old;
|
|
}
|
|
|
|
uint64_t __atomic_fetch_sub_8(volatile void *ptr, uint64_t val, int memorder)
|
|
{
|
|
(void)memorder;
|
|
uint64_t old;
|
|
memcpy(&old, (void *)ptr, sizeof(old));
|
|
uint64_t new_val = old - val;
|
|
memcpy((void *)ptr, &new_val, sizeof(new_val));
|
|
return old;
|
|
}
|
|
|
|
uint64_t __atomic_fetch_and_8(volatile void *ptr, uint64_t val, int memorder)
|
|
{
|
|
(void)memorder;
|
|
uint64_t old;
|
|
memcpy(&old, (void *)ptr, sizeof(old));
|
|
uint64_t new_val = old & val;
|
|
memcpy((void *)ptr, &new_val, sizeof(new_val));
|
|
return old;
|
|
}
|
|
|
|
uint64_t __atomic_fetch_or_8(volatile void *ptr, uint64_t val, int memorder)
|
|
{
|
|
(void)memorder;
|
|
uint64_t old;
|
|
memcpy(&old, (void *)ptr, sizeof(old));
|
|
uint64_t new_val = old | val;
|
|
memcpy((void *)ptr, &new_val, sizeof(new_val));
|
|
return old;
|
|
}
|
|
|
|
uint64_t __atomic_fetch_xor_8(volatile void *ptr, uint64_t val, int memorder)
|
|
{
|
|
(void)memorder;
|
|
uint64_t old;
|
|
memcpy(&old, (void *)ptr, sizeof(old));
|
|
uint64_t new_val = old ^ val;
|
|
memcpy((void *)ptr, &new_val, sizeof(new_val));
|
|
return old;
|
|
}
|