A method for arithmetic expression optimization includes receiving a first
instruction defined for a first processor having a first base, the first
instruction including an operator and at least one operand, converting
the first instruction to a second instruction optimized for a second
processor having a second base when all operands do not carry potential
overflow or when the operator is insensitive to overflow, the second base
being smaller than the first base, and converting to a wider base a third
instruction that is the source of the overflow when the at least one
operand the potential for overflow and when the operator is sensitive to
overflow. An apparatus for arithmetic expression optimization includes at
least one memory having program instructions and at least one processor
configured to use the program instructions to receive a first instruction
defined for a first processor having a first base, convert the first
instruction to a second instruction optimized for a second processor
having a second base when every one of the at least one operand does not
carry potential overflow or when the operator is insensitive to overflow,
the second base being smaller than the first base, and convert to a wider
base a third instruction that is the source of the overflow when the at
least one operand the potential for overflow and when the operator is
sensitive to overflow.