diff options
| author | Elijah Thomas <42302100+elijah-thomas774@users.noreply.github.com> | 2025-02-09 12:40:41 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-09 12:40:41 -0500 |
| commit | cec09ad02349a1058e2255d2bc0b68ad69885075 (patch) | |
| tree | 115af5aee890e1a0fd3a0b3031beefac35cfd308 /src/PowerPC_EABI_Support | |
| parent | 85bef3afb9605a6f084e35b5740a5f1b6655bfe3 (diff) | |
g3d initial pullover (#115)
* g3d Headers
* initial g3d source files -- NOT YET FIXED
* change ResFile static_cast to explicit ctor
Diffstat (limited to 'src/PowerPC_EABI_Support')
15 files changed, 432 insertions, 4 deletions
diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/algorithm b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/algorithm new file mode 100644 index 00000000..aa6ec1d2 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/algorithm @@ -0,0 +1,220 @@ +#ifndef MSL_CPP_ALGORITHM_H +#define MSL_CPP_ALGORITHM_H +#include <iterator> + +namespace std { + +template <typename T> inline const T& max(const T& a, const T& b) { + return (a < b) ? b : a; +} + +template <typename T> inline const T& min(const T& a, const T& b) { + return (b < a) ? b : a; +} + +template <typename TPtr, typename T> +inline TPtr find(TPtr first, TPtr last, const T& value) { + while (first != last && *first != value) { + ++first; + } + + return first; +} + +template <typename TPtr> inline long distance(TPtr first, TPtr last) { + random_access_iterator_tag tag; + return __distance(first, last, tag); +} + +template <typename TPtr> +inline long __distance(TPtr first, TPtr last, + random_access_iterator_tag /* tag */) { + return static_cast<long>(last - first); +} + +template <typename T> inline T& move(T& x) { + return x; +} + +template <typename T> inline void swap(T& a, T& b) { + T tmp = move(a); + a = move(b); + b = move(tmp); +} + +template <typename TIt, typename TCompare> +inline TIt min_element(TIt first, TIt last, TCompare compare) { + TIt it = first; + + if (first != last) { + for (++first; first != last; ++first) { + if (compare(*first, *it)) { + it = first; + } + } + } + + return it; +} + +template <typename TCompare, typename TIt> +inline void __selection_sort(TIt first, TIt last, TCompare compare) { + if (first == last) { + return; + } + + TIt j = last; + for (--j; first != j; ++first) { + TIt i = min_element<TIt, TCompare&>(first, last, compare); + + if (i != first) { + swap(*i, *first); + } + } +} + +template <typename TCompare, typename TIt> +void __sort132(TIt a1, TIt a2, TIt a3, TCompare compare) + __attribute__((never_inline)) { + bool b1 = !compare(*a3, *a1); + bool b2 = !compare(*a2, *a3); + + if (!b1 || !b2) { + if (!b1 && !b2) { + swap(*a1, *a2); + return; + } + + if (compare(*a2, *a1)) { + swap(*a1, *a2); + } + + if (b1) { + swap(*a2, *a3); + return; + } + + swap(*a1, *a3); + } +} + +template <typename TIt, typename TCompare> +void sort(TIt first, TIt last, TCompare compare) { + static const int SHUFFLE_MIN = -4; + static const int SHUFFLE_MAX = 5; + static const int SELECTION_SORT_MIN = 20; + + while (true) { + long len = static_cast<long>(last - first); + if (len <= 1) { + return; + } + + if (len <= SELECTION_SORT_MIN) { + __selection_sort<TCompare&, TIt>(first, last, compare); + return; + } + + static int shuffle = -4; + TIt m = first + + (len / static_cast<long>(sizeof(TIt)) + shuffle % SHUFFLE_MAX); + + if (++shuffle >= SHUFFLE_MAX) { + shuffle = SHUFFLE_MIN; + } + + TIt i1 = first + (len * static_cast<long>(sizeof(TIt) - 1) / + static_cast<long>(sizeof(TIt)) + + shuffle % SHUFFLE_MAX); + + if (++shuffle >= SHUFFLE_MAX) { + shuffle = SHUFFLE_MIN; + } + + TIt j = last - 1; + __sort132<TCompare&, TIt>(m, i1, j, compare); + + m = first; + i1 = j; + while (compare(*m, *j)) { + m++; + } + + do { + i1--; + + if (m == i1) { + break; + } + } while (!compare(*i1, *j)); + + if (m < i1) { + swap(*m, *i1); + m++; + + while (true) { + while (compare(*m, *j)) { + m++; + } + + while (!compare(*--i1, *j)) { + ; + } + + if (m < i1) { + swap(*m, *i1); + m++; + } else { + break; + } + } + } + + if (m == first) { + swap(*m, *j); + m++; + + i1 = last; + if (!compare(*first, *--i1)) { + while (m != last && !compare(*first, *m)) { + m++; + } + + if (m < i1) { + swap(*m, *i1); + } + } + + if (m < i1) { + while (true) { + while (!compare(*first, *m)) { + m++; + } + + while (compare(*first, *--i1)) { + ; + } + + if (m < i1) { + swap(*m, *i1); + m++; + } else { + break; + } + } + } + + first = m; + } else if (m - first < last - m) { + sort<TIt, TCompare&>(first, m, compare); + first = m; + } else { + sort<TIt, TCompare&>(m, last, compare); + last = m; + } + } +} + +} // namespace std + +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cctype b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cctype new file mode 100644 index 00000000..a4fa1ede --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cctype @@ -0,0 +1,12 @@ +#ifndef MSL_CPP_CCTYPE_H +#define MSL_CPP_CCTYPE_H +#include <ctype.h> +#ifdef __cplusplus + +namespace std { +using ::tolower; +using ::toupper; +} // namespace std + +#endif +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cerrno b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cerrno new file mode 100644 index 00000000..f371e9b9 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cerrno @@ -0,0 +1,4 @@ +#ifndef MSL_CPP_CERRNO_H +#define MSL_CPP_CERRNO_H +#include <errno.h> +#endif
\ No newline at end of file diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/climits b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/climits new file mode 100644 index 00000000..0740fc20 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/climits @@ -0,0 +1,4 @@ +#ifndef MSL_CPP_CLIMITS_H +#define MSL_CPP_CLIMITS_H +#include <limits.h> +#endif
\ No newline at end of file diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cmath b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cmath new file mode 100644 index 00000000..7517fae0 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cmath @@ -0,0 +1,58 @@ +#ifndef MSL_CPP_CMATH_H +#define MSL_CPP_CMATH_H +#include <math.h> +#ifdef __cplusplus + +// Remove C macro +#undef fabs + +namespace std { +using ::acos; +using ::acosf; +using ::asin; +// using ::asinf; +using ::atan; +using ::atan2; +using ::atan2f; +using ::ceil; +using ::ceilf; +using ::copysign; +using ::cos; +using ::cosf; +using ::fabsf; +using ::floor; +using ::floorf; +using ::fmod; +using ::fmodf; +using ::frexp; +using ::ldexp; +// using ::ldexpf; +using ::modf; +using ::modff; +// using ::nan; +using ::pow; +using ::scalbn; +using ::sin; +using ::sinf; +using ::sqrt; +using ::sqrtf; +using ::tan; +using ::tanf; + +inline float sqrt(float x) { + return ::sqrtf(x); +} + +// TODO: Very fake! +// inline double fabs_wrapper(double x) { +// return __fabs(x); +// } + +// inline float fabs(float x) { +// return fabs_wrapper(x); +// } + +} // namespace std + +#endif +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstddef b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstddef new file mode 100644 index 00000000..c853dd85 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstddef @@ -0,0 +1,14 @@ +#ifndef MSL_CPP_CSTDDEF_H +#define MSL_CPP_CSTDDEF_H +#include <stddef.h> +#ifdef __cplusplus + +namespace std { +using ::intptr_t; +using ::ptrdiff_t; +using ::size_t; +using ::uintptr_t; +} // namespace std + +#endif +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstdio b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstdio new file mode 100644 index 00000000..4c995a0d --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstdio @@ -0,0 +1,21 @@ +#ifndef MSL_CPP_CSTDIO_H +#define MSL_CPP_CSTDIO_H +#include <stdio.h> +#ifdef __cplusplus + +namespace std { +using ::fclose; +using ::fflush; +using ::FILE; +// using ::ftell; +// using ::fwide; +using ::snprintf; +using ::sprintf; +// using ::sscanf; +using ::vprintf; +using ::vsnprintf; +// using ::vsprintf; +} // namespace std + +#endif +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstdlib b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstdlib new file mode 100644 index 00000000..8ee47976 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstdlib @@ -0,0 +1,17 @@ +#ifndef MSL_CPP_CSTDLIB_H +#define MSL_CPP_CSTDLIB_H +#include <stdlib.h> +#ifdef __cplusplus + +// TODO: Fillout impls +namespace std { +// using ::abs; +// using ::atof; +// using ::mbstowcs; +// using ::mbtowc; +// using ::rand; +// using ::wcstombs; +} // namespace std + +#endif +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstring b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstring new file mode 100644 index 00000000..8b388ec0 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstring @@ -0,0 +1,26 @@ +#ifndef MSL_CPP_CSTRING_H +#define MSL_CPP_CSTRING_H +#include <string.h> +#ifdef __cplusplus + +namespace std { +using ::__memrchr; +using ::memchr; +using ::memcmp; +using ::memcpy; +using ::memmove; +using ::memset; +using ::strcat; +using ::strchr; +using ::strcmp; +using ::strcpy; +// using ::stricmp; +using ::strlen; +using ::strncat; +using ::strncmp; +using ::strncpy; +// using ::strstr; +} // namespace std + +#endif +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstring.h b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstring.h index c8497d85..e7bdf55e 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstring.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cstring.h @@ -4,13 +4,13 @@ #include "string.h" namespace std { -inline size_t strlen(const char* str) { +inline size_t strlen(const char *str) { return ::strlen(str); } -inline char* strcpy(char* dest, const char* src) { +inline char *strcpy(char *dest, const char *src) { return ::strcpy(dest, src); } -} // namespace std +} // namespace std -#endif
\ No newline at end of file +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cwchar b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cwchar new file mode 100644 index 00000000..7191d7a0 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/cwchar @@ -0,0 +1,21 @@ +#ifndef MSL_CPP_CWCHAR_H +#define MSL_CPP_CWCHAR_H +#include <wchar.h> +#ifdef __cplusplus + +namespace std { +using ::mbstowcs; +using ::mbtowc; +using ::swprintf; +using ::vswprintf; +using ::wcscat; +using ::wcschr; +using ::wcscmp; +using ::wcscpy; +using ::wcslen; +using ::wcsncpy; +using ::wcstombs; +} // namespace std + +#endif +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/iterator b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/iterator new file mode 100644 index 00000000..cc303806 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/iterator @@ -0,0 +1,10 @@ +#ifndef MSL_CPP_ITERATOR_H +#define MSL_CPP_ITERATOR_H + +namespace std { + +struct random_access_iterator_tag {}; + +} // namespace std + +#endif
\ No newline at end of file diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/new b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/new new file mode 100644 index 00000000..2372b4b2 --- /dev/null +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/new @@ -0,0 +1,17 @@ +#ifndef MSL_CPP_NEW_H +#define MSL_CPP_NEW_H +#include <stddef.h> +#ifdef __cplusplus + +inline void* operator new(size_t size, void* ptr) { +#pragma unused(size) + return ptr; +} + +inline void* operator new[](size_t size, void* ptr) { +#pragma unused(size) + return ptr; +} + +#endif +#endif diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/stddef.h b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/stddef.h index 121e4ac6..7a6f3f76 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/stddef.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/stddef.h @@ -13,6 +13,9 @@ typedef unsigned long size_t; typedef long ptrdiff_t; #endif +typedef signed long intptr_t; +typedef unsigned long uintptr_t; + #ifdef __MWERKS__ #define offsetof(type, member) ((size_t) & (((type *)0)->member)) #else diff --git a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/string.h b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/string.h index 4f8b1eb6..86c421b3 100644 --- a/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/string.h +++ b/src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/string.h @@ -17,6 +17,7 @@ char *strrchr(const char *str, int c); char *strchr(const char *str, int c); int strncmp(const char *str1, const char *str2, size_t n); int strcmp(const char *str1, const char *str2); +char *strncat(char *dst, const char *src, size_t n); char *strcat(char *dst, const char *src); char *strncpy(char *dst, const char *src, size_t n); char *strcpy(char *dst, const char *src); |
