Elementary number theory

Just ran into a problem with embedded support.

I’m thiking of situations where there’s no run-time allocation. The library has run-time cache line alignment and so the size of the data structure states is, to handle this situation, provided in a #define. The user declares on the stack (or as a global) an unsigned char array of the correct size that uses that.

The problem comes on ARM. Here I need to allocate aligned with both cache lines and the exclusive reservation granuale. So imagine we have a cache line of 32 bytes and an ERG of 144 bytes. I need to find the smallest value both numbers perfectly divide into.

Problem is, there is no known way to derive this number directly, e.g. in a form I could use in a #define. It can only be computed and that means something has to be running.

Comments are closed.