QoL improvements

This commit is contained in:
Alex
2023-03-27 20:11:32 +03:00
parent 3eb6923374
commit 93afcd2210
59 changed files with 612 additions and 424 deletions

View File

@ -20,13 +20,13 @@ EXTERNC int memcmp(const void *vl, const void *vr, size_t n)
EXTERNC void backspace(char s[])
{
int len = strlen(s);
int len = s_cst(int, strlen(s));
s[len - 1] = '\0';
}
EXTERNC void append(char s[], char n)
{
int len = strlen(s);
int len = s_cst(int, strlen(s));
s[len] = n;
s[len + 1] = '\0';
}
@ -184,7 +184,7 @@ EXTERNC long int strtol(const char *str, char **endptr, int base)
base = c == '0' ? 8 : 10;
cutoff = neg ? LONG_MIN : LONG_MAX;
cutlim = cutoff % base;
cutlim = s_cst(int, cutoff % base);
cutoff /= base;
for (acc = 0, any = 0;; c = *s++)
{
@ -249,7 +249,7 @@ EXTERNC unsigned long int strtoul(const char *str, char **endptr, int base)
base = c == '0' ? 8 : 10;
cutoff = neg ? LONG_MIN : LONG_MAX;
cutlim = cutoff % base;
cutlim = s_cst(int, cutoff % base);
cutoff /= base;
for (acc = 0, any = 0;; c = *s++)
{
@ -342,8 +342,12 @@ EXTERNC float sqrtf(float x)
float guess = x / 2.0f;
for (short i = 0; i < 10; i++)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
if (guess == 0.0f)
return 0.0f;
#pragma GCC diagnostic pop
guess = (guess + x / guess) / 2.0f;
}
return guess;
@ -366,7 +370,10 @@ EXTERNC float lerp(float a, float b, float t)
EXTERNC float smoothstep(float a, float b, float t)
{
t = clamp(t, 0.0, 1.0);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-conversion"
t = clamp(s_cst(double, t), 0.0, 1.0);
#pragma GCC diagnostic pop
return lerp(a, b, t * t * (3 - 2 * t));
}
@ -420,8 +427,8 @@ EXTERNC char *strtok(char *src, const char *delim)
EXTERNC int atoi(const char *String)
{
uint64_t Length = strlen((char *)String);
uint64_t OutBuffer = 0;
uint64_t Power = 1;
int OutBuffer = 0;
int Power = 1;
for (uint64_t i = Length; i > 0; --i)
{
OutBuffer += (String[i - 1] - 48) * Power;
@ -517,16 +524,16 @@ EXTERNC char *itoa(int Value, char *Buffer, int Base)
if (Base < 2 || Base > 32)
return Buffer;
int n = abs(Value);
int n = s_cst(int, abs(Value));
int i = 0;
while (n)
{
int r = n % Base;
int r = s_cst(int, n % Base);
if (r >= 10)
Buffer[i++] = 65 + (r - 10);
Buffer[i++] = s_cst(char, 65 + (r - 10));
else
Buffer[i++] = 48 + r;
Buffer[i++] = s_cst(char, 48 + r);
n = n / Base;
}
@ -550,11 +557,11 @@ EXTERNC char *ltoa(long Value, char *Buffer, int Base)
while (n)
{
int r = n % Base;
int r = s_cst(int, n % Base);
if (r >= 10)
Buffer[i++] = 65 + (r - 10);
Buffer[i++] = s_cst(char, 65 + (r - 10));
else
Buffer[i++] = 48 + r;
Buffer[i++] = s_cst(char, 48 + r);
n = n / Base;
}
@ -578,11 +585,11 @@ EXTERNC char *ultoa(unsigned long Value, char *Buffer, int Base)
while (n)
{
int r = n % Base;
int r = s_cst(int, n % Base);
if (r >= 10)
Buffer[i++] = 65 + (r - 10);
Buffer[i++] = s_cst(char, 65 + (r - 10));
else
Buffer[i++] = 48 + r;
Buffer[i++] = s_cst(char, 48 + r);
n = n / Base;
}

View File

@ -4,6 +4,9 @@
#include <limits.h>
#include <debug.h>
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
/* Some of the functions are from musl library */
/* https://www.musl-libc.org/ */
/*
@ -85,9 +88,11 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
}
if (n >= 32)
{
switch ((uintptr_t)d % 4)
{
case 1:
{
w = *(u32 *)s;
*d++ = *s++;
*d++ = *s++;
@ -105,7 +110,9 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
*(u32 *)(d + 12) = (x LS 24) | (w RS 8);
}
break;
}
case 2:
{
w = *(u32 *)s;
*d++ = *s++;
*d++ = *s++;
@ -122,7 +129,9 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
*(u32 *)(d + 12) = (x LS 16) | (w RS 16);
}
break;
}
case 3:
{
w = *(u32 *)s;
*d++ = *s++;
n -= 1;
@ -139,6 +148,11 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
}
break;
}
default:
break;
}
}
if (n & 16)
{
*d++ = *s++;
@ -158,6 +172,7 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
*d++ = *s++;
*d++ = *s++;
}
if (n & 8)
{
*d++ = *s++;
@ -169,6 +184,7 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
*d++ = *s++;
*d++ = *s++;
}
if (n & 4)
{
*d++ = *s++;
@ -176,11 +192,13 @@ void *memcpy_unsafe(void *dest, const void *src, size_t n)
*d++ = *s++;
*d++ = *s++;
}
if (n & 2)
{
*d++ = *s++;
*d++ = *s++;
}
if (n & 1)
{
*d = *s;
@ -200,18 +218,24 @@ void *memset_unsafe(void *dest, int c, size_t n)
if (!n)
return dest;
s[0] = c;
s[n - 1] = c;
if (n <= 2)
return dest;
s[1] = c;
s[2] = c;
s[n - 2] = c;
s[n - 3] = c;
if (n <= 6)
return dest;
s[3] = c;
s[n - 4] = c;
if (n <= 8)
return dest;
@ -227,14 +251,18 @@ void *memset_unsafe(void *dest, int c, size_t n)
u32 c32 = ((u32)-1) / 255 * (unsigned char)c;
*(u32 *)(s + 0) = c32;
*(u32 *)(s + n - 4) = c32;
if (n <= 8)
return dest;
*(u32 *)(s + 4) = c32;
*(u32 *)(s + 8) = c32;
*(u32 *)(s + n - 12) = c32;
*(u32 *)(s + n - 8) = c32;
if (n <= 24)
return dest;
*(u32 *)(s + 12) = c32;
*(u32 *)(s + 16) = c32;
*(u32 *)(s + 20) = c32;
@ -276,6 +304,7 @@ void *memmove_unsafe(void *dest, const void *src, size_t n)
if (d == s)
return d;
if ((uintptr_t)s - (uintptr_t)d - n <= -2 * n)
return memcpy(d, s, n);
@ -288,6 +317,7 @@ void *memmove_unsafe(void *dest, const void *src, size_t n)
{
if (!n--)
return dest;
*d++ = *s++;
}
for (; n >= WS; n -= WS, d += WS, s += WS)
@ -306,6 +336,7 @@ void *memmove_unsafe(void *dest, const void *src, size_t n)
{
if (!n--)
return dest;
d[n] = s[n];
}
while (n >= WS)

View File

@ -23,6 +23,7 @@ SOFTWARE.
*/
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#include <assert.h>
#include <cargs.h>

View File

@ -1,5 +1,8 @@
#include "liballoc_1_1.h"
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
/** Durand's Amazing Super Duper Memory functions. */
#define VERSION "1.1"

View File

@ -37,6 +37,8 @@
* THE SOFTWARE.
*/
#pragma GCC diagnostic ignored "-Wfloat-equal"
// Define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H=1 ...) to include the
// printf_config.h header file
#if PRINTF_INCLUDE_CONFIG_H
@ -354,6 +356,8 @@ static inline NIF void append_termination_with_gadget(output_gadget_t *gadget)
gadget->buffer[null_char_pos] = '\0';
}
extern void putchar(char c);
// We can't use putchar_ as is, since our output gadget
// only takes pointers to functions with an extra argument
static inline NIF void putchar_wrapper(char c, void *unused)