On Mon, 9 Jun 2003, Frank Heckenbach wrote:
Mirsad Todorovac wrote:
Normal local variables are (by definition!) created each time the routine is called. To avoid this, give them the `static' attribute (non-standard), or declare them as `const' (non-standard, BP). The latter is obviously preferrable since the array is really constant.
``Attribute (static)'' pushes copying out of function, but ``attribute (const)'' is still copying the array in each function call!,
`attribute (const)' is not the same as declaring a constant.
Sorry, I couldn't have figured out that from manual.
Besides this, since array [0..255] can be and probably should be properly aligned on 32-bit boundary,
Arrays are generally aligned the same as their elements.
That's fine, but I would like to align i.e. this char array to the cache-line boundary: to start at i686's cache line. This way prefetch of data would IMHO be most efficient.
You've surely noticed that I'm trying to learn some general behavior and rules for writting optimal code, it's more than just this DigitValue() ... ;-)
(And_then is an equivalent of {B+}, isn't it?)
No, it's just the opposite.
I thought and_then is the short-circuit version of "and".
stuff, IMHO. So, we save both time and space :-)
How often do you call the function (in the same unit), so it would save the space of that array?
Yes, in this particular example I guess you proved your point considering space.
But please note Chuck's comment on EBCDIC: if then rules and conversion function rely on being in ASCII or similar charset, while array and Chuck's initialization functions (with some loops, hopefully) are quite more general.
Besides that, consider the timing: right now array is 13% faster, and in inlined version (without fun. entry/exit) this would be even more to the array version of routine side, after removing constant call penalty ...
Mirsad