diff options
Diffstat (limited to 'src/libc')
| -rw-r--r-- | src/libc/absf.s | 15 | ||||
| -rw-r--r-- | src/libc/fmodf.c | 27 | ||||
| -rw-r--r-- | src/libc/memmove.c | 33 | ||||
| -rw-r--r-- | src/libc/memset.c | 21 | ||||
| -rw-r--r-- | src/libc/sqrt.s | 15 |
5 files changed, 111 insertions, 0 deletions
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/libc/fmodf.c b/src/libc/fmodf.c new file mode 100644 index 000000000..4ebec43bd --- /dev/null +++ b/src/libc/fmodf.c @@ -0,0 +1,27 @@ +#include "ultra64.h" + +/** + * Computes one `x` modulo `y` for floats. + * + * Acts like the standard C fmodf except does not handle Infinity. See https://en.cppreference.com/w/c/numeric/math/fmod + * for the details. It summarizes this function as follows: + * "The floating-point remainder of the division operation x/y calculated by this function is exactly the value x - n*y, + * where n is x/y with its fractional part truncated. + * + * The returned value has the same sign as x and is less or equal to y in magnitude." + * + * @param x dividend + * @param y modulus + * + * @return f32 0.0f if y is 0.0f, or x modulo y otherwise + */ +f32 fmodf(f32 x, f32 y) { + s32 n; + + if (y == 0.0f) { + return 0.0f; + } + n = x / y; + + return x - (n * y); +} diff --git a/src/libc/memmove.c b/src/libc/memmove.c new file mode 100644 index 000000000..8ff5ec5f6 --- /dev/null +++ b/src/libc/memmove.c @@ -0,0 +1,33 @@ +#include "global.h" + +/** + * memmove: copies `len` bytes from memory starting at `src` to memory starting at `dest`. + * + * Unlike memcpy(), the regions of memory may overlap. + * + * @param dest address of start of buffer to write to + * @param src address of start of buffer to read from + * @param len number of bytes to copy. + * + * @return dest + */ +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; +} diff --git a/src/libc/memset.c b/src/libc/memset.c new file mode 100644 index 000000000..ec699c7ce --- /dev/null +++ b/src/libc/memset.c @@ -0,0 +1,21 @@ +#include "global.h" + +/** + * memset: sets `len` bytes to `val` starting at address `dest`. + * + * @see There are two other memsets in this codebase, Lib_MemSet(), MemSet() + * + * @param dest address to start at + * @param val value to write (int, but interpreted as u8) + * @param len number of bytes to write + * + * @return dest + */ +void* memset(void* dest, int val, size_t len) { + u8* ptr = dest; + + while (len--) { + *ptr++ = val; + } + return dest; +} 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) |
