[fpc-devel] Do bitwise operation (1 or 2) acre about the sign ? (Giving sign related hints on compilation)
ik
idokan at gmail.com
Mon Jan 14 14:54:50 CET 2013
On Mon, Jan 14, 2013 at 3:11 PM, Martin <lazarus at mfriebe.de> wrote:
> Having recently asked about and learned that it is mainly a hint about
> performance. I have now another question about this hint:
> project1.lpr(6,9) Hint: Mixing signed expressions and longwords gives a
> 64bit result
>
> Actually not so much about the hint, as about the fact that in the below
> example fpc extends the operands to 64 bits.
>
> program Project1;
> var
> x: cardinal;
> i, j: integer;
> begin
> i:= x or j
> end.
>
> I understand the need for a 64 bit operation for +/-/</>/*/...
>
> But the "or" operator works bitwise, it does not treat the operands as
> numbers which could either be signed or unsigned? Or does it? If it does
> not, why does it need to use 64 bit?
i is an "integer" type, and you try to assign it a number that might
have 64 bit value.
It might overflow the memory itself.
Furthermore, if you are at 32 bit OS/CPU, you can not do actions on 64
bit in a normal way, because the registers are not supporting it.
So you can create your own operands and create your own custom
implementation for 64 bit numbers at 32 level (a record of two 32
integer types).
More information about the fpc-devel
mailing list