#include "memory.h"

#if !CRTLIB

__attribute((section(".text.memcpy")))
void *memcpy(void *__restrict dest, const void *__restrict src, u64 n)
{
    /* TODO: Faster memcpy */
    for (u64 i = 0; i < n; ++i) {
        ((u8 *)dest)[i] = ((u8 *)src)[i];
    }
    return dest;
}

__attribute((section(".text.memset")))
void *memset(void *dest, i32 c, u64 n)
{
    /* TODO: Faster memset */
    for (u64 i = 0; i < n; ++i) {
        ((u8 *)dest)[i] = c;
    }
    return dest;
}

__attribute((section(".text.memcmp")))
i32 memcmp(const void *p1, const void *p2, u64 n)
{
    i32 res = 0;
    for (u64 i = 0; i < n; ++i) {
        res = ((u8 *)p1)[i] - ((u8 *)p2)[i];
        if (res != 0) {
            break;
        }
    }
    return res;
}

#endif  /* !CRTLIB */
