[fpc-pascal] Conversion from C to Pascal - Left bit shift

LacaK lacak at zoznam.sk
Fri Sep 3 08:02:22 CEST 2021


Can we say that in Pascal the result of:
   E1 shl E2
is of same type as E1 ?
(so if E1 is LongWord then result is LongWord also?)

What if there is an expression on left side:
   (E1*x) shl E2
Will E1*x promote to 64 bits (on 64 bit target)?

-Laco.

> Hello *,
>
> I have code in C like this:
>   E1 << E2
> If E1 is of unsigned type then "The value of E1 << E2 is E1 
> left-shifted E2 bit positions; vacated bits are zero-filled. If E1 has 
> an unsigned type, the value of the result is E1 × 2^E2, reduced modulo 
> one more than the maximum value representable in the result type."
>
> I understand this as result of such operation does not grow over 32 
> bits, right?
>
> In Pascal I have:
>   E1 shl E2
> where E1 is of LongWord type.
>
> On 64-bit target this result of shl can overcome 32 bits (iow operates 
> on 32 bits)?
> (does also bit shift operations works on 64 bits or this only affect 
> arithmetic operations like multiply?)
>
> Assembler suggests that shl works on 32 bits: shl    %cl,%r11d
>
> -Laco.
>



More information about the fpc-pascal mailing list