diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-10-06 10:28:49 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-10-06 10:29:36 +0200 |
| commit | 6b84827f775179488ea912de37a8af1e06291f94 (patch) | |
| tree | 38db176f7a7c386667d05796724a10a57ce7df41 /dev | |
| parent | 1bd4170ed7b397002537b1427ae4cb5bcb36fa4b (diff) | |
IMP: new CRT SDK, imported from zka-dev, also updated assembly syntax.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/crt/__ndk_alloca.hxx | 15 | ||||
| -rw-r--r-- | dev/crt/__ndk_defines.hxx | 82 | ||||
| -rw-r--r-- | dev/crt/__ndk_exception.hxx | 27 | ||||
| -rw-r--r-- | dev/crt/__ndk_hint.hxx | 20 | ||||
| -rw-r--r-- | dev/crt/__ndk_malloc.hxx | 30 | ||||
| -rw-r--r-- | dev/crt/__ndk_power.inc | 35 | ||||
| -rw-r--r-- | dev/crt/base_alloc.hxx | 49 | ||||
| -rw-r--r-- | dev/crt/base_exception.hxx | 35 | ||||
| -rw-r--r-- | dev/crt/defines.hxx | 125 | ||||
| -rw-r--r-- | dev/crt/math.hxx | 62 | ||||
| -rw-r--r-- | dev/crt/power64.inc | 35 |
11 files changed, 306 insertions, 209 deletions
diff --git a/dev/crt/__ndk_alloca.hxx b/dev/crt/__ndk_alloca.hxx deleted file mode 100644 index 48732a0..0000000 --- a/dev/crt/__ndk_alloca.hxx +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -typedef void* ptr_type; -typedef __SIZE_TYPE__ size_type; - -inline ptr_type __ndk_alloca_gcc(size_type sz) -{ - return __builtin_alloca(sz); -} diff --git a/dev/crt/__ndk_defines.hxx b/dev/crt/__ndk_defines.hxx deleted file mode 100644 index 904d0ab..0000000 --- a/dev/crt/__ndk_defines.hxx +++ /dev/null @@ -1,82 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#ifndef __NDK_DEF__ -#define __NDK_DEF__ - -#ifndef __GNUC__ - -typedef __SIZE_TYPE__ size_t; - -#ifdef __LP64__ -typedef long int ssize_t; -#else -typedef int ssize_t; -#endif // __LP64__ - -typedef size_t ptrdiff_t; -typedef size_t uintptr_t; -typedef void* voidptr_t; -typedef void* any_t; -typedef char* caddr_t; - -#ifndef NULL -#define NULL ((voidptr_t)0) -#endif // !null - -#ifdef __GNUC__ -#include <crt/__ndk_alloca.hxx> -#define __ndk_alloca(sz) __ndk_alloca_gcc(sz) -#define __packed__ __attribute__((packed)) -#elif defined(__NDK__) -#define __packed__ __ndk_packed__ -#define __alloca(sz) __ndk_alloca(sz) -#endif - -#define __deref(ptr) (*(ptr)) - -#ifdef __cplusplus -#define __init_decl() \ - extern "C" \ - { - -#define __fini_decl() \ - } \ - ; - -#else -#define __init_decl() -#define __fini_decl() -#endif - -typedef long long off_t; -typedef unsigned long long uoff_t; - -typedef union float_cast { - struct - { - unsigned int mantissa : 23; - unsigned int exponent : 8; - unsigned int sign : 1; - }; - - float f; -} __packed__ float_cast_t; - -typedef union double_cast { - struct - { - unsigned long long int mantissa : 52; - unsigned int exponent : 11; - unsigned int sign : 1; - }; - - double f; -} __packed__ double_cast_t; - -#endif // ifndef __GNUC__ - -#endif /* __NDK_DEF__ */ diff --git a/dev/crt/__ndk_exception.hxx b/dev/crt/__ndk_exception.hxx deleted file mode 100644 index dac42ad..0000000 --- a/dev/crt/__ndk_exception.hxx +++ /dev/null @@ -1,27 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -/// This file is an implementation of __throw* family of functions. - -#include <exception> -#include <iostream> -#include <stdexcept> - -namespace std -{ - inline void __throw_general(void) - { - throw std::runtime_error("NDK C++ Runtime error."); - } - - inline void __throw_domain_error(const char* error) - { - std::cout << "NDK C++: Domain error: " << error << "\r"; - __throw_general(); - } -} // namespace std diff --git a/dev/crt/__ndk_hint.hxx b/dev/crt/__ndk_hint.hxx deleted file mode 100644 index 02dbc94..0000000 --- a/dev/crt/__ndk_hint.hxx +++ /dev/null @@ -1,20 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#pragma compiler(hint_manifest) - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut diff --git a/dev/crt/__ndk_malloc.hxx b/dev/crt/__ndk_malloc.hxx deleted file mode 100644 index eeaa67b..0000000 --- a/dev/crt/__ndk_malloc.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#include <algorithm> - -namespace stdx -{ - /// @brief allocate a new class. - /// @tparam KindClass the class type to allocate. - template <typename KindClass, typename... Args> - inline void* allocate(Args&&... args) - { - return new KindClass(std::forward(args)...); - } - - /// @brief free a class. - /// @tparam KindClass the class type to allocate. - template <typename KindClass> - inline void release(KindClass ptr) - { - if (!ptr) - return; - delete ptr; - } -} // namespace stdx diff --git a/dev/crt/__ndk_power.inc b/dev/crt/__ndk_power.inc deleted file mode 100644 index cada02e..0000000 --- a/dev/crt/__ndk_power.inc +++ /dev/null @@ -1,35 +0,0 @@ -# Path: SDK/__ndk_power.inc -# Language: NDK POWER Assembly support for GNU. -# Build Date: 2024-6-4 - -%ifdef __CODETOOLS__ - -%def lda li -%def sta stw -%def ldw li - -%def r0 0 -%def r1 1 -%def r2 2 -%def r3 3 -%def r4 4 -%def r5 5 -%def r6 6 -%def r7 7 -%def r8 8 -%def r9 9 -%def r10 10 -%def r11 11 -%def r12 12 -%def r13 13 -%def r14 14 -%def r15 15 -%def r16 16 -%def r17 17 -%def r18 18 -%def r19 19 -%def r20 20 - -%endif - -%def nop mr 0, 0 diff --git a/dev/crt/base_alloc.hxx b/dev/crt/base_alloc.hxx new file mode 100644 index 0000000..de15786 --- /dev/null +++ b/dev/crt/base_alloc.hxx @@ -0,0 +1,49 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <crt/defines.hxx> + +namespace std::base_alloc +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass, typename... Args> + inline KindClass* allocate(Args&&... args) + { + return new KindClass(forward(args)...); + } + + /// @brief allocate a new class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template <typename KindClass, typename... Args> + inline KindClass* allocate_nothrow(Args&&... args) noexcept + { + return allocate(forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass> + inline void release(KindClass ptr) + { + if (!ptr) + return; + + delete ptr; + } + + /// @brief destroy and free a class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template <typename KindClass> + inline void release_nothrow(KindClass ptr) noexcept + { + release(ptr); + } +} // namespace std::base_alloc diff --git a/dev/crt/base_exception.hxx b/dev/crt/base_exception.hxx new file mode 100644 index 0000000..9d3fd20 --- /dev/null +++ b/dev/crt/base_exception.hxx @@ -0,0 +1,35 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <crt/defines.hxx> + +/// @brief CRT exit, with exit code (!!! exits all threads. !!!) +/// @param code +/// @return +extern "C" int __exit(int code); + +/// @brief Standard C++ namespace +namespace std +{ + inline void __throw_general(void) + { + __exit(33); + } + + inline void __throw_domain_error(const char* error) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } + + inline void __throw_bad_array_new_length(void) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } +} // namespace std diff --git a/dev/crt/defines.hxx b/dev/crt/defines.hxx new file mode 100644 index 0000000..d9670ac --- /dev/null +++ b/dev/crt/defines.hxx @@ -0,0 +1,125 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __NDK_DEFINES_HXX__ +#define __NDK_DEFINES_HXX__ + +#include <stdint.h> +#include <stddef.h> + +#ifndef __GNUC__ + +typedef __SIZE_TYPE__ size_t; + +#ifdef __LP64__ +typedef long int ssize_t; +#else +typedef int ssize_t; +#endif // __LP64__ + +typedef void* ptr_type; +typedef __SIZE_TYPE__ size_type; + +typedef size_t ptrdiff_t; +typedef size_t uintptr_t; +typedef void* voidptr_t; +typedef void* any_t; +typedef char* caddr_t; + +#ifndef NULL +#define NULL ((voidptr_t)0) +#endif // !null + +#ifdef __GNUC__ +#include <crt/alloca.hxx> +#elif defined(__NDK__) +#define __alloca(sz) __ndk_alloca(sz) +#endif + +#define __deref(ptr) (*(ptr)) + +#ifdef __cplusplus +#define __init_decl() \ + extern "C" \ + { +#define __fini_decl() \ + } \ + ; +#else +#define __init_decl() +#define __fini_decl() +#endif + +#if __has_builtin(__builtin_alloca) +#define alloca(sz) __builtin_alloca(sz) +#ifdef __alloca +#undef __alloca +#endif +#define __alloca alloca +#else +#warning ! alloca not detected ! +#endif + +typedef long long off_t; +typedef unsigned long long uoff_t; + +typedef union float_cast { + struct + { + unsigned int mantissa : 23; + unsigned int exponent : 8; + unsigned int sign : 1; + }; + + float f; +} __attribute__((packed)) float_cast_t; + +typedef union double_cast { + struct + { + unsigned long long int mantissa : 52; + unsigned int exponent : 11; + unsigned int sign : 1; + }; + + double f; +} __attribute__((packed)) double_cast_t; + +#endif // ifndef __GNUC__ + +/// Include these helpers as well. + +#ifdef __STD_CXX__ + +#include <crt/base_exception.hxx> +#include <crt/base_alloc.hxx> + +#endif // ifdef __STD_CXX__ + +namespace std +{ + /// @brief Forward object. + /// @tparam Args the object type. + /// @param arg the object. + /// @return object's rvalue + template <typename Args> + inline Args&& forward(Args& arg) + { + return static_cast<Args&&>(arg); + } + + /// @brief Move object. + /// @tparam Args the object type. + /// @param arg the object. + /// @return object's rvalue + template <typename Args> + inline Args&& move(Args&& arg) + { + return static_cast<Args&&>(arg); + } +} // namespace std + +#endif /* __NDK_DEFINES_HXX__ */ diff --git a/dev/crt/math.hxx b/dev/crt/math.hxx new file mode 100644 index 0000000..56bb123 --- /dev/null +++ b/dev/crt/math.hxx @@ -0,0 +1,62 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <crt/defines.hxx> + +/// @file Math.hxx +/// @brief Math functions. + +#ifdef __ZKA_USE_DOUBLE__ +typedef double real_type; +#else +typedef float real_type; +#endif + +namespace std::math +{ + /// @brief Power function, with Repeat argument. + template <size_t Exponent> + inline real_type pow(real_type in) + { + if (Exponent == 0) + return 1; // Any number to the power of 0 is 1. + + if (Exponent == 1) + return in; // Any number to the power of 1 is itself. + + size_t cnt = Exponent; + + real_type result = 1; + + for (auto i = 0; i < cnt; ++i) + result *= in; + + return result; + } + + /// @brief Square of function, with Base template argument. + /// @param of Base argument to find sqquare of + template <size_t Base> + inline real_type sqr(real_type in) + { + if (in == 0) + return 0; + + return pow<1 / Base>(in); + } + + /// @brief Linear interpolation equation solver. + /// @param from where? + /// @param to to? + /// @param Updated diff value according to difference. + inline real_type lerp(real_type to, real_type from, real_type stat) + { + real_type diff = (to - from); + return from + (diff * stat); + } +} // namespace std::math diff --git a/dev/crt/power64.inc b/dev/crt/power64.inc new file mode 100644 index 0000000..23013c1 --- /dev/null +++ b/dev/crt/power64.inc @@ -0,0 +1,35 @@ +# Path: SDK/__ndk_power.inc +# Language: NDK POWER Assembly support for GNU. +# Build Date: 2024-6-4 + +%ifdef __CODETOOLS__ + +%define lda li +%define sta stw +%define ldw li + +%define r0 0 +%define r1 1 +%define r2 2 +%define r3 3 +%define r4 4 +%define r5 5 +%define r6 6 +%define r7 7 +%define r8 8 +%define r9 9 +%define r10 10 +%define r11 11 +%define r12 12 +%define r13 13 +%define r14 14 +%define r15 15 +%define r16 16 +%define r17 17 +%define r18 18 +%define r19 19 +%define r20 20 + +%endif + +%define nop mr 0, 0 |
