38333e9e07
* Optimised parsing functions and other minor optimisations UnsetZ has been reduced by a byte, and between 17 and 28 cycles saved based on branching. Since branching is based on a being 0, it shouldn't have to branch very often and so be 28 cycles saved most the time. Including the initial call, the old version was 60 cycles, so this should be nearly twice as fast. fmtHex has been reduced by 4 bytes and between 3 and 8 cycles based on branching. fmtHexPair had a redundant "and" removed, saving two bytes and seven cycles. parseHex has been reduced by 7 bytes. Due to so much branching, it's hard to say if it's faster, but it should be since it's fewer operations and now conditional returns are used which are a cycle faster than conditional jumps. I think there's more to improve here, but I haven't come up with anything yet. * Major parsing optimisations Totally reworked both parseDecimal and parseDecimalDigit parseDecimalDigit no longer exists, as it could be replaced by an inline alternative in the 4 places it appeared. This saves one byte overall, as the inline version is 4 bytes, 1 byte more than a call, and removing the function saved 5 bytes. It has been reduced from between 52 and 35 cycles (35 on error, so we'd expect 52 cycles to be more common unless someone's really bad at programming) to 14 cycles, so 2-3 times faster. parseDecimal has been reduced by a byte, and now the main loop is just about twice as fast, but with increased overhead. To put this into perspective, if we ignore error cases: For decimals of length 1 it'll be 1.20x faster, for decimals of length 2, 1.41x faster, for length 3, 1.51x faster, for length 4, 1.57x faster, and for length 5 and above, at least 1.48x faster (even faster if there's leading zeroes or not the worst case scenario). I believe there is still room for improvement, since the first iteration can be nearly replaced with "ld l, c" since 0*10=0, but when I tried this I could either add a zero check into the main loop, adding around 40 cycles and 10 bytes, or add 20 bytes to the overhead, and I don't think either of those options are worth it. * Inlined parseDecimalDigit See previous commit, and /lib/parse.asm, for details * Fixed tabs and spacing * Fixed tabs and spacing * Better explanation and layout * Corrected error in comments, and a new parseHex 5 bytes saved in parseHex, again hard to say what that does to speed, the shortest possible speed is probably a little slower but I think non-error cases should be around 9 cycles faster for decimal and 18 cycles faster for hex as there's now only two conditional returns and no compliment carries. * Fixed the new parseHex I accidentally did `add 0xe9` without specifying `a` * Commented the use of daa I made the comments surrounding my use of daa much clearer, so it isn't quite so mystical what's being done here. * Removed skip leading zeroes, added skip first multiply Now instead of skipping leading zeroes, the first digit is loaded directly into hl without first multiplying by 10. This means the first loop is skipped in the overhead, making the method 2-3 times faster overall, and is now faster for the more common fewer digit cases too. The number of bytes is exactly the same, and the inner loop is slightly faster too thanks to no longer needing to load a into c. To be more precise about the speed increase over the current code, for decimals of length 1 it'll be 3.18x faster, for decimals of length 2, 2.50x faster, for length 3, 2.31x faster, for length 4, 2.22x faster, and for length 5 and above, at least 2.03x faster. In terms of cycles, this is around 100+(132*length) cycles saved per decimal. * Fixed erroring out for all number >0x1999 I fixed the errors for numbers >0x1999, sadly it is now 6 bytes bigger, so 5 bytes larger than the original, but the speed increases should still hold. * Fixed more errors, clearer choice of constants * Clearer choice of constants * Moved and indented comment about fmtHex's method * Marked inlined parseDecimalDigit uses * Renamed .error, removed trailing whitespace, more verbose comments. |
||
---|---|---|
.. | ||
sms | ||
acia.asm | ||
blockdev_cmds.asm | ||
blockdev.asm | ||
core.asm | ||
err.h | ||
fs_cmds.asm | ||
fs.asm | ||
kbd.asm | ||
mmap.asm | ||
parse.asm | ||
pgm.asm | ||
README.md | ||
sdc.asm | ||
shell.asm | ||
stdio.asm | ||
user.h.example |
Kernel
Bits and pieces of code that you can assemble to build a kernel for your machine.
These parts are made to be glued together in a single glue.asm
file you write
yourself.
This code is designed to be assembled by Collapse OS' own [zasm][zasm].
Defines
Each part can have its own constants, but some constant are made to be defined externally. We already have some of those external definitions in platform includes, but we can have more defines than this.
Each part has a "DEFINES" section listing the constant it expects to be defined. Make sure that you have these constants defined before you include the file.
Variable management
Each part can define variables. These variables are defined as addresses in
RAM. We know where RAM start from the RAMSTART
constant in platform includes,
but because those parts are made to be glued together in no pre-defined order,
we need a system to align variables from different modules in RAM.
This is why each part that has variable expect a <PARTNAME>_RAMSTART
constant to be defined and, in turn, defines a <PARTNAME>_RAMEND
constant to
carry to the following part.
Thus, code that glue parts together could look like:
MOD1_RAMSTART .equ RAMSTART
#include "mod1.asm"
MOD2_RAMSTART .equ MOD1_RAMEND
#include "mod2.asm"
Stack management
Keeping the stack "balanced" is a big challenge when writing assembler code. Those push and pop need to correspond, otherwise we end up with completely broken code.
The usual "push/pop" at the beginning and end of a routine is rather easy to manage, nothing special about them.
The problem is for the "inner" push and pop, which are often necessary in routines handling more data at once. In those cases, we walk on eggshells.
A naive approach could be to indent the code between those push/pop, but indent level would quickly become too big to fit in 80 chars.
I've tried ASCII art in some places, where comments next to push/pop have "|" indicating the scope of the push/pop. It's nice, but it makes code complicated to edit, especially when dense comments are involved. The pipes have to go through them.
Of course, one could add descriptions next to each push/pop describing what is being pushed, and I do it in some places, but it doesn't help much in easily tracking down stack levels.
So, what I've started doing is to accompany each "non-routine" (at the beginning and end of a routine) push/pop with "--> lvl X" and "<-- lvl X" comments. Example:
push af ; --> lvl 1
inc a
push af ; --> lvl 2
inc a
pop af ; <-- lvl 2
pop af ; <-- lvl 1
I think that this should do the trick, so I'll do this consistently from now on. [zasm]: ../apps/zasm/README.md