Skip to content

Commit 6062234

Browse files
authored
Add fpc build config & fix some compiler warnings (#48)
1 parent 3581a20 commit 6062234

11 files changed

Lines changed: 109 additions & 37 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*.ocx
5151

5252
# Delphi autogenerated files (duplicated info)
53-
*.cfg
53+
#*.cfg
5454
*.hpp
5555
*Resource.rc
5656

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Customize messages displayed by FPC.
2+
#
3+
# FPC emits assembler and generics-related warnings that are unavoidable
4+
# in HashLib4Pascal's SIMD inline assembly and generic collections usage.
5+
# We suppress them here using -vmXXX options.
6+
7+
# =====================================================================
8+
# Assembler reader warnings (07xxx) — SIMD inline assembly
9+
# =====================================================================
10+
11+
# Warning: Use of +offset(%ebp) for parameters invalid here
12+
-vm7102
13+
14+
# Warning: Use of +offset(%ebp) for parameters invalid here
15+
# Our SIMD compress/block routines use explicit stack-relative addressing
16+
# which the assembler reader flags but is intentional and correct.
17+
-vm7103
18+
19+
# Warning: Use of -offset(%ebp) is not recommended for local variable access
20+
-vm7104
21+
22+
# Warning: Check size of memory operand "xxx: memory-operand-size is N bits, but expected [N bits]"
23+
# FPC's assembler reader cannot always determine the correct operand size
24+
# for SSE/AVX/PCLMULQDQ memory references. The generated code is correct.
25+
-vm7121
26+
27+
# Warning: Check size of memory operand "xxx: memory-operand-size is N bits, but expected [N bits + M byte offset]"
28+
-vm7122
29+
30+
# Warning: Check "xxx: offset of memory operand is negative"
31+
-vm7123
32+
33+
# =====================================================================
34+
# Parser / type warnings (03xxx, 04xxx)
35+
# =====================================================================
36+
37+
# Warning: Constructor should be public
38+
-vm3018
39+
40+
# =====================================================================
41+
# Generics warnings/hints (FPC 3.2 RTL)
42+
# =====================================================================
43+
44+
#IFDEF VER3_2
45+
# Warning: Constructing a class with abstract method (generics.dictionaries)
46+
-vm4046
47+
#ENDIF
48+
49+
# Warning: function result variable of a managed type does not seem to be initialized (generics.defaults)
50+
-vm5093
51+
52+
# Hint: Found abstract method (generics)
53+
-vm5062

HashLib.Tests/FreePascal.Tests/HashLib.Tests.lpi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
<UseHeaptrc Value="True"/>
114114
</Debugging>
115115
</Linking>
116+
<Other>
117+
<ConfigFile>
118+
<CustomConfigFile Value="True"/>
119+
<ConfigFilePath Value="..\..\BuildConfig\FPC\HashLibFPCMessages.cfg"/>
120+
</ConfigFile>
121+
</Other>
116122
</CompilerOptions>
117123
<Debugging>
118124
<Exceptions Count="3">

HashLib.Tests/FreePascal.Tests/HashLibConsole.lpi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@
132132
<IncludeFiles Value="$(ProjOutDir)"/>
133133
<OtherUnitFiles Value="..\src"/>
134134
</SearchPaths>
135+
<Other>
136+
<ConfigFile>
137+
<CustomConfigFile Value="True"/>
138+
<ConfigFilePath Value="..\..\BuildConfig\FPC\HashLibFPCMessages.cfg"/>
139+
</ConfigFile>
140+
</Other>
135141
</CompilerOptions>
136142
<Debugging>
137143
<Exceptions Count="3">

HashLib/src/Checksum/HlpAdler32Dispatch.pas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ implementation
1818
const
1919
ModAdler = UInt32(65521);
2020
NMAX = UInt32(5552);
21-
BLOCK_SIZE = UInt32(32);
22-
MAX_BLOCKS_PER_CHUNK = NMAX div BLOCK_SIZE; // 173
21+
// MAX_BLOCKS_PER_CHUNK = NMAX div UInt32(32); // 173
2322

2423
Adler32Constants: array [0 .. 63] of Byte = (
2524
// Offset 0..31: weights [32,31,...,1]
@@ -94,6 +93,8 @@ procedure Adler32_ProcessBlocks_Avx2(AData: PByte; ANumBlocks: UInt32;
9493

9594
procedure Adler32_Update_Simd(AData: PByte; ALength: UInt32; ASums: Pointer;
9695
AProcessBlocks: TProcessBlocksProc);
96+
const
97+
BLOCK_SIZE = UInt32(32);
9798
var
9899
LChunkLen, LBlocks: UInt32;
99100
LPSumA, LPSumB: PUInt32;

HashLib/src/Crypto/HlpBlake3.pas

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,8 @@ function TBlake3.TBlake3ChunkState.Node: TBlake3Node;
358358
begin
359359
Result := N.Clone();
360360
// pad the remaining space in the block with zeros
361-
TArrayUtils.FillMemory(@(Block[BlockLen]), (System.Length(Block) - BlockLen) *
362-
System.SizeOf(Byte), 0);
363-
TConverters.le32_copy(@(Block[0]), 0, @(Result.Block[0]), 0,
364-
BlockSizeInBytes);
361+
TArrayUtils.FillMemory(@(Block[BlockLen]), (Int64(System.Length(Block)) - BlockLen) * System.SizeOf(Byte), 0);
362+
TConverters.le32_copy(@(Block[0]), 0, @(Result.Block[0]), 0, BlockSizeInBytes);
365363
Result.BlockLen := UInt32(BlockLen);
366364
Result.Flags := Result.Flags or FlagChunkEnd;
367365
end;

HashLib/src/Crypto/HlpSHA3Dispatch.pas

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -433,30 +433,30 @@ procedure KeccakF1600_Absorb_Scalar(AState: Pointer; AData: PByte;
433433
64- 2, 64-15, 64-25, 64-20,
434434
64-44, 64-43, 64-21, 64-14);
435435
Iotas: (
436-
$0000000000000001, $0000000000000001, $0000000000000001, $0000000000000001,
437-
$0000000000008082, $0000000000008082, $0000000000008082, $0000000000008082,
438-
$800000000000808A, $800000000000808A, $800000000000808A, $800000000000808A,
439-
$8000000080008000, $8000000080008000, $8000000080008000, $8000000080008000,
440-
$000000000000808B, $000000000000808B, $000000000000808B, $000000000000808B,
441-
$0000000080000001, $0000000080000001, $0000000080000001, $0000000080000001,
442-
$8000000080008081, $8000000080008081, $8000000080008081, $8000000080008081,
443-
$8000000000008009, $8000000000008009, $8000000000008009, $8000000000008009,
444-
$000000000000008A, $000000000000008A, $000000000000008A, $000000000000008A,
445-
$0000000000000088, $0000000000000088, $0000000000000088, $0000000000000088,
446-
$0000000080008009, $0000000080008009, $0000000080008009, $0000000080008009,
447-
$000000008000000A, $000000008000000A, $000000008000000A, $000000008000000A,
448-
$000000008000808B, $000000008000808B, $000000008000808B, $000000008000808B,
449-
$800000000000008B, $800000000000008B, $800000000000008B, $800000000000008B,
450-
$8000000000008089, $8000000000008089, $8000000000008089, $8000000000008089,
451-
$8000000000008003, $8000000000008003, $8000000000008003, $8000000000008003,
452-
$8000000000008002, $8000000000008002, $8000000000008002, $8000000000008002,
453-
$8000000000000080, $8000000000000080, $8000000000000080, $8000000000000080,
454-
$000000000000800A, $000000000000800A, $000000000000800A, $000000000000800A,
455-
$800000008000000A, $800000008000000A, $800000008000000A, $800000008000000A,
456-
$8000000080008081, $8000000080008081, $8000000080008081, $8000000080008081,
457-
$8000000000008080, $8000000000008080, $8000000000008080, $8000000000008080,
458-
$0000000080000001, $0000000080000001, $0000000080000001, $0000000080000001,
459-
$8000000080008008, $8000000080008008, $8000000080008008, $8000000080008008);
436+
UInt64($0000000000000001), UInt64($0000000000000001), UInt64($0000000000000001), UInt64($0000000000000001),
437+
UInt64($0000000000008082), UInt64($0000000000008082), UInt64($0000000000008082), UInt64($0000000000008082),
438+
UInt64($800000000000808A), UInt64($800000000000808A), UInt64($800000000000808A), UInt64($800000000000808A),
439+
UInt64($8000000080008000), UInt64($8000000080008000), UInt64($8000000080008000), UInt64($8000000080008000),
440+
UInt64($000000000000808B), UInt64($000000000000808B), UInt64($000000000000808B), UInt64($000000000000808B),
441+
UInt64($0000000080000001), UInt64($0000000080000001), UInt64($0000000080000001), UInt64($0000000080000001),
442+
UInt64($8000000080008081), UInt64($8000000080008081), UInt64($8000000080008081), UInt64($8000000080008081),
443+
UInt64($8000000000008009), UInt64($8000000000008009), UInt64($8000000000008009), UInt64($8000000000008009),
444+
UInt64($000000000000008A), UInt64($000000000000008A), UInt64($000000000000008A), UInt64($000000000000008A),
445+
UInt64($0000000000000088), UInt64($0000000000000088), UInt64($0000000000000088), UInt64($0000000000000088),
446+
UInt64($0000000080008009), UInt64($0000000080008009), UInt64($0000000080008009), UInt64($0000000080008009),
447+
UInt64($000000008000000A), UInt64($000000008000000A), UInt64($000000008000000A), UInt64($000000008000000A),
448+
UInt64($000000008000808B), UInt64($000000008000808B), UInt64($000000008000808B), UInt64($000000008000808B),
449+
UInt64($800000000000008B), UInt64($800000000000008B), UInt64($800000000000008B), UInt64($800000000000008B),
450+
UInt64($8000000000008089), UInt64($8000000000008089), UInt64($8000000000008089), UInt64($8000000000008089),
451+
UInt64($8000000000008003), UInt64($8000000000008003), UInt64($8000000000008003), UInt64($8000000000008003),
452+
UInt64($8000000000008002), UInt64($8000000000008002), UInt64($8000000000008002), UInt64($8000000000008002),
453+
UInt64($8000000000000080), UInt64($8000000000000080), UInt64($8000000000000080), UInt64($8000000000000080),
454+
UInt64($000000000000800A), UInt64($000000000000800A), UInt64($000000000000800A), UInt64($000000000000800A),
455+
UInt64($800000008000000A), UInt64($800000008000000A), UInt64($800000008000000A), UInt64($800000008000000A),
456+
UInt64($8000000080008081), UInt64($8000000080008081), UInt64($8000000080008081), UInt64($8000000080008081),
457+
UInt64($8000000000008080), UInt64($8000000000008080), UInt64($8000000000008080), UInt64($8000000000008080),
458+
UInt64($0000000080000001), UInt64($0000000080000001), UInt64($0000000080000001), UInt64($0000000080000001),
459+
UInt64($8000000080008008), UInt64($8000000080008008), UInt64($8000000080008008), UInt64($8000000080008008));
460460
Jagged: (
461461
0, 32, 40, 48, 56, 80, 192, 104, 144, 184,
462462
64, 128, 200, 176, 120, 88, 96, 168, 208, 152,

HashLib/src/Hash128/HlpXXHash128.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,10 @@ procedure TXXHash128.DigestLong(var AAcc: TXXH3AccArray);
423423
begin
424424
LSecret := PByte(FState.FCustomSecret);
425425

426-
if FState.FBufferedSize >= TXXH3Core.XXH_STRIPE_LEN then
426+
if FState.FBufferedSize >= UInt32(TXXH3Core.XXH_STRIPE_LEN) then
427427
begin
428428
LNbStripes := Int32((FState.FBufferedSize - 1) div
429-
TXXH3Core.XXH_STRIPE_LEN);
429+
UInt32(TXXH3Core.XXH_STRIPE_LEN));
430430
LNbStripesSoFar := FState.FNbStripesSoFar;
431431
TXXH3Core.XXH3_consumeStripes(AAcc, LNbStripesSoFar,
432432
TXXH3Core.XXH3_STRIPES_PER_BLOCK, PByte(FState.FBuffer), LSecret,

HashLib/src/Hash32/HlpPJW.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ TPJW = class sealed(THash, IHash32, ITransformBlock)
2323
BitsInUnsignedInt = Int32(System.SizeOf(UInt32) * 8);
2424
ThreeQuarters = Int32(BitsInUnsignedInt * 3) shr 2;
2525
OneEighth = Int32(BitsInUnsignedInt shr 3);
26-
HighBits = UInt32(UInt32MaxValue shl (BitsInUnsignedInt - OneEighth));
26+
HighBits = UInt32(not ((UInt32(1) shl (BitsInUnsignedInt - OneEighth)) - 1));
27+
//HighBits = UInt32(UInt32MaxValue shl (BitsInUnsignedInt - OneEighth));
28+
NotHighBits = HighBits xor UInt32MaxValue;
2729

2830
public
2931
constructor Create();
@@ -76,7 +78,7 @@ procedure TPJW.TransformBytes(const AData: THashLibByteArray;
7678
LTest := FHash and HighBits;
7779
if (LTest <> 0) then
7880
begin
79-
FHash := ((FHash xor (LTest shr ThreeQuarters)) and (not HighBits));
81+
FHash := ((FHash xor (LTest shr ThreeQuarters)) and NotHighBits);
8082
end;
8183
System.Inc(LIdx);
8284
System.Dec(ALength);

HashLib/src/Hash64/HlpXXHash3.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,10 @@ procedure TXXHash3.DigestLong(var AAcc: TXXH3AccArray);
639639
begin
640640
LSecret := PByte(FState.FCustomSecret);
641641

642-
if FState.FBufferedSize >= TXXH3Core.XXH_STRIPE_LEN then
642+
if FState.FBufferedSize >= UInt32(TXXH3Core.XXH_STRIPE_LEN) then
643643
begin
644644
LNbStripes := Int32((FState.FBufferedSize - 1) div
645-
TXXH3Core.XXH_STRIPE_LEN);
645+
UInt32(TXXH3Core.XXH_STRIPE_LEN));
646646
LNbStripesSoFar := FState.FNbStripesSoFar;
647647
TXXH3Core.XXH3_consumeStripes(AAcc, LNbStripesSoFar,
648648
TXXH3Core.XXH3_STRIPES_PER_BLOCK, PByte(FState.FBuffer), LSecret,

0 commit comments

Comments
 (0)