58 Commits

Author SHA1 Message Date
Myles Busig
017a88c966 Remove implicit inline attribute from ALWAYS_INLINE target option
May cause issues when multiple non-standard attributes are used.
Standard attributes must come before all non-standard attributes.
2024-07-27 18:17:42 -06:00
Myles Busig
cbf82e2b73 Add architecture specific target option macros
These macros are defined in target.hpp. This commit adds the macros:

NOINLINE - Never inline the function
ALWAYS_INLINE - Force the function to be inlined (also adds the inline
attribute to the function)

TARGET_ARM_MODE - Compile all future functions in ARM mode until
TARGET_END_MODE is reached. No-op if not compiling for ARM.
TARGET_THUMB_MODE - Compile all future functions in thumb mode until
TARGET_END_MODE is reached. No-op if not compiling for ARM.
TARGET_END_MODE - Undo the last TARGET_*_MODE option.

ARM_MODE - Compile this function in ARM mode.
THUMB_MODE - Compile this function in thumb mode.
2024-07-27 17:52:39 -06:00
Myles Busig
7e5a7291e6 Add initial queue implementation 2024-07-26 11:03:08 -06:00
Myles Busig
b7683d45d5 Add initial vector implementation 2024-07-25 22:55:47 -06:00
Myles Busig
f4e4ef353a Completely rewrite FSM implementation
Previously, each FSM class could only have one instance because of the
use of globals. This new implementation only uses memory allocated on
the stack, so multiple instances can be created at once. Dynamic
allocation is still unused. Additionally, this approach uses a more
logical separation between the FSM, states, and events.
2024-07-21 21:55:13 -06:00
Myles Busig
c1cdde88c8 Add default constructor to string_view 2024-06-22 16:43:45 -06:00
Myles Busig
b53bedbcb7 Add ability to disable logging
If MTL_LOGGING_DISABLED is defined, logging is disabled. Otherwise, it
is enabled.
2024-06-19 19:36:26 -06:00
Myles Busig
ed2610d60f Add additional documentation for log 2024-06-19 19:32:46 -06:00
Myles Busig
1738dd9f63 Change log level to use an enum instead of uint 2024-06-19 19:29:45 -06:00
Myles Busig
4c14f1e9e2 Change basic_string_stream to not clear the buffer on flush
If the buffer is cleared when flushed, the class does not function
correctly as a string builder. For example, if a string is built with a
newline inside, everything before the newline will be cleared and the
string will be incomplete. Clearing the buffer on flush only makes sense
for applications such as logging or writting to a file.
2024-04-10 08:46:21 -06:00
Myles Busig
dff9316987 Refactor string_stream and string_streamx, and provide ENDL selection
option

This commit refactors string_stream and string_streamx into a common
basic_string_stream template class. When the EXT template == true, the
string_streamx formatting options are enabled, they default to disabled.
These options are enabled at compile time, and do not affect performance
when they are disabled. By implementing the two streams in this manner,
duplicated code is removed.

This commit also adds the ENDL template paramter. When ENDL is set to
zero, no endline character is printed when piping mtl::endl. Otherwise,
the character is printed. Defaults to '\n'. This allows logging on the
GBA to handle mtl::endl correctly and not print two newlines on the MGBA
emulator.
2024-04-10 08:39:30 -06:00
Myles Busig
1d41674dc1 Fix udiv100000 and udiv1000000000 ASM macros changing the source
register
2024-04-04 04:18:36 -06:00
Myles Busig
55b1658e45 Change architecture dependent compilation to not use janky hacks
Previously didn't add the source to the target if a source of the same
name already existed. This was janky because these files would be
considered the same: src/foo.cpp src/armv4t/bar/baz/foo.cpp, even though
they really shouldn't. What should happen instead, is that the symbols
of the architecture-specific code should not be overridden by the common
implementation regardless of where the file is placed. This means that
if the files src/foo.cpp and src/armv4t/bar.cpp contain implementations
of the function foo, the armv4t implementation will be exported
even though it uses a different filename from the common
implementation. This commit implements this behaviour by using
the way symbols are naturally resolved. Multiple smaller
libraries are built for each architecture dependent code.
Afterwards the libraries are linked into one, with the arch specific
libraries linked first.
2024-04-04 04:11:07 -06:00
Myles Busig
93a8603ce0 Fix inaccurate implementation of udiv100000 and udiv1000000000
Both assembly macros failed when given large numbers ending in 9. For
example, udiv100000 of 3999999999 produced 40000 instead of 39999.
Similarly, udiv1000000000 of 3999999999 produced 4 instead of 3.

Both of the previous implementations failed the Granlund-Montgomery
integer division algorithm. This commit replaces these macros with the
correct implementation generated by clang for a constant integer
division. I do not understand how this implementation works. All other
macros do pass the Granlund-Montgomery algorithm.
2024-04-01 19:45:51 -06:00
Myles Busig
725fadf22a Change common to_string implementations to use snprintf instead of itoa 2024-03-27 00:59:39 -06:00
Myles Busig
002bd5a17a Fix type stdin instead of stdout 2024-03-27 00:59:10 -06:00
Myles Busig
81a44afbb4 Add log 2024-03-27 00:32:54 -06:00
Myles Busig
93656fc50f Change CMake to not build the common implementation when there is a
platform specific alternative
2024-03-27 00:31:15 -06:00
Myles Busig
f1275bfcc5 Fix incorrect usage of platform specific function 2024-03-27 00:30:45 -06:00
Myles Busig
eb21945c81 Add source directory for GBA specific files 2024-03-26 23:24:48 -06:00
Myles Busig
e5b0e242e8 Add string_streamx
string_streamx is a string_stream with additional formatting options.
Currently the only extra option is the ability to expand strings to a
length using a fill character, along with left/right justification. More
options similar to std::stringstream may be added in the future. These
extra options do come at a performance cost, and string_stream should be
preferred unless the extra options are absolutely needed.
2024-03-26 23:06:58 -06:00
Myles Busig
8e431297a6 Add string_stream 2024-03-25 21:24:28 -06:00
Myles Busig
f13352975c Add to_string functions for intx, uintx, bool, void* 2024-03-25 21:17:53 -06:00
Myles Busig
efd61da7d0 Add string_stream pipe modifiers 2024-03-25 21:17:03 -06:00
Myles Busig
45cdce1135 Remove armv4t specific include directory from build
Directory was removed in a previous commit.
2024-03-25 17:18:31 -06:00
Myles Busig
dbdf8b6e3c Change armv4t integer to string conversion to use an unrolled loop
This implementation also writes the digits from left to right instead of
right to left. Using this method we can write the string to the
beginning of the buffer and still avoid reversing the string. It also
has the benefit of being slightly slower than the previous
implementation. The function's signature changed as well because there
is no longer a reason to pass the buffer size or a pointer to output the
start of the string.
2024-03-25 17:13:29 -06:00
Myles Busig
bd1efb0bf9 Add armv4t assembly macros for division by 10^x, x=[1,9] 2024-03-25 17:11:49 -06:00
Myles Busig
cf77d1041d Add architecture dependent declarations in utility.hpp and add
math/tostring helpers
2024-03-24 21:27:58 -06:00
Myles Busig
0cf2b2f45e Rename armv4t math macro file 2024-03-24 21:26:43 -06:00
Myles Busig
0a84391c39 Add armv4t assembly optimized integer to string conversion functions 2024-03-24 01:07:24 -06:00
Myles Busig
998e3adf4d Add armv4t assembly optimized division and modulo by 10 2024-03-24 00:30:56 -06:00
Myles Busig
6d5c083616 Optimize string single character append
Now uses a specialized implementation instead of the append multiple
characters implementation. Useful for appending single characters to
string streams (ex. newline).
2024-03-21 20:35:22 -06:00
Myles Busig
8e58ff710d Add exceptions
Can't use std::exception because it dynamically allocates memory. This
implementation doesn't allocate memory, but also doesn't allow leaving
an exception message.
2024-03-13 00:36:58 -06:00
Myles Busig
829220d5ca Add support for debug-build specific files 2024-03-12 00:40:02 -06:00
Myles Busig
c7918a2b8b Update CMakeLists.txt to use globbing, and support arch. dependent files
CONFIGURE_DEPENDS option was added in CMake v3.12. This option allows the
build system to automatically re-run CMake if the glob changes, solving the
major issue with globbing. May have a performance impact, but it should be
negligible compared to the time spent building.
2024-03-10 21:55:50 -06:00
Myles Busig
a8c30df08e Implement istring replace, append, erase 2024-03-10 20:50:09 -06:00
Myles Busig
72a6bbe584 Remove istring::append with template 2024-03-07 21:49:55 -07:00
Myles Busig
63284206a2 Remove istring::push_back / istring::pop_back 2024-03-07 21:41:15 -07:00
Myles Busig
cf90307a1f Implement istring comparison operators
Not thoroughly tested.
2024-03-07 21:29:44 -07:00
Myles Busig
b6746d7ac0 Remove iterators from string and string_view
Iterators could probably be implemented efficiently, but it is not a
priority at the moment. They are removed for the time being.
2024-03-07 19:38:00 -07:00
Myles Busig
ca8aae6c66 Change istring to use string_view for the majority of its operations
The istring and string_view operators have identical implementations. By
changing the istring operators to cast to string_view and use that
implementation instead, the number of redundant implementations is
reduced. This does incurr a small performance penalty, around 15 cycles
when tested on the MGBA Gameboy Advance emulator (uses an armv7tdmi).
When compared to the time operations take, the performance difference is
negligible. Ex. An insertion with two 8 character strings takes around
450 cycles.
2024-03-07 16:28:18 -07:00
Myles Busig
8d8ceb0456 Document istring::insert 2024-03-07 16:09:32 -07:00
Myles Busig
18246e131f Implement istring::insert with given index and count 2024-03-07 16:07:21 -07:00
Myles Busig
cb4f9d2861 Implement string::copy and string_view::copy 2024-03-07 15:57:29 -07:00
Myles Busig
674371a66d Change string_view to use char_traits instead of custom strlen 2024-03-07 15:55:00 -07:00
Myles Busig
6f98434a18 Fix mtl_rmemcpy32 incorrectly calculating the number of bytes and words 2024-03-07 15:53:10 -07:00
Myles Busig
fefdce4e41 Fix incorrect memcpy 2024-03-07 14:44:17 -07:00
Myles Busig
e8601d7807 Change strings to use mtl::memmove instead of memcpy ot std::memmove 2024-03-07 14:32:46 -07:00
Myles Busig
7bfc38d978 Change strings to use string_view instead of const char*
Because the length of a string_view is computed at compile time, it is
faster for simple copies.
2024-03-07 14:25:39 -07:00
Myles Busig
99bb7d4b6e Add initial string_view implementation 2024-03-07 14:24:10 -07:00