Merged revisions 3543 via svnmerge from

http://peter@svn.freepascal.org/svn/fpc/trunk

........
r3543 | florian | 2006-05-15 21:42:13 +0200 (Mon, 15 May 2006) | 2 lines

* endian conversion functions

........

git-svn-id: branches/fixes_2_0@3848 -
This commit is contained in:
peter 2006-06-12 06:12:12 +00:00
parent bfdc6b8951
commit 884b08065a
2 changed files with 325 additions and 0 deletions

View File

@ -1143,3 +1143,300 @@ end;
{$endif FPC_SYSTEM_HAS_SYSRESETFPU}
{$ifndef FPC_SYSTEM_HAS_SWAPENDIAN}
function SwapEndian(const AValue: SmallInt): SmallInt;
begin
Result := (AValue shr 8) or (AValue shl 8);
end;
function SwapEndian(const AValue: Word): Word;
begin
Result := (AValue shr 8) or (AValue shl 8);
end;
function SwapEndian(const AValue: LongInt): LongInt;
begin
Result := (AValue shl 24)
or ((AValue and $0000FF00) shl 8)
or ((AValue and $00FF0000) shr 8)
or (AValue shr 24);
end;
function SwapEndian(const AValue: DWord): DWord;
begin
Result := (AValue shl 24)
or ((AValue and $0000FF00) shl 8)
or ((AValue and $00FF0000) shr 8)
or (AValue shr 24);
end;
function SwapEndian(const AValue: Int64): Int64;
begin
Result := (AValue shl 56)
or ((AValue and $000000000000FF00) shl 40)
or ((AValue and $0000000000FF0000) shl 24)
or ((AValue and $00000000FF000000) shl 8)
or ((AValue and $000000FF00000000) shr 8)
or ((AValue and $0000FF0000000000) shr 24)
or ((AValue and $00FF000000000000) shr 40)
or (AValue shr 56);
end;
function SwapEndian(const AValue: QWord): QWord;
begin
Result := (AValue shl 56)
or ((AValue and $000000000000FF00) shl 40)
or ((AValue and $0000000000FF0000) shl 24)
or ((AValue and $00000000FF000000) shl 8)
or ((AValue and $000000FF00000000) shr 8)
or ((AValue and $0000FF0000000000) shr 24)
or ((AValue and $00FF000000000000) shr 40)
or (AValue shr 56);
end;
{$endif FPC_SYSTEM_HAS_SWAPENDIAN}
function BEtoN(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function BEtoN(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function BEtoN(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function BEtoN(const AValue: DWord): DWord;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function BEtoN(const AValue: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function BEtoN(const AValue: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function LEtoN(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function LEtoN(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function LEtoN(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function LEtoN(const AValue: DWord): DWord;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function LEtoN(const AValue: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function LEtoN(const AValue: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoBE(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoBE(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoBE(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoBE(const AValue: DWord): DWord;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoBE(const AValue: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoBE(const AValue: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_BIG}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoLE(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoLE(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoLE(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoLE(const AValue: DWord): DWord;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoLE(const AValue: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;
function NtoLE(const AValue: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{$IFDEF ENDIAN_LITTLE}
Result := AValue;
{$ELSE}
Result := SwapEndian(AValue);
{$ENDIF}
end;

View File

@ -432,6 +432,34 @@ Function odd(l:Longword):Boolean;[internconst:fpc_in_const_odd];{$ifdef SYSTEMIN
Function odd(l:Int64):Boolean;[internconst:fpc_in_const_odd];{$ifdef SYSTEMINLINE}inline;{$endif}
Function odd(l:QWord):Boolean;[internconst:fpc_in_const_odd];{$ifdef SYSTEMINLINE}inline;{$endif}
function BEtoN(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
function BEtoN(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
function BEtoN(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
function BEtoN(const AValue: DWord): DWord;{$ifdef SYSTEMINLINE}inline;{$endif}
function BEtoN(const AValue: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
function BEtoN(const AValue: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
function LEtoN(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
function LEtoN(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
function LEtoN(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
function LEtoN(const AValue: DWord): DWord;{$ifdef SYSTEMINLINE}inline;{$endif}
function LEtoN(const AValue: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
function LEtoN(const AValue: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoBE(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoBE(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoBE(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoBE(const AValue: DWord): DWord;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoBE(const AValue: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoBE(const AValue: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoLE(const AValue: SmallInt): SmallInt;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoLE(const AValue: Word): Word;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoLE(const AValue: LongInt): LongInt;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoLE(const AValue: DWord): DWord;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoLE(const AValue: Int64): Int64;{$ifdef SYSTEMINLINE}inline;{$endif}
function NtoLE(const AValue: QWord): QWord;{$ifdef SYSTEMINLINE}inline;{$endif}
{ float math routines }
{$I mathh.inc}