←back to thread

156 points cpldcpu | 1 comments | | HN request time: 0.283s | source
Show context
Someone ◴[] No.41895673[source]
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)

replies(4): >>41895876 #>>41896253 #>>41897172 #>>41898306 #
1. varispeed ◴[] No.41898306[source]
There is probably a way to change calling convention to use something else instead of stack.