Skip to content

Commit edca110

Browse files
committed
Update unrar to 7.0b3
1 parent 51c9257 commit edca110

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+429
-272
lines changed

vendor/unrar/arccmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ void Archive::ViewComment()
174174
auto EndPos=CmtBuf.find(0x1A);
175175
if (EndPos!=std::wstring::npos)
176176
CmtSize=EndPos;
177-
mprintf(L"\n");
177+
mprintf(St(MArcComment));
178+
mprintf(L":\n");
178179
OutComment(CmtBuf);
179180
}
180181
}

vendor/unrar/archive.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ class Archive:public File
8585
HEADER_TYPE GetHeaderType() {return CurHeaderType;}
8686
CommandData* GetCommandData() {return Cmd;}
8787
void SetSilentOpen(bool Mode) {SilentOpen=Mode;}
88-
#if 0
89-
void GetRecoveryInfo(bool Required,int64 *Size,int *Percent);
90-
#endif
9188
#ifdef USE_QOPEN
9289
bool Open(const std::wstring &Name,uint Mode=FMF_READ) override;
9390
int Read(void *Data,size_t Size) override;

vendor/unrar/arcread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ size_t Archive::ReadHeader15()
424424
NextBlockPos=SafeAdd(NextBlockPos,hd->PackSize,0);
425425

426426
bool CRCProcessedOnly=hd->CommentInHeader;
427-
ushort HeaderCRC=Raw.GetCRC15(CRCProcessedOnly);
427+
uint HeaderCRC=Raw.GetCRC15(CRCProcessedOnly);
428428
if (hd->HeadCRC!=HeaderCRC)
429429
{
430430
BrokenHeader=true;
@@ -507,7 +507,7 @@ size_t Archive::ReadHeader15()
507507
break;
508508
}
509509

510-
ushort HeaderCRC=Raw.GetCRC15(false);
510+
uint HeaderCRC=Raw.GetCRC15(false);
511511

512512
// Old AV header does not have header CRC properly set.
513513
// Old Unix owners header didn't include string fields into header size,
@@ -649,7 +649,7 @@ size_t Archive::ReadHeader50()
649649
}
650650

651651
int SizeToRead=int(BlockSize);
652-
SizeToRead-=FirstReadSize-SizeBytes-4; // Adjust overread size bytes if any.
652+
SizeToRead-=int(FirstReadSize-SizeBytes-4); // Adjust overread size bytes if any.
653653
uint HeaderSize=4+SizeBytes+(uint)BlockSize;
654654

655655
if (SizeToRead<0 || HeaderSize<SIZEOF_SHORTBLOCKHEAD5)

vendor/unrar/blake2sp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void blake2sp_init( blake2sp_state *S )
2020

2121
blake2s_init_param( &S->R, 0, 1 ); // Init root.
2222

23-
for( uint i = 0; i < PARALLELISM_DEGREE; ++i )
23+
for( uint32 i = 0; i < PARALLELISM_DEGREE; ++i )
2424
blake2s_init_param( &S->S[i], i, 0 ); // Init leaf.
2525

2626
S->R.last_node = 1;
@@ -49,6 +49,8 @@ void Blake2ThreadData::Update()
4949
if (_SSE_Version>=SSE_SSE && inlen__ >= 2 * PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES)
5050
_mm_prefetch((char*)(in__ + PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES), _MM_HINT_T0);
5151
#endif
52+
// We tried to _forceinline blake2s_update and blake2s_compress_sse,
53+
// but it didn't improve performance.
5254
blake2s_update( S, in__, BLAKE2S_BLOCKBYTES );
5355
in__ += PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES;
5456
inlen__ -= PARALLELISM_DEGREE * BLAKE2S_BLOCKBYTES;

vendor/unrar/cmdfilter.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,28 @@ bool CommandData::CheckArgs(StringList *Args,bool Dir,const std::wstring &CheckN
3535
}
3636
else
3737
{
38+
// This code doesn't allow to apply -n and -x wildcard masks without
39+
// trailing slash to folders unless these masks are * and *.*.
40+
// See the changes history below.
3841
// 2023.03.26: Previously we removed this code completely to let
39-
// -npath\* include empty folders in 'path' too. But then we received
40-
// an email from user not willing -x*.avi to exclude folders like
41-
// dir.avi with non-avi files. Also rar.txt mentions that masks like
42-
// *.avi exclude only files. Initially we wanted masks like -npath\*
43-
// or -xpath\* to match the entire contents of path including empty
44-
// folders and added the special check for "*" and "*.*".
45-
// But this is not very straightforward, when *.* and *.avi are
46-
// processed differently, especially taking into account that
47-
// we can specify the exact folder name without wildcards to process
48-
// it and masks like 'dir*\' can be used to exclude folders.
49-
// So we decided to skip all usual wildcard masks for folders.
42+
// 'rar a arc dir -ndir\path\*' include empty folders in 'path' too.
43+
// But then we received an email from user not willing -x*.avi to
44+
// exclude folders like dir.avi with non-avi files. Also rar.txt
45+
// mentions that masks like *.avi exclude only files. Initially
46+
// we wanted masks like -npath\* or -xpath\* to match the entire
47+
// contents of path including empty folders and added the special
48+
// check for "*" and "*.*". But this is not very straightforward,
49+
// when *.* and *.avi are processed differently, especially taking
50+
// into account that we can specify the exact folder name without
51+
// wildcards to process it and masks like 'dir*\' can be used to
52+
// exclude folders. So we decided to skip all usual wildcard masks
53+
// for folders.
54+
// 2023.11.22: We returned the special check for "*" and "*.*",
55+
// because users expected 'rar a arc dir -xdir\*' to exclude
56+
// everything including subfolders in 'dir'. For now we returned it
57+
// both for -n and -x, but we can limit it to -x only if needed.
5058
std::wstring Name=PointToName(CurMask);
51-
if (IsWildcard(Name)/* && wcscmp(Name,L"*")!=0 && wcscmp(Name,L"*.*")!=0*/)
59+
if (IsWildcard(Name) && Name!=L"*" && Name!=L"*.*")
5260
continue;
5361
}
5462
}

vendor/unrar/coder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22

3-
inline unsigned int RangeCoder::GetChar()
3+
inline byte RangeCoder::GetChar()
44
{
5-
return(UnpackRead->GetChar());
5+
return UnpackRead->GetChar();
66
}
77

88

@@ -11,8 +11,8 @@ void RangeCoder::InitDecoder(Unpack *UnpackRead)
1111
RangeCoder::UnpackRead=UnpackRead;
1212

1313
low=code=0;
14-
range=uint(-1);
15-
for (int i=0;i < 4;i++)
14+
range=0xffffffff;
15+
for (uint i = 0; i < 4; i++)
1616
code=(code << 8) | GetChar();
1717
}
1818

vendor/unrar/coder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class RangeCoder
1111
inline uint GetCurrentShiftCount(uint SHIFT);
1212
inline void Decode();
1313
inline void PutChar(unsigned int c);
14-
inline unsigned int GetChar();
14+
inline byte GetChar();
1515

1616
uint low, code, range;
1717
struct SUBRANGE

vendor/unrar/crc.cpp

Lines changed: 96 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#define USE_SLICING
2121
#endif
2222

23-
static uint crc_tables[8][256]; // Tables for Slicing-by-8.
23+
static uint crc_tables[16][256]; // Tables for Slicing-by-16.
24+
25+
#ifdef USE_NEON_CRC32
26+
static bool CRC_Neon;
27+
#endif
2428

2529

2630
// Build the classic CRC32 lookup table.
@@ -36,6 +40,19 @@ void InitCRC32(uint *CRCTab)
3640
C=(C & 1) ? (C>>1)^0xEDB88320 : (C>>1);
3741
CRCTab[I]=C;
3842
}
43+
44+
#ifdef USE_NEON_CRC32
45+
#ifdef _APPLE
46+
// getauxval isn't available in OS X
47+
uint Value=0;
48+
size_t Size=sizeof(Value);
49+
int RetCode=sysctlbyname("hw.optional.armv8_crc32",&Value,&Size,NULL,0);
50+
CRC_Neon=RetCode==0 && Value!=0;
51+
#else
52+
CRC_Neon=(getauxval(AT_HWCAP) & HWCAP_CRC32)!=0;
53+
#endif
54+
#endif
55+
3956
}
4057

4158

@@ -47,7 +64,7 @@ static void InitTables()
4764
for (uint I=0;I<256;I++) // Build additional lookup tables.
4865
{
4966
uint C=crc_tables[0][I];
50-
for (uint J=1;J<8;J++)
67+
for (uint J=1;J<16;J++)
5168
{
5269
C=crc_tables[0][(byte)C]^(C>>8);
5370
crc_tables[J][I]=C;
@@ -63,29 +80,66 @@ uint CRC32(uint StartCRC,const void *Addr,size_t Size)
6380
{
6481
byte *Data=(byte *)Addr;
6582

83+
#ifdef USE_NEON_CRC32
84+
if (CRC_Neon)
85+
{
86+
for (;Size>=8;Size-=8,Data+=8)
87+
#ifdef __clang__
88+
StartCRC = __builtin_arm_crc32d(StartCRC, RawGet8(Data));
89+
#else
90+
StartCRC = __builtin_aarch64_crc32x(StartCRC, RawGet8(Data));
91+
#endif
92+
for (;Size>0;Size--,Data++) // Process left data.
93+
#ifdef __clang__
94+
StartCRC = __builtin_arm_crc32b(StartCRC, *Data);
95+
#else
96+
StartCRC = __builtin_aarch64_crc32b(StartCRC, *Data);
97+
#endif
98+
return StartCRC;
99+
}
100+
#endif
101+
66102
#ifdef USE_SLICING
67-
// Align Data to 8 for better performance and to avoid ALLOW_MISALIGNED
103+
// Align Data to 16 for better performance and to avoid ALLOW_MISALIGNED
68104
// check below.
69-
for (;Size>0 && ((size_t)Data & 7);Size--,Data++)
105+
for (;Size>0 && ((size_t)Data & 15)!=0;Size--,Data++)
70106
StartCRC=crc_tables[0][(byte)(StartCRC^Data[0])]^(StartCRC>>8);
71107

72-
for (;Size>=8;Size-=8,Data+=8)
108+
// 2023.12.06: We switched to slicing-by-16, which seems to be faster than
109+
// slicing-by-8 on modern CPUs. Slicing-by-32 would require 32 KB for tables
110+
// and could be limited by L1 cache size on some CPUs.
111+
for (;Size>=16;Size-=16,Data+=16)
73112
{
74113
#ifdef BIG_ENDIAN
75-
StartCRC ^= Data[0]|(Data[1] << 8)|(Data[2] << 16)|(Data[3] << 24);
76-
uint NextData = Data[4]|(Data[5] << 8)|(Data[6] << 16)|(Data[7] << 24);
114+
StartCRC ^= RawGet4(Data);
115+
uint D1 = RawGet4(Data+4);
116+
uint D2 = RawGet4(Data+8);
117+
uint D3 = RawGet4(Data+12);
77118
#else
119+
// We avoid RawGet4 here for performance reason, to access uint32
120+
// directly even if ALLOW_MISALIGNED isn't defined. We can do it,
121+
// because we aligned 'Data' above.
78122
StartCRC ^= *(uint32 *) Data;
79-
uint NextData = *(uint32 *) (Data+4);
123+
uint D1 = *(uint32 *) (Data+4);
124+
uint D2 = *(uint32 *) (Data+8);
125+
uint D3 = *(uint32 *) (Data+12);
80126
#endif
81-
StartCRC = crc_tables[7][(byte) StartCRC ] ^
82-
crc_tables[6][(byte)(StartCRC >> 8) ] ^
83-
crc_tables[5][(byte)(StartCRC >> 16)] ^
84-
crc_tables[4][(byte)(StartCRC >> 24)] ^
85-
crc_tables[3][(byte) NextData ] ^
86-
crc_tables[2][(byte)(NextData >> 8) ] ^
87-
crc_tables[1][(byte)(NextData >> 16)] ^
88-
crc_tables[0][(byte)(NextData >> 24)];
127+
StartCRC = crc_tables[15][(byte) StartCRC ] ^
128+
crc_tables[14][(byte)(StartCRC >> 8) ] ^
129+
crc_tables[13][(byte)(StartCRC >> 16)] ^
130+
crc_tables[12][(byte)(StartCRC >> 24)] ^
131+
crc_tables[11][(byte) D1 ] ^
132+
crc_tables[10][(byte)(D1 >> 8) ] ^
133+
crc_tables[ 9][(byte)(D1 >> 16)] ^
134+
crc_tables[ 8][(byte)(D1 >> 24)] ^
135+
crc_tables[ 7][(byte) D2 ] ^
136+
crc_tables[ 6][(byte)(D2 >> 8)] ^
137+
crc_tables[ 5][(byte)(D2 >> 16)] ^
138+
crc_tables[ 4][(byte)(D2 >> 24)] ^
139+
crc_tables[ 3][(byte) D3 ] ^
140+
crc_tables[ 2][(byte)(D3 >> 8)] ^
141+
crc_tables[ 1][(byte)(D3 >> 16)] ^
142+
crc_tables[ 0][(byte)(D3 >> 24)];
89143
}
90144
#endif
91145

@@ -111,74 +165,6 @@ ushort Checksum14(ushort StartCRC,const void *Addr,size_t Size)
111165
#endif
112166

113167

114-
#if 0
115-
static uint64 crc64_tables[8][256]; // Tables for Slicing-by-8 for CRC64.
116-
117-
void InitCRC64(uint64 *CRCTab)
118-
{
119-
const uint64 poly=INT32TO64(0xC96C5795, 0xD7870F42); // 0xC96C5795D7870F42;
120-
for (uint I=0;I<256;I++)
121-
{
122-
uint64 C=I;
123-
for (uint J=0;J<8;J++)
124-
C=(C & 1) ? (C>>1)^poly: (C>>1);
125-
CRCTab[I]=C;
126-
}
127-
}
128-
129-
130-
static void InitTables64()
131-
{
132-
InitCRC64(crc64_tables[0]);
133-
134-
for (uint I=0;I<256;I++) // Build additional lookup tables.
135-
{
136-
uint64 C=crc64_tables[0][I];
137-
for (uint J=1;J<8;J++)
138-
{
139-
C=crc64_tables[0][(byte)C]^(C>>8);
140-
crc64_tables[J][I]=C;
141-
}
142-
}
143-
}
144-
145-
146-
// We cannot place the intialization to CRC64(), because we use this function
147-
// in multithreaded mode and it conflicts with multithreading.
148-
struct CallInitCRC64 {CallInitCRC64() {InitTables64();}} static CallInit64;
149-
150-
uint64 CRC64(uint64 StartCRC,const void *Addr,size_t Size)
151-
{
152-
byte *Data=(byte *)Addr;
153-
154-
// Align Data to 8 for better performance.
155-
for (;Size>0 && ((size_t)Data & 7)!=0;Size--,Data++)
156-
StartCRC=crc64_tables[0][(byte)(StartCRC^Data[0])]^(StartCRC>>8);
157-
158-
for (byte *DataEnd=Data+Size/8*8; Data<DataEnd; Data+=8 )
159-
{
160-
uint64 Index=StartCRC;
161-
#ifdef BIG_ENDIAN
162-
Index ^= (uint64(Data[0])|(uint64(Data[1])<<8)|(uint64(Data[2])<<16)|(uint64(Data[3])<<24))|
163-
(uint64(Data[4])<<32)|(uint64(Data[5])<<40)|(uint64(Data[6])<<48)|(uint64(Data[7])<<56);
164-
#else
165-
Index ^= *(uint64 *)Data;
166-
#endif
167-
StartCRC = crc64_tables[ 7 ] [ ( byte ) (Index ) ] ^
168-
crc64_tables[ 6 ] [ ( byte ) (Index >> 8 ) ] ^
169-
crc64_tables[ 5 ] [ ( byte ) (Index >> 16 ) ] ^
170-
crc64_tables[ 4 ] [ ( byte ) (Index >> 24 ) ] ^
171-
crc64_tables[ 3 ] [ ( byte ) (Index >> 32 ) ] ^
172-
crc64_tables[ 2 ] [ ( byte ) (Index >> 40 ) ] ^
173-
crc64_tables[ 1 ] [ ( byte ) (Index >> 48 ) ] ^
174-
crc64_tables[ 0 ] [ ( byte ) (Index >> 56 ) ] ;
175-
}
176-
177-
for (Size%=8;Size>0;Size--,Data++) // Process left data.
178-
StartCRC=crc64_tables[0][(byte)(StartCRC^Data[0])]^(StartCRC>>8);
179-
180-
return StartCRC;
181-
}
182168

183169

184170
#if 0
@@ -187,6 +173,11 @@ struct TestCRCStruct {TestCRCStruct() {TestCRC();exit(0);}} GlobalTesCRC;
187173

188174
void TestCRC()
189175
{
176+
// This function is invoked from global object and _SSE_Version is global
177+
// and can be initialized after this function. So we explicitly initialize
178+
// it here to enable SSE support in Blake2sp.
179+
_SSE_Version=GetSSEVersion();
180+
190181
const uint FirstSize=300;
191182
byte b[FirstSize];
192183

@@ -252,23 +243,38 @@ void TestCRC()
252243

253244
const size_t BufSize=0x100000;
254245
byte *Buf=new byte[BufSize];
255-
memset(Buf,0,BufSize);
246+
GetRnd(Buf,BufSize);
256247

257248
clock_t StartTime=clock();
258249
r32=0xffffffff;
259-
const uint BufCount=5000;
250+
const uint64 BufCount=5000;
260251
for (uint I=0;I<BufCount;I++)
261252
r32=CRC32(r32,Buf,BufSize);
262253
if (r32!=0) // Otherwise compiler optimizer removes CRC calculation.
263-
mprintf(L"\nCRC32 speed: %d MB/s",BufCount*1000/(clock()-StartTime));
254+
mprintf(L"\nCRC32 speed: %llu MB/s",BufCount*CLOCKS_PER_SEC/(clock()-StartTime));
255+
256+
StartTime=clock();
257+
DataHash Hash;
258+
Hash.Init(HASH_CRC32,MaxPoolThreads);
259+
const uint64 BufCountMT=20000;
260+
for (uint I=0;I<BufCountMT;I++)
261+
Hash.Update(Buf,BufSize);
262+
HashValue Result;
263+
Hash.Result(&Result);
264+
mprintf(L"\nCRC32 MT speed: %llu MB/s",BufCountMT*CLOCKS_PER_SEC/(clock()-StartTime));
265+
266+
StartTime=clock();
267+
Hash.Init(HASH_BLAKE2,MaxPoolThreads);
268+
for (uint I=0;I<BufCount;I++)
269+
Hash.Update(Buf,BufSize);
270+
Hash.Result(&Result);
271+
mprintf(L"\nBlake2sp speed: %llu MB/s",BufCount*CLOCKS_PER_SEC/(clock()-StartTime));
264272

265273
StartTime=clock();
266274
r64=0xffffffffffffffff;
267275
for (uint I=0;I<BufCount;I++)
268276
r64=CRC64(r64,Buf,BufSize);
269277
if (r64!=0) // Otherwise compiler optimizer removes CRC calculation.
270-
mprintf(L"\nCRC64 speed: %d MB/s",BufCount*1000/(clock()-StartTime));
278+
mprintf(L"\nCRC64 speed: %llu MB/s",BufCount*CLOCKS_PER_SEC/(clock()-StartTime));
271279
}
272280
#endif
273-
274-
#endif

0 commit comments

Comments
 (0)