mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-07 21:49:27 +01:00
* fixed crc sample
git-svn-id: trunk@12574 -
This commit is contained in:
parent
4ab7922296
commit
f0dc1a133f
@ -11,10 +11,10 @@ const
|
|||||||
testseq1: string = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGTVIRGATTSYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
|
testseq1: string = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGTVIRGATTSYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
|
||||||
testseq2: string = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGDVIRGATTHYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
|
testseq2: string = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGDVIRGATTHYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
|
||||||
|
|
||||||
test1_crc64: qword = 1;
|
test1_crc64: qword = 14444300186948028230;
|
||||||
test2_crc64: qword = 1;
|
test2_crc64: qword = 3310614217963326015;
|
||||||
test1_crc32: longword = 1;
|
test1_crc32: longword = 3319070459;
|
||||||
test2_crc32: longword = 1;
|
test2_crc32: longword = 1148765760;
|
||||||
|
|
||||||
|
|
||||||
procedure perform_crc32(const name, testcase: string; result: longword);
|
procedure perform_crc32(const name, testcase: string; result: longword);
|
||||||
@ -24,11 +24,11 @@ begin
|
|||||||
crc := crc32(0,nil,0);
|
crc := crc32(0,nil,0);
|
||||||
crc := crc32(crc,@testcase[1],length(testcase));
|
crc := crc32(crc,@testcase[1],length(testcase));
|
||||||
|
|
||||||
write(name,': ');
|
write(name,'(size=',length(testcase),'): ');
|
||||||
if crc=result then
|
if crc=result then
|
||||||
writeln('passed')
|
writeln('passed')
|
||||||
else
|
else
|
||||||
writeln('failed');
|
writeln('failed (got=',crc,',expected=',result,')');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure perform_crc64(const name, testcase: string; result: qword);
|
procedure perform_crc64(const name, testcase: string; result: qword);
|
||||||
@ -38,11 +38,11 @@ begin
|
|||||||
crc := crc64(0,nil,0);
|
crc := crc64(0,nil,0);
|
||||||
crc := crc64(crc,@testcase[1],length(testcase));
|
crc := crc64(crc,@testcase[1],length(testcase));
|
||||||
|
|
||||||
write(name,': ');
|
write(name,'(size=',length(testcase),'): ');
|
||||||
if crc=result then
|
if crc=result then
|
||||||
writeln('passed')
|
writeln('passed')
|
||||||
else
|
else
|
||||||
writeln('failed');
|
writeln('failed (got=',crc,',expected=',result,')');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -67,6 +67,11 @@ implementation
|
|||||||
* CRC32
|
* CRC32
|
||||||
******************************************************************************)
|
******************************************************************************)
|
||||||
|
|
||||||
|
const
|
||||||
|
CRC32_XINIT = $FFFFFFFF;
|
||||||
|
CRC32_XOROT = $FFFFFFFF;
|
||||||
|
|
||||||
|
|
||||||
{$IFDEF DYNAMIC_CRC_TABLE}
|
{$IFDEF DYNAMIC_CRC_TABLE}
|
||||||
|
|
||||||
{local}
|
{local}
|
||||||
@ -213,14 +218,13 @@ end;
|
|||||||
function crc32 (crc : cardinal; buf : Pbyte; len : cardinal): cardinal;
|
function crc32 (crc : cardinal; buf : Pbyte; len : cardinal): cardinal;
|
||||||
begin
|
begin
|
||||||
if buf = nil then
|
if buf = nil then
|
||||||
exit(0);
|
exit(0{CRC32_XINIT});
|
||||||
|
|
||||||
{$IFDEF DYNAMIC_CRC_TABLE}
|
{$IFDEF DYNAMIC_CRC_TABLE}
|
||||||
if crc32_table_empty then
|
if crc32_table_empty then
|
||||||
make_crc32_table;
|
make_crc32_table;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
crc := crc xor cardinal($ffffffff);
|
|
||||||
while (len >= 8) do
|
while (len >= 8) do
|
||||||
begin
|
begin
|
||||||
crc := crc32_table[(crc xor buf^) and $ff] xor (crc shr 8);
|
crc := crc32_table[(crc xor buf^) and $ff] xor (crc shr 8);
|
||||||
@ -249,7 +253,7 @@ begin
|
|||||||
dec(len);
|
dec(len);
|
||||||
until (len = 0);
|
until (len = 0);
|
||||||
|
|
||||||
result := crc xor cardinal($ffffffff);
|
result := crc; //xor CRC32_XOROT;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user