summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcadmic <cadmic24@gmail.com>2024-08-19 22:15:24 -0700
committerGitHub <noreply@github.com>2024-08-20 01:15:24 -0400
commitec70295357c198c48660e2ab5670c15ef6a661cf (patch)
tree0c46c5493c7538ced1e2d1ab6344251bd2673d31 /src
parentaba1bb88a3ed369ab450345a65f0176ceb0e482c (diff)
Move non-libultra libc functions to src/libc/ (#2055)
* Move non-libultra libc functions to src/libc/ * Add explicit nops in delay slots * Don't rely on CPP expanding undefined macros to 0 * Delete old Makefile rules * Fix type of memset()
Diffstat (limited to 'src')
-rw-r--r--src/code/__osMalloc.c12
-rw-r--r--src/code/code_80069420.c2
-rw-r--r--src/code/z_camera.c2
-rw-r--r--src/code/z_lib.c2
-rw-r--r--src/code/z_quake.c2
-rw-r--r--src/code/z_view.c2
-rw-r--r--src/gcc_fix/missing_gcc_functions.c32
-rw-r--r--src/libc/absf.s15
-rw-r--r--src/libc/fmodf.c (renamed from src/code/fmodf.c)0
-rw-r--r--src/libc/memmove.c (renamed from src/code/__osMemmove.c)2
-rw-r--r--src/libc/memset.c (renamed from src/code/__osMemset.c)4
-rw-r--r--src/libc/sqrt.s15
-rw-r--r--src/libultra/libc/absf.c9
-rw-r--r--src/libultra/libc/sqrt.c9
14 files changed, 44 insertions, 64 deletions
diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c
index 5c4a423d2..bcd0132db 100644
--- a/src/code/__osMalloc.c
+++ b/src/code/__osMalloc.c
@@ -25,15 +25,15 @@
#define FILL_ALLOC_BLOCK(arena, alloc, size) \
if ((arena)->flag & FILL_ALLOC_BLOCK_FLAG) \
- __osMemset(alloc, BLOCK_ALLOC_MAGIC, size)
+ memset(alloc, BLOCK_ALLOC_MAGIC, size)
#define FILL_FREE_BLOCK_HEADER(arena, node) \
if ((arena)->flag & FILL_FREE_BLOCK_FLAG) \
- __osMemset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode))
+ memset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode))
#define FILL_FREE_BLOCK_CONTENTS(arena, node) \
if ((arena)->flag & FILL_FREE_BLOCK_FLAG) \
- __osMemset((void*)((u32)(node) + sizeof(ArenaNode)), BLOCK_FREE_MAGIC, (node)->size)
+ memset((void*)((u32)(node) + sizeof(ArenaNode)), BLOCK_FREE_MAGIC, (node)->size)
#define CHECK_FREE_BLOCK(arena, node) \
if ((arena)->flag & CHECK_FREE_BLOCK_FLAG) \
@@ -179,7 +179,7 @@ void __osMallocAddBlock(Arena* arena, void* start, s32 size) {
if (size2 > (s32)sizeof(ArenaNode)) {
#if OOT_DEBUG
- __osMemset(firstNode, BLOCK_UNINIT_MAGIC, size2);
+ memset(firstNode, BLOCK_UNINIT_MAGIC, size2);
#endif
firstNode->next = NULL;
firstNode->prev = NULL;
@@ -210,7 +210,7 @@ void ArenaImpl_RemoveAllBlocks(Arena* arena) {
iter = arena->head;
while (iter != NULL) {
next = NODE_GET_NEXT(iter);
- __osMemset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode));
+ memset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode));
iter = next;
}
@@ -635,7 +635,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
}
node->next = newNext;
node->size = newSize;
- __osMemmove(node->next, next, sizeof(ArenaNode));
+ memmove(node->next, next, sizeof(ArenaNode));
} else {
// "Allocate a new memory block and move the contents"
osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n");
diff --git a/src/code/code_80069420.c b/src/code/code_80069420.c
index 9a190edcf..a08567dd6 100644
--- a/src/code/code_80069420.c
+++ b/src/code/code_80069420.c
@@ -27,7 +27,7 @@ void* MemCpy(void* dest, const void* src, s32 len) {
/**
* memset: sets `len` bytes to `val` starting at address `dest`.
*
- * @see There are two other memsets in this codebase, Lib_MemSet(), __osMemset().
+ * @see There are two other memsets in this codebase, Lib_MemSet(), memset().
* This one is unused.
*
* @param dest address to start at
diff --git a/src/code/z_camera.c b/src/code/z_camera.c
index 019a4a895..9597e7c19 100644
--- a/src/code/z_camera.c
+++ b/src/code/z_camera.c
@@ -7449,7 +7449,7 @@ void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, PlayState
s16 curUID;
s16 j;
- __osMemset(camera, 0, sizeof(Camera));
+ memset(camera, 0, sizeof(Camera));
if (sInitRegs) {
s32 i;
diff --git a/src/code/z_lib.c b/src/code/z_lib.c
index 5eba9346f..d5f59a2a8 100644
--- a/src/code/z_lib.c
+++ b/src/code/z_lib.c
@@ -16,7 +16,7 @@
* - the arguments are in a different order,
* - `val` is a `u8` instead of the standard `s32`.
*
- * @see There are two other memsets in this codebase, __osMemset(), MemSet()
+ * @see There are two other memsets in this codebase, memset(), MemSet()
*
* @param dest address to start at
* @param len number of bytes to write
diff --git a/src/code/z_quake.c b/src/code/z_quake.c
index 317d05347..4c318b938 100644
--- a/src/code/z_quake.c
+++ b/src/code/z_quake.c
@@ -170,7 +170,7 @@ QuakeRequest* Quake_RequestImpl(Camera* camera, u32 type) {
s16 index = Quake_GetFreeIndex();
QuakeRequest* req = &sQuakeRequests[index];
- __osMemset(req, 0, sizeof(QuakeRequest));
+ memset(req, 0, sizeof(QuakeRequest));
req->cam = camera;
req->camId = camera->camId;
diff --git a/src/code/z_view.c b/src/code/z_view.c
index 31563b959..780fd7f40 100644
--- a/src/code/z_view.c
+++ b/src/code/z_view.c
@@ -24,7 +24,7 @@ View* View_New(GraphicsContext* gfxCtx) {
View* view = SYSTEM_ARENA_MALLOC(sizeof(View), "../z_view.c", 285);
if (view != NULL) {
- __osMemset(view, 0, sizeof(View));
+ memset(view, 0, sizeof(View));
View_Init(view, gfxCtx);
}
diff --git a/src/gcc_fix/missing_gcc_functions.c b/src/gcc_fix/missing_gcc_functions.c
index b95556937..76bf8e9db 100644
--- a/src/gcc_fix/missing_gcc_functions.c
+++ b/src/gcc_fix/missing_gcc_functions.c
@@ -26,38 +26,6 @@ int memcmp(const void* s1, const void* s2, size_t n) {
return 0;
}
-void* memset(void* str, int c, size_t n) {
- u8* m = str;
- size_t i;
-
- for (i = 0; i < n; i++) {
- m[i] = c;
- }
-
- return str;
-}
-
-void* memmove(void* dest, const void* src, size_t len) {
- u8* d = dest;
- const u8* s = src;
-
- if (d == s) {
- return dest;
- }
- if (d < s) {
- while (len--) {
- *d++ = *s++;
- }
- } else {
- d += len - 1;
- s += len - 1;
- while (len--) {
- *d-- = *s--;
- }
- }
- return dest;
-}
-
// Conversions involving 64-bit integer types required by the O32 MIPS ABI.
// f32 -> u64, negative values become 0
diff --git a/src/libc/absf.s b/src/libc/absf.s
new file mode 100644
index 000000000..9df0c0a38
--- /dev/null
+++ b/src/libc/absf.s
@@ -0,0 +1,15 @@
+#include "ultra64/asm.h"
+
+#if OOT_DEBUG
+.set noreorder
+#endif
+
+.section .text
+
+.balign 16
+
+LEAF(absf)
+ abs.s $f0, $f12
+ jr $ra
+ nop
+END(absf)
diff --git a/src/code/fmodf.c b/src/libc/fmodf.c
index 4ebec43bd..4ebec43bd 100644
--- a/src/code/fmodf.c
+++ b/src/libc/fmodf.c
diff --git a/src/code/__osMemmove.c b/src/libc/memmove.c
index 892fee5ee..8ff5ec5f6 100644
--- a/src/code/__osMemmove.c
+++ b/src/libc/memmove.c
@@ -11,7 +11,7 @@
*
* @return dest
*/
-void* __osMemmove(void* dest, const void* src, size_t len) {
+void* memmove(void* dest, const void* src, size_t len) {
u8* d = dest;
const u8* s = src;
diff --git a/src/code/__osMemset.c b/src/libc/memset.c
index 703d3a8c1..ec699c7ce 100644
--- a/src/code/__osMemset.c
+++ b/src/libc/memset.c
@@ -6,12 +6,12 @@
* @see There are two other memsets in this codebase, Lib_MemSet(), MemSet()
*
* @param dest address to start at
- * @param val value to write (s32, but interpreted as u8)
+ * @param val value to write (int, but interpreted as u8)
* @param len number of bytes to write
*
* @return dest
*/
-void* __osMemset(void* dest, s32 val, size_t len) {
+void* memset(void* dest, int val, size_t len) {
u8* ptr = dest;
while (len--) {
diff --git a/src/libc/sqrt.s b/src/libc/sqrt.s
new file mode 100644
index 000000000..b4246ec86
--- /dev/null
+++ b/src/libc/sqrt.s
@@ -0,0 +1,15 @@
+#include "ultra64/asm.h"
+
+#if OOT_DEBUG
+.set noreorder
+#endif
+
+.section .text
+
+.balign 16
+
+LEAF(sqrt)
+ sqrt.d $f0, $f12
+ jr $ra
+ nop
+END(sqrt)
diff --git a/src/libultra/libc/absf.c b/src/libultra/libc/absf.c
deleted file mode 100644
index 73c99f460..000000000
--- a/src/libultra/libc/absf.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "global.h"
-
-float absf(float n) {
-#ifndef __GNUC__
- return fabsf(n);
-#else
- return __builtin_fabsf(n);
-#endif
-}
diff --git a/src/libultra/libc/sqrt.c b/src/libultra/libc/sqrt.c
deleted file mode 100644
index a9a4403a3..000000000
--- a/src/libultra/libc/sqrt.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "global.h"
-
-double sqrt(double f) {
-#ifndef __GNUC__
- return sqrt(f);
-#else
- return __builtin_sqrt(f);
-#endif
-}