3 ms·
FTA: “One major issue when programming these devices in C is that every function call consumes RAM for the return stack and function parameters. This is unavoid
by Someone 2y ago
FTA: “One major issue when programming these devices in C is that every function call consumes RAM for the return stack and function parameters. This is unavoidable”
It’s not completely unavoidable: don’t use function parameters (globals are your friends on these CPUs). You can’t avoid having a return stack, but you can make as few function calls as possible (ideally zero, but you may have to write functions to fit things into ROM)
> *”To solve this, I flattened the inference code”
I think that’s “make as few function calls as possible”
> and implemented the inner loop in assembly to optimize variable usage.
That _should_ only make a difference for memory usage if your C compiler isn’t perfect (but of course, it never is, certainly on CPUs like this one, which is a poor fit for C)
- dpassens 2y agoYou could kind of avoid the return stack, if you only ever do tail calls. Obviously, that's pretty unrealistic, but it's possible.
- ska 2y agoAssuming your compiler implements TCO properly, also.
- cpldcpu 2y ago>That _should_ only make a difference for memory usage if your C compiler isn’t perfect Considering that the PMC150 has an accumulator based 8 bit architecture which is almost hostile to C, it is safe to assume that the compiler is not perfect :)
- whobre 2y agoI bet something like Forth would work better on such a microcontroller. It is known to produce very high code density and embedding assembly is usually very straightforward.
- varispeed 2y agoThere is probably a way to change calling convention to use something else instead of stack.