{$MODE FPC}
{$MODESWITCH DEFAULTPARAMETERS}
{$MODESWITCH OUT}
{$MODESWITCH RESULT}
unit dint128;

interface

type
TInt128 = packed record
{$IFDEF ENDIAN_LITTLE}
  H: QWord;
  L: QWord;
{$ELSE}
  L: QWord;
  H: QWord;
{$ENDIF}
end;

operator := (I: Int64): TInt128; inline;
operator shl (O: TInt128; I: LongInt): TInt128; inline;
operator shr (O: TInt128; I: LongInt): TInt128; inline;

implementation

operator := (I: Int64): TInt128;
begin
  Result.L := QWord(I);
  if I < 0 then begin
    Result.H := QWord(-1);
  end else
    Result.H := 0;
end;

operator shl (O: TInt128; I: LongInt): TInt128;
begin
  Result.L := O.H shl I;
  Result.H := (O.H shl I) and (O.L shr (64 - I));
end;

operator shr (O: TInt128; I: LongInt): TInt128;
begin
  Result.L := (O.L shr I) and (O.H shl (64 - I));
  Result.H := O.H shr I;
end;

end.
