[OT] The Usual Arithmetic Confusions
Elronnd
elronnd at elronnd.net
Fri Feb 4 22:15:37 UTC 2022
On Friday, 4 February 2022 at 21:13:10 UTC, Walter Bright wrote:
> It's slower, too.
Not anymore. And div can be faster on smaller integers.
> You're paying a 3 size byte penalty for using short arithmetic
> rather than int arithmetic.
1. You are very careful to demonstrate short arithmetic, not byte
arithmetic, which is the same size as int arithmetic on x86.
2. Cycle-counting (or byte-counting) is not a sensible approach
to language design. It is relevant to language implementation,
maybe; and whole-program performance may be relevant to language
design; but these sorts of changes are marginal and should not
get in the way of correct semantics.
3. Your code example actually does exactly what you
suggest--using short arithmetic for storage. It just happens
that in this case using short calculations rather than int
calculations yields the same result and smaller code.
4. (continued from 3) in a larger, more interesting expression,
regardless of language semantics, the compiler will generally be
free to use ints for intermediates.
More information about the Digitalmars-d
mailing list