[fpc-devel] bitwise shift oddity a << b
Mark Morgan Lloyd
markMLl.fpc-devel at telemetry.co.uk
Tue May 19 10:22:53 CEST 2015
Jonas Maebe wrote:
> Martin Frb wrote:
>> What is supposed to happen if the 2nd argument is negative?
>
> I would propose to document it as "undefined behaviour", just like C
> does (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf ,
> section 4.5.7). The reason is that the behaviour can differ depending on
> the cpu, so if you want to guarantee consistent behaviour on all
> platforms, you can no longer just emit a shift left/right instruction
> and have to add all kinds of checks.
>
> Maybe we should support emitting range checks for the right operand
> though (to give an error if it falls outside the range of shift values
> whose behaviour is defined).
Alternatively, could it be coopted into something useful e.g. a count of
the zero bits on the left/right of the operand?
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-devel
mailing list