title: Strange SHL operation in Delphi XE
body: <p>What's wrong with <code>v:=v shl b</code>? I'm trying to calculate <i>mask</i> = 2<sup><i>n</i></sup>-1 like <code>mask:=1 shl n-1</code>, but fails for integer variable n=64.</p>
  
  <pre><code>program UInt64Test;
  
  {$APPTYPE CONSOLE}
  
  var
    u,v,w:uint64;
  const
    a=64;
  var
    b:integer=a;
    c:integer=a-1;
  
  begin
    u:=1; v:=1; w:=1;
    u:=u shl a;
    v:=v shl b;
    w:=w shl 1 shl c;
    writeln(u);
    writeln(v);
    writeln(w);
    readln;
  end.
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>0
  1
  0
  </code></pre>
  
  <p>I suspected <code>v</code> to be zero too.</p>
  
  <p>Solved like <code>2 shl (n-1)-1</code>. In this case compiler perform machine <code>shl</code> (not <code>__llshl</code>):</p>
  
  <pre><code>function reciprocal(o:uint64;n:byte=64):uint64; // result * o = 1 (mod 2ⁿ)
  var
    b,m,t:uint64;
  begin
    result:=0;
    t:=2 shl (n-1)-1;
    m:=0; b:=1;
    while b&lt;&gt;0 do begin
      m:=m or b;
      if ((o*result) and m)&lt;&gt;1 then result:=result or b;
      b:=(b shl 1) and t;
    end;
  end;
  </code></pre>
  
  <p>... but, I'm not happy.</p>