[llvm-commits] [test-suite] r170306 [1/7] - in /test-suite/trunk: ./ MultiSource/Benchmarks/ MultiSource/Benchmarks/7zip/ MultiSource/Benchmarks/7zip/C/ MultiSource/Benchmarks/7zip/C/LzmaUtil/ MultiSource/Benchmarks/7zip/CPP/ MultiSource/Benchmarks/7zip/CPP/7zip/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ MultiSource/Ben...

Michael Gottesman mgottesman at apple.com
Sun Dec 16 21:23:34 PST 2012


Author: mgottesman
Date: Sun Dec 16 23:23:25 2012
New Revision: 170306

URL: http://llvm.org/viewvc/llvm-project?rev=170306&view=rev
Log:
Added test 7zip-benchmark.

Added:
    test-suite/trunk/MultiSource/Benchmarks/7zip/
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf2.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcOpt.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcT8.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zStream.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zVersion.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.back3
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back2
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra86.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/BraIA64.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzHash.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Dec.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Enc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Dec.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Enc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/RotateDefs.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Types.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzDec.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzIn.c
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zExtract.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zItem.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ApmHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArchiveExports.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArjHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Bz2Handler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabItem.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ParseProperties.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ParseProperties.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/CpioHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/CramfsHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/DebHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/DeflateProps.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/DeflateProps.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/DllExports2.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/DmgHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ElfHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/FatHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/FlvHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/GzHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Hfs/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Hfs/HfsHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Hfs/HfsHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Hfs/HfsIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Hfs/HfsIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Hfs/HfsRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/IArchive.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/IsoHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/IsoHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/IsoHeader.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/IsoHeader.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/IsoIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/IsoIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/IsoItem.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Iso/IsoRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/LzhHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/LzmaHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/MachoHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/MbrHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/MslzHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/MubHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Nsis/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Nsis/NsisDecode.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Nsis/NsisDecode.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Nsis/NsisHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Nsis/NsisHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Nsis/NsisIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Nsis/NsisIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Nsis/NsisRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/NtfsHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/PeHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/PpmdHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarHeader.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarHeader.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarItem.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarItem.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/RpmHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/SplitHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/SquashfsHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/SwfHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarHandlerOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarHeader.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarHeader.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarItem.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarOut.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarUpdate.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Tar/TarUpdate.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Udf/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Udf/UdfHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Udf/UdfHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Udf/UdfIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Udf/UdfIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Udf/UdfRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/VhdHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Wim/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Wim/WimHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Wim/WimHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Wim/WimHandlerOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Wim/WimIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Wim/WimIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Wim/WimRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/XarHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/XzHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ZHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipAddCommon.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipCompressionMode.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipHandler.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipHeader.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipHeader.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipIn.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipIn.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipItem.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipItem.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipItemEx.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipOut.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipUpdate.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Zip/ZipUpdate.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Alone/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Alone/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Alone/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Alone/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Alone7z/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Alone7z/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Alone7z/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Alone7z/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/AloneGCOV/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/AloneGCOV/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Format7zFree/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Format7zFree/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Format7zFree/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/Format7zFree/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/SFXCon/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/SFXCon/Main.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/SFXCon/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/SFXCon/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Bundles/SFXCon/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/CMAKE/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/CMAKE/CMakeLists_7zFM.txt
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/CMAKE/CMakeLists_7zG.txt
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/CMAKE/CMakeLists_7za.txt
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/CMAKE/CMakeLists_ALL.txt
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/CMAKE/CMakeLists_Format7zFree.txt
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/CMAKE/generate.sh   (with props)
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/CMAKE/generate_xcode.sh   (with props)
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/CWrappers.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/CWrappers.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/CreateCoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/CreateCoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/FilePathAutoRename.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/FilePathAutoRename.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/FileStreams.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/FileStreams.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/FilterCoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/FilterCoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/InBuffer.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/InBuffer.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/InOutTempBuffer.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/InOutTempBuffer.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/LimitedStreams.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/LimitedStreams.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/LockedStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/LockedStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/MemBlocks.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/MemBlocks.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/MethodId.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/MethodId.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/MethodProps.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/MethodProps.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/OffsetStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/OffsetStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/OutBuffer.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/OutBuffer.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/OutMemStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/OutMemStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/ProgressMt.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/ProgressMt.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/ProgressUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/ProgressUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/RegisterArc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/RegisterCodec.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/StreamBinder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/StreamBinder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/StreamObjects.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/StreamObjects.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/StreamUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/StreamUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/VirtThread.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Common/VirtThread.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ArjDecoder1.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ArjDecoder1.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ArjDecoder2.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ArjDecoder2.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Const.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Crc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Crc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Register.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Register.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlEncoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmEncoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ByteSwap.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CodecExports.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Deflate64Register.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateConst.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeltaFilter.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports2.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/HuffmanDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Register.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Mtf8.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoderBit.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RarCodecsRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAesRegister.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Guid.txt
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/ICoder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IDecl.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IPassword.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IProgress.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/MyVersion.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/generate.sh   (with props)
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/premake4.lua
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PropID.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/test_emul/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/TestUI.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOut.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/IFolderArchive.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/Client7z.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/ClientCodec.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DirItem.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExitCode.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractMode.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/IFileExtractCallback.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Property.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Update.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Update.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/UpdateAction.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/UpdateAction.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/UpdateCallback.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/UpdateCallback.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/UpdatePair.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/UpdatePair.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/UpdateProduce.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/UpdateProduce.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/WorkDir.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/WorkDir.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ZipRegistry.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ZipRegistry.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/BenchCon.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/BenchCon.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/ConsoleClose.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/ConsoleClose.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/ExtractCallbackConsole.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/ExtractCallbackConsole.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/List.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/List.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/Main.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/MainAr.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/OpenCallbackConsole.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/OpenCallbackConsole.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/PercentPrinter.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/PercentPrinter.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/UpdateCallbackConsole.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/UserInputUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/UserInputUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Console/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Explorer/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Explorer/ContextMenu.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Explorer/MyMessages.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Explorer/MyMessages.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/App.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/App.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/AppState.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/BrowseDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ClassDefs.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ComboDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ComboDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ComboDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ComboDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/CopyDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/CopyDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/CopyDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/CopyDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/DialogSize.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ExtractCallback.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ExtractCallback.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FM.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FM_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FSDrives.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FSDrives.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FSFolder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FSFolder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FSFolderCopy.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FileFolderPluginOpen.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FileFolderPluginOpen.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FormatUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/FormatUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/HelpUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/IFolder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/LangUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/LangUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ListViewDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ListViewDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ListViewDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ListViewDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/MessagesDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/MessagesDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/MessagesDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/MessagesDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/MyLoadMenu.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/MyLoadMenu.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/NetFolder.h.OUT
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/OpenCallback.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/OpenCallback.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/OverwriteDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/OverwriteDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/OverwriteDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/OverwriteDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/Panel.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/Panel.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelCopy.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelCrc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelCrc.cpp.back
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelFolderChange.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelItemOpen.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelItems.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelListNotify.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelMenu.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelOperations.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelSelect.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelSort.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PanelSplitFile.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PasswordDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PasswordDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PasswordDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PasswordDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PluginInterface.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PluginLoader.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ProgramLocation.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ProgramLocation.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ProgressDialog2.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ProgressDialog2.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ProgressDialog2Res.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ProgressDialog2_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ProgressDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PropertyName.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PropertyName.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/PropertyNameRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/RegistryAssociations.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/RegistryAssociations.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/RegistryPlugins.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/RegistryUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/RegistryUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/RootFolder.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/RootFolder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/SplitDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/SplitDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/SplitDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/SplitDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/SplitUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/SplitUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/StringUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/StringUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/SysIconUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/SysIconUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/TextPairs.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/TextPairs.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/UpdateCallback100.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/UpdateCallback100.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ViewSettings.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/ViewSettings.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/err
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/Add2PNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/AddPNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/Copy2PNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/CopyPNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/Delete2PNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/DeletePNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/Extract2PNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/ExtractPNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/Info2PNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/InfoPNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/Move2PNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/MovePNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/ParentFolder.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/Test2PNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/res/TestPNG.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/resource.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/resourceGui.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/FileManager/wxFM.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/BenchmarkDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/BenchmarkDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/BenchmarkDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/BenchmarkDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/CompressDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/CompressDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/CompressDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/CompressDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/ExtractDialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/ExtractDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/ExtractDialogRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/ExtractDialog_rc.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/ExtractGUI.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/ExtractGUI.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/ExtractRes.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/GUI.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/UpdateCallbackGUI.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/UpdateCallbackGUI.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/UpdateGUI.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/UpdateGUI.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/err
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/resource2.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/GUI/wxGUI.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/FileDir.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/FileFind.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/IntToString.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/MyString.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/MyVector.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/StringConvert.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/Threads.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/wine_date_and_time.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/wxP7ZIP.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/P7ZIP/wxP7ZIP.o
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/AutoPtr.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/Buffer.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/CRC.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/C_FileIO.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/C_FileIO.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/ComTry.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/CommandLineParser.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/CommandLineParser.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/Defs.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/DynamicBuffer.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/IntToString.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/IntToString.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/Lang.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/Lang.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/ListFileUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/ListFileUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyCom.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyException.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyGuidDef.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyInitGuid.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyMap.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyMap.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyString.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyString.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyUnknown.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyVector.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyVector.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyWindows.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyWindows.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyXml.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/MyXml.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/NewHandler.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/StdInStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/StdInStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/StdOutStream.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/StdOutStream.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/StringConvert.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/StringConvert.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/StringToInt.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/StringToInt.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/TextConfig.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/TextConfig.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/Types.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/UTFConvert.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/UTFConvert.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/Wildcard.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Common/Wildcard.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/COM.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/COM.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Clipboard.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Clipboard.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/CommonDialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/ComboBox.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/Controls.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/Dialog.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/Dialog.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/DialogImpl.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/Edit.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/ListView.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/ProgressBar.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/Static.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/StatusBar.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/Window2.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Control/Window2.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/DLL.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/DLL.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Defs.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Error.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Error.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/FileDir.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/FileDir.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/FileFind.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/FileFind.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/FileIO.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/FileIO.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/FileName.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/FileName.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Menu.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/NtCheck.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/PropVariant.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/PropVariant.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/PropVariantConversions.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/PropVariantConversions.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/PropVariantUtils.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/PropVariantUtils.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Registry.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Registry.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/ResourceString.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Shell.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Synchronization.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Synchronization.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Synchronization2.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/System.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/System.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Thread.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Time.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Time.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Window.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/Windows/Window.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/include_windows/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/include_windows/basetyps.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/include_windows/tchar.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/include_windows/windows.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/StdAfx.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/config.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/initguid.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/makefile.depend
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/makefile.list
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/myAddExeFlag.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/myGetTickCount.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/myPrivate.h
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/mySplitCommandLine.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/test_emul.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/wine_GetXXXDefaultLangID.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/myWindows/wine_date_and_time.cpp
    test-suite/trunk/MultiSource/Benchmarks/7zip/License.txt
    test-suite/trunk/MultiSource/Benchmarks/7zip/Makefile
    test-suite/trunk/MultiSource/Benchmarks/7zip/unRarLicense.txt
Modified:
    test-suite/trunk/LICENSE.TXT
    test-suite/trunk/MultiSource/Benchmarks/Makefile

Modified: test-suite/trunk/LICENSE.TXT
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/LICENSE.TXT?rev=170306&r1=170305&r2=170306&view=diff
==============================================================================
--- test-suite/trunk/LICENSE.TXT (original)
+++ test-suite/trunk/LICENSE.TXT Sun Dec 16 23:23:25 2012
@@ -103,6 +103,7 @@
 jpeg:               llvm-test/MultiSource/Benchmarks/mediabench/jpeg
 mpeg2:              llvm-test/MultiSource/Benchmarks/mediabench/mpeg2
 TSVC:               llvm-test/MultiSource/Benchmarks/TSVC
+7zip (Benchmark):   llvm-test/MultiSource/Benchmarks/7zip
 Dhrystone:          llvm-test/SingleSource/Benchmarks/Dhrystone
 SingleSource Tests: llvm-test/SingleSource/Benchmarks/Misc
                     llvm-test/SingleSource/CustomChecked

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,39 @@
+/* 7zBuf.h -- Byte Buffer
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_BUF_H
+#define __7Z_BUF_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct
+{
+  Byte *data;
+  size_t size;
+} CBuf;
+
+void Buf_Init(CBuf *p);
+int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
+void Buf_Free(CBuf *p, ISzAlloc *alloc);
+
+typedef struct
+{
+  Byte *data;
+  size_t size;
+  size_t pos;
+} CDynBuf;
+
+void DynBuf_Construct(CDynBuf *p);
+void DynBuf_SeekToBeg(CDynBuf *p);
+int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);
+void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf2.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf2.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf2.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zBuf2.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,45 @@
+/* 7zBuf2.c -- Byte Buffer
+2008-10-04 : Igor Pavlov : Public domain */
+
+#include <string.h>
+#include "7zBuf.h"
+
+void DynBuf_Construct(CDynBuf *p)
+{
+  p->data = 0;
+  p->size = 0;
+  p->pos = 0;
+}
+
+void DynBuf_SeekToBeg(CDynBuf *p)
+{
+  p->pos = 0;
+}
+
+int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)
+{
+  if (size > p->size - p->pos)
+  {
+    size_t newSize = p->pos + size;
+    Byte *data;
+    newSize += newSize / 4;
+    data = (Byte *)alloc->Alloc(alloc, newSize);
+    if (data == 0)
+      return 0;
+    p->size = newSize;
+    memcpy(data, p->data, p->pos);
+    alloc->Free(alloc, p->data);
+    p->data = data;
+  }
+  memcpy(p->data + p->pos, buf, size);
+  p->pos += size;
+  return 1;
+}
+
+void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->data);
+  p->data = 0;
+  p->size = 0;
+  p->pos = 0;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,76 @@
+/* 7zCrc.c -- CRC32 calculation
+2009-11-23 : Igor Pavlov : Public domain */
+
+#include "7zCrc.h"
+#include "CpuArch.h"
+
+#define kCrcPoly 0xEDB88320
+
+#ifdef MY_CPU_LE
+#define CRC_NUM_TABLES 8
+#else
+#define CRC_NUM_TABLES 1
+#endif
+
+typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table);
+
+static CRC_FUNC g_CrcUpdate;
+UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
+
+#if CRC_NUM_TABLES == 1
+
+#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+
+static UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table)
+{
+  const Byte *p = (const Byte *)data;
+  for (; size > 0; size--, p++)
+    v = CRC_UPDATE_BYTE_2(v, *p);
+  return v;
+}
+
+#else
+
+UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
+UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
+
+#endif
+
+UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
+{
+  return g_CrcUpdate(v, data, size, g_CrcTable);
+}
+
+UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
+{
+  return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL;
+}
+
+void MY_FAST_CALL CrcGenerateTable()
+{
+  UInt32 i;
+  for (i = 0; i < 256; i++)
+  {
+    UInt32 r = i;
+    unsigned j;
+    for (j = 0; j < 8; j++)
+      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
+    g_CrcTable[i] = r;
+  }
+  #if CRC_NUM_TABLES == 1
+  g_CrcUpdate = CrcUpdateT1;
+  #else
+  for (; i < 256 * CRC_NUM_TABLES; i++)
+  {
+    UInt32 r = g_CrcTable[i - 256];
+    g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
+  }
+  g_CrcUpdate = CrcUpdateT4;
+/* FIXME
+  #ifdef MY_CPU_X86_OR_AMD64
+  if (!CPU_Is_InOrder())
+    g_CrcUpdate = CrcUpdateT8;
+  #endif
+*/
+  #endif
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrc.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,25 @@
+/* 7zCrc.h -- CRC32 calculation
+2009-11-21 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_CRC_H
+#define __7Z_CRC_H
+
+#include "Types.h"
+
+EXTERN_C_BEGIN
+
+extern UInt32 g_CrcTable[];
+
+/* Call CrcGenerateTable one time before other CRC functions */
+void MY_FAST_CALL CrcGenerateTable(void);
+
+#define CRC_INIT_VAL 0xFFFFFFFF
+#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL)
+#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+
+UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
+UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
+
+EXTERN_C_END
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcOpt.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcOpt.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcOpt.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcOpt.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,34 @@
+/* 7zCrcOpt.c -- CRC32 calculation : optimized version
+2009-11-23 : Igor Pavlov : Public domain */
+
+#include "CpuArch.h"
+
+#ifdef MY_CPU_LE
+
+#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+
+UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
+{
+  const Byte *p = (const Byte *)data;
+  for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
+    v = CRC_UPDATE_BYTE_2(v, *p);
+  for (; size >= 4; size -= 4, p += 4)
+  {
+    v ^= *(const UInt32 *)p;
+    v =
+      table[0x300 + (v & 0xFF)] ^
+      table[0x200 + ((v >> 8) & 0xFF)] ^
+      table[0x100 + ((v >> 16) & 0xFF)] ^
+      table[0x000 + ((v >> 24))];
+  }
+  for (; size > 0; size--, p++)
+    v = CRC_UPDATE_BYTE_2(v, *p);
+  return v;
+}
+
+UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table)
+{
+  return CrcUpdateT4(v, data, size, table);
+}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcT8.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcT8.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcT8.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zCrcT8.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,43 @@
+/* 7zCrcT8.c -- CRC32 calculation with 8 tables
+2008-03-19
+Igor Pavlov
+Public domain */
+
+#include "7zCrc.h"
+
+#define kCrcPoly 0xEDB88320
+#define CRC_NUM_TABLES 8
+
+UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
+
+void MY_FAST_CALL CrcGenerateTable()
+{
+  UInt32 i;
+  for (i = 0; i < 256; i++)
+  {
+    UInt32 r = i;
+    int j;
+    for (j = 0; j < 8; j++)
+      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
+    g_CrcTable[i] = r;
+  }
+  #if CRC_NUM_TABLES > 1
+  for (; i < 256 * CRC_NUM_TABLES; i++)
+  {
+    UInt32 r = g_CrcTable[i - 256];
+    g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
+  }
+  #endif
+}
+
+UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
+
+UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
+{
+  return CrcUpdateT8(v, data, size, g_CrcTable);
+}
+
+UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
+{
+  return CrcUpdateT8(CRC_INIT_VAL, data, size, g_CrcTable) ^ 0xFFFFFFFF;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zStream.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zStream.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zStream.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zStream.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,169 @@
+/* 7zStream.c -- 7z Stream functions
+2010-03-11 : Igor Pavlov : Public domain */
+
+#include <string.h>
+
+#include "Types.h"
+
+SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
+{
+  while (size != 0)
+  {
+    size_t processed = size;
+    RINOK(stream->Read(stream, buf, &processed));
+    if (processed == 0)
+      return errorType;
+    buf = (void *)((Byte *)buf + processed);
+    size -= processed;
+  }
+  return SZ_OK;
+}
+
+SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
+{
+  return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
+}
+
+SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
+{
+  size_t processed = 1;
+  RINOK(stream->Read(stream, buf, &processed));
+  return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
+}
+
+SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
+{
+  Int64 t = offset;
+  return stream->Seek(stream, &t, SZ_SEEK_SET);
+}
+
+SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
+{
+  const void *lookBuf;
+  if (*size == 0)
+    return SZ_OK;
+  RINOK(stream->Look(stream, &lookBuf, size));
+  memcpy(buf, lookBuf, *size);
+  return stream->Skip(stream, *size);
+}
+
+SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
+{
+  while (size != 0)
+  {
+    size_t processed = size;
+    RINOK(stream->Read(stream, buf, &processed));
+    if (processed == 0)
+      return errorType;
+    buf = (void *)((Byte *)buf + processed);
+    size -= processed;
+  }
+  return SZ_OK;
+}
+
+SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
+{
+  return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
+}
+
+static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size)
+{
+  SRes res = SZ_OK;
+  CLookToRead *p = (CLookToRead *)pp;
+  size_t size2 = p->size - p->pos;
+  if (size2 == 0 && *size > 0)
+  {
+    p->pos = 0;
+    size2 = LookToRead_BUF_SIZE;
+    res = p->realStream->Read(p->realStream, p->buf, &size2);
+    p->size = size2;
+  }
+  if (size2 < *size)
+    *size = size2;
+  *buf = p->buf + p->pos;
+  return res;
+}
+
+static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size)
+{
+  SRes res = SZ_OK;
+  CLookToRead *p = (CLookToRead *)pp;
+  size_t size2 = p->size - p->pos;
+  if (size2 == 0 && *size > 0)
+  {
+    p->pos = 0;
+    if (*size > LookToRead_BUF_SIZE)
+      *size = LookToRead_BUF_SIZE;
+    res = p->realStream->Read(p->realStream, p->buf, size);
+    size2 = p->size = *size;
+  }
+  if (size2 < *size)
+    *size = size2;
+  *buf = p->buf + p->pos;
+  return res;
+}
+
+static SRes LookToRead_Skip(void *pp, size_t offset)
+{
+  CLookToRead *p = (CLookToRead *)pp;
+  p->pos += offset;
+  return SZ_OK;
+}
+
+static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
+{
+  CLookToRead *p = (CLookToRead *)pp;
+  size_t rem = p->size - p->pos;
+  if (rem == 0)
+    return p->realStream->Read(p->realStream, buf, size);
+  if (rem > *size)
+    rem = *size;
+  memcpy(buf, p->buf + p->pos, rem);
+  p->pos += rem;
+  *size = rem;
+  return SZ_OK;
+}
+
+static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
+{
+  CLookToRead *p = (CLookToRead *)pp;
+  p->pos = p->size = 0;
+  return p->realStream->Seek(p->realStream, pos, origin);
+}
+
+void LookToRead_CreateVTable(CLookToRead *p, int lookahead)
+{
+  p->s.Look = lookahead ?
+      LookToRead_Look_Lookahead :
+      LookToRead_Look_Exact;
+  p->s.Skip = LookToRead_Skip;
+  p->s.Read = LookToRead_Read;
+  p->s.Seek = LookToRead_Seek;
+}
+
+void LookToRead_Init(CLookToRead *p)
+{
+  p->pos = p->size = 0;
+}
+
+static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
+{
+  CSecToLook *p = (CSecToLook *)pp;
+  return LookInStream_LookRead(p->realStream, buf, size);
+}
+
+void SecToLook_CreateVTable(CSecToLook *p)
+{
+  p->s.Read = SecToLook_Read;
+}
+
+static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
+{
+  CSecToRead *p = (CSecToRead *)pp;
+  return p->realStream->Read(p->realStream, buf, size);
+}
+
+void SecToRead_CreateVTable(CSecToRead *p)
+{
+  p->s.Read = SecToRead_Read;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zVersion.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zVersion.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zVersion.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/7zVersion.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,7 @@
+#define MY_VER_MAJOR 9
+#define MY_VER_MINOR 20
+#define MY_VER_BUILD 0
+#define MY_VERSION "9.20"
+#define MY_DATE "2010-11-18"
+#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
+#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,284 @@
+/* Aes.c -- AES encryption / decryption
+2009-11-23 : Igor Pavlov : Public domain */
+
+#include "Aes.h"
+#include "CpuArch.h"
+
+static UInt32 T[256 * 4];
+static Byte Sbox[256] = {
+  0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
+  0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
+  0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
+  0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
+  0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
+  0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
+  0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
+  0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
+  0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
+  0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
+  0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
+  0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
+  0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
+  0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
+  0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
+  0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16};
+
+void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks);
+void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks);
+void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks);
+
+void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
+void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
+void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
+
+AES_CODE_FUNC g_AesCbc_Encode;
+AES_CODE_FUNC g_AesCbc_Decode;
+AES_CODE_FUNC g_AesCtr_Code;
+
+static UInt32 D[256 * 4];
+static Byte InvS[256];
+
+static Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
+
+#define xtime(x) ((((x) << 1) ^ (((x) & 0x80) != 0 ? 0x1B : 0)) & 0xFF)
+
+#define Ui32(a0, a1, a2, a3) ((UInt32)(a0) | ((UInt32)(a1) << 8) | ((UInt32)(a2) << 16) | ((UInt32)(a3) << 24))
+
+#define gb0(x) ( (x)          & 0xFF)
+#define gb1(x) (((x) >> ( 8)) & 0xFF)
+#define gb2(x) (((x) >> (16)) & 0xFF)
+#define gb3(x) (((x) >> (24)) & 0xFF)
+
+void AesGenTables(void)
+{
+  unsigned i;
+  for (i = 0; i < 256; i++)
+    InvS[Sbox[i]] = (Byte)i;
+  for (i = 0; i < 256; i++)
+  {
+    {
+      UInt32 a1 = Sbox[i];
+      UInt32 a2 = xtime(a1);
+      UInt32 a3 = a2 ^ a1;
+      T[        i] = Ui32(a2, a1, a1, a3);
+      T[0x100 + i] = Ui32(a3, a2, a1, a1);
+      T[0x200 + i] = Ui32(a1, a3, a2, a1);
+      T[0x300 + i] = Ui32(a1, a1, a3, a2);
+    }
+    {
+      UInt32 a1 = InvS[i];
+      UInt32 a2 = xtime(a1);
+      UInt32 a4 = xtime(a2);
+      UInt32 a8 = xtime(a4);
+      UInt32 a9 = a8 ^ a1;
+      UInt32 aB = a8 ^ a2 ^ a1;
+      UInt32 aD = a8 ^ a4 ^ a1;
+      UInt32 aE = a8 ^ a4 ^ a2;
+      D[        i] = Ui32(aE, a9, aD, aB);
+      D[0x100 + i] = Ui32(aB, aE, a9, aD);
+      D[0x200 + i] = Ui32(aD, aB, aE, a9);
+      D[0x300 + i] = Ui32(a9, aD, aB, aE);
+    }
+  }
+  g_AesCbc_Encode = AesCbc_Encode;
+  g_AesCbc_Decode = AesCbc_Decode;
+  g_AesCtr_Code = AesCtr_Code;
+/* FIXME
+  #ifdef MY_CPU_X86_OR_AMD64
+  if (CPU_Is_Aes_Supported())
+  {
+    g_AesCbc_Encode = AesCbc_Encode_Intel;
+    g_AesCbc_Decode = AesCbc_Decode_Intel;
+    g_AesCtr_Code = AesCtr_Code_Intel;
+  }
+  #endif
+*/
+}
+
+#define HT(i, x, s) (T + (x << 8))[gb ## x(s[(i + x) & 3])]
+#define HT4(m, i, s, p) m[i] = \
+    HT(i, 0, s) ^ \
+    HT(i, 1, s) ^ \
+    HT(i, 2, s) ^ \
+    HT(i, 3, s) ^ w[p + i]
+/* such order (2031) in HT16 is for VC6/K8 speed optimization) */
+#define HT16(m, s, p) \
+    HT4(m, 2, s, p); \
+    HT4(m, 0, s, p); \
+    HT4(m, 3, s, p); \
+    HT4(m, 1, s, p); \
+
+#define FT(i, x) Sbox[gb ## x(m[(i + x) & 3])]
+#define FT4(i) dest[i] = Ui32(FT(i, 0), FT(i, 1), FT(i, 2), FT(i, 3)) ^ w[i];
+
+#define HD(i, x, s) (D + (x << 8))[gb ## x(s[(i - x) & 3])]
+#define HD4(m, i, s, p) m[i] = \
+    HD(i, 0, s) ^ \
+    HD(i, 1, s) ^ \
+    HD(i, 2, s) ^ \
+    HD(i, 3, s) ^ w[p + i];
+/* such order (0231) in HD16 is for VC6/K8 speed optimization) */
+#define HD16(m, s, p) \
+    HD4(m, 0, s, p); \
+    HD4(m, 2, s, p); \
+    HD4(m, 3, s, p); \
+    HD4(m, 1, s, p); \
+
+#define FD(i, x) InvS[gb ## x(m[(i - x) & 3])]
+#define FD4(i) dest[i] = Ui32(FD(i, 0), FD(i, 1), FD(i, 2), FD(i, 3)) ^ w[i];
+
+void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *w, const Byte *key, unsigned keySize)
+{
+  unsigned i, wSize;
+  wSize = keySize + 28;
+  keySize /= 4;
+  w[0] = ((UInt32)keySize / 2) + 3;
+  w += 4;
+
+  for (i = 0; i < keySize; i++, key += 4)
+    w[i] = GetUi32(key);
+
+  for (; i < wSize; i++)
+  {
+    UInt32 t = w[i - 1];
+    unsigned rem = i % keySize;
+    if (rem == 0)
+      t = Ui32(Sbox[gb1(t)] ^ Rcon[i / keySize], Sbox[gb2(t)], Sbox[gb3(t)], Sbox[gb0(t)]);
+    else if (keySize > 6 && rem == 4)
+      t = Ui32(Sbox[gb0(t)], Sbox[gb1(t)], Sbox[gb2(t)], Sbox[gb3(t)]);
+    w[i] = w[i - keySize] ^ t;
+  }
+}
+
+void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *w, const Byte *key, unsigned keySize)
+{
+  unsigned i, num;
+  Aes_SetKey_Enc(w, key, keySize);
+  num = keySize + 20;
+  w += 8;
+  for (i = 0; i < num; i++)
+  {
+    UInt32 r = w[i];
+    w[i] =
+      D[        Sbox[gb0(r)]] ^
+      D[0x100 + Sbox[gb1(r)]] ^
+      D[0x200 + Sbox[gb2(r)]] ^
+      D[0x300 + Sbox[gb3(r)]];
+  }
+}
+
+/* Aes_Encode and Aes_Decode functions work with little-endian words.
+  src and dest are pointers to 4 UInt32 words.
+  arc and dest can point to same block */
+
+static void Aes_Encode(const UInt32 *w, UInt32 *dest, const UInt32 *src)
+{
+  UInt32 s[4];
+  UInt32 m[4];
+  UInt32 numRounds2 = w[0];
+  w += 4;
+  s[0] = src[0] ^ w[0];
+  s[1] = src[1] ^ w[1];
+  s[2] = src[2] ^ w[2];
+  s[3] = src[3] ^ w[3];
+  w += 4;
+  for (;;)
+  {
+    HT16(m, s, 0);
+    if (--numRounds2 == 0)
+      break;
+    HT16(s, m, 4);
+    w += 8;
+  }
+  w += 4;
+  FT4(0); FT4(1); FT4(2); FT4(3);
+}
+
+static void Aes_Decode(const UInt32 *w, UInt32 *dest, const UInt32 *src)
+{
+  UInt32 s[4];
+  UInt32 m[4];
+  UInt32 numRounds2 = w[0];
+  w += 4 + numRounds2 * 8;
+  s[0] = src[0] ^ w[0];
+  s[1] = src[1] ^ w[1];
+  s[2] = src[2] ^ w[2];
+  s[3] = src[3] ^ w[3];
+  for (;;)
+  {
+    w -= 8;
+    HD16(m, s, 4);
+    if (--numRounds2 == 0)
+      break;
+    HD16(s, m, 0);
+  }
+  FD4(0); FD4(1); FD4(2); FD4(3);
+}
+
+void AesCbc_Init(UInt32 *p, const Byte *iv)
+{
+  unsigned i;
+  for (i = 0; i < 4; i++)
+    p[i] = GetUi32(iv + i * 4);
+}
+
+void MY_FAST_CALL AesCbc_Encode(UInt32 *p, Byte *data, size_t numBlocks)
+{
+  for (; numBlocks != 0; numBlocks--, data += AES_BLOCK_SIZE)
+  {
+    p[0] ^= GetUi32(data);
+    p[1] ^= GetUi32(data + 4);
+    p[2] ^= GetUi32(data + 8);
+    p[3] ^= GetUi32(data + 12);
+    
+    Aes_Encode(p + 4, p, p);
+    
+    SetUi32(data,      p[0]);
+    SetUi32(data + 4,  p[1]);
+    SetUi32(data + 8,  p[2]);
+    SetUi32(data + 12, p[3]);
+  }
+}
+
+void MY_FAST_CALL AesCbc_Decode(UInt32 *p, Byte *data, size_t numBlocks)
+{
+  UInt32 in[4], out[4];
+  for (; numBlocks != 0; numBlocks--, data += AES_BLOCK_SIZE)
+  {
+    in[0] = GetUi32(data);
+    in[1] = GetUi32(data + 4);
+    in[2] = GetUi32(data + 8);
+    in[3] = GetUi32(data + 12);
+
+    Aes_Decode(p + 4, out, in);
+
+    SetUi32(data,      p[0] ^ out[0]);
+    SetUi32(data + 4,  p[1] ^ out[1]);
+    SetUi32(data + 8,  p[2] ^ out[2]);
+    SetUi32(data + 12, p[3] ^ out[3]);
+    
+    p[0] = in[0];
+    p[1] = in[1];
+    p[2] = in[2];
+    p[3] = in[3];
+  }
+}
+
+void MY_FAST_CALL AesCtr_Code(UInt32 *p, Byte *data, size_t numBlocks)
+{
+  for (; numBlocks != 0; numBlocks--)
+  {
+    UInt32 temp[4];
+    Byte buf[16];
+    int i;
+    if (++p[0] == 0)
+      p[1]++;
+    Aes_Encode(p + 4, temp, p);
+    SetUi32(buf,      temp[0]);
+    SetUi32(buf + 4,  temp[1]);
+    SetUi32(buf + 8,  temp[2]);
+    SetUi32(buf + 12, temp[3]);
+    for (i = 0; i < 16; i++)
+      *data++ ^= buf[i];
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Aes.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,38 @@
+/* Aes.h -- AES encryption / decryption
+2009-11-23 : Igor Pavlov : Public domain */
+
+#ifndef __AES_H
+#define __AES_H
+
+#include "Types.h"
+
+EXTERN_C_BEGIN
+
+#define AES_BLOCK_SIZE 16
+
+/* Call AesGenTables one time before other AES functions */
+void AesGenTables(void);
+
+/* UInt32 pointers must be 16-byte aligned */
+
+/* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */
+#define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4)
+
+/* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */
+/* keySize = 16 or 24 or 32 (bytes) */
+typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize);
+void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize);
+void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize);
+
+/* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */
+void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
+/* data - 16-byte aligned pointer to data */
+/* numBlocks - the number of 16-byte blocks in data array */
+typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks);
+extern AES_CODE_FUNC g_AesCbc_Encode;
+extern AES_CODE_FUNC g_AesCbc_Decode;
+extern AES_CODE_FUNC g_AesCtr_Code;
+
+EXTERN_C_END
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.back3
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.back3?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.back3 (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.back3 Sun Dec 16 23:23:25 2012
@@ -0,0 +1,238 @@
+/* Alloc.c -- Memory allocation functions
+2008-09-24
+Igor Pavlov
+Public domain */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#ifdef _7ZIP_LARGE_PAGES
+
+#ifdef __linux__
+
+#ifndef _7ZIP_ST
+#include <pthread.h>
+#endif
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+
+#ifndef SHM_HUGETLB
+#warning SHM_HUGETLB undefined ?
+#define SHM_HUGETLB 04000
+#endif
+
+/* Only ia64 requires this */
+#ifdef __ia64__
+#define ADDR (void *)(0x8000000000000000UL)
+#define SHMAT_FLAGS (SHM_RND)
+#else
+#define ADDR (void *)(0x0UL)
+#define SHMAT_FLAGS (0)
+#endif
+
+
+#endif /*  __linux__ */
+
+#endif /* _7ZIP_LARGE_PAGES */
+
+#include "Alloc.h"
+
+/* #define _SZ_ALLOC_DEBUG */
+
+/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
+#ifdef _SZ_ALLOC_DEBUG
+#include <stdio.h>
+int g_allocCount = 0;
+int g_allocCountMid = 0;
+int g_allocCountBig = 0;
+#endif
+
+void *MyAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  {
+    void *p = malloc(size);
+    fprintf(stderr, "\nAlloc %10d bytes, count = %10d,  addr = %8X", size, g_allocCount++, (unsigned)p);
+    return p;
+  }
+  #else
+  return malloc(size);
+  #endif
+}
+
+void MyFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree; count = %10d,  addr = %8X", --g_allocCount, (unsigned)address);
+  #endif
+  free(address);
+}
+
+#ifdef __linux__
+#define _7ZIP_MAX_HUGE_ALLOCS 64
+static void *g_HugePageAddr[_7ZIP_MAX_HUGE_ALLOCS] = { NULL };
+static void *g_HugePageShmid[_7ZIP_MAX_HUGE_ALLOCS];
+static size_t g_HugePageLen[_7ZIP_MAX_HUGE_ALLOCS];
+#endif
+
+static void *VirtualAlloc(void *address, size_t size, int AllocLargePages)
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  if (AllocLargePages)
+  {
+    #ifdef __linux__
+    /* huge pages support for Linux; added by Joachim Henke */
+    #ifndef _7ZIP_ST
+    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    #endif
+    int i;
+
+    address = NULL;
+    #ifndef _7ZIP_ST
+    pthread_mutex_lock(&mutex);
+    #endif
+    for (i = 0; i < _7ZIP_MAX_HUGE_ALLOCS; ++i)
+    {
+      if (g_HugePageAddr[i] == NULL)
+      {
+        char *shmaddr;
+        int shmid = shmget(2, size, SHM_HUGETLB | IPC_CREAT | SHM_R | SHM_W);
+        if (shmid < 0)
+        {
+          fprintf(stderr,"Warning shmget : %s\n",strerror(errno));
+          address = NULL;
+          break;
+        }
+        shmaddr = shmat(shmid, ADDR, SHMAT_FLAGS);
+        if (shmaddr == (char *)-1)
+        {
+          fprintf(stderr,"Warning shmat : %s\n",strerror(errno));
+          shmctl(shmid, IPC_RMID, NULL);
+          address = NULL;
+          break;
+        }
+        
+        g_HugePageShmid[i] = shmid;
+        g_HugePageLen[i] = size;
+        g_HugePageAddr[i] = address;
+printf("HUGE[%d]=%ld %p\n",i,(long)size,address);
+        break;
+      }
+    }
+    #ifndef _7ZIP_ST
+    pthread_mutex_unlock(&mutex);
+    #endif
+    return address;
+    #endif
+  }
+  #endif
+  return malloc(size);
+}
+
+static int VirtualFree(void *address)
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  #ifdef __linux__
+  int i;
+
+  for (i = 0; i < _7ZIP_MAX_HUGE_ALLOCS; ++i)
+  {
+    if (g_HugePageAddr[i] == address)
+    {
+      shmdt(g_HugePageAddr[i]);
+      shmctl(g_HugePageLen[i], IPC_RMID, NULL);
+      g_HugePageAddr[i] = NULL;
+      return 1;
+    }
+  }
+  #endif
+  #endif
+  free(address);
+  return 1;
+}
+
+void *MidAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  fprintf(stderr, "\nAlloc_Mid %10d bytes;  count = %10d", size, g_allocCountMid++);
+  #endif
+  return VirtualAlloc(0, size, 0);
+}
+
+void MidFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
+  #endif
+  if (address == 0)
+    return;
+  VirtualFree(address);
+}
+
+#ifdef _7ZIP_LARGE_PAGES
+size_t g_LargePageSize = 0;
+#endif
+
+void SetLargePageSize()
+{
+printf("SetLargePageSize : <>\n");
+  #ifdef _7ZIP_LARGE_PAGES
+  size_t size = 0;
+
+#if defined(__linux__)
+  size = sysconf(_SC_PAGESIZE);
+printf("SetLargePageSize : size=%ld\n",(long)size);
+  if (size == -1) size = 0;
+#endif
+
+  if (size == 0 || (size & (size - 1)) != 0)
+    return;
+  g_LargePageSize = size;
+printf("SetLargePageSize : %ld\n",(long)g_LargePageSize);
+  #endif
+}
+
+
+void *BigAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  fprintf(stderr, "\nAlloc_Big %10d bytes;  count = %10d", size, g_allocCountBig++);
+  #endif
+  
+  #ifdef _7ZIP_LARGE_PAGES
+  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
+  {
+    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),1);
+printf("BigAlloc : %ld %ld => %p\n",(long)g_LargePageSize,(long)size,res);
+    if (res != 0)
+      return res;
+  }
+  #endif
+  return VirtualAlloc(0, size, 0);
+}
+
+void BigFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
+  #endif
+  
+  if (address == 0)
+    return;
+  VirtualFree(address);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,280 @@
+/* Alloc.c -- Memory allocation functions
+2008-09-24
+Igor Pavlov
+Public domain */
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef _7ZIP_LARGE_PAGES
+#ifdef __linux__
+#ifndef _7ZIP_ST
+#include <pthread.h>
+#endif
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <mntent.h>
+#endif
+#endif
+
+#include "Alloc.h"
+
+/* #define _SZ_ALLOC_DEBUG */
+
+/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
+#ifdef _SZ_ALLOC_DEBUG
+#include <stdio.h>
+int g_allocCount = 0;
+int g_allocCountMid = 0;
+int g_allocCountBig = 0;
+#endif
+
+void *MyAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  {
+    void *p = malloc(size);
+    fprintf(stderr, "\nAlloc %10d bytes, count = %10d,  addr = %8X", size, g_allocCount++, (unsigned)p);
+    return p;
+  }
+  #else
+  return malloc(size);
+  #endif
+}
+
+void MyFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree; count = %10d,  addr = %8X", --g_allocCount, (unsigned)address);
+  #endif
+  free(address);
+}
+
+#ifndef _WIN32
+
+#ifdef _7ZIP_LARGE_PAGES
+
+#ifdef __linux__
+#define _7ZIP_MAX_HUGE_ALLOCS 64
+static void *g_HugePageAddr[_7ZIP_MAX_HUGE_ALLOCS] = { NULL };
+static size_t g_HugePageLen[_7ZIP_MAX_HUGE_ALLOCS];
+static char *g_HugetlbPath;
+#endif
+
+#endif
+
+static void *VirtualAlloc(size_t size, int memLargePages)
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  if (memLargePages)
+  {
+    #ifdef __linux__
+    /* huge pages support for Linux; added by Joachim Henke */
+    #ifndef _7ZIP_ST
+    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    #endif
+    int i;
+
+    void * address = NULL;
+    #ifndef _7ZIP_ST
+    pthread_mutex_lock(&mutex);
+    #endif
+    for (i = 0; i < _7ZIP_MAX_HUGE_ALLOCS; ++i)
+    {
+      if (g_HugePageAddr[i] == NULL)
+      {
+        int fd, pathlen = strlen(g_HugetlbPath);
+        char tempname[pathlen+12];
+
+        memcpy(tempname, g_HugetlbPath, pathlen);
+        memcpy(tempname + pathlen, "/7z-XXXXXX", 11);
+        fd = mkstemp(tempname);
+        unlink(tempname);
+        if (fd < 0)
+        {
+          fprintf(stderr,"cant't open %s (%s)\n",tempname,strerror(errno));
+          break;
+        }
+        address = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+        close(fd);
+        if (address == MAP_FAILED)
+        {
+          address = NULL;
+          break;
+        }
+        g_HugePageLen[i] = size;
+        g_HugePageAddr[i] = address;
+// fprintf(stderr,"HUGE[%d]=%ld %p\n",i,(long)size,address);
+        break;
+      }
+    }
+    #ifndef _7ZIP_ST
+    pthread_mutex_unlock(&mutex);
+    #endif
+    return address;
+    #endif
+  }
+  #endif
+  return malloc(size);
+}
+
+static int VirtualFree(void *address)
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  #ifdef __linux__
+  int i;
+
+  for (i = 0; i < _7ZIP_MAX_HUGE_ALLOCS; ++i)
+  {
+    if (g_HugePageAddr[i] == address)
+    {
+      munmap(address, g_HugePageLen[i]);
+      g_HugePageAddr[i] = NULL;
+      return 1;
+    }
+  }
+  #endif
+  #endif
+  free(address);
+  return 1;
+}
+
+#endif
+
+void *MidAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  fprintf(stderr, "\nAlloc_Mid %10d bytes;  count = %10d", size, g_allocCountMid++);
+  #endif
+  return VirtualAlloc(size, 0);
+}
+
+void MidFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
+  #endif
+  if (address == 0)
+    return;
+  VirtualFree(address);
+}
+
+#ifdef _7ZIP_LARGE_PAGES
+size_t g_LargePageSize = 0;
+#ifdef _WIN32
+typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
+#elif defined(__linux__)
+size_t largePageMinimum()
+{
+  size_t size;
+
+  g_HugetlbPath = getenv("HUGETLB_PATH");
+
+  if (g_HugetlbPath == NULL)
+  {
+    // not defined => try to find out the directory
+    static char dir_hugetlbfs[1024];
+    const char * filename = "/etc/mtab"; // mounted filesystems
+    FILE *fp;
+    struct mntent * info;
+
+    dir_hugetlbfs[0]=0;
+
+    fp = setmntent(filename,"r");
+    if (fp)
+    {
+      info = getmntent(fp);
+      while(info)
+      {
+/*
+        printf("%s:\n",info->mnt_fsname);
+        printf("  dir='%s'\n",info->mnt_dir);
+        printf("  type='%s'\n",info->mnt_type);
+*/
+
+        if (strcmp(info->mnt_type,"hugetlbfs") == 0)
+        {
+          strcpy(dir_hugetlbfs,info->mnt_dir);
+          break;
+        }
+
+        info = getmntent(fp);
+      }
+      endmntent(fp);
+    }
+
+    if (dir_hugetlbfs[0])
+    {
+      g_HugetlbPath = dir_hugetlbfs;
+      // fprintf(stderr," Found hugetlbfs = '%s'\n",g_HugetlbPath);
+    }
+  }
+  if (g_HugetlbPath == NULL || (size = pathconf(g_HugetlbPath, _PC_REC_MIN_XFER_SIZE)) <= getpagesize())
+    return 0;
+  return size;
+}
+#else
+#define largePageMinimum() 0
+#endif
+#endif
+
+void SetLargePageSize()
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  size_t size;
+  #ifdef _WIN32
+  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
+        GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
+  if (largePageMinimum == 0)
+    return;
+  #endif
+  size = largePageMinimum();
+  if (size == 0 || (size & (size - 1)) != 0)
+    return;
+  g_LargePageSize = size;
+  // fprintf(stderr,"SetLargePageSize : %ld\n",(long)g_LargePageSize);
+  #endif
+}
+
+
+void *BigAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  fprintf(stderr, "\nAlloc_Big %10d bytes;  count = %10d", size, g_allocCountBig++);
+  #endif
+  
+  #ifdef _7ZIP_LARGE_PAGES
+  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
+  {
+    void *res = VirtualAlloc( (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), 1);
+    if (res != 0)
+      return res;
+  }
+  #endif
+  return VirtualAlloc(size, 0);
+}
+
+void BigFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
+  #endif
+  
+  if (address == 0)
+    return;
+  VirtualFree(address);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back Sun Dec 16 23:23:25 2012
@@ -0,0 +1,243 @@
+/* Alloc.c -- Memory allocation functions
+2008-09-24
+Igor Pavlov
+Public domain */
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+#include <stdlib.h>
+
+#ifdef _7ZIP_LARGE_PAGES
+#ifdef __linux__
+#ifndef _7ZIP_ST
+#include <pthread.h>
+#endif
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#endif
+#endif
+
+#include "Alloc.h"
+
+/* #define _SZ_ALLOC_DEBUG */
+
+/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
+#ifdef _SZ_ALLOC_DEBUG
+#include <stdio.h>
+int g_allocCount = 0;
+int g_allocCountMid = 0;
+int g_allocCountBig = 0;
+#endif
+
+void *MyAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  {
+    void *p = malloc(size);
+    fprintf(stderr, "\nAlloc %10d bytes, count = %10d,  addr = %8X", size, g_allocCount++, (unsigned)p);
+    return p;
+  }
+  #else
+  return malloc(size);
+  #endif
+}
+
+void MyFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree; count = %10d,  addr = %8X", --g_allocCount, (unsigned)address);
+  #endif
+  free(address);
+}
+
+#ifndef _WIN32
+
+#define PAGE_READWRITE 0x04
+#define MEM_COMMIT 0x1000
+#define MEM_RELEASE 0x8000
+#ifdef _7ZIP_LARGE_PAGES
+#define MEM_LARGE_PAGES 0x20000000
+#ifdef __linux__
+#define _7ZIP_MAX_HUGE_ALLOCS 64
+static void *g_HugePageAddr[_7ZIP_MAX_HUGE_ALLOCS] = { NULL };
+static size_t g_HugePageLen[_7ZIP_MAX_HUGE_ALLOCS];
+static char *g_HugetlbPath;
+#endif
+#endif
+
+static void *VirtualAlloc(void *address, size_t size, unsigned int type, unsigned int protect)
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  if (type & MEM_LARGE_PAGES)
+  {
+    #ifdef __linux__
+    /* huge pages support for Linux; added by Joachim Henke */
+    #ifndef _7ZIP_ST
+    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    #endif
+    int i;
+
+    address = NULL;
+    #ifndef _7ZIP_ST
+    pthread_mutex_lock(&mutex);
+    #endif
+    for (i = 0; i < _7ZIP_MAX_HUGE_ALLOCS; ++i)
+    {
+      if (g_HugePageAddr[i] == NULL)
+      {
+        int fd, pathlen = strlen(g_HugetlbPath);
+        char tempname[pathlen+12];
+
+        memcpy(tempname, g_HugetlbPath, pathlen);
+        memcpy(tempname + pathlen, "/7z-XXXXXX", 11);
+        fd = mkstemp(tempname);
+printf("BigAlloc(%s)=>%d\n",tempname,fd);
+        unlink(tempname);
+        if (fd < 0)
+          break;
+        address = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+        close(fd);
+        if (address == MAP_FAILED)
+        {
+          address = NULL;
+          break;
+        }
+        g_HugePageLen[i] = size;
+        g_HugePageAddr[i] = address;
+printf("HUGE[%d]=%ld %p\n",i,(long)size,address);
+        break;
+      }
+    }
+    #ifndef _7ZIP_ST
+    pthread_mutex_unlock(&mutex);
+    #endif
+    return address;
+    #endif
+  }
+  #endif
+  return malloc(size);
+}
+
+static int VirtualFree(void *address, size_t size, unsigned int type)
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  #ifdef __linux__
+  int i;
+
+  for (i = 0; i < _7ZIP_MAX_HUGE_ALLOCS; ++i)
+  {
+    if (g_HugePageAddr[i] == address)
+    {
+      munmap(address, g_HugePageLen[i]);
+      g_HugePageAddr[i] = NULL;
+      return 1;
+    }
+  }
+  #endif
+  #endif
+  free(address);
+  return 1;
+}
+
+#endif
+
+void *MidAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  fprintf(stderr, "\nAlloc_Mid %10d bytes;  count = %10d", size, g_allocCountMid++);
+  #endif
+  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
+}
+
+void MidFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
+  #endif
+  if (address == 0)
+    return;
+  VirtualFree(address, 0, MEM_RELEASE);
+}
+
+#ifndef MEM_LARGE_PAGES
+#undef _7ZIP_LARGE_PAGES
+#endif
+
+#ifdef _7ZIP_LARGE_PAGES
+size_t g_LargePageSize = 0;
+#ifdef _WIN32
+typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
+#elif defined(__linux__)
+size_t largePageMinimum()
+{
+  size_t size;
+
+  g_HugetlbPath = getenv("HUGETLB_PATH");
+  if (g_HugetlbPath == NULL || (size = pathconf(g_HugetlbPath, _PC_REC_MIN_XFER_SIZE)) <= getpagesize())
+    return 0;
+  return size;
+}
+#else
+#define largePageMinimum() 0
+#endif
+#endif
+
+void SetLargePageSize()
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  size_t size;
+  #ifdef _WIN32
+  GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
+        GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
+  if (largePageMinimum == 0)
+    return;
+  #endif
+  size = largePageMinimum();
+  if (size == 0 || (size & (size - 1)) != 0)
+    return;
+  g_LargePageSize = size;
+printf("SetLargePageSize : %ld\n",(long)g_LargePageSize);
+  #endif
+}
+
+
+void *BigAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  fprintf(stderr, "\nAlloc_Big %10d bytes;  count = %10d", size, g_allocCountBig++);
+  #endif
+  
+  #ifdef _7ZIP_LARGE_PAGES
+  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
+  {
+    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
+        MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
+printf("BigAlloc : %ld %ld => %p\n",(long)g_LargePageSize,(long)size,res);
+    if (res != 0)
+      return res;
+  }
+  #endif
+  return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
+}
+
+void BigFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
+  #endif
+  
+  if (address == 0)
+    return;
+  VirtualFree(address, 0, MEM_RELEASE);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back2
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back2?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back2 (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.c.back2 Sun Dec 16 23:23:25 2012
@@ -0,0 +1,222 @@
+/* Alloc.c -- Memory allocation functions
+2008-09-24
+Igor Pavlov
+Public domain */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef _7ZIP_LARGE_PAGES
+
+#ifdef __linux__
+
+
+
+#ifndef _7ZIP_ST
+#include <pthread.h>
+#endif
+#include <unistd.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#define PROTECTION (PROT_READ | PROT_WRITE)
+
+#ifndef MAP_HUGETLB
+#error 1
+#define MAP_HUGETLB 0x40
+#endif
+
+/* Only ia64 requires this */
+#ifdef __ia64__
+#define ADDR (void *)(0x8000000000000000UL)
+#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_FIXED)
+#else
+#define ADDR (void *)(0x0UL)
+#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB)
+#endif
+
+
+#endif /*  __linux__ */
+
+#endif /* _7ZIP_LARGE_PAGES */
+
+#include "Alloc.h"
+
+/* #define _SZ_ALLOC_DEBUG */
+
+/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
+#ifdef _SZ_ALLOC_DEBUG
+#include <stdio.h>
+int g_allocCount = 0;
+int g_allocCountMid = 0;
+int g_allocCountBig = 0;
+#endif
+
+void *MyAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  {
+    void *p = malloc(size);
+    fprintf(stderr, "\nAlloc %10d bytes, count = %10d,  addr = %8X", size, g_allocCount++, (unsigned)p);
+    return p;
+  }
+  #else
+  return malloc(size);
+  #endif
+}
+
+void MyFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree; count = %10d,  addr = %8X", --g_allocCount, (unsigned)address);
+  #endif
+  free(address);
+}
+
+#ifdef __linux__
+#define _7ZIP_MAX_HUGE_ALLOCS 64
+static void *g_HugePageAddr[_7ZIP_MAX_HUGE_ALLOCS] = { NULL };
+static size_t g_HugePageLen[_7ZIP_MAX_HUGE_ALLOCS];
+#endif
+
+static void *VirtualAlloc(void *address, size_t size, int AllocLargePages)
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  if (AllocLargePages)
+  {
+    #ifdef __linux__
+    /* huge pages support for Linux; added by Joachim Henke */
+    #ifndef _7ZIP_ST
+    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    #endif
+    int i;
+
+    address = NULL;
+    #ifndef _7ZIP_ST
+    pthread_mutex_lock(&mutex);
+    #endif
+    for (i = 0; i < _7ZIP_MAX_HUGE_ALLOCS; ++i)
+    {
+      if (g_HugePageAddr[i] == NULL)
+      {
+        address = mmap(ADDR, size, PROTECTION, FLAGS, 0, 0);
+        if (address == MAP_FAILED)
+        {
+          address = NULL;
+          break;
+        }
+        g_HugePageLen[i] = size;
+        g_HugePageAddr[i] = address;
+printf("HUGE[%d]=%ld %p\n",i,(long)size,address);
+        break;
+      }
+    }
+    #ifndef _7ZIP_ST
+    pthread_mutex_unlock(&mutex);
+    #endif
+    return address;
+    #endif
+  }
+  #endif
+  return malloc(size);
+}
+
+static int VirtualFree(void *address)
+{
+  #ifdef _7ZIP_LARGE_PAGES
+  #ifdef __linux__
+  int i;
+
+  for (i = 0; i < _7ZIP_MAX_HUGE_ALLOCS; ++i)
+  {
+    if (g_HugePageAddr[i] == address)
+    {
+      munmap(address, g_HugePageLen[i]);
+      g_HugePageAddr[i] = NULL;
+      return 1;
+    }
+  }
+  #endif
+  #endif
+  free(address);
+  return 1;
+}
+
+void *MidAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  fprintf(stderr, "\nAlloc_Mid %10d bytes;  count = %10d", size, g_allocCountMid++);
+  #endif
+  return VirtualAlloc(0, size, 0);
+}
+
+void MidFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
+  #endif
+  if (address == 0)
+    return;
+  VirtualFree(address);
+}
+
+#ifdef _7ZIP_LARGE_PAGES
+size_t g_LargePageSize = 0;
+#endif
+
+void SetLargePageSize()
+{
+printf("SetLargePageSize : <>\n");
+  #ifdef _7ZIP_LARGE_PAGES
+  size_t size = 0;
+
+#if defined(__linux__)
+  size = sysconf(_SC_PAGESIZE);
+printf("SetLargePageSize : size=%ld\n",(long)size);
+  if (size == -1) size = 0;
+#endif
+
+  if (size == 0 || (size & (size - 1)) != 0)
+    return;
+  g_LargePageSize = size;
+printf("SetLargePageSize : %ld\n",(long)g_LargePageSize);
+  #endif
+}
+
+
+void *BigAlloc(size_t size)
+{
+  if (size == 0)
+    return 0;
+  #ifdef _SZ_ALLOC_DEBUG
+  fprintf(stderr, "\nAlloc_Big %10d bytes;  count = %10d", size, g_allocCountBig++);
+  #endif
+  
+  #ifdef _7ZIP_LARGE_PAGES
+  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
+  {
+    void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),1);
+printf("BigAlloc : %ld %ld => %p\n",(long)g_LargePageSize,(long)size,res);
+    if (res != 0)
+      return res;
+  }
+  #endif
+  return VirtualAlloc(0, size, 0);
+}
+
+void BigFree(void *address)
+{
+  #ifdef _SZ_ALLOC_DEBUG
+  if (address != 0)
+    fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
+  #endif
+  
+  if (address == 0)
+    return;
+  VirtualFree(address);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Alloc.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,27 @@
+/* Alloc.h -- Memory allocation functions
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __COMMON_ALLOC_H
+#define __COMMON_ALLOC_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void *MyAlloc(size_t size);
+void MyFree(void *address);
+
+void SetLargePageSize();
+
+void *MidAlloc(size_t size);
+void MidFree(void *address);
+void *BigAlloc(size_t size);
+void BigFree(void *address);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,133 @@
+/* Bra.c -- Converters for RISC code
+2010-04-16 : Igor Pavlov : Public domain */
+
+#include "Bra.h"
+
+SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+  SizeT i;
+  if (size < 4)
+    return 0;
+  size -= 4;
+  ip += 8;
+  for (i = 0; i <= size; i += 4)
+  {
+    if (data[i + 3] == 0xEB)
+    {
+      UInt32 dest;
+      UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
+      src <<= 2;
+      if (encoding)
+        dest = ip + (UInt32)i + src;
+      else
+        dest = src - (ip + (UInt32)i);
+      dest >>= 2;
+      data[i + 2] = (Byte)(dest >> 16);
+      data[i + 1] = (Byte)(dest >> 8);
+      data[i + 0] = (Byte)dest;
+    }
+  }
+  return i;
+}
+
+SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+  SizeT i;
+  if (size < 4)
+    return 0;
+  size -= 4;
+  ip += 4;
+  for (i = 0; i <= size; i += 2)
+  {
+    if ((data[i + 1] & 0xF8) == 0xF0 &&
+        (data[i + 3] & 0xF8) == 0xF8)
+    {
+      UInt32 dest;
+      UInt32 src =
+        (((UInt32)data[i + 1] & 0x7) << 19) |
+        ((UInt32)data[i + 0] << 11) |
+        (((UInt32)data[i + 3] & 0x7) << 8) |
+        (data[i + 2]);
+      
+      src <<= 1;
+      if (encoding)
+        dest = ip + (UInt32)i + src;
+      else
+        dest = src - (ip + (UInt32)i);
+      dest >>= 1;
+      
+      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
+      data[i + 0] = (Byte)(dest >> 11);
+      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
+      data[i + 2] = (Byte)dest;
+      i += 2;
+    }
+  }
+  return i;
+}
+
+SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+  SizeT i;
+  if (size < 4)
+    return 0;
+  size -= 4;
+  for (i = 0; i <= size; i += 4)
+  {
+    if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
+    {
+      UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
+        ((UInt32)data[i + 1] << 16) |
+        ((UInt32)data[i + 2] << 8) |
+        ((UInt32)data[i + 3] & (~3));
+      
+      UInt32 dest;
+      if (encoding)
+        dest = ip + (UInt32)i + src;
+      else
+        dest = src - (ip + (UInt32)i);
+      data[i + 0] = (Byte)(0x48 | ((dest >> 24) &  0x3));
+      data[i + 1] = (Byte)(dest >> 16);
+      data[i + 2] = (Byte)(dest >> 8);
+      data[i + 3] &= 0x3;
+      data[i + 3] |= dest;
+    }
+  }
+  return i;
+}
+
+SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+  UInt32 i;
+  if (size < 4)
+    return 0;
+  size -= 4;
+  for (i = 0; i <= size; i += 4)
+  {
+    if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) ||
+        (data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0))
+    {
+      UInt32 src =
+        ((UInt32)data[i + 0] << 24) |
+        ((UInt32)data[i + 1] << 16) |
+        ((UInt32)data[i + 2] << 8) |
+        ((UInt32)data[i + 3]);
+      UInt32 dest;
+      
+      src <<= 2;
+      if (encoding)
+        dest = ip + i + src;
+      else
+        dest = src - (ip + i);
+      dest >>= 2;
+      
+      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
+
+      data[i + 0] = (Byte)(dest >> 24);
+      data[i + 1] = (Byte)(dest >> 16);
+      data[i + 2] = (Byte)(dest >> 8);
+      data[i + 3] = (Byte)dest;
+    }
+  }
+  return i;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,68 @@
+/* Bra.h -- Branch converters for executables
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __BRA_H
+#define __BRA_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+These functions convert relative addresses to absolute addresses
+in CALL instructions to increase the compression ratio.
+  
+  In:
+    data     - data buffer
+    size     - size of data
+    ip       - current virtual Instruction Pinter (IP) value
+    state    - state variable for x86 converter
+    encoding - 0 (for decoding), 1 (for encoding)
+  
+  Out:
+    state    - state variable for x86 converter
+
+  Returns:
+    The number of processed bytes. If you call these functions with multiple calls,
+    you must start next call with first byte after block of processed bytes.
+  
+  Type   Endian  Alignment  LookAhead
+  
+  x86    little      1          4
+  ARMT   little      2          2
+  ARM    little      4          0
+  PPC     big        4          0
+  SPARC   big        4          0
+  IA64   little     16          0
+
+  size must be >= Alignment + LookAhead, if it's not last block.
+  If (size < Alignment + LookAhead), converter returns 0.
+
+  Example:
+
+    UInt32 ip = 0;
+    for ()
+    {
+      ; size must be >= Alignment + LookAhead, if it's not last block
+      SizeT processed = Convert(data, size, ip, 1);
+      data += processed;
+      size -= processed;
+      ip += processed;
+    }
+*/
+
+#define x86_Convert_Init(state) { state = 0; }
+SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
+SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra86.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra86.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra86.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Bra86.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,85 @@
+/* Bra86.c -- Converter for x86 code (BCJ)
+2008-10-04 : Igor Pavlov : Public domain */
+
+#include "Bra.h"
+
+#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
+
+const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
+const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
+
+SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
+{
+  SizeT bufferPos = 0, prevPosT;
+  UInt32 prevMask = *state & 0x7;
+  if (size < 5)
+    return 0;
+  ip += 5;
+  prevPosT = (SizeT)0 - 1;
+
+  for (;;)
+  {
+    Byte *p = data + bufferPos;
+    Byte *limit = data + size - 4;
+    for (; p < limit; p++)
+      if ((*p & 0xFE) == 0xE8)
+        break;
+    bufferPos = (SizeT)(p - data);
+    if (p >= limit)
+      break;
+    prevPosT = bufferPos - prevPosT;
+    if (prevPosT > 3)
+      prevMask = 0;
+    else
+    {
+      prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
+      if (prevMask != 0)
+      {
+        Byte b = p[4 - kMaskToBitNumber[prevMask]];
+        if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
+        {
+          prevPosT = bufferPos;
+          prevMask = ((prevMask << 1) & 0x7) | 1;
+          bufferPos++;
+          continue;
+        }
+      }
+    }
+    prevPosT = bufferPos;
+
+    if (Test86MSByte(p[4]))
+    {
+      UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
+      UInt32 dest;
+      for (;;)
+      {
+        Byte b;
+        int index;
+        if (encoding)
+          dest = (ip + (UInt32)bufferPos) + src;
+        else
+          dest = src - (ip + (UInt32)bufferPos);
+        if (prevMask == 0)
+          break;
+        index = kMaskToBitNumber[prevMask] * 8;
+        b = (Byte)(dest >> (24 - index));
+        if (!Test86MSByte(b))
+          break;
+        src = dest ^ ((1 << (32 - index)) - 1);
+      }
+      p[4] = (Byte)(~(((dest >> 24) & 1) - 1));
+      p[3] = (Byte)(dest >> 16);
+      p[2] = (Byte)(dest >> 8);
+      p[1] = (Byte)dest;
+      bufferPos += 5;
+    }
+    else
+    {
+      prevMask = ((prevMask << 1) & 0x7) | 1;
+      bufferPos++;
+    }
+  }
+  prevPosT = bufferPos - prevPosT;
+  *state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
+  return bufferPos;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/BraIA64.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/BraIA64.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/BraIA64.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/BraIA64.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,67 @@
+/* BraIA64.c -- Converter for IA-64 code
+2008-10-04 : Igor Pavlov : Public domain */
+
+#include "Bra.h"
+
+static const Byte kBranchTable[32] =
+{
+  0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0,
+  4, 4, 6, 6, 0, 0, 7, 7,
+  4, 4, 0, 0, 4, 4, 0, 0
+};
+
+SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
+{
+  SizeT i;
+  if (size < 16)
+    return 0;
+  size -= 16;
+  for (i = 0; i <= size; i += 16)
+  {
+    UInt32 instrTemplate = data[i] & 0x1F;
+    UInt32 mask = kBranchTable[instrTemplate];
+    UInt32 bitPos = 5;
+    int slot;
+    for (slot = 0; slot < 3; slot++, bitPos += 41)
+    {
+      UInt32 bytePos, bitRes;
+      UInt64 instruction, instNorm;
+      int j;
+      if (((mask >> slot) & 1) == 0)
+        continue;
+      bytePos = (bitPos >> 3);
+      bitRes = bitPos & 0x7;
+      instruction = 0;
+      for (j = 0; j < 6; j++)
+        instruction += (UInt64)data[i + j + bytePos] << (8 * j);
+
+      instNorm = instruction >> bitRes;
+      if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
+      {
+        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
+        UInt32 dest;
+        src |= ((UInt32)(instNorm >> 36) & 1) << 20;
+        
+        src <<= 4;
+        
+        if (encoding)
+          dest = ip + (UInt32)i + src;
+        else
+          dest = src - (ip + (UInt32)i);
+        
+        dest >>= 4;
+        
+        instNorm &= ~((UInt64)(0x8FFFFF) << 13);
+        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
+        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
+        
+        instruction &= (1 << bitRes) - 1;
+        instruction |= (instNorm << bitRes);
+        for (j = 0; j < 6; j++)
+          data[i + j + bytePos] = (Byte)(instruction >> (8 * j));
+      }
+    }
+  }
+  return i;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,516 @@
+/* BwtSort.c -- BWT block sorting
+2008-08-17
+Igor Pavlov
+Public domain */
+
+#include "BwtSort.h"
+#include "Sort.h"
+
+/* #define BLOCK_SORT_USE_HEAP_SORT */
+
+#define NO_INLINE MY_FAST_CALL
+
+/* Don't change it !!! */
+#define kNumHashBytes 2
+#define kNumHashValues (1 << (kNumHashBytes * 8))
+
+/* kNumRefBitsMax must be < (kNumHashBytes * 8) = 16 */
+#define kNumRefBitsMax 12
+
+#define BS_TEMP_SIZE kNumHashValues
+
+#ifdef BLOCK_SORT_EXTERNAL_FLAGS
+
+/* 32 Flags in UInt32 word */
+#define kNumFlagsBits 5
+#define kNumFlagsInWord (1 << kNumFlagsBits)
+#define kFlagsMask (kNumFlagsInWord - 1)
+#define kAllFlags 0xFFFFFFFF
+
+#else
+
+#define kNumBitsMax 20
+#define kIndexMask ((1 << kNumBitsMax) - 1)
+#define kNumExtraBits (32 - kNumBitsMax)
+#define kNumExtra0Bits (kNumExtraBits - 2)
+#define kNumExtra0Mask ((1 << kNumExtra0Bits) - 1)
+
+#define SetFinishedGroupSize(p, size) \
+  {  *(p) |= ((((size) - 1) & kNumExtra0Mask) << kNumBitsMax); \
+    if ((size) > (1 << kNumExtra0Bits)) { \
+    *(p) |= 0x40000000;  *((p) + 1) |= ((((size) - 1)>> kNumExtra0Bits) << kNumBitsMax); } } \
+
+static void SetGroupSize(UInt32 *p, UInt32 size)
+{
+  if (--size == 0)
+    return;
+  *p |= 0x80000000 | ((size & kNumExtra0Mask) << kNumBitsMax);
+  if (size >= (1 << kNumExtra0Bits))
+  {
+    *p |= 0x40000000;
+    p[1] |= ((size >> kNumExtra0Bits) << kNumBitsMax);
+  }
+}
+
+#endif
+
+/*
+SortGroup - is recursive Range-Sort function with HeapSort optimization for small blocks
+  "range" is not real range. It's only for optimization.
+returns: 1 - if there are groups, 0 - no more groups
+*/
+
+UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 groupOffset, UInt32 groupSize, int NumRefBits, UInt32 *Indices
+  #ifndef BLOCK_SORT_USE_HEAP_SORT
+  , UInt32 left, UInt32 range
+  #endif
+  )
+{
+  UInt32 *ind2 = Indices + groupOffset;
+  UInt32 *Groups;
+  if (groupSize <= 1)
+  {
+    /*
+    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+    SetFinishedGroupSize(ind2, 1);
+    #endif
+    */
+    return 0;
+  }
+  Groups = Indices + BlockSize + BS_TEMP_SIZE;
+  if (groupSize <= ((UInt32)1 << NumRefBits)
+      #ifndef BLOCK_SORT_USE_HEAP_SORT
+      && groupSize <= range
+      #endif
+      )
+  {
+    UInt32 *temp = Indices + BlockSize;
+    UInt32 j;
+    UInt32 mask, thereAreGroups, group, cg;
+    {
+      UInt32 gPrev;
+      UInt32 gRes = 0;
+      {
+        UInt32 sp = ind2[0] + NumSortedBytes;
+        if (sp >= BlockSize) sp -= BlockSize;
+        gPrev = Groups[sp];
+        temp[0] = (gPrev << NumRefBits);
+      }
+      
+      for (j = 1; j < groupSize; j++)
+      {
+        UInt32 sp = ind2[j] + NumSortedBytes;
+        UInt32 g;
+        if (sp >= BlockSize) sp -= BlockSize;
+        g = Groups[sp];
+        temp[j] = (g << NumRefBits) | j;
+        gRes |= (gPrev ^ g);
+      }
+      if (gRes == 0)
+      {
+        #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+        SetGroupSize(ind2, groupSize);
+        #endif
+        return 1;
+      }
+    }
+    
+    HeapSort(temp, groupSize);
+    mask = ((1 << NumRefBits) - 1);
+    thereAreGroups = 0;
+    
+    group = groupOffset;
+    cg = (temp[0] >> NumRefBits);
+    temp[0] = ind2[temp[0] & mask];
+
+    {
+    #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+    UInt32 *Flags = Groups + BlockSize;
+    #else
+    UInt32 prevGroupStart = 0;
+    #endif
+    
+    for (j = 1; j < groupSize; j++)
+    {
+      UInt32 val = temp[j];
+      UInt32 cgCur = (val >> NumRefBits);
+      
+      if (cgCur != cg)
+      {
+        cg = cgCur;
+        group = groupOffset + j;
+
+        #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+        {
+        UInt32 t = group - 1;
+        Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
+        }
+        #else
+        SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
+        prevGroupStart = j;
+        #endif
+      }
+      else
+        thereAreGroups = 1;
+      {
+      UInt32 ind = ind2[val & mask];
+      temp[j] = ind;
+      Groups[ind] = group;
+      }
+    }
+
+    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+    SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
+    #endif
+    }
+
+    for (j = 0; j < groupSize; j++)
+      ind2[j] = temp[j];
+    return thereAreGroups;
+  }
+
+  /* Check that all strings are in one group (cannot sort) */
+  {
+    UInt32 group, j;
+    UInt32 sp = ind2[0] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
+    group = Groups[sp];
+    for (j = 1; j < groupSize; j++)
+    {
+      sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
+      if (Groups[sp] != group)
+        break;
+    }
+    if (j == groupSize)
+    {
+      #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+      SetGroupSize(ind2, groupSize);
+      #endif
+      return 1;
+    }
+  }
+
+  #ifndef BLOCK_SORT_USE_HEAP_SORT
+  {
+  /* ---------- Range Sort ---------- */
+  UInt32 i;
+  UInt32 mid;
+  for (;;)
+  {
+    UInt32 j;
+    if (range <= 1)
+    {
+      #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+      SetGroupSize(ind2, groupSize);
+      #endif
+      return 1;
+    }
+    mid = left + ((range + 1) >> 1);
+    j = groupSize;
+    i = 0;
+    do
+    {
+      UInt32 sp = ind2[i] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
+      if (Groups[sp] >= mid)
+      {
+        for (j--; j > i; j--)
+        {
+          sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
+          if (Groups[sp] < mid)
+          {
+            UInt32 temp = ind2[i]; ind2[i] = ind2[j]; ind2[j] = temp;
+            break;
+          }
+        }
+        if (i >= j)
+          break;
+      }
+    }
+    while (++i < j);
+    if (i == 0)
+    {
+      range = range - (mid - left);
+      left = mid;
+    }
+    else if (i == groupSize)
+      range = (mid - left);
+    else
+      break;
+  }
+
+  #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+  {
+    UInt32 t = (groupOffset + i - 1);
+    UInt32 *Flags = Groups + BlockSize;
+    Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
+  }
+  #endif
+
+  {
+    UInt32 j;
+    for (j = i; j < groupSize; j++)
+      Groups[ind2[j]] = groupOffset + i;
+  }
+
+  {
+  UInt32 res = SortGroup(BlockSize, NumSortedBytes, groupOffset, i, NumRefBits, Indices, left, mid - left);
+  return res | SortGroup(BlockSize, NumSortedBytes, groupOffset + i, groupSize - i, NumRefBits, Indices, mid, range - (mid - left));
+  }
+
+  }
+
+  #else
+
+  /* ---------- Heap Sort ---------- */
+
+  {
+    UInt32 j;
+    for (j = 0; j < groupSize; j++)
+    {
+      UInt32 sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
+      ind2[j] = sp;
+    }
+
+    HeapSortRef(ind2, Groups, groupSize);
+
+    /* Write Flags */
+    {
+    UInt32 sp = ind2[0];
+    UInt32 group = Groups[sp];
+
+    #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+    UInt32 *Flags = Groups + BlockSize;
+    #else
+    UInt32 prevGroupStart = 0;
+    #endif
+
+    for (j = 1; j < groupSize; j++)
+    {
+      sp = ind2[j];
+      if (Groups[sp] != group)
+      {
+        group = Groups[sp];
+        #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+        {
+        UInt32 t = groupOffset + j - 1;
+        Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
+        }
+        #else
+        SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
+        prevGroupStart = j;
+        #endif
+      }
+    }
+
+    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+    SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
+    #endif
+    }
+    {
+    /* Write new Groups values and Check that there are groups */
+    UInt32 thereAreGroups = 0;
+    for (j = 0; j < groupSize; j++)
+    {
+      UInt32 group = groupOffset + j;
+      #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+      UInt32 subGroupSize = ((ind2[j] & ~0xC0000000) >> kNumBitsMax);
+      if ((ind2[j] & 0x40000000) != 0)
+        subGroupSize += ((ind2[j + 1] >> kNumBitsMax) << kNumExtra0Bits);
+      subGroupSize++;
+      for (;;)
+      {
+        UInt32 original = ind2[j];
+        UInt32 sp = original & kIndexMask;
+        if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
+        ind2[j] = sp | (original & ~kIndexMask);
+        Groups[sp] = group;
+        if (--subGroupSize == 0)
+          break;
+        j++;
+        thereAreGroups = 1;
+      }
+      #else
+      UInt32 *Flags = Groups + BlockSize;
+      for (;;)
+      {
+        UInt32 sp = ind2[j]; if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
+        ind2[j] = sp;
+        Groups[sp] = group;
+        if ((Flags[(groupOffset + j) >> kNumFlagsBits] & (1 << ((groupOffset + j) & kFlagsMask))) == 0)
+          break;
+        j++;
+        thereAreGroups = 1;
+      }
+      #endif
+    }
+    return thereAreGroups;
+    }
+  }
+  #endif
+}
+
+/* conditions: blockSize > 0 */
+UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
+{
+  UInt32 *counters = Indices + blockSize;
+  UInt32 i;
+  UInt32 *Groups;
+  #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+  UInt32 *Flags;
+  #endif
+
+  /* Radix-Sort for 2 bytes */
+  for (i = 0; i < kNumHashValues; i++)
+    counters[i] = 0;
+  for (i = 0; i < blockSize - 1; i++)
+    counters[((UInt32)data[i] << 8) | data[i + 1]]++;
+  counters[((UInt32)data[i] << 8) | data[0]]++;
+
+  Groups = counters + BS_TEMP_SIZE;
+  #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+  Flags = Groups + blockSize;
+    {
+      UInt32 numWords = (blockSize + kFlagsMask) >> kNumFlagsBits;
+      for (i = 0; i < numWords; i++)
+        Flags[i] = kAllFlags;
+    }
+  #endif
+
+  {
+    UInt32 sum = 0;
+    for (i = 0; i < kNumHashValues; i++)
+    {
+      UInt32 groupSize = counters[i];
+      if (groupSize > 0)
+      {
+        #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+        UInt32 t = sum + groupSize - 1;
+        Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
+        #endif
+        sum += groupSize;
+      }
+      counters[i] = sum - groupSize;
+    }
+
+    for (i = 0; i < blockSize - 1; i++)
+      Groups[i] = counters[((UInt32)data[i] << 8) | data[i + 1]];
+    Groups[i] = counters[((UInt32)data[i] << 8) | data[0]];
+
+    for (i = 0; i < blockSize - 1; i++)
+      Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i;
+    Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i;
+    
+    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+    {
+    UInt32 prev = 0;
+    for (i = 0; i < kNumHashValues; i++)
+    {
+      UInt32 prevGroupSize = counters[i] - prev;
+      if (prevGroupSize == 0)
+        continue;
+      SetGroupSize(Indices + prev, prevGroupSize);
+      prev = counters[i];
+    }
+    }
+    #endif
+  }
+
+  {
+  int NumRefBits;
+  UInt32 NumSortedBytes;
+  for (NumRefBits = 0; ((blockSize - 1) >> NumRefBits) != 0; NumRefBits++);
+  NumRefBits = 32 - NumRefBits;
+  if (NumRefBits > kNumRefBitsMax)
+    NumRefBits = kNumRefBitsMax;
+
+  for (NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1)
+  {
+    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+    UInt32 finishedGroupSize = 0;
+    #endif
+    UInt32 newLimit = 0;
+    for (i = 0; i < blockSize;)
+    {
+      UInt32 groupSize;
+      #ifdef BLOCK_SORT_EXTERNAL_FLAGS
+
+      if ((Flags[i >> kNumFlagsBits] & (1 << (i & kFlagsMask))) == 0)
+      {
+        i++;
+        continue;
+      }
+      for (groupSize = 1;
+        (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
+        groupSize++);
+      
+      groupSize++;
+
+      #else
+
+      groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
+      {
+      Bool finishedGroup = ((Indices[i] & 0x80000000) == 0);
+      if ((Indices[i] & 0x40000000) != 0)
+      {
+        groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
+        Indices[i + 1] &= kIndexMask;
+      }
+      Indices[i] &= kIndexMask;
+      groupSize++;
+      if (finishedGroup || groupSize == 1)
+      {
+        Indices[i - finishedGroupSize] &= kIndexMask;
+        if (finishedGroupSize > 1)
+          Indices[i - finishedGroupSize + 1] &= kIndexMask;
+        {
+        UInt32 newGroupSize = groupSize + finishedGroupSize;
+        SetFinishedGroupSize(Indices + i - finishedGroupSize, newGroupSize);
+        finishedGroupSize = newGroupSize;
+        }
+        i += groupSize;
+        continue;
+      }
+      finishedGroupSize = 0;
+      }
+
+      #endif
+      
+      if (NumSortedBytes >= blockSize)
+      {
+        UInt32 j;
+        for (j = 0; j < groupSize; j++)
+        {
+          UInt32 t = (i + j);
+          /* Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); */
+          Groups[Indices[t]] = t;
+        }
+      }
+      else
+        if (SortGroup(blockSize, NumSortedBytes, i, groupSize, NumRefBits, Indices
+          #ifndef BLOCK_SORT_USE_HEAP_SORT
+          , 0, blockSize
+          #endif
+          ) != 0)
+          newLimit = i + groupSize;
+      i += groupSize;
+    }
+    if (newLimit == 0)
+      break;
+  }
+  }
+  #ifndef BLOCK_SORT_EXTERNAL_FLAGS
+  for (i = 0; i < blockSize;)
+  {
+    UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
+    if ((Indices[i] & 0x40000000) != 0)
+    {
+      groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
+      Indices[i + 1] &= kIndexMask;
+    }
+    Indices[i] &= kIndexMask;
+    groupSize++;
+    i += groupSize;
+  }
+  #endif
+  return Groups[0];
+}
+

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/BwtSort.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,30 @@
+/* BwtSort.h -- BWT block sorting
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __BWT_SORT_H
+#define __BWT_SORT_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M */
+/* #define BLOCK_SORT_EXTERNAL_FLAGS */
+
+#ifdef BLOCK_SORT_EXTERNAL_FLAGS
+#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) ((((blockSize) + 31) >> 5))
+#else
+#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) 0
+#endif
+
+#define BLOCK_SORT_BUF_SIZE(blockSize) ((blockSize) * 2 + BLOCK_SORT_EXTERNAL_SIZE(blockSize) + (1 << 16))
+
+UInt32 BlockSort(UInt32 *indices, const Byte *data, UInt32 blockSize);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,168 @@
+/* CpuArch.c -- CPU specific code
+2010-10-26: Igor Pavlov : Public domain */
+
+#include "CpuArch.h"
+
+#ifdef MY_CPU_X86_OR_AMD64
+
+#if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__)
+#define USE_ASM
+#endif
+
+#if defined(USE_ASM) && !defined(MY_CPU_AMD64)
+static UInt32 CheckFlag(UInt32 flag)
+{
+  #ifdef _MSC_VER
+  __asm pushfd;
+  __asm pop EAX;
+  __asm mov EDX, EAX;
+  __asm xor EAX, flag;
+  __asm push EAX;
+  __asm popfd;
+  __asm pushfd;
+  __asm pop EAX;
+  __asm xor EAX, EDX;
+  __asm push EDX;
+  __asm popfd;
+  __asm and flag, EAX;
+  #else
+  __asm__ __volatile__ (
+    "pushf\n\t"
+    "pop  %%EAX\n\t"
+    "movl %%EAX,%%EDX\n\t"
+    "xorl %0,%%EAX\n\t"
+    "push %%EAX\n\t"
+    "popf\n\t"
+    "pushf\n\t"
+    "pop  %%EAX\n\t"
+    "xorl %%EDX,%%EAX\n\t"
+    "push %%EDX\n\t"
+    "popf\n\t"
+    "andl %%EAX, %0\n\t":
+    "=c" (flag) : "c" (flag));
+  #endif
+  return flag;
+}
+#define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False;
+#else
+#define CHECK_CPUID_IS_SUPPORTED
+#endif
+
+static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
+{
+  #ifdef USE_ASM
+
+  #ifdef _MSC_VER
+
+  UInt32 a2, b2, c2, d2;
+  __asm xor EBX, EBX;
+  __asm xor ECX, ECX;
+  __asm xor EDX, EDX;
+  __asm mov EAX, function;
+  __asm cpuid;
+  __asm mov a2, EAX;
+  __asm mov b2, EBX;
+  __asm mov c2, ECX;
+  __asm mov d2, EDX;
+
+  *a = a2;
+  *b = b2;
+  *c = c2;
+  *d = d2;
+
+  #else
+
+  __asm__ __volatile__ (
+    "cpuid"
+    : "=a" (*a) ,
+      "=b" (*b) ,
+      "=c" (*c) ,
+      "=d" (*d)
+    : "0" (function)) ;
+
+  #endif
+  
+  #else
+
+  int CPUInfo[4];
+  __cpuid(CPUInfo, function);
+  *a = CPUInfo[0];
+  *b = CPUInfo[1];
+  *c = CPUInfo[2];
+  *d = CPUInfo[3];
+
+  #endif
+}
+
+Bool x86cpuid_CheckAndRead(Cx86cpuid *p)
+{
+  CHECK_CPUID_IS_SUPPORTED
+  MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);
+  MyCPUID(1, &p->ver, &p->b, &p->c, &p->d);
+  return True;
+}
+
+static UInt32 kVendors[][3] =
+{
+  { 0x756E6547, 0x49656E69, 0x6C65746E},
+  { 0x68747541, 0x69746E65, 0x444D4163},
+  { 0x746E6543, 0x48727561, 0x736C7561}
+};
+
+int x86cpuid_GetFirm(const Cx86cpuid *p)
+{
+  unsigned i;
+  for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++)
+  {
+    const UInt32 *v = kVendors[i];
+    if (v[0] == p->vendor[0] &&
+        v[1] == p->vendor[1] &&
+        v[2] == p->vendor[2])
+      return (int)i;
+  }
+  return -1;
+}
+
+Bool CPU_Is_InOrder()
+{
+  Cx86cpuid p;
+  int firm;
+  UInt32 family, model;
+  if (!x86cpuid_CheckAndRead(&p))
+    return True;
+  family = x86cpuid_GetFamily(&p);
+  model = x86cpuid_GetModel(&p);
+  firm = x86cpuid_GetFirm(&p);
+  switch (firm)
+  {
+    case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && model == 0x100C));
+    case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA)));
+    case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF));
+  }
+  return True;
+}
+
+#if !defined(MY_CPU_AMD64) && defined(_WIN32)
+static Bool CPU_Sys_Is_SSE_Supported()
+{
+  OSVERSIONINFO vi;
+  vi.dwOSVersionInfoSize = sizeof(vi);
+  if (!GetVersionEx(&vi))
+    return False;
+  return (vi.dwMajorVersion >= 5);
+}
+#define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False;
+#else
+#define CHECK_SYS_SSE_SUPPORT
+#endif
+
+Bool CPU_Is_Aes_Supported()
+{
+  Cx86cpuid p;
+  CHECK_SYS_SSE_SUPPORT
+  if (!x86cpuid_CheckAndRead(&p))
+    return False;
+  return (p.c >> 25) & 1;
+}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/CpuArch.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,155 @@
+/* CpuArch.h -- CPU specific code
+2010-10-26: Igor Pavlov : Public domain */
+
+#ifndef __CPU_ARCH_H
+#define __CPU_ARCH_H
+
+#include "Types.h"
+
+EXTERN_C_BEGIN
+
+/*
+MY_CPU_LE means that CPU is LITTLE ENDIAN.
+If MY_CPU_LE is not defined, we don't know about that property of platform (it can be LITTLE ENDIAN).
+
+MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
+If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of platform.
+*/
+
+#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__)
+#define MY_CPU_AMD64
+#endif
+
+#if defined(MY_CPU_AMD64) || defined(_M_IA64)
+#define MY_CPU_64BIT
+#endif
+
+#if defined(_M_IX86) || defined(__i386__)
+#define MY_CPU_X86
+#endif
+
+#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
+#define MY_CPU_X86_OR_AMD64
+#endif
+
+#if defined(MY_CPU_X86) || defined(_M_ARM)
+#define MY_CPU_32BIT
+#endif
+
+#if defined(_WIN32) && defined(_M_ARM)
+#define MY_CPU_ARM_LE
+#endif
+
+#if defined(_WIN32) && defined(_M_IA64)
+#define MY_CPU_IA64_LE
+#endif
+
+#if defined(MY_CPU_X86_OR_AMD64)
+#define MY_CPU_LE_UNALIGN
+#endif
+
+#if defined(MY_CPU_X86_OR_AMD64) || defined(MY_CPU_ARM_LE)  || defined(MY_CPU_IA64_LE) || defined(__ARMEL__) || defined(__MIPSEL__) || defined(__LITTLE_ENDIAN__)
+#define MY_CPU_LE
+#endif
+
+#if defined(__BIG_ENDIAN__)
+#define MY_CPU_BE
+#endif
+
+#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
+Stop_Compiling_Bad_Endian
+#endif
+
+#ifdef MY_CPU_LE_UNALIGN
+
+#define GetUi16(p) (*(const UInt16 *)(p))
+#define GetUi32(p) (*(const UInt32 *)(p))
+#define GetUi64(p) (*(const UInt64 *)(p))
+#define SetUi16(p, d) *(UInt16 *)(p) = (d);
+#define SetUi32(p, d) *(UInt32 *)(p) = (d);
+#define SetUi64(p, d) *(UInt64 *)(p) = (d);
+
+#else
+
+#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
+
+#define GetUi32(p) ( \
+             ((const Byte *)(p))[0]        | \
+    ((UInt32)((const Byte *)(p))[1] <<  8) | \
+    ((UInt32)((const Byte *)(p))[2] << 16) | \
+    ((UInt32)((const Byte *)(p))[3] << 24))
+
+#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
+
+#define SetUi16(p, d) { UInt32 _x_ = (d); \
+    ((Byte *)(p))[0] = (Byte)_x_; \
+    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); }
+
+#define SetUi32(p, d) { UInt32 _x_ = (d); \
+    ((Byte *)(p))[0] = (Byte)_x_; \
+    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
+    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
+    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
+
+#define SetUi64(p, d) { UInt64 _x64_ = (d); \
+    SetUi32(p, (UInt32)_x64_); \
+    SetUi32(((Byte *)(p)) + 4, (UInt32)(_x64_ >> 32)); }
+
+#endif
+
+#if defined(MY_CPU_LE_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
+
+#pragma intrinsic(_byteswap_ulong)
+#pragma intrinsic(_byteswap_uint64)
+#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
+#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
+
+#else
+
+#define GetBe32(p) ( \
+    ((UInt32)((const Byte *)(p))[0] << 24) | \
+    ((UInt32)((const Byte *)(p))[1] << 16) | \
+    ((UInt32)((const Byte *)(p))[2] <<  8) | \
+             ((const Byte *)(p))[3] )
+
+#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
+
+#endif
+
+#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
+
+
+#ifdef MY_CPU_X86_OR_AMD64
+
+typedef struct
+{
+  UInt32 maxFunc;
+  UInt32 vendor[3];
+  UInt32 ver;
+  UInt32 b;
+  UInt32 c;
+  UInt32 d;
+} Cx86cpuid;
+
+enum
+{
+  CPU_FIRM_INTEL,
+  CPU_FIRM_AMD,
+  CPU_FIRM_VIA
+};
+
+Bool x86cpuid_CheckAndRead(Cx86cpuid *p);
+int x86cpuid_GetFirm(const Cx86cpuid *p);
+
+#define x86cpuid_GetFamily(p) (((p)->ver >> 8) & 0xFF00F)
+#define x86cpuid_GetModel(p) (((p)->ver >> 4) & 0xF00F)
+#define x86cpuid_GetStepping(p) ((p)->ver & 0xF)
+
+Bool CPU_Is_InOrder();
+Bool CPU_Is_Aes_Supported();
+
+#endif
+
+EXTERN_C_END
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,62 @@
+/* Delta.c -- Delta converter
+2009-05-26 : Igor Pavlov : Public domain */
+
+#include "Delta.h"
+
+void Delta_Init(Byte *state)
+{
+  unsigned i;
+  for (i = 0; i < DELTA_STATE_SIZE; i++)
+    state[i] = 0;
+}
+
+static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)
+{
+  unsigned i;
+  for (i = 0; i < size; i++)
+    dest[i] = src[i];
+}
+
+void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
+{
+  Byte buf[DELTA_STATE_SIZE];
+  unsigned j = 0;
+  MyMemCpy(buf, state, delta);
+  {
+    SizeT i;
+    for (i = 0; i < size;)
+    {
+      for (j = 0; j < delta && i < size; i++, j++)
+      {
+        Byte b = data[i];
+        data[i] = (Byte)(b - buf[j]);
+        buf[j] = b;
+      }
+    }
+  }
+  if (j == delta)
+    j = 0;
+  MyMemCpy(state, buf + j, delta - j);
+  MyMemCpy(state + delta - j, buf, j);
+}
+
+void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
+{
+  Byte buf[DELTA_STATE_SIZE];
+  unsigned j = 0;
+  MyMemCpy(buf, state, delta);
+  {
+    SizeT i;
+    for (i = 0; i < size;)
+    {
+      for (j = 0; j < delta && i < size; i++, j++)
+      {
+        buf[j] = data[i] = (Byte)(buf[j] + data[i]);
+      }
+    }
+  }
+  if (j == delta)
+    j = 0;
+  MyMemCpy(state, buf + j, delta - j);
+  MyMemCpy(state + delta - j, buf, j);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Delta.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,23 @@
+/* Delta.h -- Delta converter
+2009-04-15 : Igor Pavlov : Public domain */
+
+#ifndef __DELTA_H
+#define __DELTA_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DELTA_STATE_SIZE 256
+
+void Delta_Init(Byte *state);
+void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size);
+void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,146 @@
+/* HuffEnc.c -- functions for Huffman encoding
+2009-09-02 : Igor Pavlov : Public domain */
+
+#include "HuffEnc.h"
+#include "Sort.h"
+
+#define kMaxLen 16
+#define NUM_BITS 10
+#define MASK ((1 << NUM_BITS) - 1)
+
+#define NUM_COUNTERS 64
+
+#define HUFFMAN_SPEED_OPT
+
+void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)
+{
+  UInt32 num = 0;
+  /* if (maxLen > 10) maxLen = 10; */
+  {
+    UInt32 i;
+    
+    #ifdef HUFFMAN_SPEED_OPT
+    
+    UInt32 counters[NUM_COUNTERS];
+    for (i = 0; i < NUM_COUNTERS; i++)
+      counters[i] = 0;
+    for (i = 0; i < numSymbols; i++)
+    {
+      UInt32 freq = freqs[i];
+      counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;
+    }
+ 
+    for (i = 1; i < NUM_COUNTERS; i++)
+    {
+      UInt32 temp = counters[i];
+      counters[i] = num;
+      num += temp;
+    }
+
+    for (i = 0; i < numSymbols; i++)
+    {
+      UInt32 freq = freqs[i];
+      if (freq == 0)
+        lens[i] = 0;
+      else
+        p[counters[((freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1)]++] = i | (freq << NUM_BITS);
+    }
+    counters[0] = 0;
+    HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]);
+    
+    #else
+
+    for (i = 0; i < numSymbols; i++)
+    {
+      UInt32 freq = freqs[i];
+      if (freq == 0)
+        lens[i] = 0;
+      else
+        p[num++] = i | (freq << NUM_BITS);
+    }
+    HeapSort(p, num);
+
+    #endif
+  }
+
+  if (num < 2)
+  {
+    unsigned minCode = 0;
+    unsigned maxCode = 1;
+    if (num == 1)
+    {
+      maxCode = (unsigned)p[0] & MASK;
+      if (maxCode == 0)
+        maxCode++;
+    }
+    p[minCode] = 0;
+    p[maxCode] = 1;
+    lens[minCode] = lens[maxCode] = 1;
+    return;
+  }
+  
+  {
+    UInt32 b, e, i;
+  
+    i = b = e = 0;
+    do
+    {
+      UInt32 n, m, freq;
+      n = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
+      freq = (p[n] & ~MASK);
+      p[n] = (p[n] & MASK) | (e << NUM_BITS);
+      m = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
+      freq += (p[m] & ~MASK);
+      p[m] = (p[m] & MASK) | (e << NUM_BITS);
+      p[e] = (p[e] & MASK) | freq;
+      e++;
+    }
+    while (num - e > 1);
+    
+    {
+      UInt32 lenCounters[kMaxLen + 1];
+      for (i = 0; i <= kMaxLen; i++)
+        lenCounters[i] = 0;
+      
+      p[--e] &= MASK;
+      lenCounters[1] = 2;
+      while (e > 0)
+      {
+        UInt32 len = (p[p[--e] >> NUM_BITS] >> NUM_BITS) + 1;
+        p[e] = (p[e] & MASK) | (len << NUM_BITS);
+        if (len >= maxLen)
+          for (len = maxLen - 1; lenCounters[len] == 0; len--);
+        lenCounters[len]--;
+        lenCounters[len + 1] += 2;
+      }
+      
+      {
+        UInt32 len;
+        i = 0;
+        for (len = maxLen; len != 0; len--)
+        {
+          UInt32 num;
+          for (num = lenCounters[len]; num != 0; num--)
+            lens[p[i++] & MASK] = (Byte)len;
+        }
+      }
+      
+      {
+        UInt32 nextCodes[kMaxLen + 1];
+        {
+          UInt32 code = 0;
+          UInt32 len;
+          for (len = 1; len <= kMaxLen; len++)
+            nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;
+        }
+        /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */
+
+        {
+          UInt32 i;
+          for (i = 0; i < numSymbols; i++)
+            p[i] = nextCodes[lens[i]]++;
+        }
+      }
+    }
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/HuffEnc.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,27 @@
+/* HuffEnc.h -- Huffman encoding
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __HUFF_ENC_H
+#define __HUFF_ENC_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+Conditions:
+  num <= 1024 = 2 ^ NUM_BITS
+  Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS)
+  maxLen <= 16 = kMaxLen
+  Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)
+*/
+ 
+void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,761 @@
+/* LzFind.c -- Match finder for LZ algorithms
+2009-04-22 : Igor Pavlov : Public domain */
+
+#include <string.h>
+
+#include "LzFind.h"
+#include "LzHash.h"
+
+#define kEmptyHashValue 0
+#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
+#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
+#define kNormalizeMask (~(kNormalizeStepMin - 1))
+#define kMaxHistorySize ((UInt32)3 << 30)
+
+#define kStartMaxLen 3
+
+static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
+{
+  if (!p->directInput)
+  {
+    alloc->Free(alloc, p->bufferBase);
+    p->bufferBase = 0;
+  }
+}
+
+/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
+
+static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
+{
+  UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
+  if (p->directInput)
+  {
+    p->blockSize = blockSize;
+    return 1;
+  }
+  if (p->bufferBase == 0 || p->blockSize != blockSize)
+  {
+    LzInWindow_Free(p, alloc);
+    p->blockSize = blockSize;
+    p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
+  }
+  return (p->bufferBase != 0);
+}
+
+Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
+Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
+
+UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
+
+void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
+{
+  p->posLimit -= subValue;
+  p->pos -= subValue;
+  p->streamPos -= subValue;
+}
+
+static void MatchFinder_ReadBlock(CMatchFinder *p)
+{
+  if (p->streamEndWasReached || p->result != SZ_OK)
+    return;
+  if (p->directInput)
+  {
+    UInt32 curSize = 0xFFFFFFFF - p->streamPos;
+    if (curSize > p->directInputRem)
+      curSize = (UInt32)p->directInputRem;
+    p->directInputRem -= curSize;
+    p->streamPos += curSize;
+    if (p->directInputRem == 0)
+      p->streamEndWasReached = 1;
+    return;
+  }
+  for (;;)
+  {
+    Byte *dest = p->buffer + (p->streamPos - p->pos);
+    size_t size = (p->bufferBase + p->blockSize - dest);
+    if (size == 0)
+      return;
+    p->result = p->stream->Read(p->stream, dest, &size);
+    if (p->result != SZ_OK)
+      return;
+    if (size == 0)
+    {
+      p->streamEndWasReached = 1;
+      return;
+    }
+    p->streamPos += (UInt32)size;
+    if (p->streamPos - p->pos > p->keepSizeAfter)
+      return;
+  }
+}
+
+void MatchFinder_MoveBlock(CMatchFinder *p)
+{
+  memmove(p->bufferBase,
+    p->buffer - p->keepSizeBefore,
+    (size_t)(p->streamPos - p->pos + p->keepSizeBefore));
+  p->buffer = p->bufferBase + p->keepSizeBefore;
+}
+
+int MatchFinder_NeedMove(CMatchFinder *p)
+{
+  if (p->directInput)
+    return 0;
+  /* if (p->streamEndWasReached) return 0; */
+  return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
+}
+
+void MatchFinder_ReadIfRequired(CMatchFinder *p)
+{
+  if (p->streamEndWasReached)
+    return;
+  if (p->keepSizeAfter >= p->streamPos - p->pos)
+    MatchFinder_ReadBlock(p);
+}
+
+static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
+{
+  if (MatchFinder_NeedMove(p))
+    MatchFinder_MoveBlock(p);
+  MatchFinder_ReadBlock(p);
+}
+
+static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
+{
+  p->cutValue = 32;
+  p->btMode = 1;
+  p->numHashBytes = 4;
+  p->bigHash = 0;
+}
+
+#define kCrcPoly 0xEDB88320
+
+void MatchFinder_Construct(CMatchFinder *p)
+{
+  UInt32 i;
+  p->bufferBase = 0;
+  p->directInput = 0;
+  p->hash = 0;
+  MatchFinder_SetDefaultSettings(p);
+
+  for (i = 0; i < 256; i++)
+  {
+    UInt32 r = i;
+    int j;
+    for (j = 0; j < 8; j++)
+      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
+    p->crc[i] = r;
+  }
+}
+
+static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->hash);
+  p->hash = 0;
+}
+
+void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
+{
+  MatchFinder_FreeThisClassMemory(p, alloc);
+  LzInWindow_Free(p, alloc);
+}
+
+static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
+{
+  size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
+  if (sizeInBytes / sizeof(CLzRef) != num)
+    return 0;
+  return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
+}
+
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
+    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
+    ISzAlloc *alloc)
+{
+  UInt32 sizeReserv;
+  if (historySize > kMaxHistorySize)
+  {
+    MatchFinder_Free(p, alloc);
+    return 0;
+  }
+  sizeReserv = historySize >> 1;
+  if (historySize > ((UInt32)2 << 30))
+    sizeReserv = historySize >> 2;
+  sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
+
+  p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
+  p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
+  /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
+  if (LzInWindow_Create(p, sizeReserv, alloc))
+  {
+    UInt32 newCyclicBufferSize = historySize + 1;
+    UInt32 hs;
+    p->matchMaxLen = matchMaxLen;
+    {
+      p->fixedHashSize = 0;
+      if (p->numHashBytes == 2)
+        hs = (1 << 16) - 1;
+      else
+      {
+        hs = historySize - 1;
+        hs |= (hs >> 1);
+        hs |= (hs >> 2);
+        hs |= (hs >> 4);
+        hs |= (hs >> 8);
+        hs >>= 1;
+        hs |= 0xFFFF; /* don't change it! It's required for Deflate */
+        if (hs > (1 << 24))
+        {
+          if (p->numHashBytes == 3)
+            hs = (1 << 24) - 1;
+          else
+            hs >>= 1;
+        }
+      }
+      p->hashMask = hs;
+      hs++;
+      if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
+      if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
+      if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
+      hs += p->fixedHashSize;
+    }
+
+    {
+      UInt32 prevSize = p->hashSizeSum + p->numSons;
+      UInt32 newSize;
+      p->historySize = historySize;
+      p->hashSizeSum = hs;
+      p->cyclicBufferSize = newCyclicBufferSize;
+      p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);
+      newSize = p->hashSizeSum + p->numSons;
+      if (p->hash != 0 && prevSize == newSize)
+        return 1;
+      MatchFinder_FreeThisClassMemory(p, alloc);
+      p->hash = AllocRefs(newSize, alloc);
+      if (p->hash != 0)
+      {
+        p->son = p->hash + p->hashSizeSum;
+        return 1;
+      }
+    }
+  }
+  MatchFinder_Free(p, alloc);
+  return 0;
+}
+
+static void MatchFinder_SetLimits(CMatchFinder *p)
+{
+  UInt32 limit = kMaxValForNormalize - p->pos;
+  UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
+  if (limit2 < limit)
+    limit = limit2;
+  limit2 = p->streamPos - p->pos;
+  if (limit2 <= p->keepSizeAfter)
+  {
+    if (limit2 > 0)
+      limit2 = 1;
+  }
+  else
+    limit2 -= p->keepSizeAfter;
+  if (limit2 < limit)
+    limit = limit2;
+  {
+    UInt32 lenLimit = p->streamPos - p->pos;
+    if (lenLimit > p->matchMaxLen)
+      lenLimit = p->matchMaxLen;
+    p->lenLimit = lenLimit;
+  }
+  p->posLimit = p->pos + limit;
+}
+
+void MatchFinder_Init(CMatchFinder *p)
+{
+  UInt32 i;
+  for (i = 0; i < p->hashSizeSum; i++)
+    p->hash[i] = kEmptyHashValue;
+  p->cyclicBufferPos = 0;
+  p->buffer = p->bufferBase;
+  p->pos = p->streamPos = p->cyclicBufferSize;
+  p->result = SZ_OK;
+  p->streamEndWasReached = 0;
+  MatchFinder_ReadBlock(p);
+  MatchFinder_SetLimits(p);
+}
+
+static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
+{
+  return (p->pos - p->historySize - 1) & kNormalizeMask;
+}
+
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
+{
+  UInt32 i;
+  for (i = 0; i < numItems; i++)
+  {
+    UInt32 value = items[i];
+    if (value <= subValue)
+      value = kEmptyHashValue;
+    else
+      value -= subValue;
+    items[i] = value;
+  }
+}
+
+static void MatchFinder_Normalize(CMatchFinder *p)
+{
+  UInt32 subValue = MatchFinder_GetSubValue(p);
+  MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
+  MatchFinder_ReduceOffsets(p, subValue);
+}
+
+static void MatchFinder_CheckLimits(CMatchFinder *p)
+{
+  if (p->pos == kMaxValForNormalize)
+    MatchFinder_Normalize(p);
+  if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
+    MatchFinder_CheckAndMoveAndRead(p);
+  if (p->cyclicBufferPos == p->cyclicBufferSize)
+    p->cyclicBufferPos = 0;
+  MatchFinder_SetLimits(p);
+}
+
+static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
+    UInt32 *distances, UInt32 maxLen)
+{
+  son[_cyclicBufferPos] = curMatch;
+  for (;;)
+  {
+    UInt32 delta = pos - curMatch;
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+      return distances;
+    {
+      const Byte *pb = cur - delta;
+      curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
+      if (pb[maxLen] == cur[maxLen] && *pb == *cur)
+      {
+        UInt32 len = 0;
+        while (++len != lenLimit)
+          if (pb[len] != cur[len])
+            break;
+        if (maxLen < len)
+        {
+          *distances++ = maxLen = len;
+          *distances++ = delta - 1;
+          if (len == lenLimit)
+            return distances;
+        }
+      }
+    }
+  }
+}
+
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
+    UInt32 *distances, UInt32 maxLen)
+{
+  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
+  UInt32 len0 = 0, len1 = 0;
+  for (;;)
+  {
+    UInt32 delta = pos - curMatch;
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+    {
+      *ptr0 = *ptr1 = kEmptyHashValue;
+      return distances;
+    }
+    {
+      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+      const Byte *pb = cur - delta;
+      UInt32 len = (len0 < len1 ? len0 : len1);
+      if (pb[len] == cur[len])
+      {
+        if (++len != lenLimit && pb[len] == cur[len])
+          while (++len != lenLimit)
+            if (pb[len] != cur[len])
+              break;
+        if (maxLen < len)
+        {
+          *distances++ = maxLen = len;
+          *distances++ = delta - 1;
+          if (len == lenLimit)
+          {
+            *ptr1 = pair[0];
+            *ptr0 = pair[1];
+            return distances;
+          }
+        }
+      }
+      if (pb[len] < cur[len])
+      {
+        *ptr1 = curMatch;
+        ptr1 = pair + 1;
+        curMatch = *ptr1;
+        len1 = len;
+      }
+      else
+      {
+        *ptr0 = curMatch;
+        ptr0 = pair;
+        curMatch = *ptr0;
+        len0 = len;
+      }
+    }
+  }
+}
+
+static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
+{
+  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
+  UInt32 len0 = 0, len1 = 0;
+  for (;;)
+  {
+    UInt32 delta = pos - curMatch;
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+    {
+      *ptr0 = *ptr1 = kEmptyHashValue;
+      return;
+    }
+    {
+      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+      const Byte *pb = cur - delta;
+      UInt32 len = (len0 < len1 ? len0 : len1);
+      if (pb[len] == cur[len])
+      {
+        while (++len != lenLimit)
+          if (pb[len] != cur[len])
+            break;
+        {
+          if (len == lenLimit)
+          {
+            *ptr1 = pair[0];
+            *ptr0 = pair[1];
+            return;
+          }
+        }
+      }
+      if (pb[len] < cur[len])
+      {
+        *ptr1 = curMatch;
+        ptr1 = pair + 1;
+        curMatch = *ptr1;
+        len1 = len;
+      }
+      else
+      {
+        *ptr0 = curMatch;
+        ptr0 = pair;
+        curMatch = *ptr0;
+        len0 = len;
+      }
+    }
+  }
+}
+
+#define MOVE_POS \
+  ++p->cyclicBufferPos; \
+  p->buffer++; \
+  if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
+
+#define MOVE_POS_RET MOVE_POS return offset;
+
+static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
+
+#define GET_MATCHES_HEADER2(minLen, ret_op) \
+  UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
+  lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
+  cur = p->buffer;
+
+#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
+#define SKIP_HEADER(minLen)        GET_MATCHES_HEADER2(minLen, continue)
+
+#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
+
+#define GET_MATCHES_FOOTER(offset, maxLen) \
+  offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
+  distances + offset, maxLen) - distances); MOVE_POS_RET;
+
+#define SKIP_FOOTER \
+  SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
+
+static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 offset;
+  GET_MATCHES_HEADER(2)
+  HASH2_CALC;
+  curMatch = p->hash[hashValue];
+  p->hash[hashValue] = p->pos;
+  offset = 0;
+  GET_MATCHES_FOOTER(offset, 1)
+}
+
+UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 offset;
+  GET_MATCHES_HEADER(3)
+  HASH_ZIP_CALC;
+  curMatch = p->hash[hashValue];
+  p->hash[hashValue] = p->pos;
+  offset = 0;
+  GET_MATCHES_FOOTER(offset, 2)
+}
+
+static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 hash2Value, delta2, maxLen, offset;
+  GET_MATCHES_HEADER(3)
+
+  HASH3_CALC;
+
+  delta2 = p->pos - p->hash[hash2Value];
+  curMatch = p->hash[kFix3HashSize + hashValue];
+  
+  p->hash[hash2Value] =
+  p->hash[kFix3HashSize + hashValue] = p->pos;
+
+
+  maxLen = 2;
+  offset = 0;
+  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
+  {
+    for (; maxLen != lenLimit; maxLen++)
+      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
+        break;
+    distances[0] = maxLen;
+    distances[1] = delta2 - 1;
+    offset = 2;
+    if (maxLen == lenLimit)
+    {
+      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
+      MOVE_POS_RET;
+    }
+  }
+  GET_MATCHES_FOOTER(offset, maxLen)
+}
+
+static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
+  GET_MATCHES_HEADER(4)
+
+  HASH4_CALC;
+
+  delta2 = p->pos - p->hash[                hash2Value];
+  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
+  curMatch = p->hash[kFix4HashSize + hashValue];
+  
+  p->hash[                hash2Value] =
+  p->hash[kFix3HashSize + hash3Value] =
+  p->hash[kFix4HashSize + hashValue] = p->pos;
+
+  maxLen = 1;
+  offset = 0;
+  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
+  {
+    distances[0] = maxLen = 2;
+    distances[1] = delta2 - 1;
+    offset = 2;
+  }
+  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
+  {
+    maxLen = 3;
+    distances[offset + 1] = delta3 - 1;
+    offset += 2;
+    delta2 = delta3;
+  }
+  if (offset != 0)
+  {
+    for (; maxLen != lenLimit; maxLen++)
+      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
+        break;
+    distances[offset - 2] = maxLen;
+    if (maxLen == lenLimit)
+    {
+      SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
+      MOVE_POS_RET;
+    }
+  }
+  if (maxLen < 3)
+    maxLen = 3;
+  GET_MATCHES_FOOTER(offset, maxLen)
+}
+
+static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
+  GET_MATCHES_HEADER(4)
+
+  HASH4_CALC;
+
+  delta2 = p->pos - p->hash[                hash2Value];
+  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
+  curMatch = p->hash[kFix4HashSize + hashValue];
+
+  p->hash[                hash2Value] =
+  p->hash[kFix3HashSize + hash3Value] =
+  p->hash[kFix4HashSize + hashValue] = p->pos;
+
+  maxLen = 1;
+  offset = 0;
+  if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
+  {
+    distances[0] = maxLen = 2;
+    distances[1] = delta2 - 1;
+    offset = 2;
+  }
+  if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
+  {
+    maxLen = 3;
+    distances[offset + 1] = delta3 - 1;
+    offset += 2;
+    delta2 = delta3;
+  }
+  if (offset != 0)
+  {
+    for (; maxLen != lenLimit; maxLen++)
+      if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
+        break;
+    distances[offset - 2] = maxLen;
+    if (maxLen == lenLimit)
+    {
+      p->son[p->cyclicBufferPos] = curMatch;
+      MOVE_POS_RET;
+    }
+  }
+  if (maxLen < 3)
+    maxLen = 3;
+  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+    distances + offset, maxLen) - (distances));
+  MOVE_POS_RET
+}
+
+UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
+{
+  UInt32 offset;
+  GET_MATCHES_HEADER(3)
+  HASH_ZIP_CALC;
+  curMatch = p->hash[hashValue];
+  p->hash[hashValue] = p->pos;
+  offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+    distances, 2) - (distances));
+  MOVE_POS_RET
+}
+
+static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    SKIP_HEADER(2)
+    HASH2_CALC;
+    curMatch = p->hash[hashValue];
+    p->hash[hashValue] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    SKIP_HEADER(3)
+    HASH_ZIP_CALC;
+    curMatch = p->hash[hashValue];
+    p->hash[hashValue] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+
+static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    UInt32 hash2Value;
+    SKIP_HEADER(3)
+    HASH3_CALC;
+    curMatch = p->hash[kFix3HashSize + hashValue];
+    p->hash[hash2Value] =
+    p->hash[kFix3HashSize + hashValue] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+
+static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    UInt32 hash2Value, hash3Value;
+    SKIP_HEADER(4)
+    HASH4_CALC;
+    curMatch = p->hash[kFix4HashSize + hashValue];
+    p->hash[                hash2Value] =
+    p->hash[kFix3HashSize + hash3Value] = p->pos;
+    p->hash[kFix4HashSize + hashValue] = p->pos;
+    SKIP_FOOTER
+  }
+  while (--num != 0);
+}
+
+static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    UInt32 hash2Value, hash3Value;
+    SKIP_HEADER(4)
+    HASH4_CALC;
+    curMatch = p->hash[kFix4HashSize + hashValue];
+    p->hash[                hash2Value] =
+    p->hash[kFix3HashSize + hash3Value] =
+    p->hash[kFix4HashSize + hashValue] = p->pos;
+    p->son[p->cyclicBufferPos] = curMatch;
+    MOVE_POS
+  }
+  while (--num != 0);
+}
+
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
+{
+  do
+  {
+    SKIP_HEADER(3)
+    HASH_ZIP_CALC;
+    curMatch = p->hash[hashValue];
+    p->hash[hashValue] = p->pos;
+    p->son[p->cyclicBufferPos] = curMatch;
+    MOVE_POS
+  }
+  while (--num != 0);
+}
+
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
+{
+  vTable->Init = (Mf_Init_Func)MatchFinder_Init;
+  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
+  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
+  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
+  if (!p->btMode)
+  {
+    vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
+    vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
+  }
+  else if (p->numHashBytes == 2)
+  {
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
+    vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
+  }
+  else if (p->numHashBytes == 3)
+  {
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
+    vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
+  }
+  else
+  {
+    vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
+    vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFind.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,115 @@
+/* LzFind.h -- Match finder for LZ algorithms
+2009-04-22 : Igor Pavlov : Public domain */
+
+#ifndef __LZ_FIND_H
+#define __LZ_FIND_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef UInt32 CLzRef;
+
+typedef struct _CMatchFinder
+{
+  Byte *buffer;
+  UInt32 pos;
+  UInt32 posLimit;
+  UInt32 streamPos;
+  UInt32 lenLimit;
+
+  UInt32 cyclicBufferPos;
+  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
+
+  UInt32 matchMaxLen;
+  CLzRef *hash;
+  CLzRef *son;
+  UInt32 hashMask;
+  UInt32 cutValue;
+
+  Byte *bufferBase;
+  ISeqInStream *stream;
+  int streamEndWasReached;
+
+  UInt32 blockSize;
+  UInt32 keepSizeBefore;
+  UInt32 keepSizeAfter;
+
+  UInt32 numHashBytes;
+  int directInput;
+  size_t directInputRem;
+  int btMode;
+  int bigHash;
+  UInt32 historySize;
+  UInt32 fixedHashSize;
+  UInt32 hashSizeSum;
+  UInt32 numSons;
+  SRes result;
+  UInt32 crc[256];
+} CMatchFinder;
+
+#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
+#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
+
+#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
+
+int MatchFinder_NeedMove(CMatchFinder *p);
+Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
+void MatchFinder_MoveBlock(CMatchFinder *p);
+void MatchFinder_ReadIfRequired(CMatchFinder *p);
+
+void MatchFinder_Construct(CMatchFinder *p);
+
+/* Conditions:
+     historySize <= 3 GB
+     keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
+*/
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
+    UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
+    ISzAlloc *alloc);
+void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
+void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
+void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
+
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
+    UInt32 *distances, UInt32 maxLen);
+
+/*
+Conditions:
+  Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
+  Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
+*/
+
+typedef void (*Mf_Init_Func)(void *object);
+typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
+typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
+typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
+typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
+typedef void (*Mf_Skip_Func)(void *object, UInt32);
+
+typedef struct _IMatchFinder
+{
+  Mf_Init_Func Init;
+  Mf_GetIndexByte_Func GetIndexByte;
+  Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
+  Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
+  Mf_GetMatches_Func GetMatches;
+  Mf_Skip_Func Skip;
+} IMatchFinder;
+
+void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
+
+void MatchFinder_Init(CMatchFinder *p);
+UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
+UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
+void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
+void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,793 @@
+/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
+2009-09-20 : Igor Pavlov : Public domain */
+
+#include "LzHash.h"
+
+#include "LzFindMt.h"
+
+void MtSync_Construct(CMtSync *p)
+{
+  p->wasCreated = False;
+  p->csWasInitialized = False;
+  p->csWasEntered = False;
+  Thread_Construct(&p->thread);
+  Event_Construct(&p->canStart);
+  Event_Construct(&p->wasStarted);
+  Event_Construct(&p->wasStopped);
+  Semaphore_Construct(&p->freeSemaphore);
+  Semaphore_Construct(&p->filledSemaphore);
+}
+
+void MtSync_GetNextBlock(CMtSync *p)
+{
+  if (p->needStart)
+  {
+    p->numProcessedBlocks = 1;
+    p->needStart = False;
+    p->stopWriting = False;
+    p->exit = False;
+    Event_Reset(&p->wasStarted);
+    Event_Reset(&p->wasStopped);
+
+    Event_Set(&p->canStart);
+    Event_Wait(&p->wasStarted);
+  }
+  else
+  {
+    CriticalSection_Leave(&p->cs);
+    p->csWasEntered = False;
+    p->numProcessedBlocks++;
+    Semaphore_Release1(&p->freeSemaphore);
+  }
+  Semaphore_Wait(&p->filledSemaphore);
+  CriticalSection_Enter(&p->cs);
+  p->csWasEntered = True;
+}
+
+/* MtSync_StopWriting must be called if Writing was started */
+
+void MtSync_StopWriting(CMtSync *p)
+{
+  UInt32 myNumBlocks = p->numProcessedBlocks;
+  if (!Thread_WasCreated(&p->thread) || p->needStart)
+    return;
+  p->stopWriting = True;
+  if (p->csWasEntered)
+  {
+    CriticalSection_Leave(&p->cs);
+    p->csWasEntered = False;
+  }
+  Semaphore_Release1(&p->freeSemaphore);
+ 
+  Event_Wait(&p->wasStopped);
+
+  while (myNumBlocks++ != p->numProcessedBlocks)
+  {
+    Semaphore_Wait(&p->filledSemaphore);
+    Semaphore_Release1(&p->freeSemaphore);
+  }
+  p->needStart = True;
+}
+
+void MtSync_Destruct(CMtSync *p)
+{
+  if (Thread_WasCreated(&p->thread))
+  {
+    MtSync_StopWriting(p);
+    p->exit = True;
+    if (p->needStart)
+      Event_Set(&p->canStart);
+    Thread_Wait(&p->thread);
+    Thread_Close(&p->thread);
+  }
+  if (p->csWasInitialized)
+  {
+    CriticalSection_Delete(&p->cs);
+    p->csWasInitialized = False;
+  }
+
+  Event_Close(&p->canStart);
+  Event_Close(&p->wasStarted);
+  Event_Close(&p->wasStopped);
+  Semaphore_Close(&p->freeSemaphore);
+  Semaphore_Close(&p->filledSemaphore);
+
+  p->wasCreated = False;
+}
+
+#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
+
+static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
+{
+  if (p->wasCreated)
+    return SZ_OK;
+
+  RINOK_THREAD(CriticalSection_Init(&p->cs));
+  p->csWasInitialized = True;
+
+  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));
+  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));
+  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
+  
+  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));
+  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));
+
+  p->needStart = True;
+  
+  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));
+  p->wasCreated = True;
+  return SZ_OK;
+}
+
+static SRes MtSync_Create(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void *), void *obj, UInt32 numBlocks)
+{
+  SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);
+  if (res != SZ_OK)
+    MtSync_Destruct(p);
+  return res;
+}
+
+void MtSync_Init(CMtSync *p) { p->needStart = True; }
+
+#define kMtMaxValForNormalize 0xFFFFFFFF
+
+#define DEF_GetHeads2(name, v, action) \
+static void GetHeads ## name(const Byte *p, UInt32 pos, \
+UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \
+{ action; for (; numHeads != 0; numHeads--) { \
+const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++;  } }
+
+#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)
+
+DEF_GetHeads2(2,  (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )
+DEF_GetHeads(3,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
+DEF_GetHeads(4,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)
+DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
+/* DEF_GetHeads(5,  (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask) */
+
+void HashThreadFunc(CMatchFinderMt *mt)
+{
+  CMtSync *p = &mt->hashSync;
+  for (;;)
+  {
+    UInt32 numProcessedBlocks = 0;
+    Event_Wait(&p->canStart);
+    Event_Set(&p->wasStarted);
+    for (;;)
+    {
+      if (p->exit)
+        return;
+      if (p->stopWriting)
+      {
+        p->numProcessedBlocks = numProcessedBlocks;
+        Event_Set(&p->wasStopped);
+        break;
+      }
+
+      {
+        CMatchFinder *mf = mt->MatchFinder;
+        if (MatchFinder_NeedMove(mf))
+        {
+          CriticalSection_Enter(&mt->btSync.cs);
+          CriticalSection_Enter(&mt->hashSync.cs);
+          {
+            const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);
+            const Byte *afterPtr;
+            MatchFinder_MoveBlock(mf);
+            afterPtr = MatchFinder_GetPointerToCurrentPos(mf);
+            mt->pointerToCurPos -= beforePtr - afterPtr;
+            mt->buffer -= beforePtr - afterPtr;
+          }
+          CriticalSection_Leave(&mt->btSync.cs);
+          CriticalSection_Leave(&mt->hashSync.cs);
+          continue;
+        }
+
+        Semaphore_Wait(&p->freeSemaphore);
+
+        MatchFinder_ReadIfRequired(mf);
+        if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))
+        {
+          UInt32 subValue = (mf->pos - mf->historySize - 1);
+          MatchFinder_ReduceOffsets(mf, subValue);
+          MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);
+        }
+        {
+          UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;
+          UInt32 num = mf->streamPos - mf->pos;
+          heads[0] = 2;
+          heads[1] = num;
+          if (num >= mf->numHashBytes)
+          {
+            num = num - mf->numHashBytes + 1;
+            if (num > kMtHashBlockSize - 2)
+              num = kMtHashBlockSize - 2;
+            mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);
+            heads[0] += num;
+          }
+          mf->pos += num;
+          mf->buffer += num;
+        }
+      }
+
+      Semaphore_Release1(&p->filledSemaphore);
+    }
+  }
+}
+
+void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
+{
+  MtSync_GetNextBlock(&p->hashSync);
+  p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;
+  p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];
+  p->hashNumAvail = p->hashBuf[p->hashBufPos++];
+}
+
+#define kEmptyHashValue 0
+
+/* #define MFMT_GM_INLINE */
+
+#ifdef MFMT_GM_INLINE
+
+#define NO_INLINE MY_FAST_CALL
+
+Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
+    UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
+    UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)
+{
+  do
+  {
+  UInt32 *distances = _distances + 1;
+  UInt32 curMatch = pos - *hash++;
+
+  CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+  CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
+  UInt32 len0 = 0, len1 = 0;
+  UInt32 cutValue = _cutValue;
+  UInt32 maxLen = _maxLen;
+  for (;;)
+  {
+    UInt32 delta = pos - curMatch;
+    if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+    {
+      *ptr0 = *ptr1 = kEmptyHashValue;
+      break;
+    }
+    {
+      CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+      const Byte *pb = cur - delta;
+      UInt32 len = (len0 < len1 ? len0 : len1);
+      if (pb[len] == cur[len])
+      {
+        if (++len != lenLimit && pb[len] == cur[len])
+          while (++len != lenLimit)
+            if (pb[len] != cur[len])
+              break;
+        if (maxLen < len)
+        {
+          *distances++ = maxLen = len;
+          *distances++ = delta - 1;
+          if (len == lenLimit)
+          {
+            *ptr1 = pair[0];
+            *ptr0 = pair[1];
+            break;
+          }
+        }
+      }
+      if (pb[len] < cur[len])
+      {
+        *ptr1 = curMatch;
+        ptr1 = pair + 1;
+        curMatch = *ptr1;
+        len1 = len;
+      }
+      else
+      {
+        *ptr0 = curMatch;
+        ptr0 = pair;
+        curMatch = *ptr0;
+        len0 = len;
+      }
+    }
+  }
+  pos++;
+  _cyclicBufferPos++;
+  cur++;
+  {
+    UInt32 num = (UInt32)(distances - _distances);
+    *_distances = num - 1;
+    _distances += num;
+    limit -= num;
+  }
+  }
+  while (limit > 0 && --size != 0);
+  *posRes = pos;
+  return limit;
+}
+
+#endif
+
+void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
+{
+  UInt32 numProcessed = 0;
+  UInt32 curPos = 2;
+  UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);
+  distances[1] = p->hashNumAvail;
+  while (curPos < limit)
+  {
+    if (p->hashBufPos == p->hashBufPosLimit)
+    {
+      MatchFinderMt_GetNextBlock_Hash(p);
+      distances[1] = numProcessed + p->hashNumAvail;
+      if (p->hashNumAvail >= p->numHashBytes)
+        continue;
+      for (; p->hashNumAvail != 0; p->hashNumAvail--)
+        distances[curPos++] = 0;
+      break;
+    }
+    {
+      UInt32 size = p->hashBufPosLimit - p->hashBufPos;
+      UInt32 lenLimit = p->matchMaxLen;
+      UInt32 pos = p->pos;
+      UInt32 cyclicBufferPos = p->cyclicBufferPos;
+      if (lenLimit >= p->hashNumAvail)
+        lenLimit = p->hashNumAvail;
+      {
+        UInt32 size2 = p->hashNumAvail - lenLimit + 1;
+        if (size2 < size)
+          size = size2;
+        size2 = p->cyclicBufferSize - cyclicBufferPos;
+        if (size2 < size)
+          size = size2;
+      }
+      #ifndef MFMT_GM_INLINE
+      while (curPos < limit && size-- != 0)
+      {
+        UInt32 *startDistances = distances + curPos;
+        UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],
+          pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
+          startDistances + 1, p->numHashBytes - 1) - startDistances);
+        *startDistances = num - 1;
+        curPos += num;
+        cyclicBufferPos++;
+        pos++;
+        p->buffer++;
+      }
+      #else
+      {
+        UInt32 posRes;
+        curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
+          distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);
+        p->hashBufPos += posRes - pos;
+        cyclicBufferPos += posRes - pos;
+        p->buffer += posRes - pos;
+        pos = posRes;
+      }
+      #endif
+
+      numProcessed += pos - p->pos;
+      p->hashNumAvail -= pos - p->pos;
+      p->pos = pos;
+      if (cyclicBufferPos == p->cyclicBufferSize)
+        cyclicBufferPos = 0;
+      p->cyclicBufferPos = cyclicBufferPos;
+    }
+  }
+  distances[0] = curPos;
+}
+
+void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)
+{
+  CMtSync *sync = &p->hashSync;
+  if (!sync->needStart)
+  {
+    CriticalSection_Enter(&sync->cs);
+    sync->csWasEntered = True;
+  }
+  
+  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);
+
+  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)
+  {
+    UInt32 subValue = p->pos - p->cyclicBufferSize;
+    MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);
+    p->pos -= subValue;
+  }
+
+  if (!sync->needStart)
+  {
+    CriticalSection_Leave(&sync->cs);
+    sync->csWasEntered = False;
+  }
+}
+
+void BtThreadFunc(CMatchFinderMt *mt)
+{
+  CMtSync *p = &mt->btSync;
+  for (;;)
+  {
+    UInt32 blockIndex = 0;
+    Event_Wait(&p->canStart);
+    Event_Set(&p->wasStarted);
+    for (;;)
+    {
+      if (p->exit)
+        return;
+      if (p->stopWriting)
+      {
+        p->numProcessedBlocks = blockIndex;
+        MtSync_StopWriting(&mt->hashSync);
+        Event_Set(&p->wasStopped);
+        break;
+      }
+      Semaphore_Wait(&p->freeSemaphore);
+      BtFillBlock(mt, blockIndex++);
+      Semaphore_Release1(&p->filledSemaphore);
+    }
+  }
+}
+
+void MatchFinderMt_Construct(CMatchFinderMt *p)
+{
+  p->hashBuf = 0;
+  MtSync_Construct(&p->hashSync);
+  MtSync_Construct(&p->btSync);
+}
+
+void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->hashBuf);
+  p->hashBuf = 0;
+}
+
+void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
+{
+  MtSync_Destruct(&p->hashSync);
+  MtSync_Destruct(&p->btSync);
+  MatchFinderMt_FreeMem(p, alloc);
+}
+
+#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)
+#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
+
+static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p);  return 0; }
+static unsigned MY_STD_CALL BtThreadFunc2(void *p)
+{
+  Byte allocaDummy[0x180];
+  int i = 0;
+  for (i = 0; i < 16; i++)
+    allocaDummy[i] = (Byte)i;
+  BtThreadFunc((CMatchFinderMt *)p);
+  return 0;
+}
+
+SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
+    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)
+{
+  CMatchFinder *mf = p->MatchFinder;
+  p->historySize = historySize;
+  if (kMtBtBlockSize <= matchMaxLen * 4)
+    return SZ_ERROR_PARAM;
+  if (p->hashBuf == 0)
+  {
+    p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));
+    if (p->hashBuf == 0)
+      return SZ_ERROR_MEM;
+    p->btBuf = p->hashBuf + kHashBufferSize;
+  }
+  keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);
+  keepAddBufferAfter += kMtHashBlockSize;
+  if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))
+    return SZ_ERROR_MEM;
+
+  RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));
+  RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));
+  return SZ_OK;
+}
+
+/* Call it after ReleaseStream / SetStream */
+void MatchFinderMt_Init(CMatchFinderMt *p)
+{
+  CMatchFinder *mf = p->MatchFinder;
+  p->btBufPos = p->btBufPosLimit = 0;
+  p->hashBufPos = p->hashBufPosLimit = 0;
+  MatchFinder_Init(mf);
+  p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);
+  p->btNumAvailBytes = 0;
+  p->lzPos = p->historySize + 1;
+
+  p->hash = mf->hash;
+  p->fixedHashSize = mf->fixedHashSize;
+  p->crc = mf->crc;
+
+  p->son = mf->son;
+  p->matchMaxLen = mf->matchMaxLen;
+  p->numHashBytes = mf->numHashBytes;
+  p->pos = mf->pos;
+  p->buffer = mf->buffer;
+  p->cyclicBufferPos = mf->cyclicBufferPos;
+  p->cyclicBufferSize = mf->cyclicBufferSize;
+  p->cutValue = mf->cutValue;
+}
+
+/* ReleaseStream is required to finish multithreading */
+void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
+{
+  MtSync_StopWriting(&p->btSync);
+  /* p->MatchFinder->ReleaseStream(); */
+}
+
+void MatchFinderMt_Normalize(CMatchFinderMt *p)
+{
+  MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);
+  p->lzPos = p->historySize + 1;
+}
+
+void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
+{
+  UInt32 blockIndex;
+  MtSync_GetNextBlock(&p->btSync);
+  blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);
+  p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;
+  p->btBufPosLimit += p->btBuf[p->btBufPos++];
+  p->btNumAvailBytes = p->btBuf[p->btBufPos++];
+  if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)
+    MatchFinderMt_Normalize(p);
+}
+
+const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)
+{
+  return p->pointerToCurPos;
+}
+
+#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);
+
+UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)
+{
+  GET_NEXT_BLOCK_IF_REQUIRED;
+  return p->btNumAvailBytes;
+}
+
+Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)
+{
+  return p->pointerToCurPos[index];
+}
+
+UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
+{
+  UInt32 hash2Value, curMatch2;
+  UInt32 *hash = p->hash;
+  const Byte *cur = p->pointerToCurPos;
+  UInt32 lzPos = p->lzPos;
+  MT_HASH2_CALC
+      
+  curMatch2 = hash[hash2Value];
+  hash[hash2Value] = lzPos;
+
+  if (curMatch2 >= matchMinPos)
+    if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
+    {
+      *distances++ = 2;
+      *distances++ = lzPos - curMatch2 - 1;
+    }
+  return distances;
+}
+
+UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
+{
+  UInt32 hash2Value, hash3Value, curMatch2, curMatch3;
+  UInt32 *hash = p->hash;
+  const Byte *cur = p->pointerToCurPos;
+  UInt32 lzPos = p->lzPos;
+  MT_HASH3_CALC
+
+  curMatch2 = hash[                hash2Value];
+  curMatch3 = hash[kFix3HashSize + hash3Value];
+  
+  hash[                hash2Value] =
+  hash[kFix3HashSize + hash3Value] =
+    lzPos;
+
+  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
+  {
+    distances[1] = lzPos - curMatch2 - 1;
+    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
+    {
+      distances[0] = 3;
+      return distances + 2;
+    }
+    distances[0] = 2;
+    distances += 2;
+  }
+  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
+  {
+    *distances++ = 3;
+    *distances++ = lzPos - curMatch3 - 1;
+  }
+  return distances;
+}
+
+/*
+UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
+{
+  UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;
+  UInt32 *hash = p->hash;
+  const Byte *cur = p->pointerToCurPos;
+  UInt32 lzPos = p->lzPos;
+  MT_HASH4_CALC
+      
+  curMatch2 = hash[                hash2Value];
+  curMatch3 = hash[kFix3HashSize + hash3Value];
+  curMatch4 = hash[kFix4HashSize + hash4Value];
+  
+  hash[                hash2Value] =
+  hash[kFix3HashSize + hash3Value] =
+  hash[kFix4HashSize + hash4Value] =
+    lzPos;
+
+  if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
+  {
+    distances[1] = lzPos - curMatch2 - 1;
+    if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
+    {
+      distances[0] =  (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;
+      return distances + 2;
+    }
+    distances[0] = 2;
+    distances += 2;
+  }
+  if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
+  {
+    distances[1] = lzPos - curMatch3 - 1;
+    if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])
+    {
+      distances[0] = 4;
+      return distances + 2;
+    }
+    distances[0] = 3;
+    distances += 2;
+  }
+
+  if (curMatch4 >= matchMinPos)
+    if (
+      cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&
+      cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]
+      )
+    {
+      *distances++ = 4;
+      *distances++ = lzPos - curMatch4 - 1;
+    }
+  return distances;
+}
+*/
+
+#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
+
+UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
+{
+  const UInt32 *btBuf = p->btBuf + p->btBufPos;
+  UInt32 len = *btBuf++;
+  p->btBufPos += 1 + len;
+  p->btNumAvailBytes--;
+  {
+    UInt32 i;
+    for (i = 0; i < len; i += 2)
+    {
+      *distances++ = *btBuf++;
+      *distances++ = *btBuf++;
+    }
+  }
+  INCREASE_LZ_POS
+  return len;
+}
+
+UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
+{
+  const UInt32 *btBuf = p->btBuf + p->btBufPos;
+  UInt32 len = *btBuf++;
+  p->btBufPos += 1 + len;
+
+  if (len == 0)
+  {
+    if (p->btNumAvailBytes-- >= 4)
+      len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));
+  }
+  else
+  {
+    /* Condition: there are matches in btBuf with length < p->numHashBytes */
+    UInt32 *distances2;
+    p->btNumAvailBytes--;
+    distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);
+    do
+    {
+      *distances2++ = *btBuf++;
+      *distances2++ = *btBuf++;
+    }
+    while ((len -= 2) != 0);
+    len  = (UInt32)(distances2 - (distances));
+  }
+  INCREASE_LZ_POS
+  return len;
+}
+
+#define SKIP_HEADER2_MT  do { GET_NEXT_BLOCK_IF_REQUIRED
+#define SKIP_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;
+#define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);
+
+void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)
+{
+  SKIP_HEADER2_MT { p->btNumAvailBytes--;
+  SKIP_FOOTER_MT
+}
+
+void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
+{
+  SKIP_HEADER_MT(2)
+      UInt32 hash2Value;
+      MT_HASH2_CALC
+      hash[hash2Value] = p->lzPos;
+  SKIP_FOOTER_MT
+}
+
+void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
+{
+  SKIP_HEADER_MT(3)
+      UInt32 hash2Value, hash3Value;
+      MT_HASH3_CALC
+      hash[kFix3HashSize + hash3Value] =
+      hash[                hash2Value] =
+        p->lzPos;
+  SKIP_FOOTER_MT
+}
+
+/*
+void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
+{
+  SKIP_HEADER_MT(4)
+      UInt32 hash2Value, hash3Value, hash4Value;
+      MT_HASH4_CALC
+      hash[kFix4HashSize + hash4Value] =
+      hash[kFix3HashSize + hash3Value] =
+      hash[                hash2Value] =
+        p->lzPos;
+  SKIP_FOOTER_MT
+}
+*/
+
+void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
+{
+  vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;
+  vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;
+  vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;
+  vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;
+  vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;
+  switch(p->MatchFinder->numHashBytes)
+  {
+    case 2:
+      p->GetHeadsFunc = GetHeads2;
+      p->MixMatchesFunc = (Mf_Mix_Matches)0;
+      vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;
+      vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;
+      break;
+    case 3:
+      p->GetHeadsFunc = GetHeads3;
+      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;
+      vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;
+      break;
+    default:
+    /* case 4: */
+      p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;
+      /* p->GetHeadsFunc = GetHeads4; */
+      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;
+      vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;
+      break;
+    /*
+    default:
+      p->GetHeadsFunc = GetHeads5;
+      p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;
+      vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;
+      break;
+    */
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzFindMt.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,105 @@
+/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __LZ_FIND_MT_H
+#define __LZ_FIND_MT_H
+
+#include "LzFind.h"
+#include "Threads.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define kMtHashBlockSize (1 << 13)
+#define kMtHashNumBlocks (1 << 3)
+#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
+
+#define kMtBtBlockSize (1 << 14)
+#define kMtBtNumBlocks (1 << 6)
+#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
+
+typedef struct _CMtSync
+{
+  Bool wasCreated;
+  Bool needStart;
+  Bool exit;
+  Bool stopWriting;
+
+  CThread thread;
+  CAutoResetEvent canStart;
+  CAutoResetEvent wasStarted;
+  CAutoResetEvent wasStopped;
+  CSemaphore freeSemaphore;
+  CSemaphore filledSemaphore;
+  Bool csWasInitialized;
+  Bool csWasEntered;
+  CCriticalSection cs;
+  UInt32 numProcessedBlocks;
+} CMtSync;
+
+typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
+
+/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
+#define kMtCacheLineDummy 128
+
+typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
+  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
+
+typedef struct _CMatchFinderMt
+{
+  /* LZ */
+  const Byte *pointerToCurPos;
+  UInt32 *btBuf;
+  UInt32 btBufPos;
+  UInt32 btBufPosLimit;
+  UInt32 lzPos;
+  UInt32 btNumAvailBytes;
+
+  UInt32 *hash;
+  UInt32 fixedHashSize;
+  UInt32 historySize;
+  const UInt32 *crc;
+
+  Mf_Mix_Matches MixMatchesFunc;
+  
+  /* LZ + BT */
+  CMtSync btSync;
+  Byte btDummy[kMtCacheLineDummy];
+
+  /* BT */
+  UInt32 *hashBuf;
+  UInt32 hashBufPos;
+  UInt32 hashBufPosLimit;
+  UInt32 hashNumAvail;
+
+  CLzRef *son;
+  UInt32 matchMaxLen;
+  UInt32 numHashBytes;
+  UInt32 pos;
+  Byte *buffer;
+  UInt32 cyclicBufferPos;
+  UInt32 cyclicBufferSize; /* it must be historySize + 1 */
+  UInt32 cutValue;
+
+  /* BT + Hash */
+  CMtSync hashSync;
+  /* Byte hashDummy[kMtCacheLineDummy]; */
+  
+  /* Hash */
+  Mf_GetHeads GetHeadsFunc;
+  CMatchFinder *MatchFinder;
+} CMatchFinderMt;
+
+void MatchFinderMt_Construct(CMatchFinderMt *p);
+void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
+SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
+    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
+void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
+void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzHash.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzHash.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzHash.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzHash.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,54 @@
+/* LzHash.h -- HASH functions for LZ algorithms
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __LZ_HASH_H
+#define __LZ_HASH_H
+
+#define kHash2Size (1 << 10)
+#define kHash3Size (1 << 16)
+#define kHash4Size (1 << 20)
+
+#define kFix3HashSize (kHash2Size)
+#define kFix4HashSize (kHash2Size + kHash3Size)
+#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
+
+#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
+
+#define HASH3_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  hash2Value = temp & (kHash2Size - 1); \
+  hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
+
+#define HASH4_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  hash2Value = temp & (kHash2Size - 1); \
+  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
+  hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
+
+#define HASH5_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  hash2Value = temp & (kHash2Size - 1); \
+  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
+  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
+  hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
+  hash4Value &= (kHash4Size - 1); }
+
+/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
+#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
+
+
+#define MT_HASH2_CALC \
+  hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
+
+#define MT_HASH3_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  hash2Value = temp & (kHash2Size - 1); \
+  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
+
+#define MT_HASH4_CALC { \
+  UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
+  hash2Value = temp & (kHash2Size - 1); \
+  hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
+  hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,356 @@
+/* Lzma2Dec.c -- LZMA2 Decoder
+2009-05-03 : Igor Pavlov : Public domain */
+
+/* #define SHOW_DEBUG_INFO */
+
+#ifdef SHOW_DEBUG_INFO
+#include <stdio.h>
+#endif
+
+#include <string.h>
+
+#include "Lzma2Dec.h"
+
+/*
+00000000  -  EOS
+00000001 U U  -  Uncompressed Reset Dic
+00000010 U U  -  Uncompressed No Reset
+100uuuuu U U P P  -  LZMA no reset
+101uuuuu U U P P  -  LZMA reset state
+110uuuuu U U P P S  -  LZMA reset state + new prop
+111uuuuu U U P P S  -  LZMA reset state + new prop + reset dic
+
+  u, U - Unpack Size
+  P - Pack Size
+  S - Props
+*/
+
+#define LZMA2_CONTROL_LZMA (1 << 7)
+#define LZMA2_CONTROL_COPY_NO_RESET 2
+#define LZMA2_CONTROL_COPY_RESET_DIC 1
+#define LZMA2_CONTROL_EOF 0
+
+#define LZMA2_IS_UNCOMPRESSED_STATE(p) (((p)->control & LZMA2_CONTROL_LZMA) == 0)
+
+#define LZMA2_GET_LZMA_MODE(p) (((p)->control >> 5) & 3)
+#define LZMA2_IS_THERE_PROP(mode) ((mode) >= 2)
+
+#define LZMA2_LCLP_MAX 4
+#define LZMA2_DIC_SIZE_FROM_PROP(p) (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11))
+
+#ifdef SHOW_DEBUG_INFO
+#define PRF(x) x
+#else
+#define PRF(x)
+#endif
+
+typedef enum
+{
+  LZMA2_STATE_CONTROL,
+  LZMA2_STATE_UNPACK0,
+  LZMA2_STATE_UNPACK1,
+  LZMA2_STATE_PACK0,
+  LZMA2_STATE_PACK1,
+  LZMA2_STATE_PROP,
+  LZMA2_STATE_DATA,
+  LZMA2_STATE_DATA_CONT,
+  LZMA2_STATE_FINISHED,
+  LZMA2_STATE_ERROR
+} ELzma2State;
+
+static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props)
+{
+  UInt32 dicSize;
+  if (prop > 40)
+    return SZ_ERROR_UNSUPPORTED;
+  dicSize = (prop == 40) ? 0xFFFFFFFF : LZMA2_DIC_SIZE_FROM_PROP(prop);
+  props[0] = (Byte)LZMA2_LCLP_MAX;
+  props[1] = (Byte)(dicSize);
+  props[2] = (Byte)(dicSize >> 8);
+  props[3] = (Byte)(dicSize >> 16);
+  props[4] = (Byte)(dicSize >> 24);
+  return SZ_OK;
+}
+
+SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
+{
+  Byte props[LZMA_PROPS_SIZE];
+  RINOK(Lzma2Dec_GetOldProps(prop, props));
+  return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
+}
+
+SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
+{
+  Byte props[LZMA_PROPS_SIZE];
+  RINOK(Lzma2Dec_GetOldProps(prop, props));
+  return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
+}
+
+void Lzma2Dec_Init(CLzma2Dec *p)
+{
+  p->state = LZMA2_STATE_CONTROL;
+  p->needInitDic = True;
+  p->needInitState = True;
+  p->needInitProp = True;
+  LzmaDec_Init(&p->decoder);
+}
+
+static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
+{
+  switch(p->state)
+  {
+    case LZMA2_STATE_CONTROL:
+      p->control = b;
+      PRF(printf("\n %4X ", p->decoder.dicPos));
+      PRF(printf(" %2X", b));
+      if (p->control == 0)
+        return LZMA2_STATE_FINISHED;
+      if (LZMA2_IS_UNCOMPRESSED_STATE(p))
+      {
+        if ((p->control & 0x7F) > 2)
+          return LZMA2_STATE_ERROR;
+        p->unpackSize = 0;
+      }
+      else
+        p->unpackSize = (UInt32)(p->control & 0x1F) << 16;
+      return LZMA2_STATE_UNPACK0;
+    
+    case LZMA2_STATE_UNPACK0:
+      p->unpackSize |= (UInt32)b << 8;
+      return LZMA2_STATE_UNPACK1;
+    
+    case LZMA2_STATE_UNPACK1:
+      p->unpackSize |= (UInt32)b;
+      p->unpackSize++;
+      PRF(printf(" %8d", p->unpackSize));
+      return (LZMA2_IS_UNCOMPRESSED_STATE(p)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
+    
+    case LZMA2_STATE_PACK0:
+      p->packSize = (UInt32)b << 8;
+      return LZMA2_STATE_PACK1;
+
+    case LZMA2_STATE_PACK1:
+      p->packSize |= (UInt32)b;
+      p->packSize++;
+      PRF(printf(" %8d", p->packSize));
+      return LZMA2_IS_THERE_PROP(LZMA2_GET_LZMA_MODE(p)) ? LZMA2_STATE_PROP:
+        (p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);
+
+    case LZMA2_STATE_PROP:
+    {
+      int lc, lp;
+      if (b >= (9 * 5 * 5))
+        return LZMA2_STATE_ERROR;
+      lc = b % 9;
+      b /= 9;
+      p->decoder.prop.pb = b / 5;
+      lp = b % 5;
+      if (lc + lp > LZMA2_LCLP_MAX)
+        return LZMA2_STATE_ERROR;
+      p->decoder.prop.lc = lc;
+      p->decoder.prop.lp = lp;
+      p->needInitProp = False;
+      return LZMA2_STATE_DATA;
+    }
+  }
+  return LZMA2_STATE_ERROR;
+}
+
+static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT size)
+{
+  memcpy(p->dic + p->dicPos, src, size);
+  p->dicPos += size;
+  if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= size)
+    p->checkDicSize = p->prop.dicSize;
+  p->processedPos += (UInt32)size;
+}
+
+void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState);
+
+SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+  SizeT inSize = *srcLen;
+  *srcLen = 0;
+  *status = LZMA_STATUS_NOT_SPECIFIED;
+
+  while (p->state != LZMA2_STATE_FINISHED)
+  {
+    SizeT dicPos = p->decoder.dicPos;
+    if (p->state == LZMA2_STATE_ERROR)
+      return SZ_ERROR_DATA;
+    if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)
+    {
+      *status = LZMA_STATUS_NOT_FINISHED;
+      return SZ_OK;
+    }
+    if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
+    {
+      if (*srcLen == inSize)
+      {
+        *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+        return SZ_OK;
+      }
+      (*srcLen)++;
+      p->state = Lzma2Dec_UpdateState(p, *src++);
+      continue;
+    }
+    {
+      SizeT destSizeCur = dicLimit - dicPos;
+      SizeT srcSizeCur = inSize - *srcLen;
+      ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
+      
+      if (p->unpackSize <= destSizeCur)
+      {
+        destSizeCur = (SizeT)p->unpackSize;
+        curFinishMode = LZMA_FINISH_END;
+      }
+
+      if (LZMA2_IS_UNCOMPRESSED_STATE(p))
+      {
+        if (*srcLen == inSize)
+        {
+          *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+          return SZ_OK;
+        }
+
+        if (p->state == LZMA2_STATE_DATA)
+        {
+          Bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC);
+          if (initDic)
+            p->needInitProp = p->needInitState = True;
+          else if (p->needInitDic)
+            return SZ_ERROR_DATA;
+          p->needInitDic = False;
+          LzmaDec_InitDicAndState(&p->decoder, initDic, False);
+        }
+
+        if (srcSizeCur > destSizeCur)
+          srcSizeCur = destSizeCur;
+
+        if (srcSizeCur == 0)
+          return SZ_ERROR_DATA;
+
+        LzmaDec_UpdateWithUncompressed(&p->decoder, src, srcSizeCur);
+
+        src += srcSizeCur;
+        *srcLen += srcSizeCur;
+        p->unpackSize -= (UInt32)srcSizeCur;
+        p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
+      }
+      else
+      {
+        SizeT outSizeProcessed;
+        SRes res;
+
+        if (p->state == LZMA2_STATE_DATA)
+        {
+          int mode = LZMA2_GET_LZMA_MODE(p);
+          Bool initDic = (mode == 3);
+          Bool initState = (mode > 0);
+          if ((!initDic && p->needInitDic) || (!initState && p->needInitState))
+            return SZ_ERROR_DATA;
+          
+          LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
+          p->needInitDic = False;
+          p->needInitState = False;
+          p->state = LZMA2_STATE_DATA_CONT;
+        }
+        if (srcSizeCur > p->packSize)
+          srcSizeCur = (SizeT)p->packSize;
+          
+        res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status);
+        
+        src += srcSizeCur;
+        *srcLen += srcSizeCur;
+        p->packSize -= (UInt32)srcSizeCur;
+
+        outSizeProcessed = p->decoder.dicPos - dicPos;
+        p->unpackSize -= (UInt32)outSizeProcessed;
+
+        RINOK(res);
+        if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
+          return res;
+
+        if (srcSizeCur == 0 && outSizeProcessed == 0)
+        {
+          if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK ||
+              p->unpackSize != 0 || p->packSize != 0)
+            return SZ_ERROR_DATA;
+          p->state = LZMA2_STATE_CONTROL;
+        }
+        if (*status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
+          *status = LZMA_STATUS_NOT_FINISHED;
+      }
+    }
+  }
+  *status = LZMA_STATUS_FINISHED_WITH_MARK;
+  return SZ_OK;
+}
+
+SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+  SizeT outSize = *destLen, inSize = *srcLen;
+  *srcLen = *destLen = 0;
+  for (;;)
+  {
+    SizeT srcSizeCur = inSize, outSizeCur, dicPos;
+    ELzmaFinishMode curFinishMode;
+    SRes res;
+    if (p->decoder.dicPos == p->decoder.dicBufSize)
+      p->decoder.dicPos = 0;
+    dicPos = p->decoder.dicPos;
+    if (outSize > p->decoder.dicBufSize - dicPos)
+    {
+      outSizeCur = p->decoder.dicBufSize;
+      curFinishMode = LZMA_FINISH_ANY;
+    }
+    else
+    {
+      outSizeCur = dicPos + outSize;
+      curFinishMode = finishMode;
+    }
+
+    res = Lzma2Dec_DecodeToDic(p, outSizeCur, src, &srcSizeCur, curFinishMode, status);
+    src += srcSizeCur;
+    inSize -= srcSizeCur;
+    *srcLen += srcSizeCur;
+    outSizeCur = p->decoder.dicPos - dicPos;
+    memcpy(dest, p->decoder.dic + dicPos, outSizeCur);
+    dest += outSizeCur;
+    outSize -= outSizeCur;
+    *destLen += outSizeCur;
+    if (res != 0)
+      return res;
+    if (outSizeCur == 0 || outSize == 0)
+      return SZ_OK;
+  }
+}
+
+SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
+{
+  CLzma2Dec decoder;
+  SRes res;
+  SizeT outSize = *destLen, inSize = *srcLen;
+  Byte props[LZMA_PROPS_SIZE];
+
+  Lzma2Dec_Construct(&decoder);
+
+  *destLen = *srcLen = 0;
+  *status = LZMA_STATUS_NOT_SPECIFIED;
+  decoder.decoder.dic = dest;
+  decoder.decoder.dicBufSize = outSize;
+
+  RINOK(Lzma2Dec_GetOldProps(prop, props));
+  RINOK(LzmaDec_AllocateProbs(&decoder.decoder, props, LZMA_PROPS_SIZE, alloc));
+  
+  *srcLen = inSize;
+  res = Lzma2Dec_DecodeToDic(&decoder, outSize, src, srcLen, finishMode, status);
+  *destLen = decoder.decoder.dicPos;
+  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
+    res = SZ_ERROR_INPUT_EOF;
+
+  LzmaDec_FreeProbs(&decoder.decoder, alloc);
+  return res;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Dec.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,84 @@
+/* Lzma2Dec.h -- LZMA2 Decoder
+2009-05-03 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA2_DEC_H
+#define __LZMA2_DEC_H
+
+#include "LzmaDec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ---------- State Interface ---------- */
+
+typedef struct
+{
+  CLzmaDec decoder;
+  UInt32 packSize;
+  UInt32 unpackSize;
+  int state;
+  Byte control;
+  Bool needInitDic;
+  Bool needInitState;
+  Bool needInitProp;
+} CLzma2Dec;
+
+#define Lzma2Dec_Construct(p) LzmaDec_Construct(&(p)->decoder)
+#define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc);
+#define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc);
+
+SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc);
+SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc);
+void Lzma2Dec_Init(CLzma2Dec *p);
+
+
+/*
+finishMode:
+  It has meaning only if the decoding reaches output limit (*destLen or dicLimit).
+  LZMA_FINISH_ANY - use smallest number of input bytes
+  LZMA_FINISH_END - read EndOfStream marker after decoding
+
+Returns:
+  SZ_OK
+    status:
+      LZMA_STATUS_FINISHED_WITH_MARK
+      LZMA_STATUS_NOT_FINISHED
+      LZMA_STATUS_NEEDS_MORE_INPUT
+  SZ_ERROR_DATA - Data error
+*/
+
+SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen,
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- One Call Interface ---------- */
+
+/*
+finishMode:
+  It has meaning only if the decoding reaches output limit (*destLen).
+  LZMA_FINISH_ANY - use smallest number of input bytes
+  LZMA_FINISH_END - read EndOfStream marker after decoding
+
+Returns:
+  SZ_OK
+    status:
+      LZMA_STATUS_FINISHED_WITH_MARK
+      LZMA_STATUS_NOT_FINISHED
+  SZ_ERROR_DATA - Data error
+  SZ_ERROR_MEM  - Memory allocation error
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+*/
+
+SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,477 @@
+/* Lzma2Enc.c -- LZMA2 Encoder
+2010-09-24 : Igor Pavlov : Public domain */
+
+/* #include <stdio.h> */
+#include <string.h>
+
+/* #define _7ZIP_ST */
+
+#include "Lzma2Enc.h"
+
+#ifndef _7ZIP_ST
+#include "MtCoder.h"
+#else
+#define NUM_MT_CODER_THREADS_MAX 1
+#endif
+
+#define LZMA2_CONTROL_LZMA (1 << 7)
+#define LZMA2_CONTROL_COPY_NO_RESET 2
+#define LZMA2_CONTROL_COPY_RESET_DIC 1
+#define LZMA2_CONTROL_EOF 0
+
+#define LZMA2_LCLP_MAX 4
+
+#define LZMA2_DIC_SIZE_FROM_PROP(p) (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11))
+
+#define LZMA2_PACK_SIZE_MAX (1 << 16)
+#define LZMA2_COPY_CHUNK_SIZE LZMA2_PACK_SIZE_MAX
+#define LZMA2_UNPACK_SIZE_MAX (1 << 21)
+#define LZMA2_KEEP_WINDOW_SIZE LZMA2_UNPACK_SIZE_MAX
+
+#define LZMA2_CHUNK_SIZE_COMPRESSED_MAX ((1 << 16) + 16)
+
+
+#define PRF(x) /* x */
+
+/* ---------- CLzma2EncInt ---------- */
+
+typedef struct
+{
+  CLzmaEncHandle enc;
+  UInt64 srcPos;
+  Byte props;
+  Bool needInitState;
+  Bool needInitProp;
+} CLzma2EncInt;
+
+static SRes Lzma2EncInt_Init(CLzma2EncInt *p, const CLzma2EncProps *props)
+{
+  Byte propsEncoded[LZMA_PROPS_SIZE];
+  SizeT propsSize = LZMA_PROPS_SIZE;
+  RINOK(LzmaEnc_SetProps(p->enc, &props->lzmaProps));
+  RINOK(LzmaEnc_WriteProperties(p->enc, propsEncoded, &propsSize));
+  p->srcPos = 0;
+  p->props = propsEncoded[0];
+  p->needInitState = True;
+  p->needInitProp = True;
+  return SZ_OK;
+}
+
+SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 keepWindowSize,
+    ISzAlloc *alloc, ISzAlloc *allocBig);
+SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
+    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig);
+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
+    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
+const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp);
+void LzmaEnc_Finish(CLzmaEncHandle pp);
+void LzmaEnc_SaveState(CLzmaEncHandle pp);
+void LzmaEnc_RestoreState(CLzmaEncHandle pp);
+
+
+static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
+    size_t *packSizeRes, ISeqOutStream *outStream)
+{
+  size_t packSizeLimit = *packSizeRes;
+  size_t packSize = packSizeLimit;
+  UInt32 unpackSize = LZMA2_UNPACK_SIZE_MAX;
+  unsigned lzHeaderSize = 5 + (p->needInitProp ? 1 : 0);
+  Bool useCopyBlock;
+  SRes res;
+
+  *packSizeRes = 0;
+  if (packSize < lzHeaderSize)
+    return SZ_ERROR_OUTPUT_EOF;
+  packSize -= lzHeaderSize;
+  
+  LzmaEnc_SaveState(p->enc);
+  res = LzmaEnc_CodeOneMemBlock(p->enc, p->needInitState,
+      outBuf + lzHeaderSize, &packSize, LZMA2_PACK_SIZE_MAX, &unpackSize);
+  
+  PRF(printf("\npackSize = %7d unpackSize = %7d  ", packSize, unpackSize));
+
+  if (unpackSize == 0)
+    return res;
+
+  if (res == SZ_OK)
+    useCopyBlock = (packSize + 2 >= unpackSize || packSize > (1 << 16));
+  else
+  {
+    if (res != SZ_ERROR_OUTPUT_EOF)
+      return res;
+    res = SZ_OK;
+    useCopyBlock = True;
+  }
+
+  if (useCopyBlock)
+  {
+    size_t destPos = 0;
+    PRF(printf("################# COPY           "));
+    while (unpackSize > 0)
+    {
+      UInt32 u = (unpackSize < LZMA2_COPY_CHUNK_SIZE) ? unpackSize : LZMA2_COPY_CHUNK_SIZE;
+      if (packSizeLimit - destPos < u + 3)
+        return SZ_ERROR_OUTPUT_EOF;
+      outBuf[destPos++] = (Byte)(p->srcPos == 0 ? LZMA2_CONTROL_COPY_RESET_DIC : LZMA2_CONTROL_COPY_NO_RESET);
+      outBuf[destPos++] = (Byte)((u - 1) >> 8);
+      outBuf[destPos++] = (Byte)(u - 1);
+      memcpy(outBuf + destPos, LzmaEnc_GetCurBuf(p->enc) - unpackSize, u);
+      unpackSize -= u;
+      destPos += u;
+      p->srcPos += u;
+      if (outStream)
+      {
+        *packSizeRes += destPos;
+        if (outStream->Write(outStream, outBuf, destPos) != destPos)
+          return SZ_ERROR_WRITE;
+        destPos = 0;
+      }
+      else
+        *packSizeRes = destPos;
+      /* needInitState = True; */
+    }
+    LzmaEnc_RestoreState(p->enc);
+    return SZ_OK;
+  }
+  {
+    size_t destPos = 0;
+    UInt32 u = unpackSize - 1;
+    UInt32 pm = (UInt32)(packSize - 1);
+    unsigned mode = (p->srcPos == 0) ? 3 : (p->needInitState ? (p->needInitProp ? 2 : 1) : 0);
+
+    PRF(printf("               "));
+
+    outBuf[destPos++] = (Byte)(LZMA2_CONTROL_LZMA | (mode << 5) | ((u >> 16) & 0x1F));
+    outBuf[destPos++] = (Byte)(u >> 8);
+    outBuf[destPos++] = (Byte)u;
+    outBuf[destPos++] = (Byte)(pm >> 8);
+    outBuf[destPos++] = (Byte)pm;
+    
+    if (p->needInitProp)
+      outBuf[destPos++] = p->props;
+    
+    p->needInitProp = False;
+    p->needInitState = False;
+    destPos += packSize;
+    p->srcPos += unpackSize;
+
+    if (outStream)
+      if (outStream->Write(outStream, outBuf, destPos) != destPos)
+        return SZ_ERROR_WRITE;
+    *packSizeRes = destPos;
+    return SZ_OK;
+  }
+}
+
+/* ---------- Lzma2 Props ---------- */
+
+void Lzma2EncProps_Init(CLzma2EncProps *p)
+{
+  LzmaEncProps_Init(&p->lzmaProps);
+  p->numTotalThreads = -1;
+  p->numBlockThreads = -1;
+  p->blockSize = 0;
+}
+
+void Lzma2EncProps_Normalize(CLzma2EncProps *p)
+{
+  int t1, t1n, t2, t3;
+  {
+    CLzmaEncProps lzmaProps = p->lzmaProps;
+    LzmaEncProps_Normalize(&lzmaProps);
+    t1n = lzmaProps.numThreads;
+  }
+
+  t1 = p->lzmaProps.numThreads;
+  t2 = p->numBlockThreads;
+  t3 = p->numTotalThreads;
+
+  if (t2 > NUM_MT_CODER_THREADS_MAX)
+    t2 = NUM_MT_CODER_THREADS_MAX;
+
+  if (t3 <= 0)
+  {
+    if (t2 <= 0)
+      t2 = 1;
+    t3 = t1n * t2;
+  }
+  else if (t2 <= 0)
+  {
+    t2 = t3 / t1n;
+    if (t2 == 0)
+    {
+      t1 = 1;
+      t2 = t3;
+    }
+    if (t2 > NUM_MT_CODER_THREADS_MAX)
+      t2 = NUM_MT_CODER_THREADS_MAX;
+  }
+  else if (t1 <= 0)
+  {
+    t1 = t3 / t2;
+    if (t1 == 0)
+      t1 = 1;
+  }
+  else
+    t3 = t1n * t2;
+
+  p->lzmaProps.numThreads = t1;
+  p->numBlockThreads = t2;
+  p->numTotalThreads = t3;
+  LzmaEncProps_Normalize(&p->lzmaProps);
+
+  if (p->blockSize == 0)
+  {
+    UInt32 dictSize = p->lzmaProps.dictSize;
+    UInt64 blockSize = (UInt64)dictSize << 2;
+    const UInt32 kMinSize = (UInt32)1 << 20;
+    const UInt32 kMaxSize = (UInt32)1 << 28;
+    if (blockSize < kMinSize) blockSize = kMinSize;
+    if (blockSize > kMaxSize) blockSize = kMaxSize;
+    if (blockSize < dictSize) blockSize = dictSize;
+    p->blockSize = (size_t)blockSize;
+  }
+}
+
+static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
+{
+  return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;
+}
+
+/* ---------- Lzma2 ---------- */
+
+typedef struct
+{
+  Byte propEncoded;
+  CLzma2EncProps props;
+  
+  Byte *outBuf;
+
+  ISzAlloc *alloc;
+  ISzAlloc *allocBig;
+
+  CLzma2EncInt coders[NUM_MT_CODER_THREADS_MAX];
+
+  #ifndef _7ZIP_ST
+  CMtCoder mtCoder;
+  #endif
+
+} CLzma2Enc;
+
+
+/* ---------- Lzma2EncThread ---------- */
+
+static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,
+  ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress)
+{
+  UInt64 packTotal = 0;
+  SRes res = SZ_OK;
+
+  if (mainEncoder->outBuf == 0)
+  {
+    mainEncoder->outBuf = (Byte *)IAlloc_Alloc(mainEncoder->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX);
+    if (mainEncoder->outBuf == 0)
+      return SZ_ERROR_MEM;
+  }
+  RINOK(Lzma2EncInt_Init(p, &mainEncoder->props));
+  RINOK(LzmaEnc_PrepareForLzma2(p->enc, inStream, LZMA2_KEEP_WINDOW_SIZE,
+      mainEncoder->alloc, mainEncoder->allocBig));
+  for (;;)
+  {
+    size_t packSize = LZMA2_CHUNK_SIZE_COMPRESSED_MAX;
+    res = Lzma2EncInt_EncodeSubblock(p, mainEncoder->outBuf, &packSize, outStream);
+    if (res != SZ_OK)
+      break;
+    packTotal += packSize;
+    res = Progress(progress, p->srcPos, packTotal);
+    if (res != SZ_OK)
+      break;
+    if (packSize == 0)
+      break;
+  }
+  LzmaEnc_Finish(p->enc);
+  if (res == SZ_OK)
+  {
+    Byte b = 0;
+    if (outStream->Write(outStream, &b, 1) != 1)
+      return SZ_ERROR_WRITE;
+  }
+  return res;
+}
+
+#ifndef _7ZIP_ST
+
+typedef struct
+{
+  IMtCoderCallback funcTable;
+  CLzma2Enc *lzma2Enc;
+} CMtCallbackImp;
+
+static SRes MtCallbackImp_Code(void *pp, unsigned index, Byte *dest, size_t *destSize,
+      const Byte *src, size_t srcSize, int finished)
+{
+  CMtCallbackImp *imp = (CMtCallbackImp *)pp;
+  CLzma2Enc *mainEncoder = imp->lzma2Enc;
+  CLzma2EncInt *p = &mainEncoder->coders[index];
+
+  SRes res = SZ_OK;
+  {
+    size_t destLim = *destSize;
+    *destSize = 0;
+
+    if (srcSize != 0)
+    {
+      RINOK(Lzma2EncInt_Init(p, &mainEncoder->props));
+     
+      RINOK(LzmaEnc_MemPrepare(p->enc, src, srcSize, LZMA2_KEEP_WINDOW_SIZE,
+          mainEncoder->alloc, mainEncoder->allocBig));
+     
+      while (p->srcPos < srcSize)
+      {
+        size_t packSize = destLim - *destSize;
+        res = Lzma2EncInt_EncodeSubblock(p, dest + *destSize, &packSize, NULL);
+        if (res != SZ_OK)
+          break;
+        *destSize += packSize;
+
+        if (packSize == 0)
+        {
+          res = SZ_ERROR_FAIL;
+          break;
+        }
+
+        if (MtProgress_Set(&mainEncoder->mtCoder.mtProgress, index, p->srcPos, *destSize) != SZ_OK)
+        {
+          res = SZ_ERROR_PROGRESS;
+          break;
+        }
+      }
+      LzmaEnc_Finish(p->enc);
+      if (res != SZ_OK)
+        return res;
+    }
+    if (finished)
+    {
+      if (*destSize == destLim)
+        return SZ_ERROR_OUTPUT_EOF;
+      dest[(*destSize)++] = 0;
+    }
+  }
+  return res;
+}
+
+#endif
+
+/* ---------- Lzma2Enc ---------- */
+
+CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  CLzma2Enc *p = (CLzma2Enc *)alloc->Alloc(alloc, sizeof(CLzma2Enc));
+  if (p == 0)
+    return NULL;
+  Lzma2EncProps_Init(&p->props);
+  Lzma2EncProps_Normalize(&p->props);
+  p->outBuf = 0;
+  p->alloc = alloc;
+  p->allocBig = allocBig;
+  {
+    unsigned i;
+    for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
+      p->coders[i].enc = 0;
+  }
+  #ifndef _7ZIP_ST
+  MtCoder_Construct(&p->mtCoder);
+  #endif
+
+  return p;
+}
+
+void Lzma2Enc_Destroy(CLzma2EncHandle pp)
+{
+  CLzma2Enc *p = (CLzma2Enc *)pp;
+  unsigned i;
+  for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
+  {
+    CLzma2EncInt *t = &p->coders[i];
+    if (t->enc)
+    {
+      LzmaEnc_Destroy(t->enc, p->alloc, p->allocBig);
+      t->enc = 0;
+    }
+  }
+
+  #ifndef _7ZIP_ST
+  MtCoder_Destruct(&p->mtCoder);
+  #endif
+
+  IAlloc_Free(p->alloc, p->outBuf);
+  IAlloc_Free(p->alloc, pp);
+}
+
+SRes Lzma2Enc_SetProps(CLzma2EncHandle pp, const CLzma2EncProps *props)
+{
+  CLzma2Enc *p = (CLzma2Enc *)pp;
+  CLzmaEncProps lzmaProps = props->lzmaProps;
+  LzmaEncProps_Normalize(&lzmaProps);
+  if (lzmaProps.lc + lzmaProps.lp > LZMA2_LCLP_MAX)
+    return SZ_ERROR_PARAM;
+  p->props = *props;
+  Lzma2EncProps_Normalize(&p->props);
+  return SZ_OK;
+}
+
+Byte Lzma2Enc_WriteProperties(CLzma2EncHandle pp)
+{
+  CLzma2Enc *p = (CLzma2Enc *)pp;
+  unsigned i;
+  UInt32 dicSize = LzmaEncProps_GetDictSize(&p->props.lzmaProps);
+  for (i = 0; i < 40; i++)
+    if (dicSize <= LZMA2_DIC_SIZE_FROM_PROP(i))
+      break;
+  return (Byte)i;
+}
+
+SRes Lzma2Enc_Encode(CLzma2EncHandle pp,
+    ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress)
+{
+  CLzma2Enc *p = (CLzma2Enc *)pp;
+  int i;
+
+  for (i = 0; i < p->props.numBlockThreads; i++)
+  {
+    CLzma2EncInt *t = &p->coders[i];
+    if (t->enc == NULL)
+    {
+      t->enc = LzmaEnc_Create(p->alloc);
+      if (t->enc == NULL)
+        return SZ_ERROR_MEM;
+    }
+  }
+
+  #ifndef _7ZIP_ST
+  if (p->props.numBlockThreads <= 1)
+  #endif
+    return Lzma2Enc_EncodeMt1(&p->coders[0], p, outStream, inStream, progress);
+
+  #ifndef _7ZIP_ST
+
+  {
+    CMtCallbackImp mtCallback;
+
+    mtCallback.funcTable.Code = MtCallbackImp_Code;
+    mtCallback.lzma2Enc = p;
+    
+    p->mtCoder.progress = progress;
+    p->mtCoder.inStream = inStream;
+    p->mtCoder.outStream = outStream;
+    p->mtCoder.alloc = p->alloc;
+    p->mtCoder.mtCallback = &mtCallback.funcTable;
+
+    p->mtCoder.blockSize = p->props.blockSize;
+    p->mtCoder.destBlockSize = p->props.blockSize + (p->props.blockSize >> 10) + 16;
+    p->mtCoder.numThreads = p->props.numBlockThreads;
+    
+    return MtCoder_Code(&p->mtCoder);
+  }
+  #endif
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Lzma2Enc.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,66 @@
+/* Lzma2Enc.h -- LZMA2 Encoder
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA2_ENC_H
+#define __LZMA2_ENC_H
+
+#include "LzmaEnc.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct
+{
+  CLzmaEncProps lzmaProps;
+  size_t blockSize;
+  int numBlockThreads;
+  int numTotalThreads;
+} CLzma2EncProps;
+
+void Lzma2EncProps_Init(CLzma2EncProps *p);
+void Lzma2EncProps_Normalize(CLzma2EncProps *p);
+
+/* ---------- CLzmaEnc2Handle Interface ---------- */
+
+/* Lzma2Enc_* functions can return the following exit codes:
+Returns:
+  SZ_OK           - OK
+  SZ_ERROR_MEM    - Memory allocation error
+  SZ_ERROR_PARAM  - Incorrect paramater in props
+  SZ_ERROR_WRITE  - Write callback error
+  SZ_ERROR_PROGRESS - some break from progress callback
+  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
+*/
+
+typedef void * CLzma2EncHandle;
+
+CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig);
+void Lzma2Enc_Destroy(CLzma2EncHandle p);
+SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props);
+Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p);
+SRes Lzma2Enc_Encode(CLzma2EncHandle p,
+    ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress);
+
+/* ---------- One Call Interface ---------- */
+
+/* Lzma2Encode
+Return code:
+  SZ_OK               - OK
+  SZ_ERROR_MEM        - Memory allocation error
+  SZ_ERROR_PARAM      - Incorrect paramater
+  SZ_ERROR_OUTPUT_EOF - output buffer overflow
+  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
+*/
+
+/*
+SRes Lzma2Encode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+    const CLzmaEncProps *props, Byte *propsEncoded, int writeEndMark,
+    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,999 @@
+/* LzmaDec.c -- LZMA Decoder
+2009-09-20 : Igor Pavlov : Public domain */
+
+#include "LzmaDec.h"
+
+#include <string.h>
+
+#define kNumTopBits 24
+#define kTopValue ((UInt32)1 << kNumTopBits)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
+
+#define RC_INIT_SIZE 5
+
+#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
+
+#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
+#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
+#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
+  { UPDATE_0(p); i = (i + i); A0; } else \
+  { UPDATE_1(p); i = (i + i) + 1; A1; }
+#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
+
+#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }
+#define TREE_DECODE(probs, limit, i) \
+  { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
+
+/* #define _LZMA_SIZE_OPT */
+
+#ifdef _LZMA_SIZE_OPT
+#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
+#else
+#define TREE_6_DECODE(probs, i) \
+  { i = 1; \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  TREE_GET_BIT(probs, i); \
+  i -= 0x40; }
+#endif
+
+#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
+
+#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
+#define UPDATE_0_CHECK range = bound;
+#define UPDATE_1_CHECK range -= bound; code -= bound;
+#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
+  { UPDATE_0_CHECK; i = (i + i); A0; } else \
+  { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
+#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
+#define TREE_DECODE_CHECK(probs, limit, i) \
+  { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
+
+
+#define kNumPosBitsMax 4
+#define kNumPosStatesMax (1 << kNumPosBitsMax)
+
+#define kLenNumLowBits 3
+#define kLenNumLowSymbols (1 << kLenNumLowBits)
+#define kLenNumMidBits 3
+#define kLenNumMidSymbols (1 << kLenNumMidBits)
+#define kLenNumHighBits 8
+#define kLenNumHighSymbols (1 << kLenNumHighBits)
+
+#define LenChoice 0
+#define LenChoice2 (LenChoice + 1)
+#define LenLow (LenChoice2 + 1)
+#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
+#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
+
+
+#define kNumStates 12
+#define kNumLitStates 7
+
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
+
+#define kNumPosSlotBits 6
+#define kNumLenToPosStates 4
+
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
+
+#define kMatchMinLen 2
+#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
+
+#define IsMatch 0
+#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
+#define IsRepG0 (IsRep + kNumStates)
+#define IsRepG1 (IsRepG0 + kNumStates)
+#define IsRepG2 (IsRepG1 + kNumStates)
+#define IsRep0Long (IsRepG2 + kNumStates)
+#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
+#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
+#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
+#define LenCoder (Align + kAlignTableSize)
+#define RepLenCoder (LenCoder + kNumLenProbs)
+#define Literal (RepLenCoder + kNumLenProbs)
+
+#define LZMA_BASE_SIZE 1846
+#define LZMA_LIT_SIZE 768
+
+#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
+
+#if Literal != LZMA_BASE_SIZE
+StopCompilingDueBUG
+#endif
+
+#define LZMA_DIC_MIN (1 << 12)
+
+/* First LZMA-symbol is always decoded.
+And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
+Out:
+  Result:
+    SZ_OK - OK
+    SZ_ERROR_DATA - Error
+  p->remainLen:
+    < kMatchSpecLenStart : normal remain
+    = kMatchSpecLenStart : finished
+    = kMatchSpecLenStart + 1 : Flush marker
+    = kMatchSpecLenStart + 2 : State Init Marker
+*/
+
+static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+{
+  CLzmaProb *probs = p->probs;
+
+  unsigned state = p->state;
+  UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
+  unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
+  unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
+  unsigned lc = p->prop.lc;
+
+  Byte *dic = p->dic;
+  SizeT dicBufSize = p->dicBufSize;
+  SizeT dicPos = p->dicPos;
+  
+  UInt32 processedPos = p->processedPos;
+  UInt32 checkDicSize = p->checkDicSize;
+  unsigned len = 0;
+
+  const Byte *buf = p->buf;
+  UInt32 range = p->range;
+  UInt32 code = p->code;
+
+  do
+  {
+    CLzmaProb *prob;
+    UInt32 bound;
+    unsigned ttt;
+    unsigned posState = processedPos & pbMask;
+
+    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
+    IF_BIT_0(prob)
+    {
+      unsigned symbol;
+      UPDATE_0(prob);
+      prob = probs + Literal;
+      if (checkDicSize != 0 || processedPos != 0)
+        prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
+        (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
+
+      if (state < kNumLitStates)
+      {
+        state -= (state < 4) ? state : 3;
+        symbol = 1;
+        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);
+      }
+      else
+      {
+        unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
+        unsigned offs = 0x100;
+        state -= (state < 10) ? 3 : 6;
+        symbol = 1;
+        do
+        {
+          unsigned bit;
+          CLzmaProb *probLit;
+          matchByte <<= 1;
+          bit = (matchByte & offs);
+          probLit = prob + offs + bit + symbol;
+          GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
+        }
+        while (symbol < 0x100);
+      }
+      dic[dicPos++] = (Byte)symbol;
+      processedPos++;
+      continue;
+    }
+    else
+    {
+      UPDATE_1(prob);
+      prob = probs + IsRep + state;
+      IF_BIT_0(prob)
+      {
+        UPDATE_0(prob);
+        state += kNumStates;
+        prob = probs + LenCoder;
+      }
+      else
+      {
+        UPDATE_1(prob);
+        if (checkDicSize == 0 && processedPos == 0)
+          return SZ_ERROR_DATA;
+        prob = probs + IsRepG0 + state;
+        IF_BIT_0(prob)
+        {
+          UPDATE_0(prob);
+          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
+          IF_BIT_0(prob)
+          {
+            UPDATE_0(prob);
+            dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
+            dicPos++;
+            processedPos++;
+            state = state < kNumLitStates ? 9 : 11;
+            continue;
+          }
+          UPDATE_1(prob);
+        }
+        else
+        {
+          UInt32 distance;
+          UPDATE_1(prob);
+          prob = probs + IsRepG1 + state;
+          IF_BIT_0(prob)
+          {
+            UPDATE_0(prob);
+            distance = rep1;
+          }
+          else
+          {
+            UPDATE_1(prob);
+            prob = probs + IsRepG2 + state;
+            IF_BIT_0(prob)
+            {
+              UPDATE_0(prob);
+              distance = rep2;
+            }
+            else
+            {
+              UPDATE_1(prob);
+              distance = rep3;
+              rep3 = rep2;
+            }
+            rep2 = rep1;
+          }
+          rep1 = rep0;
+          rep0 = distance;
+        }
+        state = state < kNumLitStates ? 8 : 11;
+        prob = probs + RepLenCoder;
+      }
+      {
+        unsigned limit, offset;
+        CLzmaProb *probLen = prob + LenChoice;
+        IF_BIT_0(probLen)
+        {
+          UPDATE_0(probLen);
+          probLen = prob + LenLow + (posState << kLenNumLowBits);
+          offset = 0;
+          limit = (1 << kLenNumLowBits);
+        }
+        else
+        {
+          UPDATE_1(probLen);
+          probLen = prob + LenChoice2;
+          IF_BIT_0(probLen)
+          {
+            UPDATE_0(probLen);
+            probLen = prob + LenMid + (posState << kLenNumMidBits);
+            offset = kLenNumLowSymbols;
+            limit = (1 << kLenNumMidBits);
+          }
+          else
+          {
+            UPDATE_1(probLen);
+            probLen = prob + LenHigh;
+            offset = kLenNumLowSymbols + kLenNumMidSymbols;
+            limit = (1 << kLenNumHighBits);
+          }
+        }
+        TREE_DECODE(probLen, limit, len);
+        len += offset;
+      }
+
+      if (state >= kNumStates)
+      {
+        UInt32 distance;
+        prob = probs + PosSlot +
+            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
+        TREE_6_DECODE(prob, distance);
+        if (distance >= kStartPosModelIndex)
+        {
+          unsigned posSlot = (unsigned)distance;
+          int numDirectBits = (int)(((distance >> 1) - 1));
+          distance = (2 | (distance & 1));
+          if (posSlot < kEndPosModelIndex)
+          {
+            distance <<= numDirectBits;
+            prob = probs + SpecPos + distance - posSlot - 1;
+            {
+              UInt32 mask = 1;
+              unsigned i = 1;
+              do
+              {
+                GET_BIT2(prob + i, i, ; , distance |= mask);
+                mask <<= 1;
+              }
+              while (--numDirectBits != 0);
+            }
+          }
+          else
+          {
+            numDirectBits -= kNumAlignBits;
+            do
+            {
+              NORMALIZE
+              range >>= 1;
+              
+              {
+                UInt32 t;
+                code -= range;
+                t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
+                distance = (distance << 1) + (t + 1);
+                code += range & t;
+              }
+              /*
+              distance <<= 1;
+              if (code >= range)
+              {
+                code -= range;
+                distance |= 1;
+              }
+              */
+            }
+            while (--numDirectBits != 0);
+            prob = probs + Align;
+            distance <<= kNumAlignBits;
+            {
+              unsigned i = 1;
+              GET_BIT2(prob + i, i, ; , distance |= 1);
+              GET_BIT2(prob + i, i, ; , distance |= 2);
+              GET_BIT2(prob + i, i, ; , distance |= 4);
+              GET_BIT2(prob + i, i, ; , distance |= 8);
+            }
+            if (distance == (UInt32)0xFFFFFFFF)
+            {
+              len += kMatchSpecLenStart;
+              state -= kNumStates;
+              break;
+            }
+          }
+        }
+        rep3 = rep2;
+        rep2 = rep1;
+        rep1 = rep0;
+        rep0 = distance + 1;
+        if (checkDicSize == 0)
+        {
+          if (distance >= processedPos)
+            return SZ_ERROR_DATA;
+        }
+        else if (distance >= checkDicSize)
+          return SZ_ERROR_DATA;
+        state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
+      }
+
+      len += kMatchMinLen;
+
+      if (limit == dicPos)
+        return SZ_ERROR_DATA;
+      {
+        SizeT rem = limit - dicPos;
+        unsigned curLen = ((rem < len) ? (unsigned)rem : len);
+        SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
+
+        processedPos += curLen;
+
+        len -= curLen;
+        if (pos + curLen <= dicBufSize)
+        {
+          Byte *dest = dic + dicPos;
+          ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
+          const Byte *lim = dest + curLen;
+          dicPos += curLen;
+          do
+            *(dest) = (Byte)*(dest + src);
+          while (++dest != lim);
+        }
+        else
+        {
+          do
+          {
+            dic[dicPos++] = dic[pos];
+            if (++pos == dicBufSize)
+              pos = 0;
+          }
+          while (--curLen != 0);
+        }
+      }
+    }
+  }
+  while (dicPos < limit && buf < bufLimit);
+  NORMALIZE;
+  p->buf = buf;
+  p->range = range;
+  p->code = code;
+  p->remainLen = len;
+  p->dicPos = dicPos;
+  p->processedPos = processedPos;
+  p->reps[0] = rep0;
+  p->reps[1] = rep1;
+  p->reps[2] = rep2;
+  p->reps[3] = rep3;
+  p->state = state;
+
+  return SZ_OK;
+}
+
+static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
+{
+  if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
+  {
+    Byte *dic = p->dic;
+    SizeT dicPos = p->dicPos;
+    SizeT dicBufSize = p->dicBufSize;
+    unsigned len = p->remainLen;
+    UInt32 rep0 = p->reps[0];
+    if (limit - dicPos < len)
+      len = (unsigned)(limit - dicPos);
+
+    if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
+      p->checkDicSize = p->prop.dicSize;
+
+    p->processedPos += len;
+    p->remainLen -= len;
+    while (len-- != 0)
+    {
+      dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
+      dicPos++;
+    }
+    p->dicPos = dicPos;
+  }
+}
+
+static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
+{
+  do
+  {
+    SizeT limit2 = limit;
+    if (p->checkDicSize == 0)
+    {
+      UInt32 rem = p->prop.dicSize - p->processedPos;
+      if (limit - p->dicPos > rem)
+        limit2 = p->dicPos + rem;
+    }
+    RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
+    if (p->processedPos >= p->prop.dicSize)
+      p->checkDicSize = p->prop.dicSize;
+    LzmaDec_WriteRem(p, limit);
+  }
+  while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
+
+  if (p->remainLen > kMatchSpecLenStart)
+  {
+    p->remainLen = kMatchSpecLenStart;
+  }
+  return 0;
+}
+
+typedef enum
+{
+  DUMMY_ERROR, /* unexpected end of input stream */
+  DUMMY_LIT,
+  DUMMY_MATCH,
+  DUMMY_REP
+} ELzmaDummy;
+
+static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
+{
+  UInt32 range = p->range;
+  UInt32 code = p->code;
+  const Byte *bufLimit = buf + inSize;
+  CLzmaProb *probs = p->probs;
+  unsigned state = p->state;
+  ELzmaDummy res;
+
+  {
+    CLzmaProb *prob;
+    UInt32 bound;
+    unsigned ttt;
+    unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
+
+    prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
+    IF_BIT_0_CHECK(prob)
+    {
+      UPDATE_0_CHECK
+
+      /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
+
+      prob = probs + Literal;
+      if (p->checkDicSize != 0 || p->processedPos != 0)
+        prob += (LZMA_LIT_SIZE *
+          ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
+          (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
+
+      if (state < kNumLitStates)
+      {
+        unsigned symbol = 1;
+        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
+      }
+      else
+      {
+        unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
+            ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
+        unsigned offs = 0x100;
+        unsigned symbol = 1;
+        do
+        {
+          unsigned bit;
+          CLzmaProb *probLit;
+          matchByte <<= 1;
+          bit = (matchByte & offs);
+          probLit = prob + offs + bit + symbol;
+          GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
+        }
+        while (symbol < 0x100);
+      }
+      res = DUMMY_LIT;
+    }
+    else
+    {
+      unsigned len;
+      UPDATE_1_CHECK;
+
+      prob = probs + IsRep + state;
+      IF_BIT_0_CHECK(prob)
+      {
+        UPDATE_0_CHECK;
+        state = 0;
+        prob = probs + LenCoder;
+        res = DUMMY_MATCH;
+      }
+      else
+      {
+        UPDATE_1_CHECK;
+        res = DUMMY_REP;
+        prob = probs + IsRepG0 + state;
+        IF_BIT_0_CHECK(prob)
+        {
+          UPDATE_0_CHECK;
+          prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
+          IF_BIT_0_CHECK(prob)
+          {
+            UPDATE_0_CHECK;
+            NORMALIZE_CHECK;
+            return DUMMY_REP;
+          }
+          else
+          {
+            UPDATE_1_CHECK;
+          }
+        }
+        else
+        {
+          UPDATE_1_CHECK;
+          prob = probs + IsRepG1 + state;
+          IF_BIT_0_CHECK(prob)
+          {
+            UPDATE_0_CHECK;
+          }
+          else
+          {
+            UPDATE_1_CHECK;
+            prob = probs + IsRepG2 + state;
+            IF_BIT_0_CHECK(prob)
+            {
+              UPDATE_0_CHECK;
+            }
+            else
+            {
+              UPDATE_1_CHECK;
+            }
+          }
+        }
+        state = kNumStates;
+        prob = probs + RepLenCoder;
+      }
+      {
+        unsigned limit, offset;
+        CLzmaProb *probLen = prob + LenChoice;
+        IF_BIT_0_CHECK(probLen)
+        {
+          UPDATE_0_CHECK;
+          probLen = prob + LenLow + (posState << kLenNumLowBits);
+          offset = 0;
+          limit = 1 << kLenNumLowBits;
+        }
+        else
+        {
+          UPDATE_1_CHECK;
+          probLen = prob + LenChoice2;
+          IF_BIT_0_CHECK(probLen)
+          {
+            UPDATE_0_CHECK;
+            probLen = prob + LenMid + (posState << kLenNumMidBits);
+            offset = kLenNumLowSymbols;
+            limit = 1 << kLenNumMidBits;
+          }
+          else
+          {
+            UPDATE_1_CHECK;
+            probLen = prob + LenHigh;
+            offset = kLenNumLowSymbols + kLenNumMidSymbols;
+            limit = 1 << kLenNumHighBits;
+          }
+        }
+        TREE_DECODE_CHECK(probLen, limit, len);
+        len += offset;
+      }
+
+      if (state < 4)
+      {
+        unsigned posSlot;
+        prob = probs + PosSlot +
+            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
+            kNumPosSlotBits);
+        TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
+        if (posSlot >= kStartPosModelIndex)
+        {
+          int numDirectBits = ((posSlot >> 1) - 1);
+
+          /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
+
+          if (posSlot < kEndPosModelIndex)
+          {
+            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
+          }
+          else
+          {
+            numDirectBits -= kNumAlignBits;
+            do
+            {
+              NORMALIZE_CHECK
+              range >>= 1;
+              code -= range & (((code - range) >> 31) - 1);
+              /* if (code >= range) code -= range; */
+            }
+            while (--numDirectBits != 0);
+            prob = probs + Align;
+            numDirectBits = kNumAlignBits;
+          }
+          {
+            unsigned i = 1;
+            do
+            {
+              GET_BIT_CHECK(prob + i, i);
+            }
+            while (--numDirectBits != 0);
+          }
+        }
+      }
+    }
+  }
+  NORMALIZE_CHECK;
+  return res;
+}
+
+
+static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
+{
+  p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
+  p->range = 0xFFFFFFFF;
+  p->needFlush = 0;
+}
+
+void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
+{
+  p->needFlush = 1;
+  p->remainLen = 0;
+  p->tempBufSize = 0;
+
+  if (initDic)
+  {
+    p->processedPos = 0;
+    p->checkDicSize = 0;
+    p->needInitState = 1;
+  }
+  if (initState)
+    p->needInitState = 1;
+}
+
+void LzmaDec_Init(CLzmaDec *p)
+{
+  p->dicPos = 0;
+  LzmaDec_InitDicAndState(p, True, True);
+}
+
+static void LzmaDec_InitStateReal(CLzmaDec *p)
+{
+  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
+  UInt32 i;
+  CLzmaProb *probs = p->probs;
+  for (i = 0; i < numProbs; i++)
+    probs[i] = kBitModelTotal >> 1;
+  p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
+  p->state = 0;
+  p->needInitState = 0;
+}
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
+    ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+  SizeT inSize = *srcLen;
+  (*srcLen) = 0;
+  LzmaDec_WriteRem(p, dicLimit);
+  
+  *status = LZMA_STATUS_NOT_SPECIFIED;
+
+  while (p->remainLen != kMatchSpecLenStart)
+  {
+      int checkEndMarkNow;
+
+      if (p->needFlush != 0)
+      {
+        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
+          p->tempBuf[p->tempBufSize++] = *src++;
+        if (p->tempBufSize < RC_INIT_SIZE)
+        {
+          *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+          return SZ_OK;
+        }
+        if (p->tempBuf[0] != 0)
+          return SZ_ERROR_DATA;
+
+        LzmaDec_InitRc(p, p->tempBuf);
+        p->tempBufSize = 0;
+      }
+
+      checkEndMarkNow = 0;
+      if (p->dicPos >= dicLimit)
+      {
+        if (p->remainLen == 0 && p->code == 0)
+        {
+          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
+          return SZ_OK;
+        }
+        if (finishMode == LZMA_FINISH_ANY)
+        {
+          *status = LZMA_STATUS_NOT_FINISHED;
+          return SZ_OK;
+        }
+        if (p->remainLen != 0)
+        {
+          *status = LZMA_STATUS_NOT_FINISHED;
+          return SZ_ERROR_DATA;
+        }
+        checkEndMarkNow = 1;
+      }
+
+      if (p->needInitState)
+        LzmaDec_InitStateReal(p);
+  
+      if (p->tempBufSize == 0)
+      {
+        SizeT processed;
+        const Byte *bufLimit;
+        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
+        {
+          int dummyRes = LzmaDec_TryDummy(p, src, inSize);
+          if (dummyRes == DUMMY_ERROR)
+          {
+            memcpy(p->tempBuf, src, inSize);
+            p->tempBufSize = (unsigned)inSize;
+            (*srcLen) += inSize;
+            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+            return SZ_OK;
+          }
+          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
+          {
+            *status = LZMA_STATUS_NOT_FINISHED;
+            return SZ_ERROR_DATA;
+          }
+          bufLimit = src;
+        }
+        else
+          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
+        p->buf = src;
+        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
+          return SZ_ERROR_DATA;
+        processed = (SizeT)(p->buf - src);
+        (*srcLen) += processed;
+        src += processed;
+        inSize -= processed;
+      }
+      else
+      {
+        unsigned rem = p->tempBufSize, lookAhead = 0;
+        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
+          p->tempBuf[rem++] = src[lookAhead++];
+        p->tempBufSize = rem;
+        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
+        {
+          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
+          if (dummyRes == DUMMY_ERROR)
+          {
+            (*srcLen) += lookAhead;
+            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
+            return SZ_OK;
+          }
+          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
+          {
+            *status = LZMA_STATUS_NOT_FINISHED;
+            return SZ_ERROR_DATA;
+          }
+        }
+        p->buf = p->tempBuf;
+        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
+          return SZ_ERROR_DATA;
+        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
+        (*srcLen) += lookAhead;
+        src += lookAhead;
+        inSize -= lookAhead;
+        p->tempBufSize = 0;
+      }
+  }
+  if (p->code == 0)
+    *status = LZMA_STATUS_FINISHED_WITH_MARK;
+  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
+}
+
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
+{
+  SizeT outSize = *destLen;
+  SizeT inSize = *srcLen;
+  *srcLen = *destLen = 0;
+  for (;;)
+  {
+    SizeT inSizeCur = inSize, outSizeCur, dicPos;
+    ELzmaFinishMode curFinishMode;
+    SRes res;
+    if (p->dicPos == p->dicBufSize)
+      p->dicPos = 0;
+    dicPos = p->dicPos;
+    if (outSize > p->dicBufSize - dicPos)
+    {
+      outSizeCur = p->dicBufSize;
+      curFinishMode = LZMA_FINISH_ANY;
+    }
+    else
+    {
+      outSizeCur = dicPos + outSize;
+      curFinishMode = finishMode;
+    }
+
+    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
+    src += inSizeCur;
+    inSize -= inSizeCur;
+    *srcLen += inSizeCur;
+    outSizeCur = p->dicPos - dicPos;
+    memcpy(dest, p->dic + dicPos, outSizeCur);
+    dest += outSizeCur;
+    outSize -= outSizeCur;
+    *destLen += outSizeCur;
+    if (res != 0)
+      return res;
+    if (outSizeCur == 0 || outSize == 0)
+      return SZ_OK;
+  }
+}
+
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->probs);
+  p->probs = 0;
+}
+
+static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->dic);
+  p->dic = 0;
+}
+
+void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
+{
+  LzmaDec_FreeProbs(p, alloc);
+  LzmaDec_FreeDict(p, alloc);
+}
+
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
+{
+  UInt32 dicSize;
+  Byte d;
+  
+  if (size < LZMA_PROPS_SIZE)
+    return SZ_ERROR_UNSUPPORTED;
+  else
+    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
+ 
+  if (dicSize < LZMA_DIC_MIN)
+    dicSize = LZMA_DIC_MIN;
+  p->dicSize = dicSize;
+
+  d = data[0];
+  if (d >= (9 * 5 * 5))
+    return SZ_ERROR_UNSUPPORTED;
+
+  p->lc = d % 9;
+  d /= 9;
+  p->pb = d / 5;
+  p->lp = d % 5;
+
+  return SZ_OK;
+}
+
+static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
+{
+  UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
+  if (p->probs == 0 || numProbs != p->numProbs)
+  {
+    LzmaDec_FreeProbs(p, alloc);
+    p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));
+    p->numProbs = numProbs;
+    if (p->probs == 0)
+      return SZ_ERROR_MEM;
+  }
+  return SZ_OK;
+}
+
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
+{
+  CLzmaProps propNew;
+  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
+  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+  p->prop = propNew;
+  return SZ_OK;
+}
+
+SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
+{
+  CLzmaProps propNew;
+  SizeT dicBufSize;
+  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
+  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
+  dicBufSize = propNew.dicSize;
+  if (p->dic == 0 || dicBufSize != p->dicBufSize)
+  {
+    LzmaDec_FreeDict(p, alloc);
+    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
+    if (p->dic == 0)
+    {
+      LzmaDec_FreeProbs(p, alloc);
+      return SZ_ERROR_MEM;
+    }
+  }
+  p->dicBufSize = dicBufSize;
+  p->prop = propNew;
+  return SZ_OK;
+}
+
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+    ELzmaStatus *status, ISzAlloc *alloc)
+{
+  CLzmaDec p;
+  SRes res;
+  SizeT inSize = *srcLen;
+  SizeT outSize = *destLen;
+  *srcLen = *destLen = 0;
+  if (inSize < RC_INIT_SIZE)
+    return SZ_ERROR_INPUT_EOF;
+
+  LzmaDec_Construct(&p);
+  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
+  if (res != 0)
+    return res;
+  p.dic = dest;
+  p.dicBufSize = outSize;
+
+  LzmaDec_Init(&p);
+  
+  *srcLen = inSize;
+  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
+
+  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
+    res = SZ_ERROR_INPUT_EOF;
+
+  (*destLen) = p.dicPos;
+  LzmaDec_FreeProbs(&p, alloc);
+  return res;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaDec.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,231 @@
+/* LzmaDec.h -- LZMA Decoder
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA_DEC_H
+#define __LZMA_DEC_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* #define _LZMA_PROB32 */
+/* _LZMA_PROB32 can increase the speed on some CPUs,
+   but memory usage for CLzmaDec::probs will be doubled in that case */
+
+#ifdef _LZMA_PROB32
+#define CLzmaProb UInt32
+#else
+#define CLzmaProb UInt16
+#endif
+
+
+/* ---------- LZMA Properties ---------- */
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct _CLzmaProps
+{
+  unsigned lc, lp, pb;
+  UInt32 dicSize;
+} CLzmaProps;
+
+/* LzmaProps_Decode - decodes properties
+Returns:
+  SZ_OK
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+
+SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
+
+
+/* ---------- LZMA Decoder state ---------- */
+
+/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
+   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
+
+#define LZMA_REQUIRED_INPUT_MAX 20
+
+typedef struct
+{
+  CLzmaProps prop;
+  CLzmaProb *probs;
+  Byte *dic;
+  const Byte *buf;
+  UInt32 range, code;
+  SizeT dicPos;
+  SizeT dicBufSize;
+  UInt32 processedPos;
+  UInt32 checkDicSize;
+  unsigned state;
+  UInt32 reps[4];
+  unsigned remainLen;
+  int needFlush;
+  int needInitState;
+  UInt32 numProbs;
+  unsigned tempBufSize;
+  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
+} CLzmaDec;
+
+#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
+
+void LzmaDec_Init(CLzmaDec *p);
+
+/* There are two types of LZMA streams:
+     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
+     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
+
+typedef enum
+{
+  LZMA_FINISH_ANY,   /* finish at any point */
+  LZMA_FINISH_END    /* block must be finished at the end */
+} ELzmaFinishMode;
+
+/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
+
+   You must use LZMA_FINISH_END, when you know that current output buffer
+   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
+
+   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
+   and output value of destLen will be less than output buffer size limit.
+   You can check status result also.
+
+   You can use multiple checks to test data integrity after full decompression:
+     1) Check Result and "status" variable.
+     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
+     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
+        You must use correct finish mode in that case. */
+
+typedef enum
+{
+  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */
+  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */
+  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */
+  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */
+  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */
+} ELzmaStatus;
+
+/* ELzmaStatus is used only as output value for function call */
+
+
+/* ---------- Interfaces ---------- */
+
+/* There are 3 levels of interfaces:
+     1) Dictionary Interface
+     2) Buffer Interface
+     3) One Call Interface
+   You can select any of these interfaces, but don't mix functions from different
+   groups for same object. */
+
+
+/* There are two variants to allocate state for Dictionary Interface:
+     1) LzmaDec_Allocate / LzmaDec_Free
+     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
+   You can use variant 2, if you set dictionary buffer manually.
+   For Buffer Interface you must always use variant 1.
+
+LzmaDec_Allocate* can return:
+  SZ_OK
+  SZ_ERROR_MEM         - Memory allocation error
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+*/
+   
+SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
+
+SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
+void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
+
+/* ---------- Dictionary Interface ---------- */
+
+/* You can use it, if you want to eliminate the overhead for data copying from
+   dictionary to some other external buffer.
+   You must work with CLzmaDec variables directly in this interface.
+
+   STEPS:
+     LzmaDec_Constr()
+     LzmaDec_Allocate()
+     for (each new stream)
+     {
+       LzmaDec_Init()
+       while (it needs more decompression)
+       {
+         LzmaDec_DecodeToDic()
+         use data from CLzmaDec::dic and update CLzmaDec::dicPos
+       }
+     }
+     LzmaDec_Free()
+*/
+
+/* LzmaDec_DecodeToDic
+   
+   The decoding to internal dictionary buffer (CLzmaDec::dic).
+   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
+
+finishMode:
+  It has meaning only if the decoding reaches output limit (dicLimit).
+  LZMA_FINISH_ANY - Decode just dicLimit bytes.
+  LZMA_FINISH_END - Stream must be finished after dicLimit.
+
+Returns:
+  SZ_OK
+    status:
+      LZMA_STATUS_FINISHED_WITH_MARK
+      LZMA_STATUS_NOT_FINISHED
+      LZMA_STATUS_NEEDS_MORE_INPUT
+      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+  SZ_ERROR_DATA - Data error
+*/
+
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- Buffer Interface ---------- */
+
+/* It's zlib-like interface.
+   See LzmaDec_DecodeToDic description for information about STEPS and return results,
+   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
+   to work with CLzmaDec variables manually.
+
+finishMode:
+  It has meaning only if the decoding reaches output limit (*destLen).
+  LZMA_FINISH_ANY - Decode just destLen bytes.
+  LZMA_FINISH_END - Stream must be finished after (*destLen).
+*/
+
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
+    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
+
+
+/* ---------- One Call Interface ---------- */
+
+/* LzmaDecode
+
+finishMode:
+  It has meaning only if the decoding reaches output limit (*destLen).
+  LZMA_FINISH_ANY - Decode just destLen bytes.
+  LZMA_FINISH_END - Stream must be finished after (*destLen).
+
+Returns:
+  SZ_OK
+    status:
+      LZMA_STATUS_FINISHED_WITH_MARK
+      LZMA_STATUS_NOT_FINISHED
+      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
+  SZ_ERROR_DATA - Data error
+  SZ_ERROR_MEM  - Memory allocation error
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+*/
+
+SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+    ELzmaStatus *status, ISzAlloc *alloc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,2268 @@
+/* LzmaEnc.c -- LZMA Encoder
+2010-04-16 : Igor Pavlov : Public domain */
+
+#include <string.h>
+
+/* #define SHOW_STAT */
+/* #define SHOW_STAT2 */
+
+#if defined(SHOW_STAT) || defined(SHOW_STAT2)
+#include <stdio.h>
+#endif
+
+#include "LzmaEnc.h"
+
+#include "LzFind.h"
+#ifndef _7ZIP_ST
+#include "LzFindMt.h"
+#endif
+
+#ifdef SHOW_STAT
+static int ttt = 0;
+#endif
+
+#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)
+
+#define kBlockSize (9 << 10)
+#define kUnpackBlockSize (1 << 18)
+#define kMatchArraySize (1 << 21)
+#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)
+
+#define kNumMaxDirectBits (31)
+
+#define kNumTopBits 24
+#define kTopValue ((UInt32)1 << kNumTopBits)
+
+#define kNumBitModelTotalBits 11
+#define kBitModelTotal (1 << kNumBitModelTotalBits)
+#define kNumMoveBits 5
+#define kProbInitValue (kBitModelTotal >> 1)
+
+#define kNumMoveReducingBits 4
+#define kNumBitPriceShiftBits 4
+#define kBitPrice (1 << kNumBitPriceShiftBits)
+
+void LzmaEncProps_Init(CLzmaEncProps *p)
+{
+  p->level = 5;
+  p->dictSize = p->mc = 0;
+  p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
+  p->writeEndMark = 0;
+}
+
+void LzmaEncProps_Normalize(CLzmaEncProps *p)
+{
+  int level = p->level;
+  if (level < 0) level = 5;
+  p->level = level;
+  if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));
+  if (p->lc < 0) p->lc = 3;
+  if (p->lp < 0) p->lp = 0;
+  if (p->pb < 0) p->pb = 2;
+  if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
+  if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
+  if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
+  if (p->numHashBytes < 0) p->numHashBytes = 4;
+  if (p->mc == 0)  p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
+  if (p->numThreads < 0)
+    p->numThreads =
+      #ifndef _7ZIP_ST
+      ((p->btMode && p->algo) ? 2 : 1);
+      #else
+      1;
+      #endif
+}
+
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
+{
+  CLzmaEncProps props = *props2;
+  LzmaEncProps_Normalize(&props);
+  return props.dictSize;
+}
+
+/* #define LZMA_LOG_BSR */
+/* Define it for Intel's CPU */
+
+
+#ifdef LZMA_LOG_BSR
+
+#define kDicLogSizeMaxCompress 30
+
+#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
+
+UInt32 GetPosSlot1(UInt32 pos)
+{
+  UInt32 res;
+  BSR2_RET(pos, res);
+  return res;
+}
+#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
+#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
+
+#else
+
+#define kNumLogBits (9 + (int)sizeof(size_t) / 2)
+#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
+
+void LzmaEnc_FastPosInit(Byte *g_FastPos)
+{
+  int c = 2, slotFast;
+  g_FastPos[0] = 0;
+  g_FastPos[1] = 1;
+  
+  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)
+  {
+    UInt32 k = (1 << ((slotFast >> 1) - 1));
+    UInt32 j;
+    for (j = 0; j < k; j++, c++)
+      g_FastPos[c] = (Byte)slotFast;
+  }
+}
+
+#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \
+  (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
+  res = p->g_FastPos[pos >> i] + (i * 2); }
+/*
+#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
+  p->g_FastPos[pos >> 6] + 12 : \
+  p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
+*/
+
+#define GetPosSlot1(pos) p->g_FastPos[pos]
+#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
+#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }
+
+#endif
+
+
+#define LZMA_NUM_REPS 4
+
+typedef unsigned CState;
+
+typedef struct
+{
+  UInt32 price;
+
+  CState state;
+  int prev1IsChar;
+  int prev2;
+
+  UInt32 posPrev2;
+  UInt32 backPrev2;
+
+  UInt32 posPrev;
+  UInt32 backPrev;
+  UInt32 backs[LZMA_NUM_REPS];
+} COptimal;
+
+#define kNumOpts (1 << 12)
+
+#define kNumLenToPosStates 4
+#define kNumPosSlotBits 6
+#define kDicLogSizeMin 0
+#define kDicLogSizeMax 32
+#define kDistTableSizeMax (kDicLogSizeMax * 2)
+
+
+#define kNumAlignBits 4
+#define kAlignTableSize (1 << kNumAlignBits)
+#define kAlignMask (kAlignTableSize - 1)
+
+#define kStartPosModelIndex 4
+#define kEndPosModelIndex 14
+#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)
+
+#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
+
+#ifdef _LZMA_PROB32
+#define CLzmaProb UInt32
+#else
+#define CLzmaProb UInt16
+#endif
+
+#define LZMA_PB_MAX 4
+#define LZMA_LC_MAX 8
+#define LZMA_LP_MAX 4
+
+#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
+
+
+#define kLenNumLowBits 3
+#define kLenNumLowSymbols (1 << kLenNumLowBits)
+#define kLenNumMidBits 3
+#define kLenNumMidSymbols (1 << kLenNumMidBits)
+#define kLenNumHighBits 8
+#define kLenNumHighSymbols (1 << kLenNumHighBits)
+
+#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
+
+#define LZMA_MATCH_LEN_MIN 2
+#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
+
+#define kNumStates 12
+
+typedef struct
+{
+  CLzmaProb choice;
+  CLzmaProb choice2;
+  CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];
+  CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];
+  CLzmaProb high[kLenNumHighSymbols];
+} CLenEnc;
+
+typedef struct
+{
+  CLenEnc p;
+  UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
+  UInt32 tableSize;
+  UInt32 counters[LZMA_NUM_PB_STATES_MAX];
+} CLenPriceEnc;
+
+typedef struct
+{
+  UInt32 range;
+  Byte cache;
+  UInt64 low;
+  UInt64 cacheSize;
+  Byte *buf;
+  Byte *bufLim;
+  Byte *bufBase;
+  ISeqOutStream *outStream;
+  UInt64 processed;
+  SRes res;
+} CRangeEnc;
+
+typedef struct
+{
+  CLzmaProb *litProbs;
+
+  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+  CLzmaProb isRep[kNumStates];
+  CLzmaProb isRepG0[kNumStates];
+  CLzmaProb isRepG1[kNumStates];
+  CLzmaProb isRepG2[kNumStates];
+  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+
+  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
+  CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+  
+  CLenPriceEnc lenEnc;
+  CLenPriceEnc repLenEnc;
+
+  UInt32 reps[LZMA_NUM_REPS];
+  UInt32 state;
+} CSaveState;
+
+typedef struct
+{
+  IMatchFinder matchFinder;
+  void *matchFinderObj;
+
+  #ifndef _7ZIP_ST
+  Bool mtMode;
+  CMatchFinderMt matchFinderMt;
+  #endif
+
+  CMatchFinder matchFinderBase;
+
+  #ifndef _7ZIP_ST
+  Byte pad[128];
+  #endif
+  
+  UInt32 optimumEndIndex;
+  UInt32 optimumCurrentIndex;
+
+  UInt32 longestMatchLength;
+  UInt32 numPairs;
+  UInt32 numAvail;
+  COptimal opt[kNumOpts];
+  
+  #ifndef LZMA_LOG_BSR
+  Byte g_FastPos[1 << kNumLogBits];
+  #endif
+
+  UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
+  UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
+  UInt32 numFastBytes;
+  UInt32 additionalOffset;
+  UInt32 reps[LZMA_NUM_REPS];
+  UInt32 state;
+
+  UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
+  UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
+  UInt32 alignPrices[kAlignTableSize];
+  UInt32 alignPriceCount;
+
+  UInt32 distTableSize;
+
+  unsigned lc, lp, pb;
+  unsigned lpMask, pbMask;
+
+  CLzmaProb *litProbs;
+
+  CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
+  CLzmaProb isRep[kNumStates];
+  CLzmaProb isRepG0[kNumStates];
+  CLzmaProb isRepG1[kNumStates];
+  CLzmaProb isRepG2[kNumStates];
+  CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
+
+  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
+  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
+  CLzmaProb posAlignEncoder[1 << kNumAlignBits];
+  
+  CLenPriceEnc lenEnc;
+  CLenPriceEnc repLenEnc;
+
+  unsigned lclp;
+
+  Bool fastMode;
+  
+  CRangeEnc rc;
+
+  Bool writeEndMark;
+  UInt64 nowPos64;
+  UInt32 matchPriceCount;
+  Bool finished;
+  Bool multiThread;
+
+  SRes result;
+  UInt32 dictSize;
+  UInt32 matchFinderCycles;
+
+  int needInit;
+
+  CSaveState saveState;
+} CLzmaEnc;
+
+void LzmaEnc_SaveState(CLzmaEncHandle pp)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  CSaveState *dest = &p->saveState;
+  int i;
+  dest->lenEnc = p->lenEnc;
+  dest->repLenEnc = p->repLenEnc;
+  dest->state = p->state;
+
+  for (i = 0; i < kNumStates; i++)
+  {
+    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
+    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
+  }
+  for (i = 0; i < kNumLenToPosStates; i++)
+    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
+  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
+  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
+  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
+  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
+  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
+  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
+  memcpy(dest->reps, p->reps, sizeof(p->reps));
+  memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
+}
+
+void LzmaEnc_RestoreState(CLzmaEncHandle pp)
+{
+  CLzmaEnc *dest = (CLzmaEnc *)pp;
+  const CSaveState *p = &dest->saveState;
+  int i;
+  dest->lenEnc = p->lenEnc;
+  dest->repLenEnc = p->repLenEnc;
+  dest->state = p->state;
+
+  for (i = 0; i < kNumStates; i++)
+  {
+    memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
+    memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
+  }
+  for (i = 0; i < kNumLenToPosStates; i++)
+    memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
+  memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
+  memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
+  memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
+  memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
+  memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
+  memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
+  memcpy(dest->reps, p->reps, sizeof(p->reps));
+  memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
+}
+
+SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  CLzmaEncProps props = *props2;
+  LzmaEncProps_Normalize(&props);
+
+  if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||
+      props.dictSize > ((UInt32)1 << kDicLogSizeMaxCompress) || props.dictSize > ((UInt32)1 << 30))
+    return SZ_ERROR_PARAM;
+  p->dictSize = props.dictSize;
+  p->matchFinderCycles = props.mc;
+  {
+    unsigned fb = props.fb;
+    if (fb < 5)
+      fb = 5;
+    if (fb > LZMA_MATCH_LEN_MAX)
+      fb = LZMA_MATCH_LEN_MAX;
+    p->numFastBytes = fb;
+  }
+  p->lc = props.lc;
+  p->lp = props.lp;
+  p->pb = props.pb;
+  p->fastMode = (props.algo == 0);
+  p->matchFinderBase.btMode = props.btMode;
+  {
+    UInt32 numHashBytes = 4;
+    if (props.btMode)
+    {
+      if (props.numHashBytes < 2)
+        numHashBytes = 2;
+      else if (props.numHashBytes < 4)
+        numHashBytes = props.numHashBytes;
+    }
+    p->matchFinderBase.numHashBytes = numHashBytes;
+  }
+
+  p->matchFinderBase.cutValue = props.mc;
+
+  p->writeEndMark = props.writeEndMark;
+
+  #ifndef _7ZIP_ST
+  /*
+  if (newMultiThread != _multiThread)
+  {
+    ReleaseMatchFinder();
+    _multiThread = newMultiThread;
+  }
+  */
+  p->multiThread = (props.numThreads > 1);
+  #endif
+
+  return SZ_OK;
+}
+
+static const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};
+static const int kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
+static const int kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
+static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
+
+#define IsCharState(s) ((s) < 7)
+
+#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
+
+#define kInfinityPrice (1 << 30)
+
+static void RangeEnc_Construct(CRangeEnc *p)
+{
+  p->outStream = 0;
+  p->bufBase = 0;
+}
+
+#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
+
+#define RC_BUF_SIZE (1 << 16)
+static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)
+{
+  if (p->bufBase == 0)
+  {
+    p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);
+    if (p->bufBase == 0)
+      return 0;
+    p->bufLim = p->bufBase + RC_BUF_SIZE;
+  }
+  return 1;
+}
+
+static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->bufBase);
+  p->bufBase = 0;
+}
+
+static void RangeEnc_Init(CRangeEnc *p)
+{
+  /* Stream.Init(); */
+  p->low = 0;
+  p->range = 0xFFFFFFFF;
+  p->cacheSize = 1;
+  p->cache = 0;
+
+  p->buf = p->bufBase;
+
+  p->processed = 0;
+  p->res = SZ_OK;
+}
+
+static void RangeEnc_FlushStream(CRangeEnc *p)
+{
+  size_t num;
+  if (p->res != SZ_OK)
+    return;
+  num = p->buf - p->bufBase;
+  if (num != p->outStream->Write(p->outStream, p->bufBase, num))
+    p->res = SZ_ERROR_WRITE;
+  p->processed += num;
+  p->buf = p->bufBase;
+}
+
+static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
+{
+  if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)
+  {
+    Byte temp = p->cache;
+    do
+    {
+      Byte *buf = p->buf;
+      *buf++ = (Byte)(temp + (Byte)(p->low >> 32));
+      p->buf = buf;
+      if (buf == p->bufLim)
+        RangeEnc_FlushStream(p);
+      temp = 0xFF;
+    }
+    while (--p->cacheSize != 0);
+    p->cache = (Byte)((UInt32)p->low >> 24);
+  }
+  p->cacheSize++;
+  p->low = (UInt32)p->low << 8;
+}
+
+static void RangeEnc_FlushData(CRangeEnc *p)
+{
+  int i;
+  for (i = 0; i < 5; i++)
+    RangeEnc_ShiftLow(p);
+}
+
+static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits)
+{
+  do
+  {
+    p->range >>= 1;
+    p->low += p->range & (0 - ((value >> --numBits) & 1));
+    if (p->range < kTopValue)
+    {
+      p->range <<= 8;
+      RangeEnc_ShiftLow(p);
+    }
+  }
+  while (numBits != 0);
+}
+
+static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)
+{
+  UInt32 ttt = *prob;
+  UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;
+  if (symbol == 0)
+  {
+    p->range = newBound;
+    ttt += (kBitModelTotal - ttt) >> kNumMoveBits;
+  }
+  else
+  {
+    p->low += newBound;
+    p->range -= newBound;
+    ttt -= ttt >> kNumMoveBits;
+  }
+  *prob = (CLzmaProb)ttt;
+  if (p->range < kTopValue)
+  {
+    p->range <<= 8;
+    RangeEnc_ShiftLow(p);
+  }
+}
+
+static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)
+{
+  symbol |= 0x100;
+  do
+  {
+    RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);
+    symbol <<= 1;
+  }
+  while (symbol < 0x10000);
+}
+
+static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)
+{
+  UInt32 offs = 0x100;
+  symbol |= 0x100;
+  do
+  {
+    matchByte <<= 1;
+    RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);
+    symbol <<= 1;
+    offs &= ~(matchByte ^ symbol);
+  }
+  while (symbol < 0x10000);
+}
+
+void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
+{
+  UInt32 i;
+  for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
+  {
+    const int kCyclesBits = kNumBitPriceShiftBits;
+    UInt32 w = i;
+    UInt32 bitCount = 0;
+    int j;
+    for (j = 0; j < kCyclesBits; j++)
+    {
+      w = w * w;
+      bitCount <<= 1;
+      while (w >= ((UInt32)1 << 16))
+      {
+        w >>= 1;
+        bitCount++;
+      }
+    }
+    ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
+  }
+}
+
+
+#define GET_PRICE(prob, symbol) \
+  p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
+
+#define GET_PRICEa(prob, symbol) \
+  ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
+
+#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
+#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
+
+#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
+#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
+
+static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)
+{
+  UInt32 price = 0;
+  symbol |= 0x100;
+  do
+  {
+    price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);
+    symbol <<= 1;
+  }
+  while (symbol < 0x10000);
+  return price;
+}
+
+static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)
+{
+  UInt32 price = 0;
+  UInt32 offs = 0x100;
+  symbol |= 0x100;
+  do
+  {
+    matchByte <<= 1;
+    price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
+    symbol <<= 1;
+    offs &= ~(matchByte ^ symbol);
+  }
+  while (symbol < 0x10000);
+  return price;
+}
+
+
+static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
+{
+  UInt32 m = 1;
+  int i;
+  for (i = numBitLevels; i != 0;)
+  {
+    UInt32 bit;
+    i--;
+    bit = (symbol >> i) & 1;
+    RangeEnc_EncodeBit(rc, probs + m, bit);
+    m = (m << 1) | bit;
+  }
+}
+
+static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
+{
+  UInt32 m = 1;
+  int i;
+  for (i = 0; i < numBitLevels; i++)
+  {
+    UInt32 bit = symbol & 1;
+    RangeEnc_EncodeBit(rc, probs + m, bit);
+    m = (m << 1) | bit;
+    symbol >>= 1;
+  }
+}
+
+static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
+{
+  UInt32 price = 0;
+  symbol |= (1 << numBitLevels);
+  while (symbol != 1)
+  {
+    price += GET_PRICEa(probs[symbol >> 1], symbol & 1);
+    symbol >>= 1;
+  }
+  return price;
+}
+
+static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
+{
+  UInt32 price = 0;
+  UInt32 m = 1;
+  int i;
+  for (i = numBitLevels; i != 0; i--)
+  {
+    UInt32 bit = symbol & 1;
+    symbol >>= 1;
+    price += GET_PRICEa(probs[m], bit);
+    m = (m << 1) | bit;
+  }
+  return price;
+}
+
+
+static void LenEnc_Init(CLenEnc *p)
+{
+  unsigned i;
+  p->choice = p->choice2 = kProbInitValue;
+  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)
+    p->low[i] = kProbInitValue;
+  for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)
+    p->mid[i] = kProbInitValue;
+  for (i = 0; i < kLenNumHighSymbols; i++)
+    p->high[i] = kProbInitValue;
+}
+
+static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)
+{
+  if (symbol < kLenNumLowSymbols)
+  {
+    RangeEnc_EncodeBit(rc, &p->choice, 0);
+    RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);
+  }
+  else
+  {
+    RangeEnc_EncodeBit(rc, &p->choice, 1);
+    if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)
+    {
+      RangeEnc_EncodeBit(rc, &p->choice2, 0);
+      RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);
+    }
+    else
+    {
+      RangeEnc_EncodeBit(rc, &p->choice2, 1);
+      RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);
+    }
+  }
+}
+
+static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)
+{
+  UInt32 a0 = GET_PRICE_0a(p->choice);
+  UInt32 a1 = GET_PRICE_1a(p->choice);
+  UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);
+  UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);
+  UInt32 i = 0;
+  for (i = 0; i < kLenNumLowSymbols; i++)
+  {
+    if (i >= numSymbols)
+      return;
+    prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);
+  }
+  for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)
+  {
+    if (i >= numSymbols)
+      return;
+    prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);
+  }
+  for (; i < numSymbols; i++)
+    prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);
+}
+
+static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)
+{
+  LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);
+  p->counters[posState] = p->tableSize;
+}
+
+static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)
+{
+  UInt32 posState;
+  for (posState = 0; posState < numPosStates; posState++)
+    LenPriceEnc_UpdateTable(p, posState, ProbPrices);
+}
+
+static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)
+{
+  LenEnc_Encode(&p->p, rc, symbol, posState);
+  if (updatePrice)
+    if (--p->counters[posState] == 0)
+      LenPriceEnc_UpdateTable(p, posState, ProbPrices);
+}
+
+
+
+
+static void MovePos(CLzmaEnc *p, UInt32 num)
+{
+  #ifdef SHOW_STAT
+  ttt += num;
+  printf("\n MovePos %d", num);
+  #endif
+  if (num != 0)
+  {
+    p->additionalOffset += num;
+    p->matchFinder.Skip(p->matchFinderObj, num);
+  }
+}
+
+static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
+{
+  UInt32 lenRes = 0, numPairs;
+  p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+  numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
+  #ifdef SHOW_STAT
+  printf("\n i = %d numPairs = %d    ", ttt, numPairs / 2);
+  ttt++;
+  {
+    UInt32 i;
+    for (i = 0; i < numPairs; i += 2)
+      printf("%2d %6d   | ", p->matches[i], p->matches[i + 1]);
+  }
+  #endif
+  if (numPairs > 0)
+  {
+    lenRes = p->matches[numPairs - 2];
+    if (lenRes == p->numFastBytes)
+    {
+      const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+      UInt32 distance = p->matches[numPairs - 1] + 1;
+      UInt32 numAvail = p->numAvail;
+      if (numAvail > LZMA_MATCH_LEN_MAX)
+        numAvail = LZMA_MATCH_LEN_MAX;
+      {
+        const Byte *pby2 = pby - distance;
+        for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);
+      }
+    }
+  }
+  p->additionalOffset++;
+  *numDistancePairsRes = numPairs;
+  return lenRes;
+}
+
+
+#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;
+#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;
+#define IsShortRep(p) ((p)->backPrev == 0)
+
+static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)
+{
+  return
+    GET_PRICE_0(p->isRepG0[state]) +
+    GET_PRICE_0(p->isRep0Long[state][posState]);
+}
+
+static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)
+{
+  UInt32 price;
+  if (repIndex == 0)
+  {
+    price = GET_PRICE_0(p->isRepG0[state]);
+    price += GET_PRICE_1(p->isRep0Long[state][posState]);
+  }
+  else
+  {
+    price = GET_PRICE_1(p->isRepG0[state]);
+    if (repIndex == 1)
+      price += GET_PRICE_0(p->isRepG1[state]);
+    else
+    {
+      price += GET_PRICE_1(p->isRepG1[state]);
+      price += GET_PRICE(p->isRepG2[state], repIndex - 2);
+    }
+  }
+  return price;
+}
+
+static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)
+{
+  return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +
+    GetPureRepPrice(p, repIndex, state, posState);
+}
+
+static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
+{
+  UInt32 posMem = p->opt[cur].posPrev;
+  UInt32 backMem = p->opt[cur].backPrev;
+  p->optimumEndIndex = cur;
+  do
+  {
+    if (p->opt[cur].prev1IsChar)
+    {
+      MakeAsChar(&p->opt[posMem])
+      p->opt[posMem].posPrev = posMem - 1;
+      if (p->opt[cur].prev2)
+      {
+        p->opt[posMem - 1].prev1IsChar = False;
+        p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;
+        p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;
+      }
+    }
+    {
+      UInt32 posPrev = posMem;
+      UInt32 backCur = backMem;
+      
+      backMem = p->opt[posPrev].backPrev;
+      posMem = p->opt[posPrev].posPrev;
+      
+      p->opt[posPrev].backPrev = backCur;
+      p->opt[posPrev].posPrev = cur;
+      cur = posPrev;
+    }
+  }
+  while (cur != 0);
+  *backRes = p->opt[0].backPrev;
+  p->optimumCurrentIndex  = p->opt[0].posPrev;
+  return p->optimumCurrentIndex;
+}
+
+#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)
+
+static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
+{
+  UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;
+  UInt32 matchPrice, repMatchPrice, normalMatchPrice;
+  UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];
+  UInt32 *matches;
+  const Byte *data;
+  Byte curByte, matchByte;
+  if (p->optimumEndIndex != p->optimumCurrentIndex)
+  {
+    const COptimal *opt = &p->opt[p->optimumCurrentIndex];
+    UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;
+    *backRes = opt->backPrev;
+    p->optimumCurrentIndex = opt->posPrev;
+    return lenRes;
+  }
+  p->optimumCurrentIndex = p->optimumEndIndex = 0;
+  
+  if (p->additionalOffset == 0)
+    mainLen = ReadMatchDistances(p, &numPairs);
+  else
+  {
+    mainLen = p->longestMatchLength;
+    numPairs = p->numPairs;
+  }
+
+  numAvail = p->numAvail;
+  if (numAvail < 2)
+  {
+    *backRes = (UInt32)(-1);
+    return 1;
+  }
+  if (numAvail > LZMA_MATCH_LEN_MAX)
+    numAvail = LZMA_MATCH_LEN_MAX;
+
+  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+  repMaxIndex = 0;
+  for (i = 0; i < LZMA_NUM_REPS; i++)
+  {
+    UInt32 lenTest;
+    const Byte *data2;
+    reps[i] = p->reps[i];
+    data2 = data - (reps[i] + 1);
+    if (data[0] != data2[0] || data[1] != data2[1])
+    {
+      repLens[i] = 0;
+      continue;
+    }
+    for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
+    repLens[i] = lenTest;
+    if (lenTest > repLens[repMaxIndex])
+      repMaxIndex = i;
+  }
+  if (repLens[repMaxIndex] >= p->numFastBytes)
+  {
+    UInt32 lenRes;
+    *backRes = repMaxIndex;
+    lenRes = repLens[repMaxIndex];
+    MovePos(p, lenRes - 1);
+    return lenRes;
+  }
+
+  matches = p->matches;
+  if (mainLen >= p->numFastBytes)
+  {
+    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
+    MovePos(p, mainLen - 1);
+    return mainLen;
+  }
+  curByte = *data;
+  matchByte = *(data - (reps[0] + 1));
+
+  if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)
+  {
+    *backRes = (UInt32)-1;
+    return 1;
+  }
+
+  p->opt[0].state = (CState)p->state;
+
+  posState = (position & p->pbMask);
+
+  {
+    const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
+    p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
+        (!IsCharState(p->state) ?
+          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
+          LitEnc_GetPrice(probs, curByte, p->ProbPrices));
+  }
+
+  MakeAsChar(&p->opt[1]);
+
+  matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
+  repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
+
+  if (matchByte == curByte)
+  {
+    UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);
+    if (shortRepPrice < p->opt[1].price)
+    {
+      p->opt[1].price = shortRepPrice;
+      MakeAsShortRep(&p->opt[1]);
+    }
+  }
+  lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);
+
+  if (lenEnd < 2)
+  {
+    *backRes = p->opt[1].backPrev;
+    return 1;
+  }
+
+  p->opt[1].posPrev = 0;
+  for (i = 0; i < LZMA_NUM_REPS; i++)
+    p->opt[0].backs[i] = reps[i];
+
+  len = lenEnd;
+  do
+    p->opt[len--].price = kInfinityPrice;
+  while (len >= 2);
+
+  for (i = 0; i < LZMA_NUM_REPS; i++)
+  {
+    UInt32 repLen = repLens[i];
+    UInt32 price;
+    if (repLen < 2)
+      continue;
+    price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);
+    do
+    {
+      UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];
+      COptimal *opt = &p->opt[repLen];
+      if (curAndLenPrice < opt->price)
+      {
+        opt->price = curAndLenPrice;
+        opt->posPrev = 0;
+        opt->backPrev = i;
+        opt->prev1IsChar = False;
+      }
+    }
+    while (--repLen >= 2);
+  }
+
+  normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
+
+  len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
+  if (len <= mainLen)
+  {
+    UInt32 offs = 0;
+    while (len > matches[offs])
+      offs += 2;
+    for (; ; len++)
+    {
+      COptimal *opt;
+      UInt32 distance = matches[offs + 1];
+
+      UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];
+      UInt32 lenToPosState = GetLenToPosState(len);
+      if (distance < kNumFullDistances)
+        curAndLenPrice += p->distancesPrices[lenToPosState][distance];
+      else
+      {
+        UInt32 slot;
+        GetPosSlot2(distance, slot);
+        curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];
+      }
+      opt = &p->opt[len];
+      if (curAndLenPrice < opt->price)
+      {
+        opt->price = curAndLenPrice;
+        opt->posPrev = 0;
+        opt->backPrev = distance + LZMA_NUM_REPS;
+        opt->prev1IsChar = False;
+      }
+      if (len == matches[offs])
+      {
+        offs += 2;
+        if (offs == numPairs)
+          break;
+      }
+    }
+  }
+
+  cur = 0;
+
+    #ifdef SHOW_STAT2
+    if (position >= 0)
+    {
+      unsigned i;
+      printf("\n pos = %4X", position);
+      for (i = cur; i <= lenEnd; i++)
+      printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price);
+    }
+    #endif
+
+  for (;;)
+  {
+    UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;
+    UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;
+    Bool nextIsChar;
+    Byte curByte, matchByte;
+    const Byte *data;
+    COptimal *curOpt;
+    COptimal *nextOpt;
+
+    cur++;
+    if (cur == lenEnd)
+      return Backward(p, backRes, cur);
+
+    newLen = ReadMatchDistances(p, &numPairs);
+    if (newLen >= p->numFastBytes)
+    {
+      p->numPairs = numPairs;
+      p->longestMatchLength = newLen;
+      return Backward(p, backRes, cur);
+    }
+    position++;
+    curOpt = &p->opt[cur];
+    posPrev = curOpt->posPrev;
+    if (curOpt->prev1IsChar)
+    {
+      posPrev--;
+      if (curOpt->prev2)
+      {
+        state = p->opt[curOpt->posPrev2].state;
+        if (curOpt->backPrev2 < LZMA_NUM_REPS)
+          state = kRepNextStates[state];
+        else
+          state = kMatchNextStates[state];
+      }
+      else
+        state = p->opt[posPrev].state;
+      state = kLiteralNextStates[state];
+    }
+    else
+      state = p->opt[posPrev].state;
+    if (posPrev == cur - 1)
+    {
+      if (IsShortRep(curOpt))
+        state = kShortRepNextStates[state];
+      else
+        state = kLiteralNextStates[state];
+    }
+    else
+    {
+      UInt32 pos;
+      const COptimal *prevOpt;
+      if (curOpt->prev1IsChar && curOpt->prev2)
+      {
+        posPrev = curOpt->posPrev2;
+        pos = curOpt->backPrev2;
+        state = kRepNextStates[state];
+      }
+      else
+      {
+        pos = curOpt->backPrev;
+        if (pos < LZMA_NUM_REPS)
+          state = kRepNextStates[state];
+        else
+          state = kMatchNextStates[state];
+      }
+      prevOpt = &p->opt[posPrev];
+      if (pos < LZMA_NUM_REPS)
+      {
+        UInt32 i;
+        reps[0] = prevOpt->backs[pos];
+        for (i = 1; i <= pos; i++)
+          reps[i] = prevOpt->backs[i - 1];
+        for (; i < LZMA_NUM_REPS; i++)
+          reps[i] = prevOpt->backs[i];
+      }
+      else
+      {
+        UInt32 i;
+        reps[0] = (pos - LZMA_NUM_REPS);
+        for (i = 1; i < LZMA_NUM_REPS; i++)
+          reps[i] = prevOpt->backs[i - 1];
+      }
+    }
+    curOpt->state = (CState)state;
+
+    curOpt->backs[0] = reps[0];
+    curOpt->backs[1] = reps[1];
+    curOpt->backs[2] = reps[2];
+    curOpt->backs[3] = reps[3];
+
+    curPrice = curOpt->price;
+    nextIsChar = False;
+    data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+    curByte = *data;
+    matchByte = *(data - (reps[0] + 1));
+
+    posState = (position & p->pbMask);
+
+    curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);
+    {
+      const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
+      curAnd1Price +=
+        (!IsCharState(state) ?
+          LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
+          LitEnc_GetPrice(probs, curByte, p->ProbPrices));
+    }
+
+    nextOpt = &p->opt[cur + 1];
+
+    if (curAnd1Price < nextOpt->price)
+    {
+      nextOpt->price = curAnd1Price;
+      nextOpt->posPrev = cur;
+      MakeAsChar(nextOpt);
+      nextIsChar = True;
+    }
+
+    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);
+    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
+    
+    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))
+    {
+      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);
+      if (shortRepPrice <= nextOpt->price)
+      {
+        nextOpt->price = shortRepPrice;
+        nextOpt->posPrev = cur;
+        MakeAsShortRep(nextOpt);
+        nextIsChar = True;
+      }
+    }
+    numAvailFull = p->numAvail;
+    {
+      UInt32 temp = kNumOpts - 1 - cur;
+      if (temp < numAvailFull)
+        numAvailFull = temp;
+    }
+
+    if (numAvailFull < 2)
+      continue;
+    numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);
+
+    if (!nextIsChar && matchByte != curByte) /* speed optimization */
+    {
+      /* try Literal + rep0 */
+      UInt32 temp;
+      UInt32 lenTest2;
+      const Byte *data2 = data - (reps[0] + 1);
+      UInt32 limit = p->numFastBytes + 1;
+      if (limit > numAvailFull)
+        limit = numAvailFull;
+
+      for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);
+      lenTest2 = temp - 1;
+      if (lenTest2 >= 2)
+      {
+        UInt32 state2 = kLiteralNextStates[state];
+        UInt32 posStateNext = (position + 1) & p->pbMask;
+        UInt32 nextRepMatchPrice = curAnd1Price +
+            GET_PRICE_1(p->isMatch[state2][posStateNext]) +
+            GET_PRICE_1(p->isRep[state2]);
+        /* for (; lenTest2 >= 2; lenTest2--) */
+        {
+          UInt32 curAndLenPrice;
+          COptimal *opt;
+          UInt32 offset = cur + 1 + lenTest2;
+          while (lenEnd < offset)
+            p->opt[++lenEnd].price = kInfinityPrice;
+          curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
+          opt = &p->opt[offset];
+          if (curAndLenPrice < opt->price)
+          {
+            opt->price = curAndLenPrice;
+            opt->posPrev = cur + 1;
+            opt->backPrev = 0;
+            opt->prev1IsChar = True;
+            opt->prev2 = False;
+          }
+        }
+      }
+    }
+    
+    startLen = 2; /* speed optimization */
+    {
+    UInt32 repIndex;
+    for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)
+    {
+      UInt32 lenTest;
+      UInt32 lenTestTemp;
+      UInt32 price;
+      const Byte *data2 = data - (reps[repIndex] + 1);
+      if (data[0] != data2[0] || data[1] != data2[1])
+        continue;
+      for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
+      while (lenEnd < cur + lenTest)
+        p->opt[++lenEnd].price = kInfinityPrice;
+      lenTestTemp = lenTest;
+      price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);
+      do
+      {
+        UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];
+        COptimal *opt = &p->opt[cur + lenTest];
+        if (curAndLenPrice < opt->price)
+        {
+          opt->price = curAndLenPrice;
+          opt->posPrev = cur;
+          opt->backPrev = repIndex;
+          opt->prev1IsChar = False;
+        }
+      }
+      while (--lenTest >= 2);
+      lenTest = lenTestTemp;
+      
+      if (repIndex == 0)
+        startLen = lenTest + 1;
+        
+      /* if (_maxMode) */
+        {
+          UInt32 lenTest2 = lenTest + 1;
+          UInt32 limit = lenTest2 + p->numFastBytes;
+          UInt32 nextRepMatchPrice;
+          if (limit > numAvailFull)
+            limit = numAvailFull;
+          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
+          lenTest2 -= lenTest + 1;
+          if (lenTest2 >= 2)
+          {
+            UInt32 state2 = kRepNextStates[state];
+            UInt32 posStateNext = (position + lenTest) & p->pbMask;
+            UInt32 curAndLenCharPrice =
+                price + p->repLenEnc.prices[posState][lenTest - 2] +
+                GET_PRICE_0(p->isMatch[state2][posStateNext]) +
+                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
+                    data[lenTest], data2[lenTest], p->ProbPrices);
+            state2 = kLiteralNextStates[state2];
+            posStateNext = (position + lenTest + 1) & p->pbMask;
+            nextRepMatchPrice = curAndLenCharPrice +
+                GET_PRICE_1(p->isMatch[state2][posStateNext]) +
+                GET_PRICE_1(p->isRep[state2]);
+            
+            /* for (; lenTest2 >= 2; lenTest2--) */
+            {
+              UInt32 curAndLenPrice;
+              COptimal *opt;
+              UInt32 offset = cur + lenTest + 1 + lenTest2;
+              while (lenEnd < offset)
+                p->opt[++lenEnd].price = kInfinityPrice;
+              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
+              opt = &p->opt[offset];
+              if (curAndLenPrice < opt->price)
+              {
+                opt->price = curAndLenPrice;
+                opt->posPrev = cur + lenTest + 1;
+                opt->backPrev = 0;
+                opt->prev1IsChar = True;
+                opt->prev2 = True;
+                opt->posPrev2 = cur;
+                opt->backPrev2 = repIndex;
+              }
+            }
+          }
+        }
+    }
+    }
+    /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */
+    if (newLen > numAvail)
+    {
+      newLen = numAvail;
+      for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);
+      matches[numPairs] = newLen;
+      numPairs += 2;
+    }
+    if (newLen >= startLen)
+    {
+      UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);
+      UInt32 offs, curBack, posSlot;
+      UInt32 lenTest;
+      while (lenEnd < cur + newLen)
+        p->opt[++lenEnd].price = kInfinityPrice;
+
+      offs = 0;
+      while (startLen > matches[offs])
+        offs += 2;
+      curBack = matches[offs + 1];
+      GetPosSlot2(curBack, posSlot);
+      for (lenTest = /*2*/ startLen; ; lenTest++)
+      {
+        UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];
+        UInt32 lenToPosState = GetLenToPosState(lenTest);
+        COptimal *opt;
+        if (curBack < kNumFullDistances)
+          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];
+        else
+          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];
+        
+        opt = &p->opt[cur + lenTest];
+        if (curAndLenPrice < opt->price)
+        {
+          opt->price = curAndLenPrice;
+          opt->posPrev = cur;
+          opt->backPrev = curBack + LZMA_NUM_REPS;
+          opt->prev1IsChar = False;
+        }
+
+        if (/*_maxMode && */lenTest == matches[offs])
+        {
+          /* Try Match + Literal + Rep0 */
+          const Byte *data2 = data - (curBack + 1);
+          UInt32 lenTest2 = lenTest + 1;
+          UInt32 limit = lenTest2 + p->numFastBytes;
+          UInt32 nextRepMatchPrice;
+          if (limit > numAvailFull)
+            limit = numAvailFull;
+          for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
+          lenTest2 -= lenTest + 1;
+          if (lenTest2 >= 2)
+          {
+            UInt32 state2 = kMatchNextStates[state];
+            UInt32 posStateNext = (position + lenTest) & p->pbMask;
+            UInt32 curAndLenCharPrice = curAndLenPrice +
+                GET_PRICE_0(p->isMatch[state2][posStateNext]) +
+                LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
+                    data[lenTest], data2[lenTest], p->ProbPrices);
+            state2 = kLiteralNextStates[state2];
+            posStateNext = (posStateNext + 1) & p->pbMask;
+            nextRepMatchPrice = curAndLenCharPrice +
+                GET_PRICE_1(p->isMatch[state2][posStateNext]) +
+                GET_PRICE_1(p->isRep[state2]);
+            
+            /* for (; lenTest2 >= 2; lenTest2--) */
+            {
+              UInt32 offset = cur + lenTest + 1 + lenTest2;
+              UInt32 curAndLenPrice;
+              COptimal *opt;
+              while (lenEnd < offset)
+                p->opt[++lenEnd].price = kInfinityPrice;
+              curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
+              opt = &p->opt[offset];
+              if (curAndLenPrice < opt->price)
+              {
+                opt->price = curAndLenPrice;
+                opt->posPrev = cur + lenTest + 1;
+                opt->backPrev = 0;
+                opt->prev1IsChar = True;
+                opt->prev2 = True;
+                opt->posPrev2 = cur;
+                opt->backPrev2 = curBack + LZMA_NUM_REPS;
+              }
+            }
+          }
+          offs += 2;
+          if (offs == numPairs)
+            break;
+          curBack = matches[offs + 1];
+          if (curBack >= kNumFullDistances)
+            GetPosSlot2(curBack, posSlot);
+        }
+      }
+    }
+  }
+}
+
+#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))
+
+static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
+{
+  UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;
+  const Byte *data;
+  const UInt32 *matches;
+
+  if (p->additionalOffset == 0)
+    mainLen = ReadMatchDistances(p, &numPairs);
+  else
+  {
+    mainLen = p->longestMatchLength;
+    numPairs = p->numPairs;
+  }
+
+  numAvail = p->numAvail;
+  *backRes = (UInt32)-1;
+  if (numAvail < 2)
+    return 1;
+  if (numAvail > LZMA_MATCH_LEN_MAX)
+    numAvail = LZMA_MATCH_LEN_MAX;
+  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+
+  repLen = repIndex = 0;
+  for (i = 0; i < LZMA_NUM_REPS; i++)
+  {
+    UInt32 len;
+    const Byte *data2 = data - (p->reps[i] + 1);
+    if (data[0] != data2[0] || data[1] != data2[1])
+      continue;
+    for (len = 2; len < numAvail && data[len] == data2[len]; len++);
+    if (len >= p->numFastBytes)
+    {
+      *backRes = i;
+      MovePos(p, len - 1);
+      return len;
+    }
+    if (len > repLen)
+    {
+      repIndex = i;
+      repLen = len;
+    }
+  }
+
+  matches = p->matches;
+  if (mainLen >= p->numFastBytes)
+  {
+    *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
+    MovePos(p, mainLen - 1);
+    return mainLen;
+  }
+
+  mainDist = 0; /* for GCC */
+  if (mainLen >= 2)
+  {
+    mainDist = matches[numPairs - 1];
+    while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)
+    {
+      if (!ChangePair(matches[numPairs - 3], mainDist))
+        break;
+      numPairs -= 2;
+      mainLen = matches[numPairs - 2];
+      mainDist = matches[numPairs - 1];
+    }
+    if (mainLen == 2 && mainDist >= 0x80)
+      mainLen = 1;
+  }
+
+  if (repLen >= 2 && (
+        (repLen + 1 >= mainLen) ||
+        (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||
+        (repLen + 3 >= mainLen && mainDist >= (1 << 15))))
+  {
+    *backRes = repIndex;
+    MovePos(p, repLen - 1);
+    return repLen;
+  }
+  
+  if (mainLen < 2 || numAvail <= 2)
+    return 1;
+
+  p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);
+  if (p->longestMatchLength >= 2)
+  {
+    UInt32 newDistance = matches[p->numPairs - 1];
+    if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||
+        (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||
+        (p->longestMatchLength > mainLen + 1) ||
+        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))
+      return 1;
+  }
+  
+  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+  for (i = 0; i < LZMA_NUM_REPS; i++)
+  {
+    UInt32 len, limit;
+    const Byte *data2 = data - (p->reps[i] + 1);
+    if (data[0] != data2[0] || data[1] != data2[1])
+      continue;
+    limit = mainLen - 1;
+    for (len = 2; len < limit && data[len] == data2[len]; len++);
+    if (len >= limit)
+      return 1;
+  }
+  *backRes = mainDist + LZMA_NUM_REPS;
+  MovePos(p, mainLen - 2);
+  return mainLen;
+}
+
+static void WriteEndMarker(CLzmaEnc *p, UInt32 posState)
+{
+  UInt32 len;
+  RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
+  RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
+  p->state = kMatchNextStates[p->state];
+  len = LZMA_MATCH_LEN_MIN;
+  LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
+  RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);
+  RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);
+  RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);
+}
+
+static SRes CheckErrors(CLzmaEnc *p)
+{
+  if (p->result != SZ_OK)
+    return p->result;
+  if (p->rc.res != SZ_OK)
+    p->result = SZ_ERROR_WRITE;
+  if (p->matchFinderBase.result != SZ_OK)
+    p->result = SZ_ERROR_READ;
+  if (p->result != SZ_OK)
+    p->finished = True;
+  return p->result;
+}
+
+static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
+{
+  /* ReleaseMFStream(); */
+  p->finished = True;
+  if (p->writeEndMark)
+    WriteEndMarker(p, nowPos & p->pbMask);
+  RangeEnc_FlushData(&p->rc);
+  RangeEnc_FlushStream(&p->rc);
+  return CheckErrors(p);
+}
+
+static void FillAlignPrices(CLzmaEnc *p)
+{
+  UInt32 i;
+  for (i = 0; i < kAlignTableSize; i++)
+    p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
+  p->alignPriceCount = 0;
+}
+
+static void FillDistancesPrices(CLzmaEnc *p)
+{
+  UInt32 tempPrices[kNumFullDistances];
+  UInt32 i, lenToPosState;
+  for (i = kStartPosModelIndex; i < kNumFullDistances; i++)
+  {
+    UInt32 posSlot = GetPosSlot1(i);
+    UInt32 footerBits = ((posSlot >> 1) - 1);
+    UInt32 base = ((2 | (posSlot & 1)) << footerBits);
+    tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);
+  }
+
+  for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
+  {
+    UInt32 posSlot;
+    const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];
+    UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];
+    for (posSlot = 0; posSlot < p->distTableSize; posSlot++)
+      posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);
+    for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)
+      posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
+
+    {
+      UInt32 *distancesPrices = p->distancesPrices[lenToPosState];
+      UInt32 i;
+      for (i = 0; i < kStartPosModelIndex; i++)
+        distancesPrices[i] = posSlotPrices[i];
+      for (; i < kNumFullDistances; i++)
+        distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];
+    }
+  }
+  p->matchPriceCount = 0;
+}
+
+void LzmaEnc_Construct(CLzmaEnc *p)
+{
+  RangeEnc_Construct(&p->rc);
+  MatchFinder_Construct(&p->matchFinderBase);
+  #ifndef _7ZIP_ST
+  MatchFinderMt_Construct(&p->matchFinderMt);
+  p->matchFinderMt.MatchFinder = &p->matchFinderBase;
+  #endif
+
+  {
+    CLzmaEncProps props;
+    LzmaEncProps_Init(&props);
+    LzmaEnc_SetProps(p, &props);
+  }
+
+  #ifndef LZMA_LOG_BSR
+  LzmaEnc_FastPosInit(p->g_FastPos);
+  #endif
+
+  LzmaEnc_InitPriceTables(p->ProbPrices);
+  p->litProbs = 0;
+  p->saveState.litProbs = 0;
+}
+
+CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)
+{
+  void *p;
+  p = alloc->Alloc(alloc, sizeof(CLzmaEnc));
+  if (p != 0)
+    LzmaEnc_Construct((CLzmaEnc *)p);
+  return p;
+}
+
+void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->litProbs);
+  alloc->Free(alloc, p->saveState.litProbs);
+  p->litProbs = 0;
+  p->saveState.litProbs = 0;
+}
+
+void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  #ifndef _7ZIP_ST
+  MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
+  #endif
+  MatchFinder_Free(&p->matchFinderBase, allocBig);
+  LzmaEnc_FreeLits(p, alloc);
+  RangeEnc_Free(&p->rc, alloc);
+}
+
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
+  alloc->Free(alloc, p);
+}
+
+static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)
+{
+  UInt32 nowPos32, startPos32;
+  if (p->needInit)
+  {
+    p->matchFinder.Init(p->matchFinderObj);
+    p->needInit = 0;
+  }
+
+  if (p->finished)
+    return p->result;
+  RINOK(CheckErrors(p));
+
+  nowPos32 = (UInt32)p->nowPos64;
+  startPos32 = nowPos32;
+
+  if (p->nowPos64 == 0)
+  {
+    UInt32 numPairs;
+    Byte curByte;
+    if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
+      return Flush(p, nowPos32);
+    ReadMatchDistances(p, &numPairs);
+    RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);
+    p->state = kLiteralNextStates[p->state];
+    curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);
+    LitEnc_Encode(&p->rc, p->litProbs, curByte);
+    p->additionalOffset--;
+    nowPos32++;
+  }
+
+  if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
+  for (;;)
+  {
+    UInt32 pos, len, posState;
+
+    if (p->fastMode)
+      len = GetOptimumFast(p, &pos);
+    else
+      len = GetOptimum(p, nowPos32, &pos);
+
+    #ifdef SHOW_STAT2
+    printf("\n pos = %4X,   len = %d   pos = %d", nowPos32, len, pos);
+    #endif
+
+    posState = nowPos32 & p->pbMask;
+    if (len == 1 && pos == (UInt32)-1)
+    {
+      Byte curByte;
+      CLzmaProb *probs;
+      const Byte *data;
+
+      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);
+      data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+      curByte = *data;
+      probs = LIT_PROBS(nowPos32, *(data - 1));
+      if (IsCharState(p->state))
+        LitEnc_Encode(&p->rc, probs, curByte);
+      else
+        LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));
+      p->state = kLiteralNextStates[p->state];
+    }
+    else
+    {
+      RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
+      if (pos < LZMA_NUM_REPS)
+      {
+        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);
+        if (pos == 0)
+        {
+          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);
+          RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));
+        }
+        else
+        {
+          UInt32 distance = p->reps[pos];
+          RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);
+          if (pos == 1)
+            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);
+          else
+          {
+            RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);
+            RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);
+            if (pos == 3)
+              p->reps[3] = p->reps[2];
+            p->reps[2] = p->reps[1];
+          }
+          p->reps[1] = p->reps[0];
+          p->reps[0] = distance;
+        }
+        if (len == 1)
+          p->state = kShortRepNextStates[p->state];
+        else
+        {
+          LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
+          p->state = kRepNextStates[p->state];
+        }
+      }
+      else
+      {
+        UInt32 posSlot;
+        RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
+        p->state = kMatchNextStates[p->state];
+        LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
+        pos -= LZMA_NUM_REPS;
+        GetPosSlot(pos, posSlot);
+        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
+        
+        if (posSlot >= kStartPosModelIndex)
+        {
+          UInt32 footerBits = ((posSlot >> 1) - 1);
+          UInt32 base = ((2 | (posSlot & 1)) << footerBits);
+          UInt32 posReduced = pos - base;
+
+          if (posSlot < kEndPosModelIndex)
+            RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);
+          else
+          {
+            RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
+            RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
+            p->alignPriceCount++;
+          }
+        }
+        p->reps[3] = p->reps[2];
+        p->reps[2] = p->reps[1];
+        p->reps[1] = p->reps[0];
+        p->reps[0] = pos;
+        p->matchPriceCount++;
+      }
+    }
+    p->additionalOffset -= len;
+    nowPos32 += len;
+    if (p->additionalOffset == 0)
+    {
+      UInt32 processed;
+      if (!p->fastMode)
+      {
+        if (p->matchPriceCount >= (1 << 7))
+          FillDistancesPrices(p);
+        if (p->alignPriceCount >= kAlignTableSize)
+          FillAlignPrices(p);
+      }
+      if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
+        break;
+      processed = nowPos32 - startPos32;
+      if (useLimits)
+      {
+        if (processed + kNumOpts + 300 >= maxUnpackSize ||
+            RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)
+          break;
+      }
+      else if (processed >= (1 << 15))
+      {
+        p->nowPos64 += nowPos32 - startPos32;
+        return CheckErrors(p);
+      }
+    }
+  }
+  p->nowPos64 += nowPos32 - startPos32;
+  return Flush(p, nowPos32);
+}
+
+#define kBigHashDicLimit ((UInt32)1 << 24)
+
+static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  UInt32 beforeSize = kNumOpts;
+  Bool btMode;
+  if (!RangeEnc_Alloc(&p->rc, alloc))
+    return SZ_ERROR_MEM;
+  btMode = (p->matchFinderBase.btMode != 0);
+  #ifndef _7ZIP_ST
+  p->mtMode = (p->multiThread && !p->fastMode && btMode);
+  #endif
+
+  {
+    unsigned lclp = p->lc + p->lp;
+    if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)
+    {
+      LzmaEnc_FreeLits(p, alloc);
+      p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
+      p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
+      if (p->litProbs == 0 || p->saveState.litProbs == 0)
+      {
+        LzmaEnc_FreeLits(p, alloc);
+        return SZ_ERROR_MEM;
+      }
+      p->lclp = lclp;
+    }
+  }
+
+  p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);
+
+  if (beforeSize + p->dictSize < keepWindowSize)
+    beforeSize = keepWindowSize - p->dictSize;
+
+  #ifndef _7ZIP_ST
+  if (p->mtMode)
+  {
+    RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));
+    p->matchFinderObj = &p->matchFinderMt;
+    MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
+  }
+  else
+  #endif
+  {
+    if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
+      return SZ_ERROR_MEM;
+    p->matchFinderObj = &p->matchFinderBase;
+    MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
+  }
+  return SZ_OK;
+}
+
+void LzmaEnc_Init(CLzmaEnc *p)
+{
+  UInt32 i;
+  p->state = 0;
+  for (i = 0 ; i < LZMA_NUM_REPS; i++)
+    p->reps[i] = 0;
+
+  RangeEnc_Init(&p->rc);
+
+
+  for (i = 0; i < kNumStates; i++)
+  {
+    UInt32 j;
+    for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
+    {
+      p->isMatch[i][j] = kProbInitValue;
+      p->isRep0Long[i][j] = kProbInitValue;
+    }
+    p->isRep[i] = kProbInitValue;
+    p->isRepG0[i] = kProbInitValue;
+    p->isRepG1[i] = kProbInitValue;
+    p->isRepG2[i] = kProbInitValue;
+  }
+
+  {
+    UInt32 num = 0x300 << (p->lp + p->lc);
+    for (i = 0; i < num; i++)
+      p->litProbs[i] = kProbInitValue;
+  }
+
+  {
+    for (i = 0; i < kNumLenToPosStates; i++)
+    {
+      CLzmaProb *probs = p->posSlotEncoder[i];
+      UInt32 j;
+      for (j = 0; j < (1 << kNumPosSlotBits); j++)
+        probs[j] = kProbInitValue;
+    }
+  }
+  {
+    for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)
+      p->posEncoders[i] = kProbInitValue;
+  }
+
+  LenEnc_Init(&p->lenEnc.p);
+  LenEnc_Init(&p->repLenEnc.p);
+
+  for (i = 0; i < (1 << kNumAlignBits); i++)
+    p->posAlignEncoder[i] = kProbInitValue;
+
+  p->optimumEndIndex = 0;
+  p->optimumCurrentIndex = 0;
+  p->additionalOffset = 0;
+
+  p->pbMask = (1 << p->pb) - 1;
+  p->lpMask = (1 << p->lp) - 1;
+}
+
+void LzmaEnc_InitPrices(CLzmaEnc *p)
+{
+  if (!p->fastMode)
+  {
+    FillDistancesPrices(p);
+    FillAlignPrices(p);
+  }
+
+  p->lenEnc.tableSize =
+  p->repLenEnc.tableSize =
+      p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
+  LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);
+  LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);
+}
+
+static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  UInt32 i;
+  for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)
+    if (p->dictSize <= ((UInt32)1 << i))
+      break;
+  p->distTableSize = i * 2;
+
+  p->finished = False;
+  p->result = SZ_OK;
+  RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));
+  LzmaEnc_Init(p);
+  LzmaEnc_InitPrices(p);
+  p->nowPos64 = 0;
+  return SZ_OK;
+}
+
+static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
+    ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  p->matchFinderBase.stream = inStream;
+  p->needInit = 1;
+  p->rc.outStream = outStream;
+  return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
+}
+
+SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
+    ISeqInStream *inStream, UInt32 keepWindowSize,
+    ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  p->matchFinderBase.stream = inStream;
+  p->needInit = 1;
+  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
+}
+
+static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
+{
+  p->matchFinderBase.directInput = 1;
+  p->matchFinderBase.bufferBase = (Byte *)src;
+  p->matchFinderBase.directInputRem = srcLen;
+}
+
+SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
+    UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  LzmaEnc_SetInputBuf(p, src, srcLen);
+  p->needInit = 1;
+
+  return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
+}
+
+void LzmaEnc_Finish(CLzmaEncHandle pp)
+{
+  #ifndef _7ZIP_ST
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  if (p->mtMode)
+    MatchFinderMt_ReleaseStream(&p->matchFinderMt);
+  #else
+  pp = pp;
+  #endif
+}
+
+typedef struct
+{
+  ISeqOutStream funcTable;
+  Byte *data;
+  SizeT rem;
+  Bool overflow;
+} CSeqOutStreamBuf;
+
+static size_t MyWrite(void *pp, const void *data, size_t size)
+{
+  CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;
+  if (p->rem < size)
+  {
+    size = p->rem;
+    p->overflow = True;
+  }
+  memcpy(p->data, data, size);
+  p->rem -= size;
+  p->data += size;
+  return size;
+}
+
+
+UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
+{
+  const CLzmaEnc *p = (CLzmaEnc *)pp;
+  return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+}
+
+const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
+{
+  const CLzmaEnc *p = (CLzmaEnc *)pp;
+  return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
+}
+
+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
+    Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  UInt64 nowPos64;
+  SRes res;
+  CSeqOutStreamBuf outStream;
+
+  outStream.funcTable.Write = MyWrite;
+  outStream.data = dest;
+  outStream.rem = *destLen;
+  outStream.overflow = False;
+
+  p->writeEndMark = False;
+  p->finished = False;
+  p->result = SZ_OK;
+
+  if (reInit)
+    LzmaEnc_Init(p);
+  LzmaEnc_InitPrices(p);
+  nowPos64 = p->nowPos64;
+  RangeEnc_Init(&p->rc);
+  p->rc.outStream = &outStream.funcTable;
+
+  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
+  
+  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
+  *destLen -= outStream.rem;
+  if (outStream.overflow)
+    return SZ_ERROR_OUTPUT_EOF;
+
+  return res;
+}
+
+static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
+{
+  SRes res = SZ_OK;
+
+  #ifndef _7ZIP_ST
+  Byte allocaDummy[0x300];
+  int i = 0;
+  for (i = 0; i < 16; i++)
+    allocaDummy[i] = (Byte)i;
+  #endif
+
+  for (;;)
+  {
+    res = LzmaEnc_CodeOneBlock(p, False, 0, 0);
+    if (res != SZ_OK || p->finished != 0)
+      break;
+    if (progress != 0)
+    {
+      res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
+      if (res != SZ_OK)
+      {
+        res = SZ_ERROR_PROGRESS;
+        break;
+      }
+    }
+  }
+  LzmaEnc_Finish(p);
+  return res;
+}
+
+SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
+    ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
+  return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
+}
+
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
+{
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+  int i;
+  UInt32 dictSize = p->dictSize;
+  if (*size < LZMA_PROPS_SIZE)
+    return SZ_ERROR_PARAM;
+  *size = LZMA_PROPS_SIZE;
+  props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
+
+  for (i = 11; i <= 30; i++)
+  {
+    if (dictSize <= ((UInt32)2 << i))
+    {
+      dictSize = (2 << i);
+      break;
+    }
+    if (dictSize <= ((UInt32)3 << i))
+    {
+      dictSize = (3 << i);
+      break;
+    }
+  }
+
+  for (i = 0; i < 4; i++)
+    props[1 + i] = (Byte)(dictSize >> (8 * i));
+  return SZ_OK;
+}
+
+SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  SRes res;
+  CLzmaEnc *p = (CLzmaEnc *)pp;
+
+  CSeqOutStreamBuf outStream;
+
+  LzmaEnc_SetInputBuf(p, src, srcLen);
+
+  outStream.funcTable.Write = MyWrite;
+  outStream.data = dest;
+  outStream.rem = *destLen;
+  outStream.overflow = False;
+
+  p->writeEndMark = writeEndMark;
+
+  p->rc.outStream = &outStream.funcTable;
+  res = LzmaEnc_MemPrepare(pp, src, srcLen, 0, alloc, allocBig);
+  if (res == SZ_OK)
+    res = LzmaEnc_Encode2(p, progress);
+
+  *destLen -= outStream.rem;
+  if (outStream.overflow)
+    return SZ_ERROR_OUTPUT_EOF;
+  return res;
+}
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
+{
+  CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
+  SRes res;
+  if (p == 0)
+    return SZ_ERROR_MEM;
+
+  res = LzmaEnc_SetProps(p, props);
+  if (res == SZ_OK)
+  {
+    res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
+    if (res == SZ_OK)
+      res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
+          writeEndMark, progress, alloc, allocBig);
+  }
+
+  LzmaEnc_Destroy(p, alloc, allocBig);
+  return res;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaEnc.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,80 @@
+/*  LzmaEnc.h -- LZMA Encoder
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA_ENC_H
+#define __LZMA_ENC_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LZMA_PROPS_SIZE 5
+
+typedef struct _CLzmaEncProps
+{
+  int level;       /*  0 <= level <= 9 */
+  UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
+                      (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
+                       default = (1 << 24) */
+  int lc;          /* 0 <= lc <= 8, default = 3 */
+  int lp;          /* 0 <= lp <= 4, default = 0 */
+  int pb;          /* 0 <= pb <= 4, default = 2 */
+  int algo;        /* 0 - fast, 1 - normal, default = 1 */
+  int fb;          /* 5 <= fb <= 273, default = 32 */
+  int btMode;      /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
+  int numHashBytes; /* 2, 3 or 4, default = 4 */
+  UInt32 mc;        /* 1 <= mc <= (1 << 30), default = 32 */
+  unsigned writeEndMark;  /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
+  int numThreads;  /* 1 or 2, default = 2 */
+} CLzmaEncProps;
+
+void LzmaEncProps_Init(CLzmaEncProps *p);
+void LzmaEncProps_Normalize(CLzmaEncProps *p);
+UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
+
+
+/* ---------- CLzmaEncHandle Interface ---------- */
+
+/* LzmaEnc_* functions can return the following exit codes:
+Returns:
+  SZ_OK           - OK
+  SZ_ERROR_MEM    - Memory allocation error
+  SZ_ERROR_PARAM  - Incorrect paramater in props
+  SZ_ERROR_WRITE  - Write callback error.
+  SZ_ERROR_PROGRESS - some break from progress callback
+  SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
+*/
+
+typedef void * CLzmaEncHandle;
+
+CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
+void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
+SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
+SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
+SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
+    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+    int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+
+/* ---------- One Call Interface ---------- */
+
+/* LzmaEncode
+Return code:
+  SZ_OK               - OK
+  SZ_ERROR_MEM        - Memory allocation error
+  SZ_ERROR_PARAM      - Incorrect paramater
+  SZ_ERROR_OUTPUT_EOF - output buffer overflow
+  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
+*/
+
+SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
+    const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+    ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,61 @@
+/* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder
+2008-04-07
+Igor Pavlov
+Public domain */
+
+#include "Lzma86Dec.h"
+
+#include "../Alloc.h"
+#include "../Bra.h"
+#include "../LzmaDec.h"
+
+#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)
+#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize)
+{
+  unsigned i;
+  if (srcLen < LZMA86_HEADER_SIZE)
+    return SZ_ERROR_INPUT_EOF;
+  *unpackSize = 0;
+  for (i = 0; i < sizeof(UInt64); i++)
+    *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i);
+  return SZ_OK;
+}
+
+SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
+{
+  SRes res;
+  int useFilter;
+  SizeT inSizePure;
+  ELzmaStatus status;
+
+  if (*srcLen < LZMA86_HEADER_SIZE)
+    return SZ_ERROR_INPUT_EOF;
+
+  useFilter = src[0];
+
+  if (useFilter > 1)
+  {
+    *destLen = 0;
+    return SZ_ERROR_UNSUPPORTED;
+  }
+
+  inSizePure = *srcLen - LZMA86_HEADER_SIZE;
+  res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure,
+      src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc);
+  *srcLen = inSizePure + LZMA86_HEADER_SIZE;
+  if (res != SZ_OK)
+    return res;
+  if (useFilter == 1)
+  {
+    UInt32 x86State;
+    x86_Convert_Init(x86State);
+    x86_Convert(dest, *destLen, 0, &x86State, 0);
+  }
+  return SZ_OK;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Dec.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,51 @@
+/* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA86_DEC_H
+#define __LZMA86_DEC_H
+
+#include "../Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+Lzma86_GetUnpackSize:
+  In:
+    src      - input data
+    srcLen   - input data size
+  Out:
+    unpackSize - size of uncompressed stream
+  Return code:
+    SZ_OK               - OK
+    SZ_ERROR_INPUT_EOF  - Error in headers
+*/
+
+SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);
+
+/*
+Lzma86_Decode:
+  In:
+    dest     - output data
+    destLen  - output data size
+    src      - input data
+    srcLen   - input data size
+  Out:
+    destLen  - processed output size
+    srcLen   - processed input size
+  Return code:
+    SZ_OK           - OK
+    SZ_ERROR_DATA  - Data error
+    SZ_ERROR_MEM   - Memory allocation error
+    SZ_ERROR_UNSUPPORTED - unsupported file
+    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer
+*/
+
+SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,113 @@
+/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
+2008-08-05
+Igor Pavlov
+Public domain */
+
+#include <string.h>
+
+#include "Lzma86Enc.h"
+
+#include "../Alloc.h"
+#include "../Bra.h"
+#include "../LzmaEnc.h"
+
+#define SZE_OUT_OVERFLOW SZE_DATA_ERROR
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)
+#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)
+
+int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
+    int level, UInt32 dictSize, int filterMode)
+{
+  size_t outSize2 = *destLen;
+  Byte *filteredStream;
+  Bool useFilter;
+  int mainResult = SZ_ERROR_OUTPUT_EOF;
+  CLzmaEncProps props;
+  LzmaEncProps_Init(&props);
+  props.level = level;
+  props.dictSize = dictSize;
+  
+  *destLen = 0;
+  if (outSize2 < LZMA86_HEADER_SIZE)
+    return SZ_ERROR_OUTPUT_EOF;
+
+  {
+    int i;
+    UInt64 t = srcLen;
+    for (i = 0; i < 8; i++, t >>= 8)
+      dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;
+  }
+
+  filteredStream = 0;
+  useFilter = (filterMode != SZ_FILTER_NO);
+  if (useFilter)
+  {
+    if (srcLen != 0)
+    {
+      filteredStream = (Byte *)MyAlloc(srcLen);
+      if (filteredStream == 0)
+        return SZ_ERROR_MEM;
+      memcpy(filteredStream, src, srcLen);
+    }
+    {
+      UInt32 x86State;
+      x86_Convert_Init(x86State);
+      x86_Convert(filteredStream, srcLen, 0, &x86State, 1);
+    }
+  }
+
+  {
+    size_t minSize = 0;
+    Bool bestIsFiltered = False;
+
+    /* passes for SZ_FILTER_AUTO:
+        0 - BCJ + LZMA
+        1 - LZMA
+        2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.
+    */
+    int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;
+
+    int i;
+    for (i = 0; i < numPasses; i++)
+    {
+      size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;
+      size_t outPropsSize = 5;
+      SRes curRes;
+      Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);
+      if (curModeIsFiltered && !bestIsFiltered)
+        break;
+      if (useFilter && i == 0)
+        curModeIsFiltered = True;
+      
+      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,
+          curModeIsFiltered ? filteredStream : src, srcLen,
+          &props, dest + 1, &outPropsSize, 0,
+          NULL, &g_Alloc, &g_Alloc);
+      
+      if (curRes != SZ_ERROR_OUTPUT_EOF)
+      {
+        if (curRes != SZ_OK)
+        {
+          mainResult = curRes;
+          break;
+        }
+        if (outSizeProcessed <= minSize || mainResult != SZ_OK)
+        {
+          minSize = outSizeProcessed;
+          bestIsFiltered = curModeIsFiltered;
+          mainResult = SZ_OK;
+        }
+      }
+    }
+    dest[0] = (bestIsFiltered ? 1 : 0);
+    *destLen = LZMA86_HEADER_SIZE + minSize;
+  }
+  if (useFilter)
+    MyFree(filteredStream);
+  return mainResult;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/LzmaUtil/Lzma86Enc.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,78 @@
+/* Lzma86Enc.h -- LZMA + x86 (BCJ) Filter Encoder
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __LZMA86_ENC_H
+#define __LZMA86_ENC_H
+
+#include "../Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+It's an example for LZMA + x86 Filter use.
+You can use .lzma86 extension, if you write that stream to file.
+.lzma86 header adds one additional byte to standard .lzma header.
+.lzma86 header (14 bytes):
+  Offset Size  Description
+    0     1    = 0 - no filter,
+               = 1 - x86 filter
+    1     1    lc, lp and pb in encoded form
+    2     4    dictSize (little endian)
+    6     8    uncompressed size (little endian)
+
+
+Lzma86_Encode
+-------------
+level - compression level: 0 <= level <= 9, the default value for "level" is 5.
+
+
+dictSize - The dictionary size in bytes. The maximum value is
+        128 MB = (1 << 27) bytes for 32-bit version
+          1 GB = (1 << 30) bytes for 64-bit version
+     The default value is 16 MB = (1 << 24) bytes, for level = 5.
+     It's recommended to use the dictionary that is larger than 4 KB and
+     that can be calculated as (1 << N) or (3 << N) sizes.
+     For better compression ratio dictSize must be >= inSize.
+
+filterMode:
+    SZ_FILTER_NO   - no Filter
+    SZ_FILTER_YES  - x86 Filter
+    SZ_FILTER_AUTO - it tries both alternatives to select best.
+              Encoder will use 2 or 3 passes:
+              2 passes when FILTER_NO provides better compression.
+              3 passes when FILTER_YES provides better compression.
+
+Lzma86Encode allocates Data with MyAlloc functions.
+RAM Requirements for compressing:
+  RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize
+      filterMode     FilterBlockSize
+     SZ_FILTER_NO         0
+     SZ_FILTER_YES      inSize
+     SZ_FILTER_AUTO     inSize
+
+
+Return code:
+  SZ_OK               - OK
+  SZ_ERROR_MEM        - Memory allocation error
+  SZ_ERROR_PARAM      - Incorrect paramater
+  SZ_ERROR_OUTPUT_EOF - output buffer overflow
+  SZ_ERROR_THREAD     - errors in multithreading functions (only for Mt version)
+*/
+
+enum ESzFilterMode
+{
+  SZ_FILTER_NO,
+  SZ_FILTER_YES,
+  SZ_FILTER_AUTO
+};
+
+SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
+    int level, UInt32 dictSize, int filterMode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,327 @@
+/* MtCoder.c -- Multi-thread Coder
+2010-09-24 : Igor Pavlov : Public domain */
+
+#include <stdio.h>
+
+#include "MtCoder.h"
+
+void LoopThread_Construct(CLoopThread *p)
+{
+  Thread_Construct(&p->thread);
+  Event_Construct(&p->startEvent);
+  Event_Construct(&p->finishedEvent);
+}
+
+void LoopThread_Close(CLoopThread *p)
+{
+  Thread_Close(&p->thread);
+  Event_Close(&p->startEvent);
+  Event_Close(&p->finishedEvent);
+}
+
+static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE LoopThreadFunc(void *pp)
+{
+  CLoopThread *p = (CLoopThread *)pp;
+  for (;;)
+  {
+    if (Event_Wait(&p->startEvent) != 0)
+      return SZ_ERROR_THREAD;
+    if (p->stop)
+      return 0;
+    p->res = p->func(p->param);
+    if (Event_Set(&p->finishedEvent) != 0)
+      return SZ_ERROR_THREAD;
+  }
+}
+
+WRes LoopThread_Create(CLoopThread *p)
+{
+  p->stop = 0;
+  RINOK(AutoResetEvent_CreateNotSignaled(&p->startEvent));
+  RINOK(AutoResetEvent_CreateNotSignaled(&p->finishedEvent));
+  return Thread_Create(&p->thread, LoopThreadFunc, p);
+}
+
+WRes LoopThread_StopAndWait(CLoopThread *p)
+{
+  p->stop = 1;
+  if (Event_Set(&p->startEvent) != 0)
+    return SZ_ERROR_THREAD;
+  return Thread_Wait(&p->thread);
+}
+
+WRes LoopThread_StartSubThread(CLoopThread *p) { return Event_Set(&p->startEvent); }
+WRes LoopThread_WaitSubThread(CLoopThread *p) { return Event_Wait(&p->finishedEvent); }
+
+static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
+{
+  return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;
+}
+
+static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress)
+{
+  unsigned i;
+  for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
+    p->inSizes[i] = p->outSizes[i] = 0;
+  p->totalInSize = p->totalOutSize = 0;
+  p->progress = progress;
+  p->res = SZ_OK;
+}
+
+static void MtProgress_Reinit(CMtProgress *p, unsigned index)
+{
+  p->inSizes[index] = 0;
+  p->outSizes[index] = 0;
+}
+
+#define UPDATE_PROGRESS(size, prev, total) \
+  if (size != (UInt64)(Int64)-1) { total += size - prev; prev = size; }
+
+SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize)
+{
+  SRes res;
+  CriticalSection_Enter(&p->cs);
+  UPDATE_PROGRESS(inSize, p->inSizes[index], p->totalInSize)
+  UPDATE_PROGRESS(outSize, p->outSizes[index], p->totalOutSize)
+  if (p->res == SZ_OK)
+    p->res = Progress(p->progress, p->totalInSize, p->totalOutSize);
+  res = p->res;
+  CriticalSection_Leave(&p->cs);
+  return res;
+}
+
+static void MtProgress_SetError(CMtProgress *p, SRes res)
+{
+  CriticalSection_Enter(&p->cs);
+  if (p->res == SZ_OK)
+    p->res = res;
+  CriticalSection_Leave(&p->cs);
+}
+
+static void MtCoder_SetError(CMtCoder* p, SRes res)
+{
+  CriticalSection_Enter(&p->cs);
+  if (p->res == SZ_OK)
+    p->res = res;
+  CriticalSection_Leave(&p->cs);
+}
+
+/* ---------- MtThread ---------- */
+
+void CMtThread_Construct(CMtThread *p, CMtCoder *mtCoder)
+{
+  p->mtCoder = mtCoder;
+  p->outBuf = 0;
+  p->inBuf = 0;
+  Event_Construct(&p->canRead);
+  Event_Construct(&p->canWrite);
+  LoopThread_Construct(&p->thread);
+}
+
+#define RINOK_THREAD(x) { if((x) != 0) return SZ_ERROR_THREAD; }
+
+static void CMtThread_CloseEvents(CMtThread *p)
+{
+  Event_Close(&p->canRead);
+  Event_Close(&p->canWrite);
+}
+
+static void CMtThread_Destruct(CMtThread *p)
+{
+  CMtThread_CloseEvents(p);
+
+  if (Thread_WasCreated(&p->thread.thread))
+  {
+    LoopThread_StopAndWait(&p->thread);
+    LoopThread_Close(&p->thread);
+  }
+
+  if (p->mtCoder->alloc)
+    IAlloc_Free(p->mtCoder->alloc, p->outBuf);
+  p->outBuf = 0;
+
+  if (p->mtCoder->alloc)
+    IAlloc_Free(p->mtCoder->alloc, p->inBuf);
+  p->inBuf = 0;
+}
+
+#define MY_BUF_ALLOC(buf, size, newSize) \
+  if (buf == 0 || size != newSize) \
+  { IAlloc_Free(p->mtCoder->alloc, buf); \
+    size = newSize; buf = (Byte *)IAlloc_Alloc(p->mtCoder->alloc, size); \
+    if (buf == 0) return SZ_ERROR_MEM; }
+
+static SRes CMtThread_Prepare(CMtThread *p)
+{
+  MY_BUF_ALLOC(p->inBuf, p->inBufSize, p->mtCoder->blockSize)
+  MY_BUF_ALLOC(p->outBuf, p->outBufSize, p->mtCoder->destBlockSize)
+
+  p->stopReading = False;
+  p->stopWriting = False;
+  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canRead));
+  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canWrite));
+
+  return SZ_OK;
+}
+
+static SRes FullRead(ISeqInStream *stream, Byte *data, size_t *processedSize)
+{
+  size_t size = *processedSize;
+  *processedSize = 0;
+  while (size != 0)
+  {
+    size_t curSize = size;
+    SRes res = stream->Read(stream, data, &curSize);
+    *processedSize += curSize;
+    data += curSize;
+    size -= curSize;
+    RINOK(res);
+    if (curSize == 0)
+      return SZ_OK;
+  }
+  return SZ_OK;
+}
+
+#define GET_NEXT_THREAD(p) &p->mtCoder->threads[p->index == p->mtCoder->numThreads  - 1 ? 0 : p->index + 1]
+
+static SRes MtThread_Process(CMtThread *p, Bool *stop)
+{
+  CMtThread *next;
+  *stop = True;
+  if (Event_Wait(&p->canRead) != 0)
+    return SZ_ERROR_THREAD;
+  
+  next = GET_NEXT_THREAD(p);
+  
+  if (p->stopReading)
+  {
+    next->stopReading = True;
+    return Event_Set(&next->canRead) == 0 ? SZ_OK : SZ_ERROR_THREAD;
+  }
+
+  {
+    size_t size = p->mtCoder->blockSize;
+    size_t destSize = p->outBufSize;
+
+    RINOK(FullRead(p->mtCoder->inStream, p->inBuf, &size));
+    next->stopReading = *stop = (size != p->mtCoder->blockSize);
+    if (Event_Set(&next->canRead) != 0)
+      return SZ_ERROR_THREAD;
+
+    RINOK(p->mtCoder->mtCallback->Code(p->mtCoder->mtCallback, p->index,
+        p->outBuf, &destSize, p->inBuf, size, *stop));
+
+    MtProgress_Reinit(&p->mtCoder->mtProgress, p->index);
+
+    if (Event_Wait(&p->canWrite) != 0)
+      return SZ_ERROR_THREAD;
+    if (p->stopWriting)
+      return SZ_ERROR_FAIL;
+    if (p->mtCoder->outStream->Write(p->mtCoder->outStream, p->outBuf, destSize) != destSize)
+      return SZ_ERROR_WRITE;
+    return Event_Set(&next->canWrite) == 0 ? SZ_OK : SZ_ERROR_THREAD;
+  }
+}
+
+static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE ThreadFunc(void *pp)
+{
+  CMtThread *p = (CMtThread *)pp;
+  for (;;)
+  {
+    Bool stop;
+    CMtThread *next = GET_NEXT_THREAD(p);
+    SRes res = MtThread_Process(p, &stop);
+    if (res != SZ_OK)
+    {
+      MtCoder_SetError(p->mtCoder, res);
+      MtProgress_SetError(&p->mtCoder->mtProgress, res);
+      next->stopReading = True;
+      next->stopWriting = True;
+      Event_Set(&next->canRead);
+      Event_Set(&next->canWrite);
+      return res;
+    }
+    if (stop)
+      return 0;
+  }
+}
+
+void MtCoder_Construct(CMtCoder* p)
+{
+  unsigned i;
+  p->alloc = 0;
+  for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
+  {
+    CMtThread *t = &p->threads[i];
+    t->index = i;
+    CMtThread_Construct(t, p);
+  }
+  CriticalSection_Init(&p->cs);
+  CriticalSection_Init(&p->mtProgress.cs);
+}
+
+void MtCoder_Destruct(CMtCoder* p)
+{
+  unsigned i;
+  for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
+    CMtThread_Destruct(&p->threads[i]);
+  CriticalSection_Delete(&p->cs);
+  CriticalSection_Delete(&p->mtProgress.cs);
+}
+
+SRes MtCoder_Code(CMtCoder *p)
+{
+  unsigned i, numThreads = p->numThreads;
+  SRes res = SZ_OK;
+  p->res = SZ_OK;
+
+  MtProgress_Init(&p->mtProgress, p->progress);
+
+  for (i = 0; i < numThreads; i++)
+  {
+    RINOK(CMtThread_Prepare(&p->threads[i]));
+  }
+
+  for (i = 0; i < numThreads; i++)
+  {
+    CMtThread *t = &p->threads[i];
+    CLoopThread *lt = &t->thread;
+
+    if (!Thread_WasCreated(&lt->thread))
+    {
+      lt->func = ThreadFunc;
+      lt->param = t;
+
+      if (LoopThread_Create(lt) != SZ_OK)
+      {
+        res = SZ_ERROR_THREAD;
+        break;
+      }
+    }
+  }
+
+  if (res == SZ_OK)
+  {
+    unsigned j;
+    for (i = 0; i < numThreads; i++)
+    {
+      CMtThread *t = &p->threads[i];
+      if (LoopThread_StartSubThread(&t->thread) != SZ_OK)
+      {
+        res = SZ_ERROR_THREAD;
+        p->threads[0].stopReading = True;
+        break;
+      }
+    }
+
+    Event_Set(&p->threads[0].canWrite);
+    Event_Set(&p->threads[0].canRead);
+
+    for (j = 0; j < i; j++)
+      LoopThread_WaitSubThread(&p->threads[j].thread);
+  }
+
+  for (i = 0; i < numThreads; i++)
+    CMtThread_CloseEvents(&p->threads[i]);
+  return (res == SZ_OK) ? p->res : res;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/MtCoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,98 @@
+/* MtCoder.h -- Multi-thread Coder
+2009-11-19 : Igor Pavlov : Public domain */
+
+#ifndef __MT_CODER_H
+#define __MT_CODER_H
+
+#include "Threads.h"
+
+EXTERN_C_BEGIN
+
+typedef struct
+{
+  CThread thread;
+  CAutoResetEvent startEvent;
+  CAutoResetEvent finishedEvent;
+  int stop;
+  
+  THREAD_FUNC_TYPE func;
+  LPVOID param;
+  THREAD_FUNC_RET_TYPE res;
+} CLoopThread;
+
+void LoopThread_Construct(CLoopThread *p);
+void LoopThread_Close(CLoopThread *p);
+WRes LoopThread_Create(CLoopThread *p);
+WRes LoopThread_StopAndWait(CLoopThread *p);
+WRes LoopThread_StartSubThread(CLoopThread *p);
+WRes LoopThread_WaitSubThread(CLoopThread *p);
+
+#ifndef _7ZIP_ST
+#define NUM_MT_CODER_THREADS_MAX 32
+#else
+#define NUM_MT_CODER_THREADS_MAX 1
+#endif
+
+typedef struct
+{
+  UInt64 totalInSize;
+  UInt64 totalOutSize;
+  ICompressProgress *progress;
+  SRes res;
+  CCriticalSection cs;
+  UInt64 inSizes[NUM_MT_CODER_THREADS_MAX];
+  UInt64 outSizes[NUM_MT_CODER_THREADS_MAX];
+} CMtProgress;
+
+SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize);
+
+struct _CMtCoder;
+
+typedef struct
+{
+  struct _CMtCoder *mtCoder;
+  Byte *outBuf;
+  size_t outBufSize;
+  Byte *inBuf;
+  size_t inBufSize;
+  unsigned index;
+  CLoopThread thread;
+
+  Bool stopReading;
+  Bool stopWriting;
+  CAutoResetEvent canRead;
+  CAutoResetEvent canWrite;
+} CMtThread;
+
+typedef struct
+{
+  SRes (*Code)(void *p, unsigned index, Byte *dest, size_t *destSize,
+      const Byte *src, size_t srcSize, int finished);
+} IMtCoderCallback;
+
+typedef struct _CMtCoder
+{
+  size_t blockSize;
+  size_t destBlockSize;
+  unsigned numThreads;
+  
+  ISeqInStream *inStream;
+  ISeqOutStream *outStream;
+  ICompressProgress *progress;
+  ISzAlloc *alloc;
+
+  IMtCoderCallback *mtCallback;
+  CCriticalSection cs;
+  SRes res;
+
+  CMtProgress mtProgress;
+  CMtThread threads[NUM_MT_CODER_THREADS_MAX];
+} CMtCoder;
+
+void MtCoder_Construct(CMtCoder* p);
+void MtCoder_Destruct(CMtCoder* p);
+SRes MtCoder_Code(CMtCoder *p);
+
+EXTERN_C_END
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,85 @@
+/* Ppmd.h -- PPMD codec common code
+2010-03-12 : Igor Pavlov : Public domain
+This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
+
+#ifndef __PPMD_H
+#define __PPMD_H
+
+#include "Types.h"
+#include "CpuArch.h"
+
+EXTERN_C_BEGIN
+
+#ifdef MY_CPU_32BIT
+  #define PPMD_32BIT
+#endif
+
+#define PPMD_INT_BITS 7
+#define PPMD_PERIOD_BITS 7
+#define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS))
+
+#define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift))
+#define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2)
+#define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob))
+#define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob))
+
+#define PPMD_N1 4
+#define PPMD_N2 4
+#define PPMD_N3 4
+#define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4)
+#define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4)
+
+#pragma pack(push,1)
+
+/* SEE-contexts for PPM-contexts with masked symbols */
+typedef struct
+{
+  UInt16 Summ; /* Freq */
+  Byte Shift;  /* Speed of Freq change; low Shift is for fast change */
+  Byte Count;  /* Count to next change of Shift */
+} CPpmd_See;
+
+#define Ppmd_See_Update(p)  if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \
+    { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); }
+
+typedef struct
+{
+  Byte Symbol;
+  Byte Freq;
+  UInt16 SuccessorLow;
+  UInt16 SuccessorHigh;
+} CPpmd_State;
+
+#pragma pack(pop)
+
+typedef
+  #ifdef PPMD_32BIT
+    CPpmd_State *
+  #else
+    UInt32
+  #endif
+  CPpmd_State_Ref;
+
+typedef
+  #ifdef PPMD_32BIT
+    void *
+  #else
+    UInt32
+  #endif
+  CPpmd_Void_Ref;
+
+typedef
+  #ifdef PPMD_32BIT
+    Byte *
+  #else
+    UInt32
+  #endif
+  CPpmd_Byte_Ref;
+
+#define PPMD_SetAllBitsIn256Bytes(p) \
+  { unsigned i; for (i = 0; i < 256 / sizeof(p[0]); i += 8) { \
+  p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }}
+
+EXTERN_C_END
+ 
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,708 @@
+/* Ppmd7.c -- PPMdH codec
+2010-03-12 : Igor Pavlov : Public domain
+This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
+
+#include <memory.h>
+
+#include "Ppmd7.h"
+
+const Byte PPMD7_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
+static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
+
+#define MAX_FREQ 124
+#define UNIT_SIZE 12
+
+#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)
+#define U2I(nu) (p->Units2Indx[(nu) - 1])
+#define I2U(indx) (p->Indx2Units[indx])
+
+#ifdef PPMD_32BIT
+  #define REF(ptr) (ptr)
+#else
+  #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))
+#endif
+
+#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr))
+
+#define CTX(ref) ((CPpmd7_Context *)Ppmd7_GetContext(p, ref))
+#define STATS(ctx) Ppmd7_GetStats(p, ctx)
+#define ONE_STATE(ctx) Ppmd7Context_OneState(ctx)
+#define SUFFIX(ctx) CTX((ctx)->Suffix)
+
+typedef CPpmd7_Context * CTX_PTR;
+
+struct CPpmd7_Node_;
+
+typedef
+  #ifdef PPMD_32BIT
+    struct CPpmd7_Node_ *
+  #else
+    UInt32
+  #endif
+  CPpmd7_Node_Ref;
+
+typedef struct CPpmd7_Node_
+{
+  UInt16 Stamp; /* must be at offset 0 as CPpmd7_Context::NumStats. Stamp=0 means free */
+  UInt16 NU;
+  CPpmd7_Node_Ref Next; /* must be at offset >= 4 */
+  CPpmd7_Node_Ref Prev;
+} CPpmd7_Node;
+
+#ifdef PPMD_32BIT
+  #define NODE(ptr) (ptr)
+#else
+  #define NODE(offs) ((CPpmd7_Node *)(p->Base + (offs)))
+#endif
+
+void Ppmd7_Construct(CPpmd7 *p)
+{
+  unsigned i, k, m;
+
+  p->Base = 0;
+
+  for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
+  {
+    unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
+    do { p->Units2Indx[k++] = (Byte)i; } while(--step);
+    p->Indx2Units[i] = (Byte)k;
+  }
+
+  p->NS2BSIndx[0] = (0 << 1);
+  p->NS2BSIndx[1] = (1 << 1);
+  memset(p->NS2BSIndx + 2, (2 << 1), 9);
+  memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11);
+
+  for (i = 0; i < 3; i++)
+    p->NS2Indx[i] = (Byte)i;
+  for (m = i, k = 1; i < 256; i++)
+  {
+    p->NS2Indx[i] = (Byte)m;
+    if (--k == 0)
+      k = (++m) - 2;
+  }
+
+  memset(p->HB2Flag, 0, 0x40);
+  memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40);
+}
+
+void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->Base);
+  p->Size = 0;
+  p->Base = 0;
+}
+
+Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc)
+{
+  if (p->Base == 0 || p->Size != size)
+  {
+    Ppmd7_Free(p, alloc);
+    p->AlignOffset =
+      #ifdef PPMD_32BIT
+        (4 - size) & 3;
+      #else
+        4 - (size & 3);
+      #endif
+    if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size
+        #ifndef PPMD_32BIT
+        + UNIT_SIZE
+        #endif
+        )) == 0)
+      return False;
+    p->Size = size;
+  }
+  return True;
+}
+
+static void InsertNode(CPpmd7 *p, void *node, unsigned indx)
+{
+  *((CPpmd_Void_Ref *)node) = p->FreeList[indx];
+  p->FreeList[indx] = REF(node);
+}
+
+static void *RemoveNode(CPpmd7 *p, unsigned indx)
+{
+  CPpmd_Void_Ref *node = (CPpmd_Void_Ref *)Ppmd7_GetPtr(p, p->FreeList[indx]);
+  p->FreeList[indx] = *node;
+  return node;
+}
+
+static void SplitBlock(CPpmd7 *p, void *ptr, unsigned oldIndx, unsigned newIndx)
+{
+  unsigned i, nu = I2U(oldIndx) - I2U(newIndx);
+  ptr = (Byte *)ptr + U2B(I2U(newIndx));
+  if (I2U(i = U2I(nu)) != nu)
+  {
+    unsigned k = I2U(--i);
+    InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1);
+  }
+  InsertNode(p, ptr, i);
+}
+
+static void GlueFreeBlocks(CPpmd7 *p)
+{
+  #ifdef PPMD_32BIT
+  CPpmd7_Node headItem;
+  CPpmd7_Node_Ref head = &headItem;
+  #else
+  CPpmd7_Node_Ref head = p->AlignOffset + p->Size;
+  #endif
+  
+  CPpmd7_Node_Ref n = head;
+  unsigned i;
+
+  p->GlueCount = 255;
+
+  /* create doubly-linked list of free blocks */
+  for (i = 0; i < PPMD_NUM_INDEXES; i++)
+  {
+    UInt16 nu = I2U(i);
+    CPpmd7_Node_Ref next = (CPpmd7_Node_Ref)p->FreeList[i];
+    p->FreeList[i] = 0;
+    while (next != 0)
+    {
+      CPpmd7_Node *node = NODE(next);
+      node->Next = n;
+      n = NODE(n)->Prev = next;
+      next = *(const CPpmd7_Node_Ref *)node;
+      node->Stamp = 0;
+      node->NU = (UInt16)nu;
+    }
+  }
+  NODE(head)->Stamp = 1;
+  NODE(head)->Next = n;
+  NODE(n)->Prev = head;
+  if (p->LoUnit != p->HiUnit)
+    ((CPpmd7_Node *)p->LoUnit)->Stamp = 1;
+  
+  /* Glue free blocks */
+  while (n != head)
+  {
+    CPpmd7_Node *node = NODE(n);
+    UInt32 nu = (UInt32)node->NU;
+    for (;;)
+    {
+      CPpmd7_Node *node2 = NODE(n) + nu;
+      nu += node2->NU;
+      if (node2->Stamp != 0 || nu >= 0x10000)
+        break;
+      NODE(node2->Prev)->Next = node2->Next;
+      NODE(node2->Next)->Prev = node2->Prev;
+      node->NU = (UInt16)nu;
+    }
+    n = node->Next;
+  }
+  
+  /* Fill lists of free blocks */
+  for (n = NODE(head)->Next; n != head;)
+  {
+    CPpmd7_Node *node = NODE(n);
+    unsigned nu;
+    CPpmd7_Node_Ref next = node->Next;
+    for (nu = node->NU; nu > 128; nu -= 128, node += 128)
+      InsertNode(p, node, PPMD_NUM_INDEXES - 1);
+    if (I2U(i = U2I(nu)) != nu)
+    {
+      unsigned k = I2U(--i);
+      InsertNode(p, node + k, nu - k - 1);
+    }
+    InsertNode(p, node, i);
+    n = next;
+  }
+}
+
+static void *AllocUnitsRare(CPpmd7 *p, unsigned indx)
+{
+  unsigned i;
+  void *retVal;
+  if (p->GlueCount == 0)
+  {
+    GlueFreeBlocks(p);
+    if (p->FreeList[indx] != 0)
+      return RemoveNode(p, indx);
+  }
+  i = indx;
+  do
+  {
+    if (++i == PPMD_NUM_INDEXES)
+    {
+      UInt32 numBytes = U2B(I2U(indx));
+      p->GlueCount--;
+      return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL);
+    }
+  }
+  while (p->FreeList[i] == 0);
+  retVal = RemoveNode(p, i);
+  SplitBlock(p, retVal, i, indx);
+  return retVal;
+}
+
+static void *AllocUnits(CPpmd7 *p, unsigned indx)
+{
+  UInt32 numBytes;
+  if (p->FreeList[indx] != 0)
+    return RemoveNode(p, indx);
+  numBytes = U2B(I2U(indx));
+  if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit))
+  {
+    void *retVal = p->LoUnit;
+    p->LoUnit += numBytes;
+    return retVal;
+  }
+  return AllocUnitsRare(p, indx);
+}
+
+#define MyMem12Cpy(dest, src, num) \
+  { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
+    do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); }
+
+static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
+{
+  unsigned i0 = U2I(oldNU);
+  unsigned i1 = U2I(newNU);
+  if (i0 == i1)
+    return oldPtr;
+  if (p->FreeList[i1] != 0)
+  {
+    void *ptr = RemoveNode(p, i1);
+    MyMem12Cpy(ptr, oldPtr, newNU);
+    InsertNode(p, oldPtr, i0);
+    return ptr;
+  }
+  SplitBlock(p, oldPtr, i0, i1);
+  return oldPtr;
+}
+
+#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16)))
+
+static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v)
+{
+  (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF);
+  (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF);
+}
+
+static void RestartModel(CPpmd7 *p)
+{
+  unsigned i, k, m;
+
+  memset(p->FreeList, 0, sizeof(p->FreeList));
+  p->Text = p->Base + p->AlignOffset;
+  p->HiUnit = p->Text + p->Size;
+  p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE;
+  p->GlueCount = 0;
+
+  p->OrderFall = p->MaxOrder;
+  p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1;
+  p->PrevSuccess = 0;
+
+  p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */
+  p->MinContext->Suffix = 0;
+  p->MinContext->NumStats = 256;
+  p->MinContext->SummFreq = 256 + 1;
+  p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */
+  p->LoUnit += U2B(256 / 2);
+  p->MinContext->Stats = REF(p->FoundState);
+  for (i = 0; i < 256; i++)
+  {
+    CPpmd_State *s = &p->FoundState[i];
+    s->Symbol = (Byte)i;
+    s->Freq = 1;
+    SetSuccessor(s, 0);
+  }
+
+  for (i = 0; i < 128; i++)
+    for (k = 0; k < 8; k++)
+    {
+      UInt16 *dest = p->BinSumm[i] + k;
+      UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 2));
+      for (m = 0; m < 64; m += 8)
+        dest[m] = val;
+    }
+  
+  for (i = 0; i < 25; i++)
+    for (k = 0; k < 16; k++)
+    {
+      CPpmd_See *s = &p->See[i][k];
+      s->Summ = (UInt16)((5 * i + 10) << (s->Shift = PPMD_PERIOD_BITS - 4));
+      s->Count = 4;
+    }
+}
+
+void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder)
+{
+  p->MaxOrder = maxOrder;
+  RestartModel(p);
+  p->DummySee.Shift = PPMD_PERIOD_BITS;
+  p->DummySee.Summ = 0; /* unused */
+  p->DummySee.Count = 64; /* unused */
+}
+
+static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)
+{
+  CPpmd_State upState;
+  CTX_PTR c = p->MinContext;
+  CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);
+  CPpmd_State *ps[PPMD7_MAX_ORDER];
+  unsigned numPs = 0;
+  
+  if (!skip)
+    ps[numPs++] = p->FoundState;
+  
+  while (c->Suffix)
+  {
+    CPpmd_Void_Ref successor;
+    CPpmd_State *s;
+    c = SUFFIX(c);
+    if (c->NumStats != 1)
+    {
+      for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++);
+    }
+    else
+      s = ONE_STATE(c);
+    successor = SUCCESSOR(s);
+    if (successor != upBranch)
+    {
+      c = CTX(successor);
+      if (numPs == 0)
+        return c;
+      break;
+    }
+    ps[numPs++] = s;
+  }
+  
+  upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch);
+  SetSuccessor(&upState, upBranch + 1);
+  
+  if (c->NumStats == 1)
+    upState.Freq = ONE_STATE(c)->Freq;
+  else
+  {
+    UInt32 cf, s0;
+    CPpmd_State *s;
+    for (s = STATS(c); s->Symbol != upState.Symbol; s++);
+    cf = s->Freq - 1;
+    s0 = c->SummFreq - c->NumStats - cf;
+    upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((2 * cf + 3 * s0 - 1) / (2 * s0))));
+  }
+
+  do
+  {
+    /* Create Child */
+    CTX_PTR c1; /* = AllocContext(p); */
+    if (p->HiUnit != p->LoUnit)
+      c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE);
+    else if (p->FreeList[0] != 0)
+      c1 = (CTX_PTR)RemoveNode(p, 0);
+    else
+    {
+      c1 = (CTX_PTR)AllocUnitsRare(p, 0);
+      if (!c1)
+        return NULL;
+    }
+    c1->NumStats = 1;
+    *ONE_STATE(c1) = upState;
+    c1->Suffix = REF(c);
+    SetSuccessor(ps[--numPs], REF(c1));
+    c = c1;
+  }
+  while (numPs != 0);
+  
+  return c;
+}
+
+static void SwapStates(CPpmd_State *t1, CPpmd_State *t2)
+{
+  CPpmd_State tmp = *t1;
+  *t1 = *t2;
+  *t2 = tmp;
+}
+
+static void UpdateModel(CPpmd7 *p)
+{
+  CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);
+  CTX_PTR c;
+  unsigned s0, ns;
+  
+  if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)
+  {
+    c = SUFFIX(p->MinContext);
+    
+    if (c->NumStats == 1)
+    {
+      CPpmd_State *s = ONE_STATE(c);
+      if (s->Freq < 32)
+        s->Freq++;
+    }
+    else
+    {
+      CPpmd_State *s = STATS(c);
+      if (s->Symbol != p->FoundState->Symbol)
+      {
+        do { s++; } while (s->Symbol != p->FoundState->Symbol);
+        if (s[0].Freq >= s[-1].Freq)
+        {
+          SwapStates(&s[0], &s[-1]);
+          s--;
+        }
+      }
+      if (s->Freq < MAX_FREQ - 9)
+      {
+        s->Freq += 2;
+        c->SummFreq += 2;
+      }
+    }
+  }
+
+  if (p->OrderFall == 0)
+  {
+    p->MinContext = p->MaxContext = CreateSuccessors(p, True);
+    if (p->MinContext == 0)
+    {
+      RestartModel(p);
+      return;
+    }
+    SetSuccessor(p->FoundState, REF(p->MinContext));
+    return;
+  }
+  
+  *p->Text++ = p->FoundState->Symbol;
+  successor = REF(p->Text);
+  if (p->Text >= p->UnitsStart)
+  {
+    RestartModel(p);
+    return;
+  }
+  
+  if (fSuccessor)
+  {
+    if (fSuccessor <= successor)
+    {
+      CTX_PTR cs = CreateSuccessors(p, False);
+      if (cs == NULL)
+      {
+        RestartModel(p);
+        return;
+      }
+      fSuccessor = REF(cs);
+    }
+    if (--p->OrderFall == 0)
+    {
+      successor = fSuccessor;
+      p->Text -= (p->MaxContext != p->MinContext);
+    }
+  }
+  else
+  {
+    SetSuccessor(p->FoundState, successor);
+    fSuccessor = REF(p->MinContext);
+  }
+  
+  s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - (p->FoundState->Freq - 1);
+  
+  for (c = p->MaxContext; c != p->MinContext; c = SUFFIX(c))
+  {
+    unsigned ns1;
+    UInt32 cf, sf;
+    if ((ns1 = c->NumStats) != 1)
+    {
+      if ((ns1 & 1) == 0)
+      {
+        /* Expand for one UNIT */
+        unsigned oldNU = ns1 >> 1;
+        unsigned i = U2I(oldNU);
+        if (i != U2I(oldNU + 1))
+        {
+          void *ptr = AllocUnits(p, i + 1);
+          void *oldPtr;
+          if (!ptr)
+          {
+            RestartModel(p);
+            return;
+          }
+          oldPtr = STATS(c);
+          MyMem12Cpy(ptr, oldPtr, oldNU);
+          InsertNode(p, oldPtr, i);
+          c->Stats = STATS_REF(ptr);
+        }
+      }
+      c->SummFreq = (UInt16)(c->SummFreq + (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) & (c->SummFreq <= 8 * ns1)));
+    }
+    else
+    {
+      CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0);
+      if (!s)
+      {
+        RestartModel(p);
+        return;
+      }
+      *s = *ONE_STATE(c);
+      c->Stats = REF(s);
+      if (s->Freq < MAX_FREQ / 4 - 1)
+        s->Freq <<= 1;
+      else
+        s->Freq = MAX_FREQ - 4;
+      c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 3));
+    }
+    cf = 2 * (UInt32)p->FoundState->Freq * (c->SummFreq + 6);
+    sf = (UInt32)s0 + c->SummFreq;
+    if (cf < 6 * sf)
+    {
+      cf = 1 + (cf > sf) + (cf >= 4 * sf);
+      c->SummFreq += 3;
+    }
+    else
+    {
+      cf = 4 + (cf >= 9 * sf) + (cf >= 12 * sf) + (cf >= 15 * sf);
+      c->SummFreq = (UInt16)(c->SummFreq + cf);
+    }
+    {
+      CPpmd_State *s = STATS(c) + ns1;
+      SetSuccessor(s, successor);
+      s->Symbol = p->FoundState->Symbol;
+      s->Freq = (Byte)cf;
+      c->NumStats = (UInt16)(ns1 + 1);
+    }
+  }
+  p->MaxContext = p->MinContext = CTX(fSuccessor);
+}
+  
+static void Rescale(CPpmd7 *p)
+{
+  unsigned i, adder, sumFreq, escFreq;
+  CPpmd_State *stats = STATS(p->MinContext);
+  CPpmd_State *s = p->FoundState;
+  {
+    CPpmd_State tmp = *s;
+    for (; s != stats; s--)
+      s[0] = s[-1];
+    *s = tmp;
+  }
+  escFreq = p->MinContext->SummFreq - s->Freq;
+  s->Freq += 4;
+  adder = (p->OrderFall != 0);
+  s->Freq = (Byte)((s->Freq + adder) >> 1);
+  sumFreq = s->Freq;
+  
+  i = p->MinContext->NumStats - 1;
+  do
+  {
+    escFreq -= (++s)->Freq;
+    s->Freq = (Byte)((s->Freq + adder) >> 1);
+    sumFreq += s->Freq;
+    if (s[0].Freq > s[-1].Freq)
+    {
+      CPpmd_State *s1 = s;
+      CPpmd_State tmp = *s1;
+      do
+        s1[0] = s1[-1];
+      while (--s1 != stats && tmp.Freq > s1[-1].Freq);
+      *s1 = tmp;
+    }
+  }
+  while (--i);
+  
+  if (s->Freq == 0)
+  {
+    unsigned numStats = p->MinContext->NumStats;
+    unsigned n0, n1;
+    do { i++; } while ((--s)->Freq == 0);
+    escFreq += i;
+    p->MinContext->NumStats = (UInt16)(p->MinContext->NumStats - i);
+    if (p->MinContext->NumStats == 1)
+    {
+      CPpmd_State tmp = *stats;
+      do
+      {
+        tmp.Freq = (Byte)(tmp.Freq - (tmp.Freq >> 1));
+        escFreq >>= 1;
+      }
+      while (escFreq > 1);
+      InsertNode(p, stats, U2I(((numStats + 1) >> 1)));
+      *(p->FoundState = ONE_STATE(p->MinContext)) = tmp;
+      return;
+    }
+    n0 = (numStats + 1) >> 1;
+    n1 = (p->MinContext->NumStats + 1) >> 1;
+    if (n0 != n1)
+      p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1));
+  }
+  p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1));
+  p->FoundState = STATS(p->MinContext);
+}
+
+CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq)
+{
+  CPpmd_See *see;
+  unsigned nonMasked = p->MinContext->NumStats - numMasked;
+  if (p->MinContext->NumStats != 256)
+  {
+    see = p->See[p->NS2Indx[nonMasked - 1]] +
+        (nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) +
+        2 * (p->MinContext->SummFreq < 11 * p->MinContext->NumStats) +
+        4 * (numMasked > nonMasked) +
+        p->HiBitsFlag;
+    {
+      unsigned r = (see->Summ >> see->Shift);
+      see->Summ = (UInt16)(see->Summ - r);
+      *escFreq = r + (r == 0);
+    }
+  }
+  else
+  {
+    see = &p->DummySee;
+    *escFreq = 1;
+  }
+  return see;
+}
+
+static void NextContext(CPpmd7 *p)
+{
+  CTX_PTR c = CTX(SUCCESSOR(p->FoundState));
+  if (p->OrderFall == 0 && (Byte *)c > p->Text)
+    p->MinContext = p->MaxContext = c;
+  else
+    UpdateModel(p);
+}
+
+void Ppmd7_Update1(CPpmd7 *p)
+{
+  CPpmd_State *s = p->FoundState;
+  s->Freq += 4;
+  p->MinContext->SummFreq += 4;
+  if (s[0].Freq > s[-1].Freq)
+  {
+    SwapStates(&s[0], &s[-1]);
+    p->FoundState = --s;
+    if (s->Freq > MAX_FREQ)
+      Rescale(p);
+  }
+  NextContext(p);
+}
+
+void Ppmd7_Update1_0(CPpmd7 *p)
+{
+  p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq);
+  p->RunLength += p->PrevSuccess;
+  p->MinContext->SummFreq += 4;
+  if ((p->FoundState->Freq += 4) > MAX_FREQ)
+    Rescale(p);
+  NextContext(p);
+}
+
+void Ppmd7_UpdateBin(CPpmd7 *p)
+{
+  p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1: 0));
+  p->PrevSuccess = 1;
+  p->RunLength++;
+  NextContext(p);
+}
+
+void Ppmd7_Update2(CPpmd7 *p)
+{
+  p->MinContext->SummFreq += 4;
+  if ((p->FoundState->Freq += 4) > MAX_FREQ)
+    Rescale(p);
+  p->RunLength = p->InitRL;
+  UpdateModel(p);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,140 @@
+/* Ppmd7.h -- PPMdH compression codec
+2010-03-12 : Igor Pavlov : Public domain
+This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
+
+/* This code supports virtual RangeDecoder and includes the implementation
+of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H.
+If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */
+
+#ifndef __PPMD7_H
+#define __PPMD7_H
+
+#include "Ppmd.h"
+
+EXTERN_C_BEGIN
+
+#define PPMD7_MIN_ORDER 2
+#define PPMD7_MAX_ORDER 64
+
+#define PPMD7_MIN_MEM_SIZE (1 << 11)
+#define PPMD7_MAX_MEM_SIZE (0xFFFFFFFF - 12 * 3)
+
+struct CPpmd7_Context_;
+
+typedef
+  #ifdef PPMD_32BIT
+    struct CPpmd7_Context_ *
+  #else
+    UInt32
+  #endif
+  CPpmd7_Context_Ref;
+
+typedef struct CPpmd7_Context_
+{
+  UInt16 NumStats;
+  UInt16 SummFreq;
+  CPpmd_State_Ref Stats;
+  CPpmd7_Context_Ref Suffix;
+} CPpmd7_Context;
+
+#define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)
+
+typedef struct
+{
+  CPpmd7_Context *MinContext, *MaxContext;
+  CPpmd_State *FoundState;
+  unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag;
+  Int32 RunLength, InitRL; /* must be 32-bit at least */
+
+  UInt32 Size;
+  UInt32 GlueCount;
+  Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;
+  UInt32 AlignOffset;
+
+  Byte Indx2Units[PPMD_NUM_INDEXES];
+  Byte Units2Indx[128];
+  CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES];
+  Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256];
+  CPpmd_See DummySee, See[25][16];
+  UInt16 BinSumm[128][64];
+} CPpmd7;
+
+void Ppmd7_Construct(CPpmd7 *p);
+Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc);
+void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc);
+void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder);
+#define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
+
+
+/* ---------- Internal Functions ---------- */
+
+extern const Byte PPMD7_kExpEscape[16];
+
+#ifdef PPMD_32BIT
+  #define Ppmd7_GetPtr(p, ptr) (ptr)
+  #define Ppmd7_GetContext(p, ptr) (ptr)
+  #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats)
+#else
+  #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
+  #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs)))
+  #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats)))
+#endif
+
+void Ppmd7_Update1(CPpmd7 *p);
+void Ppmd7_Update1_0(CPpmd7 *p);
+void Ppmd7_Update2(CPpmd7 *p);
+void Ppmd7_UpdateBin(CPpmd7 *p);
+
+#define Ppmd7_GetBinSumm(p) \
+    &p->BinSumm[Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
+    p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \
+    (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \
+    2 * p->HB2Flag[Ppmd7Context_OneState(p->MinContext)->Symbol] + \
+    ((p->RunLength >> 26) & 0x20)]
+
+CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale);
+
+
+/* ---------- Decode ---------- */
+
+typedef struct
+{
+  UInt32 (*GetThreshold)(void *p, UInt32 total);
+  void (*Decode)(void *p, UInt32 start, UInt32 size);
+  UInt32 (*DecodeBit)(void *p, UInt32 size0);
+} IPpmd7_RangeDec;
+
+typedef struct
+{
+  IPpmd7_RangeDec p;
+  UInt32 Range;
+  UInt32 Code;
+  IByteIn *Stream;
+} CPpmd7z_RangeDec;
+
+void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p);
+Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p);
+#define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
+
+int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc);
+
+
+/* ---------- Encode ---------- */
+
+typedef struct
+{
+  UInt64 Low;
+  UInt32 Range;
+  Byte Cache;
+  UInt64 CacheSize;
+  IByteOut *Stream;
+} CPpmd7z_RangeEnc;
+
+void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p);
+void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p);
+
+void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol);
+
+EXTERN_C_END
+ 
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Dec.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Dec.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Dec.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Dec.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,187 @@
+/* Ppmd7Dec.c -- PPMdH Decoder
+2010-03-12 : Igor Pavlov : Public domain
+This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
+
+#include "Ppmd7.h"
+
+#define kTopValue (1 << 24)
+
+Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p)
+{
+  unsigned i;
+  p->Code = 0;
+  p->Range = 0xFFFFFFFF;
+  if (p->Stream->Read((void *)p->Stream) != 0)
+    return False;
+  for (i = 0; i < 4; i++)
+    p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);
+  return (p->Code < 0xFFFFFFFF);
+}
+
+static UInt32 Range_GetThreshold(void *pp, UInt32 total)
+{
+  CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
+  return (p->Code) / (p->Range /= total);
+}
+
+static void Range_Normalize(CPpmd7z_RangeDec *p)
+{
+  if (p->Range < kTopValue)
+  {
+    p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);
+    p->Range <<= 8;
+    if (p->Range < kTopValue)
+    {
+      p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);
+      p->Range <<= 8;
+    }
+  }
+}
+
+static void Range_Decode(void *pp, UInt32 start, UInt32 size)
+{
+  CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
+  p->Code -= start * p->Range;
+  p->Range *= size;
+  Range_Normalize(p);
+}
+
+static UInt32 Range_DecodeBit(void *pp, UInt32 size0)
+{
+  CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
+  UInt32 newBound = (p->Range >> 14) * size0;
+  UInt32 symbol;
+  if (p->Code < newBound)
+  {
+    symbol = 0;
+    p->Range = newBound;
+  }
+  else
+  {
+    symbol = 1;
+    p->Code -= newBound;
+    p->Range -= newBound;
+  }
+  Range_Normalize(p);
+  return symbol;
+}
+
+void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p)
+{
+  p->p.GetThreshold = Range_GetThreshold;
+  p->p.Decode = Range_Decode;
+  p->p.DecodeBit = Range_DecodeBit;
+}
+
+
+#define MASK(sym) ((signed char *)charMask)[sym]
+
+int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc)
+{
+  size_t charMask[256 / sizeof(size_t)];
+  if (p->MinContext->NumStats != 1)
+  {
+    CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext);
+    unsigned i;
+    UInt32 count, hiCnt;
+    if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq))
+    {
+      Byte symbol;
+      rc->Decode(rc, 0, s->Freq);
+      p->FoundState = s;
+      symbol = s->Symbol;
+      Ppmd7_Update1_0(p);
+      return symbol;
+    }
+    p->PrevSuccess = 0;
+    i = p->MinContext->NumStats - 1;
+    do
+    {
+      if ((hiCnt += (++s)->Freq) > count)
+      {
+        Byte symbol;
+        rc->Decode(rc, hiCnt - s->Freq, s->Freq);
+        p->FoundState = s;
+        symbol = s->Symbol;
+        Ppmd7_Update1(p);
+        return symbol;
+      }
+    }
+    while (--i);
+    if (count >= p->MinContext->SummFreq)
+      return -2;
+    p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];
+    rc->Decode(rc, hiCnt, p->MinContext->SummFreq - hiCnt);
+    PPMD_SetAllBitsIn256Bytes(charMask);
+    MASK(s->Symbol) = 0;
+    i = p->MinContext->NumStats - 1;
+    do { MASK((--s)->Symbol) = 0; } while (--i);
+  }
+  else
+  {
+    UInt16 *prob = Ppmd7_GetBinSumm(p);
+    if (rc->DecodeBit(rc, *prob) == 0)
+    {
+      Byte symbol;
+      *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
+      symbol = (p->FoundState = Ppmd7Context_OneState(p->MinContext))->Symbol;
+      Ppmd7_UpdateBin(p);
+      return symbol;
+    }
+    *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
+    p->InitEsc = PPMD7_kExpEscape[*prob >> 10];
+    PPMD_SetAllBitsIn256Bytes(charMask);
+    MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0;
+    p->PrevSuccess = 0;
+  }
+  for (;;)
+  {
+    CPpmd_State *ps[256], *s;
+    UInt32 freqSum, count, hiCnt;
+    CPpmd_See *see;
+    unsigned i, num, numMasked = p->MinContext->NumStats;
+    do
+    {
+      p->OrderFall++;
+      if (!p->MinContext->Suffix)
+        return -1;
+      p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);
+    }
+    while (p->MinContext->NumStats == numMasked);
+    hiCnt = 0;
+    s = Ppmd7_GetStats(p, p->MinContext);
+    i = 0;
+    num = p->MinContext->NumStats - numMasked;
+    do
+    {
+      int k = (int)(MASK(s->Symbol));
+      hiCnt += (s->Freq & k);
+      ps[i] = s++;
+      i -= k;
+    }
+    while (i != num);
+    
+    see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum);
+    freqSum += hiCnt;
+    count = rc->GetThreshold(rc, freqSum);
+    
+    if (count < hiCnt)
+    {
+      Byte symbol;
+      CPpmd_State **pps = ps;
+      for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);
+      s = *pps;
+      rc->Decode(rc, hiCnt - s->Freq, s->Freq);
+      Ppmd_See_Update(see);
+      p->FoundState = s;
+      symbol = s->Symbol;
+      Ppmd7_Update2(p);
+      return symbol;
+    }
+    if (count >= freqSum)
+      return -2;
+    rc->Decode(rc, hiCnt, freqSum - hiCnt);
+    see->Summ = (UInt16)(see->Summ + freqSum);
+    do { MASK(ps[--i]->Symbol) = 0; } while (i != 0);
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Enc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Enc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Enc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd7Enc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,185 @@
+/* Ppmd7Enc.c -- PPMdH Encoder
+2010-03-12 : Igor Pavlov : Public domain
+This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
+
+#include "Ppmd7.h"
+
+#define kTopValue (1 << 24)
+
+void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p)
+{
+  p->Low = 0;
+  p->Range = 0xFFFFFFFF;
+  p->Cache = 0;
+  p->CacheSize = 1;
+}
+
+static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p)
+{
+  if ((UInt32)p->Low < (UInt32)0xFF000000 || (unsigned)(p->Low >> 32) != 0)
+  {
+    Byte temp = p->Cache;
+    do
+    {
+      p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32)));
+      temp = 0xFF;
+    }
+    while(--p->CacheSize != 0);
+    p->Cache = (Byte)((UInt32)p->Low >> 24);
+  }
+  p->CacheSize++;
+  p->Low = (UInt32)p->Low << 8;
+}
+
+static void RangeEnc_Encode(CPpmd7z_RangeEnc *p, UInt32 start, UInt32 size, UInt32 total)
+{
+  p->Low += start * (p->Range /= total);
+  p->Range *= size;
+  while (p->Range < kTopValue)
+  {
+    p->Range <<= 8;
+    RangeEnc_ShiftLow(p);
+  }
+}
+
+static void RangeEnc_EncodeBit_0(CPpmd7z_RangeEnc *p, UInt32 size0)
+{
+  p->Range = (p->Range >> 14) * size0;
+  while (p->Range < kTopValue)
+  {
+    p->Range <<= 8;
+    RangeEnc_ShiftLow(p);
+  }
+}
+
+static void RangeEnc_EncodeBit_1(CPpmd7z_RangeEnc *p, UInt32 size0)
+{
+  UInt32 newBound = (p->Range >> 14) * size0;
+  p->Low += newBound;
+  p->Range -= newBound;
+  while (p->Range < kTopValue)
+  {
+    p->Range <<= 8;
+    RangeEnc_ShiftLow(p);
+  }
+}
+
+void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p)
+{
+  unsigned i;
+  for (i = 0; i < 5; i++)
+    RangeEnc_ShiftLow(p);
+}
+
+
+#define MASK(sym) ((signed char *)charMask)[sym]
+
+void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol)
+{
+  size_t charMask[256 / sizeof(size_t)];
+  if (p->MinContext->NumStats != 1)
+  {
+    CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext);
+    UInt32 sum;
+    unsigned i;
+    if (s->Symbol == symbol)
+    {
+      RangeEnc_Encode(rc, 0, s->Freq, p->MinContext->SummFreq);
+      p->FoundState = s;
+      Ppmd7_Update1_0(p);
+      return;
+    }
+    p->PrevSuccess = 0;
+    sum = s->Freq;
+    i = p->MinContext->NumStats - 1;
+    do
+    {
+      if ((++s)->Symbol == symbol)
+      {
+        RangeEnc_Encode(rc, sum, s->Freq, p->MinContext->SummFreq);
+        p->FoundState = s;
+        Ppmd7_Update1(p);
+        return;
+      }
+      sum += s->Freq;
+    }
+    while (--i);
+    
+    p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];
+    PPMD_SetAllBitsIn256Bytes(charMask);
+    MASK(s->Symbol) = 0;
+    i = p->MinContext->NumStats - 1;
+    do { MASK((--s)->Symbol) = 0; } while (--i);
+    RangeEnc_Encode(rc, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq);
+  }
+  else
+  {
+    UInt16 *prob = Ppmd7_GetBinSumm(p);
+    CPpmd_State *s = Ppmd7Context_OneState(p->MinContext);
+    if (s->Symbol == symbol)
+    {
+      RangeEnc_EncodeBit_0(rc, *prob);
+      *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
+      p->FoundState = s;
+      Ppmd7_UpdateBin(p);
+      return;
+    }
+    else
+    {
+      RangeEnc_EncodeBit_1(rc, *prob);
+      *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
+      p->InitEsc = PPMD7_kExpEscape[*prob >> 10];
+      PPMD_SetAllBitsIn256Bytes(charMask);
+      MASK(s->Symbol) = 0;
+      p->PrevSuccess = 0;
+    }
+  }
+  for (;;)
+  {
+    UInt32 escFreq;
+    CPpmd_See *see;
+    CPpmd_State *s;
+    UInt32 sum;
+    unsigned i, numMasked = p->MinContext->NumStats;
+    do
+    {
+      p->OrderFall++;
+      if (!p->MinContext->Suffix)
+        return; /* EndMarker (symbol = -1) */
+      p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);
+    }
+    while (p->MinContext->NumStats == numMasked);
+    
+    see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq);
+    s = Ppmd7_GetStats(p, p->MinContext);
+    sum = 0;
+    i = p->MinContext->NumStats;
+    do
+    {
+      int cur = s->Symbol;
+      if (cur == symbol)
+      {
+        UInt32 low = sum;
+        CPpmd_State *s1 = s;
+        do
+        {
+          sum += (s->Freq & (int)(MASK(s->Symbol)));
+          s++;
+        }
+        while (--i);
+        RangeEnc_Encode(rc, low, s1->Freq, sum + escFreq);
+        Ppmd_See_Update(see);
+        p->FoundState = s1;
+        Ppmd7_Update2(p);
+        return;
+      }
+      sum += (s->Freq & (int)(MASK(cur)));
+      MASK(cur) = 0;
+      s++;
+    }
+    while (--i);
+    
+    RangeEnc_Encode(rc, sum, escFreq, sum + escFreq);
+    see->Summ = (UInt16)(see->Summ + sum + escFreq);
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,1120 @@
+/* Ppmd8.c -- PPMdI codec
+2010-03-24 : Igor Pavlov : Public domain
+This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */
+
+#include <memory.h>
+
+#include "Ppmd8.h"
+
+const Byte PPMD8_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
+static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
+
+#define MAX_FREQ 124
+#define UNIT_SIZE 12
+
+#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)
+#define U2I(nu) (p->Units2Indx[(nu) - 1])
+#define I2U(indx) (p->Indx2Units[indx])
+
+#ifdef PPMD_32BIT
+  #define REF(ptr) (ptr)
+#else
+  #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))
+#endif
+
+#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr))
+
+#define CTX(ref) ((CPpmd8_Context *)Ppmd8_GetContext(p, ref))
+#define STATS(ctx) Ppmd8_GetStats(p, ctx)
+#define ONE_STATE(ctx) Ppmd8Context_OneState(ctx)
+#define SUFFIX(ctx) CTX((ctx)->Suffix)
+
+typedef CPpmd8_Context * CTX_PTR;
+
+struct CPpmd8_Node_;
+
+typedef
+  #ifdef PPMD_32BIT
+    struct CPpmd8_Node_ *
+  #else
+    UInt32
+  #endif
+  CPpmd8_Node_Ref;
+
+typedef struct CPpmd8_Node_
+{
+  UInt32 Stamp;
+  CPpmd8_Node_Ref Next;
+  UInt32 NU;
+} CPpmd8_Node;
+
+#ifdef PPMD_32BIT
+  #define NODE(ptr) (ptr)
+#else
+  #define NODE(offs) ((CPpmd8_Node *)(p->Base + (offs)))
+#endif
+
+#define EMPTY_NODE 0xFFFFFFFF
+
+void Ppmd8_Construct(CPpmd8 *p)
+{
+  unsigned i, k, m;
+
+  p->Base = 0;
+
+  for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
+  {
+    unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
+    do { p->Units2Indx[k++] = (Byte)i; } while(--step);
+    p->Indx2Units[i] = (Byte)k;
+  }
+
+  p->NS2BSIndx[0] = (0 << 1);
+  p->NS2BSIndx[1] = (1 << 1);
+  memset(p->NS2BSIndx + 2, (2 << 1), 9);
+  memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11);
+
+  for (i = 0; i < 5; i++)
+    p->NS2Indx[i] = (Byte)i;
+  for (m = i, k = 1; i < 260; i++)
+  {
+    p->NS2Indx[i] = (Byte)m;
+    if (--k == 0)
+      k = (++m) - 4;
+  }
+}
+
+void Ppmd8_Free(CPpmd8 *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->Base);
+  p->Size = 0;
+  p->Base = 0;
+}
+
+Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc)
+{
+  if (p->Base == 0 || p->Size != size)
+  {
+    Ppmd8_Free(p, alloc);
+    p->AlignOffset =
+      #ifdef PPMD_32BIT
+        (4 - size) & 3;
+      #else
+        4 - (size & 3);
+      #endif
+    if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size)) == 0)
+      return False;
+    p->Size = size;
+  }
+  return True;
+}
+
+static void InsertNode(CPpmd8 *p, void *node, unsigned indx)
+{
+  ((CPpmd8_Node *)node)->Stamp = EMPTY_NODE;
+  ((CPpmd8_Node *)node)->Next = (CPpmd8_Node_Ref)p->FreeList[indx];
+  ((CPpmd8_Node *)node)->NU = I2U(indx);
+  p->FreeList[indx] = REF(node);
+  p->Stamps[indx]++;
+}
+
+static void *RemoveNode(CPpmd8 *p, unsigned indx)
+{
+  CPpmd8_Node *node = NODE((CPpmd8_Node_Ref)p->FreeList[indx]);
+  p->FreeList[indx] = node->Next;
+  p->Stamps[indx]--;
+  return node;
+}
+
+static void SplitBlock(CPpmd8 *p, void *ptr, unsigned oldIndx, unsigned newIndx)
+{
+  unsigned i, nu = I2U(oldIndx) - I2U(newIndx);
+  ptr = (Byte *)ptr + U2B(I2U(newIndx));
+  if (I2U(i = U2I(nu)) != nu)
+  {
+    unsigned k = I2U(--i);
+    InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1);
+  }
+  InsertNode(p, ptr, i);
+}
+
+static void GlueFreeBlocks(CPpmd8 *p)
+{
+  CPpmd8_Node_Ref head = 0;
+  CPpmd8_Node_Ref *prev = &head;
+  unsigned i;
+
+  p->GlueCount = 1 << 13;
+  memset(p->Stamps, 0, sizeof(p->Stamps));
+  
+  /* Order-0 context is always at top UNIT, so we don't need guard NODE at the end.
+     All blocks up to p->LoUnit can be free, so we need guard NODE at LoUnit. */
+  if (p->LoUnit != p->HiUnit)
+    ((CPpmd8_Node *)p->LoUnit)->Stamp = 0;
+
+  /* Glue free blocks */
+  for (i = 0; i < PPMD_NUM_INDEXES; i++)
+  {
+    CPpmd8_Node_Ref next = (CPpmd8_Node_Ref)p->FreeList[i];
+    p->FreeList[i] = 0;
+    while (next != 0)
+    {
+      CPpmd8_Node *node = NODE(next);
+      if (node->NU != 0)
+      {
+        CPpmd8_Node *node2;
+        *prev = next;
+        prev = &(node->Next);
+        while ((node2 = node + node->NU)->Stamp == EMPTY_NODE)
+        {
+          node->NU += node2->NU;
+          node2->NU = 0;
+        }
+      }
+      next = node->Next;
+    }
+  }
+  *prev = 0;
+  
+  /* Fill lists of free blocks */
+  while (head != 0)
+  {
+    CPpmd8_Node *node = NODE(head);
+    unsigned nu;
+    head = node->Next;
+    nu = node->NU;
+    if (nu == 0)
+      continue;
+    for (; nu > 128; nu -= 128, node += 128)
+      InsertNode(p, node, PPMD_NUM_INDEXES - 1);
+    if (I2U(i = U2I(nu)) != nu)
+    {
+      unsigned k = I2U(--i);
+      InsertNode(p, node + k, nu - k - 1);
+    }
+    InsertNode(p, node, i);
+  }
+}
+
+static void *AllocUnitsRare(CPpmd8 *p, unsigned indx)
+{
+  unsigned i;
+  void *retVal;
+  if (p->GlueCount == 0)
+  {
+    GlueFreeBlocks(p);
+    if (p->FreeList[indx] != 0)
+      return RemoveNode(p, indx);
+  }
+  i = indx;
+  do
+  {
+    if (++i == PPMD_NUM_INDEXES)
+    {
+      UInt32 numBytes = U2B(I2U(indx));
+      p->GlueCount--;
+      return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL);
+    }
+  }
+  while (p->FreeList[i] == 0);
+  retVal = RemoveNode(p, i);
+  SplitBlock(p, retVal, i, indx);
+  return retVal;
+}
+
+static void *AllocUnits(CPpmd8 *p, unsigned indx)
+{
+  UInt32 numBytes;
+  if (p->FreeList[indx] != 0)
+    return RemoveNode(p, indx);
+  numBytes = U2B(I2U(indx));
+  if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit))
+  {
+    void *retVal = p->LoUnit;
+    p->LoUnit += numBytes;
+    return retVal;
+  }
+  return AllocUnitsRare(p, indx);
+}
+
+#define MyMem12Cpy(dest, src, num) \
+  { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
+    do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); }
+
+static void *ShrinkUnits(CPpmd8 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
+{
+  unsigned i0 = U2I(oldNU);
+  unsigned i1 = U2I(newNU);
+  if (i0 == i1)
+    return oldPtr;
+  if (p->FreeList[i1] != 0)
+  {
+    void *ptr = RemoveNode(p, i1);
+    MyMem12Cpy(ptr, oldPtr, newNU);
+    InsertNode(p, oldPtr, i0);
+    return ptr;
+  }
+  SplitBlock(p, oldPtr, i0, i1);
+  return oldPtr;
+}
+
+static void FreeUnits(CPpmd8 *p, void *ptr, unsigned nu)
+{
+  InsertNode(p, ptr, U2I(nu));
+}
+
+static void SpecialFreeUnit(CPpmd8 *p, void *ptr)
+{
+  if ((Byte *)ptr != p->UnitsStart)
+    InsertNode(p, ptr, 0);
+  else
+  {
+    #ifdef PPMD8_FREEZE_SUPPORT
+    *(UInt32 *)ptr = EMPTY_NODE; /* it's used for (Flags == 0xFF) check in RemoveBinContexts */
+    #endif
+    p->UnitsStart += UNIT_SIZE;
+  }
+}
+
+static void *MoveUnitsUp(CPpmd8 *p, void *oldPtr, unsigned nu)
+{
+  unsigned indx = U2I(nu);
+  void *ptr;
+  if ((Byte *)oldPtr > p->UnitsStart + 16 * 1024 || REF(oldPtr) > p->FreeList[indx])
+    return oldPtr;
+  ptr = RemoveNode(p, indx);
+  MyMem12Cpy(ptr, oldPtr, nu);
+  if ((Byte*)oldPtr != p->UnitsStart)
+    InsertNode(p, oldPtr, indx);
+  else
+    p->UnitsStart += U2B(I2U(indx));
+  return ptr;
+}
+
+static void ExpandTextArea(CPpmd8 *p)
+{
+  UInt32 count[PPMD_NUM_INDEXES];
+  unsigned i;
+  memset(count, 0, sizeof(count));
+  if (p->LoUnit != p->HiUnit)
+    ((CPpmd8_Node *)p->LoUnit)->Stamp = 0;
+  
+  {
+    CPpmd8_Node *node = (CPpmd8_Node *)p->UnitsStart;
+    for (; node->Stamp == EMPTY_NODE; node += node->NU)
+    {
+      node->Stamp = 0;
+      count[U2I(node->NU)]++;
+    }
+    p->UnitsStart = (Byte *)node;
+  }
+  
+  for (i = 0; i < PPMD_NUM_INDEXES; i++)
+  {
+    CPpmd8_Node_Ref *next = (CPpmd8_Node_Ref *)&p->FreeList[i];
+    while (count[i] != 0)
+    {
+      CPpmd8_Node *node = NODE(*next);
+      while (node->Stamp == 0)
+      {
+        *next = node->Next;
+        node = NODE(*next);
+        p->Stamps[i]--;
+        if (--count[i] == 0)
+          break;
+      }
+      next = &node->Next;
+    }
+  }
+}
+
+#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16)))
+
+static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v)
+{
+  (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF);
+  (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF);
+}
+
+#define RESET_TEXT(offs) { p->Text = p->Base + p->AlignOffset + (offs); }
+
+static void RestartModel(CPpmd8 *p)
+{
+  unsigned i, k, m, r;
+
+  memset(p->FreeList, 0, sizeof(p->FreeList));
+  memset(p->Stamps, 0, sizeof(p->Stamps));
+  RESET_TEXT(0);
+  p->HiUnit = p->Text + p->Size;
+  p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE;
+  p->GlueCount = 0;
+
+  p->OrderFall = p->MaxOrder;
+  p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1;
+  p->PrevSuccess = 0;
+
+  p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */
+  p->MinContext->Suffix = 0;
+  p->MinContext->NumStats = 255;
+  p->MinContext->Flags = 0;
+  p->MinContext->SummFreq = 256 + 1;
+  p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */
+  p->LoUnit += U2B(256 / 2);
+  p->MinContext->Stats = REF(p->FoundState);
+  for (i = 0; i < 256; i++)
+  {
+    CPpmd_State *s = &p->FoundState[i];
+    s->Symbol = (Byte)i;
+    s->Freq = 1;
+    SetSuccessor(s, 0);
+  }
+
+  for (i = m = 0; m < 25; m++)
+  {
+    while (p->NS2Indx[i] == m)
+      i++;
+    for (k = 0; k < 8; k++)
+    {
+      UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 1));
+      UInt16 *dest = p->BinSumm[m] + k;
+      for (r = 0; r < 64; r += 8)
+        dest[r] = val;
+    }
+  }
+
+  for (i = m = 0; m < 24; m++)
+  {
+    while (p->NS2Indx[i + 3] == m + 3)
+      i++;
+    for (k = 0; k < 32; k++)
+    {
+      CPpmd_See *s = &p->See[m][k];
+      s->Summ = (UInt16)((2 * i + 5) << (s->Shift = PPMD_PERIOD_BITS - 4));
+      s->Count = 7;
+    }
+  }
+}
+
+void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod)
+{
+  p->MaxOrder = maxOrder;
+  p->RestoreMethod = restoreMethod;
+  RestartModel(p);
+  p->DummySee.Shift = PPMD_PERIOD_BITS;
+  p->DummySee.Summ = 0; /* unused */
+  p->DummySee.Count = 64; /* unused */
+}
+
+static void Refresh(CPpmd8 *p, CTX_PTR ctx, unsigned oldNU, unsigned scale)
+{
+  unsigned i = ctx->NumStats, escFreq, sumFreq, flags;
+  CPpmd_State *s = (CPpmd_State *)ShrinkUnits(p, STATS(ctx), oldNU, (i + 2) >> 1);
+  ctx->Stats = REF(s);
+  #ifdef PPMD8_FREEZE_SUPPORT
+  /* fixed over Shkarin's code. Fixed code is not compatible with original code for some files in FREEZE mode. */
+  scale |= (ctx->SummFreq >= ((UInt32)1 << 15));
+  #endif
+  flags = (ctx->Flags & (0x10 + 0x04 * scale)) + 0x08 * (s->Symbol >= 0x40);
+  escFreq = ctx->SummFreq - s->Freq;
+  sumFreq = (s->Freq = (Byte)((s->Freq + scale) >> scale));
+  do
+  {
+    escFreq -= (++s)->Freq;
+    sumFreq += (s->Freq = (Byte)((s->Freq + scale) >> scale));
+    flags |= 0x08 * (s->Symbol >= 0x40);
+  }
+  while (--i);
+  ctx->SummFreq = (UInt16)(sumFreq + ((escFreq + scale) >> scale));
+  ctx->Flags = (Byte)flags;
+}
+
+static void SwapStates(CPpmd_State *t1, CPpmd_State *t2)
+{
+  CPpmd_State tmp = *t1;
+  *t1 = *t2;
+  *t2 = tmp;
+}
+
+static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order)
+{
+  int i;
+  unsigned tmp;
+  CPpmd_State *s;
+  
+  if (!ctx->NumStats)
+  {
+    s = ONE_STATE(ctx);
+    if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart)
+    {
+      if (order < p->MaxOrder)
+        SetSuccessor(s, CutOff(p, CTX(SUCCESSOR(s)), order + 1));
+      else
+        SetSuccessor(s, 0);
+      if (SUCCESSOR(s) || order <= 9) /* O_BOUND */
+        return REF(ctx);
+    }
+    SpecialFreeUnit(p, ctx);
+    return 0;
+  }
+
+  ctx->Stats = STATS_REF(MoveUnitsUp(p, STATS(ctx), tmp = ((unsigned)ctx->NumStats + 2) >> 1));
+
+  for (s = STATS(ctx) + (i = ctx->NumStats); s >= STATS(ctx); s--)
+    if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) < p->UnitsStart)
+    {
+      CPpmd_State *s2 = STATS(ctx) + (i--);
+      SetSuccessor(s, 0);
+      SwapStates(s, s2);
+    }
+    else if (order < p->MaxOrder)
+      SetSuccessor(s, CutOff(p, CTX(SUCCESSOR(s)), order + 1));
+    else
+      SetSuccessor(s, 0);
+    
+  if (i != ctx->NumStats && order)
+  {
+    ctx->NumStats = (Byte)i;
+    s = STATS(ctx);
+    if (i < 0)
+    {
+      FreeUnits(p, s, tmp);
+      SpecialFreeUnit(p, ctx);
+      return 0;
+    }
+    if (i == 0)
+    {
+      ctx->Flags = (ctx->Flags & 0x10) + 0x08 * (s->Symbol >= 0x40);
+      *ONE_STATE(ctx) = *s;
+      FreeUnits(p, s, tmp);
+      ONE_STATE(ctx)->Freq = (Byte)((unsigned)ONE_STATE(ctx)->Freq + 11) >> 3;
+    }
+    else
+      Refresh(p, ctx, tmp, ctx->SummFreq > 16 * i);
+  }
+  return REF(ctx);
+}
+
+#ifdef PPMD8_FREEZE_SUPPORT
+static CPpmd_Void_Ref RemoveBinContexts(CPpmd8 *p, CTX_PTR ctx, unsigned order)
+{
+  CPpmd_State *s;
+  if (!ctx->NumStats)
+  {
+    s = ONE_STATE(ctx);
+    if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart && order < p->MaxOrder)
+      SetSuccessor(s, RemoveBinContexts(p, CTX(SUCCESSOR(s)), order + 1));
+    else
+      SetSuccessor(s, 0);
+    /* Suffix context can be removed already, since different (high-order)
+       Successors may refer to same context. So we check Flags == 0xFF (Stamp == EMPTY_NODE) */
+    if (!SUCCESSOR(s) && (!SUFFIX(ctx)->NumStats || SUFFIX(ctx)->Flags == 0xFF))
+    {
+      FreeUnits(p, ctx, 1);
+      return 0;
+    }
+    else
+      return REF(ctx);
+  }
+
+  for (s = STATS(ctx) + ctx->NumStats; s >= STATS(ctx); s--)
+    if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart && order < p->MaxOrder)
+      SetSuccessor(s, RemoveBinContexts(p, CTX(SUCCESSOR(s)), order + 1));
+    else
+      SetSuccessor(s, 0);
+  
+  return REF(ctx);
+}
+#endif
+
+static UInt32 GetUsedMemory(const CPpmd8 *p)
+{
+  UInt32 v = 0;
+  unsigned i;
+  for (i = 0; i < PPMD_NUM_INDEXES; i++)
+    v += p->Stamps[i] * I2U(i);
+  return p->Size - (UInt32)(p->HiUnit - p->LoUnit) - (UInt32)(p->UnitsStart - p->Text) - U2B(v);
+}
+
+#ifdef PPMD8_FREEZE_SUPPORT
+  #define RESTORE_MODEL(c1, fSuccessor) RestoreModel(p, c1, fSuccessor)
+#else
+  #define RESTORE_MODEL(c1, fSuccessor) RestoreModel(p, c1)
+#endif
+
+static void RestoreModel(CPpmd8 *p, CTX_PTR c1
+    #ifdef PPMD8_FREEZE_SUPPORT
+    , CTX_PTR fSuccessor
+    #endif
+    )
+{
+  CTX_PTR c;
+  CPpmd_State *s;
+  RESET_TEXT(0);
+  for (c = p->MaxContext; c != c1; c = SUFFIX(c))
+    if (--(c->NumStats) == 0)
+    {
+      s = STATS(c);
+      c->Flags = (c->Flags & 0x10) + 0x08 * (s->Symbol >= 0x40);
+      *ONE_STATE(c) = *s;
+      SpecialFreeUnit(p, s);
+      ONE_STATE(c)->Freq = (ONE_STATE(c)->Freq + 11) >> 3;
+    }
+    else
+      Refresh(p, c, (c->NumStats+3) >> 1, 0);
+ 
+  for (; c != p->MinContext; c = SUFFIX(c))
+    if (!c->NumStats)
+      ONE_STATE(c)->Freq -= ONE_STATE(c)->Freq >> 1;
+    else if ((c->SummFreq += 4) > 128 + 4 * c->NumStats)
+      Refresh(p, c, (c->NumStats + 2) >> 1, 1);
+
+  #ifdef PPMD8_FREEZE_SUPPORT
+  if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
+  {
+    p->MaxContext = fSuccessor;
+    p->GlueCount += !(p->Stamps[1] & 1);
+  }
+  else if (p->RestoreMethod == PPMD8_RESTORE_METHOD_FREEZE)
+  {
+    while (p->MaxContext->Suffix)
+      p->MaxContext = SUFFIX(p->MaxContext);
+    RemoveBinContexts(p, p->MaxContext, 0);
+    p->RestoreMethod++;
+    p->GlueCount = 0;
+    p->OrderFall = p->MaxOrder;
+  }
+  else
+  #endif
+  if (p->RestoreMethod == PPMD8_RESTORE_METHOD_RESTART || GetUsedMemory(p) < (p->Size >> 1))
+    RestartModel(p);
+  else
+  {
+    while (p->MaxContext->Suffix)
+      p->MaxContext = SUFFIX(p->MaxContext);
+    do
+    {
+      CutOff(p, p->MaxContext, 0);
+      ExpandTextArea(p);
+    }
+    while (GetUsedMemory(p) > 3 * (p->Size >> 2));
+    p->GlueCount = 0;
+    p->OrderFall = p->MaxOrder;
+  }
+}
+
+static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c)
+{
+  CPpmd_State upState;
+  Byte flags;
+  CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);
+  /* fixed over Shkarin's code. Maybe it could work without + 1 too. */
+  CPpmd_State *ps[PPMD8_MAX_ORDER + 1];
+  unsigned numPs = 0;
+  
+  if (!skip)
+    ps[numPs++] = p->FoundState;
+  
+  while (c->Suffix)
+  {
+    CPpmd_Void_Ref successor;
+    CPpmd_State *s;
+    c = SUFFIX(c);
+    if (s1)
+    {
+      s = s1;
+      s1 = NULL;
+    }
+    else if (c->NumStats != 0)
+    {
+      for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++);
+      if (s->Freq < MAX_FREQ - 9)
+      {
+        s->Freq++;
+        c->SummFreq++;
+      }
+    }
+    else
+    {
+      s = ONE_STATE(c);
+      s->Freq += (!SUFFIX(c)->NumStats & (s->Freq < 24));
+    }
+    successor = SUCCESSOR(s);
+    if (successor != upBranch)
+    {
+      c = CTX(successor);
+      if (numPs == 0)
+        return c;
+      break;
+    }
+    ps[numPs++] = s;
+  }
+  
+  upState.Symbol = *(const Byte *)Ppmd8_GetPtr(p, upBranch);
+  SetSuccessor(&upState, upBranch + 1);
+  flags = 0x10 * (p->FoundState->Symbol >= 0x40) + 0x08 * (upState.Symbol >= 0x40);
+
+  if (c->NumStats == 0)
+    upState.Freq = ONE_STATE(c)->Freq;
+  else
+  {
+    UInt32 cf, s0;
+    CPpmd_State *s;
+    for (s = STATS(c); s->Symbol != upState.Symbol; s++);
+    cf = s->Freq - 1;
+    s0 = c->SummFreq - c->NumStats - cf;
+    upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((cf + 2 * s0 - 3) / s0)));
+  }
+
+  do
+  {
+    /* Create Child */
+    CTX_PTR c1; /* = AllocContext(p); */
+    if (p->HiUnit != p->LoUnit)
+      c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE);
+    else if (p->FreeList[0] != 0)
+      c1 = (CTX_PTR)RemoveNode(p, 0);
+    else
+    {
+      c1 = (CTX_PTR)AllocUnitsRare(p, 0);
+      if (!c1)
+        return NULL;
+    }
+    c1->NumStats = 0;
+    c1->Flags = flags;
+    *ONE_STATE(c1) = upState;
+    c1->Suffix = REF(c);
+    SetSuccessor(ps[--numPs], REF(c1));
+    c = c1;
+  }
+  while (numPs != 0);
+  
+  return c;
+}
+
+static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c)
+{
+  CPpmd_State *s = NULL;
+  CTX_PTR c1 = c;
+  CPpmd_Void_Ref upBranch = REF(p->Text);
+  
+  #ifdef PPMD8_FREEZE_SUPPORT
+  /* The BUG in Shkarin's code was fixed: ps could overflow in CUT_OFF mode. */
+  CPpmd_State *ps[PPMD8_MAX_ORDER + 1];
+  unsigned numPs = 0;
+  ps[numPs++] = p->FoundState;
+  #endif
+
+  SetSuccessor(p->FoundState, upBranch);
+  p->OrderFall++;
+
+  for (;;)
+  {
+    if (s1)
+    {
+      c = SUFFIX(c);
+      s = s1;
+      s1 = NULL;
+    }
+    else
+    {
+      if (!c->Suffix)
+      {
+        #ifdef PPMD8_FREEZE_SUPPORT
+        if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
+        {
+          do { SetSuccessor(ps[--numPs], REF(c)); } while (numPs);
+          RESET_TEXT(1);
+          p->OrderFall = 1;
+        }
+        #endif
+        return c;
+      }
+      c = SUFFIX(c);
+      if (c->NumStats)
+      {
+        if ((s = STATS(c))->Symbol != p->FoundState->Symbol)
+          do { s++; } while (s->Symbol != p->FoundState->Symbol);
+        if (s->Freq < MAX_FREQ - 9)
+        {
+          s->Freq += 2;
+          c->SummFreq += 2;
+        }
+      }
+      else
+      {
+        s = ONE_STATE(c);
+        s->Freq += (s->Freq < 32);
+      }
+    }
+    if (SUCCESSOR(s))
+      break;
+    #ifdef PPMD8_FREEZE_SUPPORT
+    ps[numPs++] = s;
+    #endif
+    SetSuccessor(s, upBranch);
+    p->OrderFall++;
+  }
+  
+  #ifdef PPMD8_FREEZE_SUPPORT
+  if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
+  {
+    c = CTX(SUCCESSOR(s));
+    do { SetSuccessor(ps[--numPs], REF(c)); } while (numPs);
+    RESET_TEXT(1);
+    p->OrderFall = 1;
+    return c;
+  }
+  else
+  #endif
+  if (SUCCESSOR(s) <= upBranch)
+  {
+    CTX_PTR successor;
+    CPpmd_State *s1 = p->FoundState;
+    p->FoundState = s;
+
+    successor = CreateSuccessors(p, False, NULL, c);
+    if (successor == NULL)
+      SetSuccessor(s, 0);
+    else
+      SetSuccessor(s, REF(successor));
+    p->FoundState = s1;
+  }
+  
+  if (p->OrderFall == 1 && c1 == p->MaxContext)
+  {
+    SetSuccessor(p->FoundState, SUCCESSOR(s));
+    p->Text--;
+  }
+  if (SUCCESSOR(s) == 0)
+    return NULL;
+  return CTX(SUCCESSOR(s));
+}
+
+static void UpdateModel(CPpmd8 *p)
+{
+  CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);
+  CTX_PTR c;
+  unsigned s0, ns, fFreq = p->FoundState->Freq;
+  Byte flag, fSymbol = p->FoundState->Symbol;
+  CPpmd_State *s = NULL;
+  
+  if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)
+  {
+    c = SUFFIX(p->MinContext);
+    
+    if (c->NumStats == 0)
+    {
+      s = ONE_STATE(c);
+      if (s->Freq < 32)
+        s->Freq++;
+    }
+    else
+    {
+      s = STATS(c);
+      if (s->Symbol != p->FoundState->Symbol)
+      {
+        do { s++; } while (s->Symbol != p->FoundState->Symbol);
+        if (s[0].Freq >= s[-1].Freq)
+        {
+          SwapStates(&s[0], &s[-1]);
+          s--;
+        }
+      }
+      if (s->Freq < MAX_FREQ - 9)
+      {
+        s->Freq += 2;
+        c->SummFreq += 2;
+      }
+    }
+  }
+  
+  c = p->MaxContext;
+  if (p->OrderFall == 0 && fSuccessor)
+  {
+    CTX_PTR cs = CreateSuccessors(p, True, s, p->MinContext);
+    if (cs == 0)
+    {
+      SetSuccessor(p->FoundState, 0);
+      RESTORE_MODEL(c, CTX(fSuccessor));
+    }
+    else
+    {
+      SetSuccessor(p->FoundState, REF(cs));
+      p->MaxContext = cs;
+    }
+    return;
+  }
+  
+  *p->Text++ = p->FoundState->Symbol;
+  successor = REF(p->Text);
+  if (p->Text >= p->UnitsStart)
+  {
+    RESTORE_MODEL(c, CTX(fSuccessor)); /* check it */
+    return;
+  }
+  
+  if (!fSuccessor)
+  {
+    CTX_PTR cs = ReduceOrder(p, s, p->MinContext);
+    if (cs == NULL)
+    {
+      RESTORE_MODEL(c, 0);
+      return;
+    }
+    fSuccessor = REF(cs);
+  }
+  else if ((Byte *)Ppmd8_GetPtr(p, fSuccessor) < p->UnitsStart)
+  {
+    CTX_PTR cs = CreateSuccessors(p, False, s, p->MinContext);
+    if (cs == NULL)
+    {
+      RESTORE_MODEL(c, 0);
+      return;
+    }
+    fSuccessor = REF(cs);
+  }
+  
+  if (--p->OrderFall == 0)
+  {
+    successor = fSuccessor;
+    p->Text -= (p->MaxContext != p->MinContext);
+  }
+  #ifdef PPMD8_FREEZE_SUPPORT
+  else if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
+  {
+    successor = fSuccessor;
+    RESET_TEXT(0);
+    p->OrderFall = 0;
+  }
+  #endif
+  
+  s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - fFreq;
+  flag = 0x08 * (fSymbol >= 0x40);
+  
+  for (; c != p->MinContext; c = SUFFIX(c))
+  {
+    unsigned ns1;
+    UInt32 cf, sf;
+    if ((ns1 = c->NumStats) != 0)
+    {
+      if ((ns1 & 1) != 0)
+      {
+        /* Expand for one UNIT */
+        unsigned oldNU = (ns1 + 1) >> 1;
+        unsigned i = U2I(oldNU);
+        if (i != U2I(oldNU + 1))
+        {
+          void *ptr = AllocUnits(p, i + 1);
+          void *oldPtr;
+          if (!ptr)
+          {
+            RESTORE_MODEL(c, CTX(fSuccessor));
+            return;
+          }
+          oldPtr = STATS(c);
+          MyMem12Cpy(ptr, oldPtr, oldNU);
+          InsertNode(p, oldPtr, i);
+          c->Stats = STATS_REF(ptr);
+        }
+      }
+      c->SummFreq = (UInt16)(c->SummFreq + (3 * ns1 + 1 < ns));
+    }
+    else
+    {
+      CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0);
+      if (!s)
+      {
+        RESTORE_MODEL(c, CTX(fSuccessor));
+        return;
+      }
+      *s = *ONE_STATE(c);
+      c->Stats = REF(s);
+      if (s->Freq < MAX_FREQ / 4 - 1)
+        s->Freq <<= 1;
+      else
+        s->Freq = MAX_FREQ - 4;
+      c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 2));
+    }
+    cf = 2 * fFreq * (c->SummFreq + 6);
+    sf = (UInt32)s0 + c->SummFreq;
+    if (cf < 6 * sf)
+    {
+      cf = 1 + (cf > sf) + (cf >= 4 * sf);
+      c->SummFreq += 4;
+    }
+    else
+    {
+      cf = 4 + (cf > 9 * sf) + (cf > 12 * sf) + (cf > 15 * sf);
+      c->SummFreq = (UInt16)(c->SummFreq + cf);
+    }
+    {
+      CPpmd_State *s = STATS(c) + ns1 + 1;
+      SetSuccessor(s, successor);
+      s->Symbol = fSymbol;
+      s->Freq = (Byte)cf;
+      c->Flags |= flag;
+      c->NumStats = (Byte)(ns1 + 1);
+    }
+  }
+  p->MaxContext = p->MinContext = CTX(fSuccessor);
+}
+  
+static void Rescale(CPpmd8 *p)
+{
+  unsigned i, adder, sumFreq, escFreq;
+  CPpmd_State *stats = STATS(p->MinContext);
+  CPpmd_State *s = p->FoundState;
+  {
+    CPpmd_State tmp = *s;
+    for (; s != stats; s--)
+      s[0] = s[-1];
+    *s = tmp;
+  }
+  escFreq = p->MinContext->SummFreq - s->Freq;
+  s->Freq += 4;
+  adder = (p->OrderFall != 0
+      #ifdef PPMD8_FREEZE_SUPPORT
+      || p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE
+      #endif
+      );
+  s->Freq = (Byte)((s->Freq + adder) >> 1);
+  sumFreq = s->Freq;
+  
+  i = p->MinContext->NumStats;
+  do
+  {
+    escFreq -= (++s)->Freq;
+    s->Freq = (Byte)((s->Freq + adder) >> 1);
+    sumFreq += s->Freq;
+    if (s[0].Freq > s[-1].Freq)
+    {
+      CPpmd_State *s1 = s;
+      CPpmd_State tmp = *s1;
+      do
+        s1[0] = s1[-1];
+      while (--s1 != stats && tmp.Freq > s1[-1].Freq);
+      *s1 = tmp;
+    }
+  }
+  while (--i);
+  
+  if (s->Freq == 0)
+  {
+    unsigned numStats = p->MinContext->NumStats;
+    unsigned n0, n1;
+    do { i++; } while ((--s)->Freq == 0);
+    escFreq += i;
+    p->MinContext->NumStats = (Byte)(p->MinContext->NumStats - i);
+    if (p->MinContext->NumStats == 0)
+    {
+      CPpmd_State tmp = *stats;
+      tmp.Freq = (Byte)((2 * tmp.Freq + escFreq - 1) / escFreq);
+      if (tmp.Freq > MAX_FREQ / 3)
+        tmp.Freq = MAX_FREQ / 3;
+      InsertNode(p, stats, U2I((numStats + 2) >> 1));
+      p->MinContext->Flags = (p->MinContext->Flags & 0x10) + 0x08 * (tmp.Symbol >= 0x40);
+      *(p->FoundState = ONE_STATE(p->MinContext)) = tmp;
+      return;
+    }
+    n0 = (numStats + 2) >> 1;
+    n1 = (p->MinContext->NumStats + 2) >> 1;
+    if (n0 != n1)
+      p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1));
+    p->MinContext->Flags &= ~0x08;
+    p->MinContext->Flags |= 0x08 * ((s = STATS(p->MinContext))->Symbol >= 0x40);
+    i = p->MinContext->NumStats;
+    do { p->MinContext->Flags |= 0x08*((++s)->Symbol >= 0x40); } while (--i);
+  }
+  p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1));
+  p->MinContext->Flags |= 0x4;
+  p->FoundState = STATS(p->MinContext);
+}
+
+CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked1, UInt32 *escFreq)
+{
+  CPpmd_See *see;
+  if (p->MinContext->NumStats != 0xFF)
+  {
+    see = p->See[p->NS2Indx[p->MinContext->NumStats + 2] - 3] +
+        (p->MinContext->SummFreq > 11 * ((unsigned)p->MinContext->NumStats + 1)) +
+        2 * (2 * (unsigned)p->MinContext->NumStats <
+        ((unsigned)SUFFIX(p->MinContext)->NumStats + numMasked1)) +
+        p->MinContext->Flags;
+    {
+      unsigned r = (see->Summ >> see->Shift);
+      see->Summ = (UInt16)(see->Summ - r);
+      *escFreq = r + (r == 0);
+    }
+  }
+  else
+  {
+    see = &p->DummySee;
+    *escFreq = 1;
+  }
+  return see;
+}
+
+static void NextContext(CPpmd8 *p)
+{
+  CTX_PTR c = CTX(SUCCESSOR(p->FoundState));
+  if (p->OrderFall == 0 && (Byte *)c >= p->UnitsStart)
+    p->MinContext = p->MaxContext = c;
+  else
+  {
+    UpdateModel(p);
+    p->MinContext = p->MaxContext;
+  }
+}
+
+void Ppmd8_Update1(CPpmd8 *p)
+{
+  CPpmd_State *s = p->FoundState;
+  s->Freq += 4;
+  p->MinContext->SummFreq += 4;
+  if (s[0].Freq > s[-1].Freq)
+  {
+    SwapStates(&s[0], &s[-1]);
+    p->FoundState = --s;
+    if (s->Freq > MAX_FREQ)
+      Rescale(p);
+  }
+  NextContext(p);
+}
+
+void Ppmd8_Update1_0(CPpmd8 *p)
+{
+  p->PrevSuccess = (2 * p->FoundState->Freq >= p->MinContext->SummFreq);
+  p->RunLength += p->PrevSuccess;
+  p->MinContext->SummFreq += 4;
+  if ((p->FoundState->Freq += 4) > MAX_FREQ)
+    Rescale(p);
+  NextContext(p);
+}
+
+void Ppmd8_UpdateBin(CPpmd8 *p)
+{
+  p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 196));
+  p->PrevSuccess = 1;
+  p->RunLength++;
+  NextContext(p);
+}
+
+void Ppmd8_Update2(CPpmd8 *p)
+{
+  p->MinContext->SummFreq += 4;
+  if ((p->FoundState->Freq += 4) > MAX_FREQ)
+    Rescale(p);
+  p->RunLength = p->InitRL;
+  UpdateModel(p);
+  p->MinContext = p->MaxContext;
+}
+
+/* H->I changes:
+  NS2Indx
+  GlewCount, and Glue method
+  BinSum
+  See / EscFreq
+  CreateSuccessors updates more suffix contexts
+  UpdateModel consts.
+  PrevSuccess Update
+*/

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,133 @@
+/* Ppmd8.h -- PPMdI codec
+2010-03-24 : Igor Pavlov : Public domain
+This code is based on:
+  PPMd var.I (2002): Dmitry Shkarin : Public domain
+  Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
+
+#ifndef __PPMD8_H
+#define __PPMD8_H
+
+#include "Ppmd.h"
+
+EXTERN_C_BEGIN
+
+#define PPMD8_MIN_ORDER 2
+#define PPMD8_MAX_ORDER 16
+
+struct CPpmd8_Context_;
+
+typedef
+  #ifdef PPMD_32BIT
+    struct CPpmd8_Context_ *
+  #else
+    UInt32
+  #endif
+  CPpmd8_Context_Ref;
+
+typedef struct CPpmd8_Context_
+{
+  Byte NumStats;
+  Byte Flags;
+  UInt16 SummFreq;
+  CPpmd_State_Ref Stats;
+  CPpmd8_Context_Ref Suffix;
+} CPpmd8_Context;
+
+#define Ppmd8Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)
+
+/* The BUG in Shkarin's code for FREEZE mode was fixed, but that fixed
+   code is not compatible with original code for some files compressed
+   in FREEZE mode. So we disable FREEZE mode support. */
+
+enum
+{
+  PPMD8_RESTORE_METHOD_RESTART,
+  PPMD8_RESTORE_METHOD_CUT_OFF
+  #ifdef PPMD8_FREEZE_SUPPORT
+  , PPMD8_RESTORE_METHOD_FREEZE
+  #endif
+};
+
+typedef struct
+{
+  CPpmd8_Context *MinContext, *MaxContext;
+  CPpmd_State *FoundState;
+  unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder;
+  Int32 RunLength, InitRL; /* must be 32-bit at least */
+
+  UInt32 Size;
+  UInt32 GlueCount;
+  Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;
+  UInt32 AlignOffset;
+  unsigned RestoreMethod;
+
+  /* Range Coder */
+  UInt32 Range;
+  UInt32 Code;
+  UInt32 Low;
+  union
+  {
+    IByteIn *In;
+    IByteOut *Out;
+  } Stream;
+
+  Byte Indx2Units[PPMD_NUM_INDEXES];
+  Byte Units2Indx[128];
+  CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES];
+  UInt32 Stamps[PPMD_NUM_INDEXES];
+
+  Byte NS2BSIndx[256], NS2Indx[260];
+  CPpmd_See DummySee, See[24][32];
+  UInt16 BinSumm[25][64];
+} CPpmd8;
+
+void Ppmd8_Construct(CPpmd8 *p);
+Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc);
+void Ppmd8_Free(CPpmd8 *p, ISzAlloc *alloc);
+void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod);
+#define Ppmd8_WasAllocated(p) ((p)->Base != NULL)
+
+
+/* ---------- Internal Functions ---------- */
+
+extern const Byte PPMD8_kExpEscape[16];
+
+#ifdef PPMD_32BIT
+  #define Ppmd8_GetPtr(p, ptr) (ptr)
+  #define Ppmd8_GetContext(p, ptr) (ptr)
+  #define Ppmd8_GetStats(p, ctx) ((ctx)->Stats)
+#else
+  #define Ppmd8_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
+  #define Ppmd8_GetContext(p, offs) ((CPpmd8_Context *)Ppmd8_GetPtr((p), (offs)))
+  #define Ppmd8_GetStats(p, ctx) ((CPpmd_State *)Ppmd8_GetPtr((p), ((ctx)->Stats)))
+#endif
+
+void Ppmd8_Update1(CPpmd8 *p);
+void Ppmd8_Update1_0(CPpmd8 *p);
+void Ppmd8_Update2(CPpmd8 *p);
+void Ppmd8_UpdateBin(CPpmd8 *p);
+
+#define Ppmd8_GetBinSumm(p) \
+    &p->BinSumm[p->NS2Indx[Ppmd8Context_OneState(p->MinContext)->Freq - 1]][ \
+    p->NS2BSIndx[Ppmd8_GetContext(p, p->MinContext->Suffix)->NumStats] + \
+    p->PrevSuccess + p->MinContext->Flags + ((p->RunLength >> 26) & 0x20)]
+
+CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked, UInt32 *scale);
+
+
+/* ---------- Decode ---------- */
+
+Bool Ppmd8_RangeDec_Init(CPpmd8 *p);
+#define Ppmd8_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
+int Ppmd8_DecodeSymbol(CPpmd8 *p); /* returns: -1 as EndMarker, -2 as DataError */
+
+
+/* ---------- Encode ---------- */
+
+#define Ppmd8_RangeEnc_Init(p) { (p)->Low = 0; (p)->Range = 0xFFFFFFFF; }
+void Ppmd8_RangeEnc_FlushData(CPpmd8 *p);
+void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol); /* symbol = -1 means EndMarker */
+
+EXTERN_C_END
+ 
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Dec.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Dec.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Dec.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Dec.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,155 @@
+/* Ppmd8Dec.c -- PPMdI Decoder
+2010-04-16 : Igor Pavlov : Public domain
+This code is based on:
+  PPMd var.I (2002): Dmitry Shkarin : Public domain
+  Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
+
+#include "Ppmd8.h"
+
+#define kTop (1 << 24)
+#define kBot (1 << 15)
+
+Bool Ppmd8_RangeDec_Init(CPpmd8 *p)
+{
+  unsigned i;
+  p->Low = 0;
+  p->Range = 0xFFFFFFFF;
+  p->Code = 0;
+  for (i = 0; i < 4; i++)
+    p->Code = (p->Code << 8) | p->Stream.In->Read(p->Stream.In);
+  return (p->Code < 0xFFFFFFFF);
+}
+
+static UInt32 RangeDec_GetThreshold(CPpmd8 *p, UInt32 total)
+{
+  return p->Code / (p->Range /= total);
+}
+
+static void RangeDec_Decode(CPpmd8 *p, UInt32 start, UInt32 size)
+{
+  start *= p->Range;
+  p->Low += start;
+  p->Code -= start;
+  p->Range *= size;
+
+  while ((p->Low ^ (p->Low + p->Range)) < kTop ||
+      (p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1)))
+  {
+    p->Code = (p->Code << 8) | p->Stream.In->Read(p->Stream.In);
+    p->Range <<= 8;
+    p->Low <<= 8;
+  }
+}
+
+#define MASK(sym) ((signed char *)charMask)[sym]
+
+int Ppmd8_DecodeSymbol(CPpmd8 *p)
+{
+  size_t charMask[256 / sizeof(size_t)];
+  if (p->MinContext->NumStats != 0)
+  {
+    CPpmd_State *s = Ppmd8_GetStats(p, p->MinContext);
+    unsigned i;
+    UInt32 count, hiCnt;
+    if ((count = RangeDec_GetThreshold(p, p->MinContext->SummFreq)) < (hiCnt = s->Freq))
+    {
+      Byte symbol;
+      RangeDec_Decode(p, 0, s->Freq);
+      p->FoundState = s;
+      symbol = s->Symbol;
+      Ppmd8_Update1_0(p);
+      return symbol;
+    }
+    p->PrevSuccess = 0;
+    i = p->MinContext->NumStats;
+    do
+    {
+      if ((hiCnt += (++s)->Freq) > count)
+      {
+        Byte symbol;
+        RangeDec_Decode(p, hiCnt - s->Freq, s->Freq);
+        p->FoundState = s;
+        symbol = s->Symbol;
+        Ppmd8_Update1(p);
+        return symbol;
+      }
+    }
+    while (--i);
+    if (count >= p->MinContext->SummFreq)
+      return -2;
+    RangeDec_Decode(p, hiCnt, p->MinContext->SummFreq - hiCnt);
+    PPMD_SetAllBitsIn256Bytes(charMask);
+    MASK(s->Symbol) = 0;
+    i = p->MinContext->NumStats;
+    do { MASK((--s)->Symbol) = 0; } while (--i);
+  }
+  else
+  {
+    UInt16 *prob = Ppmd8_GetBinSumm(p);
+    if (((p->Code / (p->Range >>= 14)) < *prob))
+    {
+      Byte symbol;
+      RangeDec_Decode(p, 0, *prob);
+      *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
+      symbol = (p->FoundState = Ppmd8Context_OneState(p->MinContext))->Symbol;
+      Ppmd8_UpdateBin(p);
+      return symbol;
+    }
+    RangeDec_Decode(p, *prob, (1 << 14) - *prob);
+    *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
+    p->InitEsc = PPMD8_kExpEscape[*prob >> 10];
+    PPMD_SetAllBitsIn256Bytes(charMask);
+    MASK(Ppmd8Context_OneState(p->MinContext)->Symbol) = 0;
+    p->PrevSuccess = 0;
+  }
+  for (;;)
+  {
+    CPpmd_State *ps[256], *s;
+    UInt32 freqSum, count, hiCnt;
+    CPpmd_See *see;
+    unsigned i, num, numMasked = p->MinContext->NumStats;
+    do
+    {
+      p->OrderFall++;
+      if (!p->MinContext->Suffix)
+        return -1;
+      p->MinContext = Ppmd8_GetContext(p, p->MinContext->Suffix);
+    }
+    while (p->MinContext->NumStats == numMasked);
+    hiCnt = 0;
+    s = Ppmd8_GetStats(p, p->MinContext);
+    i = 0;
+    num = p->MinContext->NumStats - numMasked;
+    do
+    {
+      int k = (int)(MASK(s->Symbol));
+      hiCnt += (s->Freq & k);
+      ps[i] = s++;
+      i -= k;
+    }
+    while (i != num);
+    
+    see = Ppmd8_MakeEscFreq(p, numMasked, &freqSum);
+    freqSum += hiCnt;
+    count = RangeDec_GetThreshold(p, freqSum);
+    
+    if (count < hiCnt)
+    {
+      Byte symbol;
+      CPpmd_State **pps = ps;
+      for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);
+      s = *pps;
+      RangeDec_Decode(p, hiCnt - s->Freq, s->Freq);
+      Ppmd_See_Update(see);
+      p->FoundState = s;
+      symbol = s->Symbol;
+      Ppmd8_Update2(p);
+      return symbol;
+    }
+    if (count >= freqSum)
+      return -2;
+    RangeDec_Decode(p, hiCnt, freqSum - hiCnt);
+    see->Summ = (UInt16)(see->Summ + freqSum);
+    do { MASK(ps[--i]->Symbol) = 0; } while (i != 0);
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Enc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Enc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Enc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Ppmd8Enc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,161 @@
+/* Ppmd8Enc.c -- PPMdI Encoder
+2010-04-16 : Igor Pavlov : Public domain
+This code is based on:
+  PPMd var.I (2002): Dmitry Shkarin : Public domain
+  Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
+
+#include "Ppmd8.h"
+
+#define kTop (1 << 24)
+#define kBot (1 << 15)
+
+void Ppmd8_RangeEnc_FlushData(CPpmd8 *p)
+{
+  unsigned i;
+  for (i = 0; i < 4; i++, p->Low <<= 8 )
+    p->Stream.Out->Write(p->Stream.Out, (Byte)(p->Low >> 24));
+}
+
+static void RangeEnc_Normalize(CPpmd8 *p)
+{
+  while ((p->Low ^ (p->Low + p->Range)) < kTop ||
+      (p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1)))
+  {
+    p->Stream.Out->Write(p->Stream.Out, (Byte)(p->Low >> 24));
+    p->Range <<= 8;
+    p->Low <<= 8;
+  }
+}
+
+static void RangeEnc_Encode(CPpmd8 *p, UInt32 start, UInt32 size, UInt32 total)
+{
+  p->Low += start * (p->Range /= total);
+  p->Range *= size;
+  RangeEnc_Normalize(p);
+}
+
+static void RangeEnc_EncodeBit_0(CPpmd8 *p, UInt32 size0)
+{
+  p->Range >>= 14;
+  p->Range *= size0;
+  RangeEnc_Normalize(p);
+}
+
+static void RangeEnc_EncodeBit_1(CPpmd8 *p, UInt32 size0)
+{
+  p->Low += size0 * (p->Range >>= 14);
+  p->Range *= ((1 << 14) - size0);
+  RangeEnc_Normalize(p);
+}
+
+
+#define MASK(sym) ((signed char *)charMask)[sym]
+
+void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol)
+{
+  size_t charMask[256 / sizeof(size_t)];
+  if (p->MinContext->NumStats != 0)
+  {
+    CPpmd_State *s = Ppmd8_GetStats(p, p->MinContext);
+    UInt32 sum;
+    unsigned i;
+    if (s->Symbol == symbol)
+    {
+      RangeEnc_Encode(p, 0, s->Freq, p->MinContext->SummFreq);
+      p->FoundState = s;
+      Ppmd8_Update1_0(p);
+      return;
+    }
+    p->PrevSuccess = 0;
+    sum = s->Freq;
+    i = p->MinContext->NumStats;
+    do
+    {
+      if ((++s)->Symbol == symbol)
+      {
+        RangeEnc_Encode(p, sum, s->Freq, p->MinContext->SummFreq);
+        p->FoundState = s;
+        Ppmd8_Update1(p);
+        return;
+      }
+      sum += s->Freq;
+    }
+    while (--i);
+    
+    PPMD_SetAllBitsIn256Bytes(charMask);
+    MASK(s->Symbol) = 0;
+    i = p->MinContext->NumStats;
+    do { MASK((--s)->Symbol) = 0; } while (--i);
+    RangeEnc_Encode(p, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq);
+  }
+  else
+  {
+    UInt16 *prob = Ppmd8_GetBinSumm(p);
+    CPpmd_State *s = Ppmd8Context_OneState(p->MinContext);
+    if (s->Symbol == symbol)
+    {
+      RangeEnc_EncodeBit_0(p, *prob);
+      *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
+      p->FoundState = s;
+      Ppmd8_UpdateBin(p);
+      return;
+    }
+    else
+    {
+      RangeEnc_EncodeBit_1(p, *prob);
+      *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
+      p->InitEsc = PPMD8_kExpEscape[*prob >> 10];
+      PPMD_SetAllBitsIn256Bytes(charMask);
+      MASK(s->Symbol) = 0;
+      p->PrevSuccess = 0;
+    }
+  }
+  for (;;)
+  {
+    UInt32 escFreq;
+    CPpmd_See *see;
+    CPpmd_State *s;
+    UInt32 sum;
+    unsigned i, numMasked = p->MinContext->NumStats;
+    do
+    {
+      p->OrderFall++;
+      if (!p->MinContext->Suffix)
+        return; /* EndMarker (symbol = -1) */
+      p->MinContext = Ppmd8_GetContext(p, p->MinContext->Suffix);
+    }
+    while (p->MinContext->NumStats == numMasked);
+    
+    see = Ppmd8_MakeEscFreq(p, numMasked, &escFreq);
+    s = Ppmd8_GetStats(p, p->MinContext);
+    sum = 0;
+    i = p->MinContext->NumStats + 1;
+    do
+    {
+      int cur = s->Symbol;
+      if (cur == symbol)
+      {
+        UInt32 low = sum;
+        CPpmd_State *s1 = s;
+        do
+        {
+          sum += (s->Freq & (int)(MASK(s->Symbol)));
+          s++;
+        }
+        while (--i);
+        RangeEnc_Encode(p, low, s1->Freq, sum + escFreq);
+        Ppmd_See_Update(see);
+        p->FoundState = s1;
+        Ppmd8_Update2(p);
+        return;
+      }
+      sum += (s->Freq & (int)(MASK(cur)));
+      MASK(cur) = 0;
+      s++;
+    }
+    while (--i);
+    
+    RangeEnc_Encode(p, sum, escFreq, sum + escFreq);
+    see->Summ = (UInt16)(see->Summ + sum + escFreq);
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/RotateDefs.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/RotateDefs.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/RotateDefs.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/RotateDefs.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,20 @@
+/* RotateDefs.h -- Rotate functions
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __ROTATE_DEFS_H
+#define __ROTATE_DEFS_H
+
+#ifdef _MSC_VER
+
+#include <stdlib.h>
+#define rotlFixed(x, n) _rotl((x), (n))
+#define rotrFixed(x, n) _rotr((x), (n))
+
+#else
+
+#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
+#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
+
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,204 @@
+/* Crypto/Sha256.c -- SHA-256 Hash
+2010-06-11 : Igor Pavlov : Public domain
+This code is based on public domain code from Wei Dai's Crypto++ library. */
+
+#include "RotateDefs.h"
+#include "Sha256.h"
+
+/* define it for speed optimization */
+/* #define _SHA256_UNROLL */
+/* #define _SHA256_UNROLL2 */
+
+void Sha256_Init(CSha256 *p)
+{
+  p->state[0] = 0x6a09e667;
+  p->state[1] = 0xbb67ae85;
+  p->state[2] = 0x3c6ef372;
+  p->state[3] = 0xa54ff53a;
+  p->state[4] = 0x510e527f;
+  p->state[5] = 0x9b05688c;
+  p->state[6] = 0x1f83d9ab;
+  p->state[7] = 0x5be0cd19;
+  p->count = 0;
+}
+
+#define S0(x) (rotrFixed(x, 2) ^ rotrFixed(x,13) ^ rotrFixed(x, 22))
+#define S1(x) (rotrFixed(x, 6) ^ rotrFixed(x,11) ^ rotrFixed(x, 25))
+#define s0(x) (rotrFixed(x, 7) ^ rotrFixed(x,18) ^ (x >> 3))
+#define s1(x) (rotrFixed(x,17) ^ rotrFixed(x,19) ^ (x >> 10))
+
+#define blk0(i) (W[i] = data[i])
+#define blk2(i) (W[i&15] += s1(W[(i-2)&15]) + W[(i-7)&15] + s0(W[(i-15)&15]))
+
+#define Ch(x,y,z) (z^(x&(y^z)))
+#define Maj(x,y,z) ((x&y)|(z&(x|y)))
+
+#define a(i) T[(0-(i))&7]
+#define b(i) T[(1-(i))&7]
+#define c(i) T[(2-(i))&7]
+#define d(i) T[(3-(i))&7]
+#define e(i) T[(4-(i))&7]
+#define f(i) T[(5-(i))&7]
+#define g(i) T[(6-(i))&7]
+#define h(i) T[(7-(i))&7]
+
+
+#ifdef _SHA256_UNROLL2
+
+#define R(a,b,c,d,e,f,g,h, i) h += S1(e) + Ch(e,f,g) + K[i+j] + (j?blk2(i):blk0(i));\
+  d += h; h += S0(a) + Maj(a, b, c)
+
+#define RX_8(i) \
+  R(a,b,c,d,e,f,g,h, i); \
+  R(h,a,b,c,d,e,f,g, i+1); \
+  R(g,h,a,b,c,d,e,f, i+2); \
+  R(f,g,h,a,b,c,d,e, i+3); \
+  R(e,f,g,h,a,b,c,d, i+4); \
+  R(d,e,f,g,h,a,b,c, i+5); \
+  R(c,d,e,f,g,h,a,b, i+6); \
+  R(b,c,d,e,f,g,h,a, i+7)
+
+#else
+
+#define R(i) h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[i+j] + (j?blk2(i):blk0(i));\
+  d(i) += h(i); h(i) += S0(a(i)) + Maj(a(i), b(i), c(i))
+
+#ifdef _SHA256_UNROLL
+
+#define RX_8(i) R(i+0); R(i+1); R(i+2); R(i+3); R(i+4); R(i+5); R(i+6); R(i+7);
+
+#endif
+
+#endif
+
+static const UInt32 K[64] = {
+  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+  0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+  0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+  0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+  0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+  0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+  0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+  0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+  0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+  0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+  0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+  0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+  0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+  0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
+};
+
+static void Sha256_Transform(UInt32 *state, const UInt32 *data)
+{
+  UInt32 W[16];
+  unsigned j;
+  #ifdef _SHA256_UNROLL2
+  UInt32 a,b,c,d,e,f,g,h;
+  a = state[0];
+  b = state[1];
+  c = state[2];
+  d = state[3];
+  e = state[4];
+  f = state[5];
+  g = state[6];
+  h = state[7];
+  #else
+  UInt32 T[8];
+  for (j = 0; j < 8; j++)
+    T[j] = state[j];
+  #endif
+
+  for (j = 0; j < 64; j += 16)
+  {
+    #if defined(_SHA256_UNROLL) || defined(_SHA256_UNROLL2)
+    RX_8(0); RX_8(8);
+    #else
+    unsigned i;
+    for (i = 0; i < 16; i++) { R(i); }
+    #endif
+  }
+
+  #ifdef _SHA256_UNROLL2
+  state[0] += a;
+  state[1] += b;
+  state[2] += c;
+  state[3] += d;
+  state[4] += e;
+  state[5] += f;
+  state[6] += g;
+  state[7] += h;
+  #else
+  for (j = 0; j < 8; j++)
+    state[j] += T[j];
+  #endif
+  
+  /* Wipe variables */
+  /* memset(W, 0, sizeof(W)); */
+  /* memset(T, 0, sizeof(T)); */
+}
+
+#undef S0
+#undef S1
+#undef s0
+#undef s1
+
+static void Sha256_WriteByteBlock(CSha256 *p)
+{
+  UInt32 data32[16];
+  unsigned i;
+  for (i = 0; i < 16; i++)
+    data32[i] =
+      ((UInt32)(p->buffer[i * 4    ]) << 24) +
+      ((UInt32)(p->buffer[i * 4 + 1]) << 16) +
+      ((UInt32)(p->buffer[i * 4 + 2]) <<  8) +
+      ((UInt32)(p->buffer[i * 4 + 3]));
+  Sha256_Transform(p->state, data32);
+}
+
+void Sha256_Update(CSha256 *p, const Byte *data, size_t size)
+{
+  UInt32 curBufferPos = (UInt32)p->count & 0x3F;
+  while (size > 0)
+  {
+    p->buffer[curBufferPos++] = *data++;
+    p->count++;
+    size--;
+    if (curBufferPos == 64)
+    {
+      curBufferPos = 0;
+      Sha256_WriteByteBlock(p);
+    }
+  }
+}
+
+void Sha256_Final(CSha256 *p, Byte *digest)
+{
+  UInt64 lenInBits = (p->count << 3);
+  UInt32 curBufferPos = (UInt32)p->count & 0x3F;
+  unsigned i;
+  p->buffer[curBufferPos++] = 0x80;
+  while (curBufferPos != (64 - 8))
+  {
+    curBufferPos &= 0x3F;
+    if (curBufferPos == 0)
+      Sha256_WriteByteBlock(p);
+    p->buffer[curBufferPos++] = 0;
+  }
+  for (i = 0; i < 8; i++)
+  {
+    p->buffer[curBufferPos++] = (Byte)(lenInBits >> 56);
+    lenInBits <<= 8;
+  }
+  Sha256_WriteByteBlock(p);
+
+  for (i = 0; i < 8; i++)
+  {
+    *digest++ = (Byte)(p->state[i] >> 24);
+    *digest++ = (Byte)(p->state[i] >> 16);
+    *digest++ = (Byte)(p->state[i] >> 8);
+    *digest++ = (Byte)(p->state[i]);
+  }
+  Sha256_Init(p);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sha256.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,26 @@
+/* Sha256.h -- SHA-256 Hash
+2010-06-11 : Igor Pavlov : Public domain */
+
+#ifndef __CRYPTO_SHA256_H
+#define __CRYPTO_SHA256_H
+
+#include "Types.h"
+
+EXTERN_C_BEGIN
+
+#define SHA256_DIGEST_SIZE 32
+
+typedef struct
+{
+  UInt32 state[8];
+  UInt64 count;
+  Byte buffer[64];
+} CSha256;
+
+void Sha256_Init(CSha256 *p);
+void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
+void Sha256_Final(CSha256 *p, Byte *digest);
+
+EXTERN_C_END
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,93 @@
+/* Sort.c -- Sort functions
+2010-09-17 : Igor Pavlov : Public domain */
+
+#include "Sort.h"
+
+#define HeapSortDown(p, k, size, temp) \
+  { for (;;) { \
+    UInt32 s = (k << 1); \
+    if (s > size) break; \
+    if (s < size && p[s + 1] > p[s]) s++; \
+    if (temp >= p[s]) break; \
+    p[k] = p[s]; k = s; \
+  } p[k] = temp; }
+
+void HeapSort(UInt32 *p, UInt32 size)
+{
+  if (size <= 1)
+    return;
+  p--;
+  {
+    UInt32 i = size / 2;
+    do
+    {
+      UInt32 temp = p[i];
+      UInt32 k = i;
+      HeapSortDown(p, k, size, temp)
+    }
+    while (--i != 0);
+  }
+  /*
+  do
+  {
+    UInt32 k = 1;
+    UInt32 temp = p[size];
+    p[size--] = p[1];
+    HeapSortDown(p, k, size, temp)
+  }
+  while (size > 1);
+  */
+  while (size > 3)
+  {
+    UInt32 temp = p[size];
+    UInt32 k = (p[3] > p[2]) ? 3 : 2;
+    p[size--] = p[1];
+    p[1] = p[k];
+    HeapSortDown(p, k, size, temp)
+  }
+  {
+    UInt32 temp = p[size];
+    p[size] = p[1];
+    if (size > 2 && p[2] < temp)
+    {
+      p[1] = p[2];
+      p[2] = temp;
+    }
+    else
+      p[1] = temp;
+  }
+}
+
+/*
+#define HeapSortRefDown(p, vals, n, size, temp) \
+  { UInt32 k = n; UInt32 val = vals[temp]; for (;;) { \
+    UInt32 s = (k << 1); \
+    if (s > size) break; \
+    if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \
+    if (val >= vals[p[s]]) break; \
+    p[k] = p[s]; k = s; \
+  } p[k] = temp; }
+
+void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size)
+{
+  if (size <= 1)
+    return;
+  p--;
+  {
+    UInt32 i = size / 2;
+    do
+    {
+      UInt32 temp = p[i];
+      HeapSortRefDown(p, vals, i, size, temp);
+    }
+    while (--i != 0);
+  }
+  do
+  {
+    UInt32 temp = p[size];
+    p[size--] = p[1];
+    HeapSortRefDown(p, vals, 1, size, temp);
+  }
+  while (size > 1);
+}
+*/

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Sort.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,20 @@
+/* Sort.h -- Sort functions
+2009-02-07 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_SORT_H
+#define __7Z_SORT_H
+
+#include "Types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void HeapSort(UInt32 *p, UInt32 size);
+/* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,582 @@
+/* Threads.c */
+
+#include "Threads.h"
+
+#ifdef ENV_BEOS
+#include <kernel/OS.h>
+#else
+#include <pthread.h>
+#include <stdlib.h>
+#endif
+
+#include <errno.h>
+
+#if defined(__linux__) 
+#define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
+#endif
+
+#ifdef ENV_BEOS
+
+/* TODO : optimize the code and verify the returned values */ 
+
+WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
+{ 
+	thread->_tid = spawn_thread((int32 (*)(void *))startAddress, "CThread", B_LOW_PRIORITY, parameter);
+	if (thread->_tid >= B_OK) {
+		resume_thread(thread->_tid);
+	} else {
+		thread->_tid = B_BAD_THREAD_ID;
+	}
+	thread->_created = 1;
+	return 0; // SZ_OK;
+}
+
+WRes Thread_Wait(CThread *thread)
+{
+  int ret;
+
+  if (thread->_created == 0)
+    return EINVAL;
+
+  if (thread->_tid >= B_OK) 
+  {
+    status_t exit_value;
+    wait_for_thread(thread->_tid, &exit_value);
+    thread->_tid = B_BAD_THREAD_ID;
+  } else {
+    return EINVAL;
+  }
+  
+  thread->_created = 0;
+  
+  return 0;
+}
+
+WRes Thread_Close(CThread *thread)
+{
+    if (!thread->_created) return SZ_OK;
+    
+    thread->_tid = B_BAD_THREAD_ID;
+    thread->_created = 0;
+    return SZ_OK;
+}
+
+
+WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
+{
+  p->_index_waiting = 0;
+  p->_manual_reset  = manualReset;
+  p->_state         = (initialSignaled ? TRUE : FALSE);
+  p->_created       = 1;
+  p->_sem           = create_sem(1,"event");
+  return 0;
+}
+
+WRes Event_Set(CEvent *p) {
+  int index;
+  acquire_sem(p->_sem);
+  p->_state = TRUE;
+  for(index = 0 ; index < p->_index_waiting ; index++)
+  {
+     send_data(p->_waiting[index], '7zCN', NULL, 0);
+  }
+  p->_index_waiting = 0;
+  release_sem(p->_sem);
+  return 0;
+}
+
+WRes Event_Reset(CEvent *p) {
+  acquire_sem(p->_sem);
+  p->_state = FALSE;
+  release_sem(p->_sem);
+  return 0;
+}
+ 
+WRes Event_Wait(CEvent *p) {
+  acquire_sem(p->_sem);
+  while (p->_state == FALSE)
+  {
+    thread_id sender; 
+    p->_waiting[p->_index_waiting++] = find_thread(NULL);
+    release_sem(p->_sem);
+    /* int msg = */ receive_data(&sender, NULL, 0);
+    acquire_sem(p->_sem);
+  }
+  if (p->_manual_reset == FALSE)
+  {
+     p->_state = FALSE;
+  }
+  release_sem(p->_sem);
+  return 0;
+}
+
+WRes Event_Close(CEvent *p) { 
+  if (p->_created)
+  {
+    p->_created = 0;
+    delete_sem(p->_sem);
+  }
+  return 0;
+}
+
+WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
+{
+  p->_index_waiting = 0;
+  p->_count         = initiallyCount;
+  p->_maxCount      = maxCount;
+  p->_created       = 1;
+  p->_sem           = create_sem(1,"sem");
+  return 0;
+}
+
+WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
+{
+  UInt32 newCount;
+  int index;
+  
+  if (releaseCount < 1) return EINVAL;
+
+  acquire_sem(p->_sem);
+  newCount = p->_count + releaseCount;
+  if (newCount > p->_maxCount)
+  {
+    release_sem(p->_sem);
+    return EINVAL;
+  }
+  p->_count = newCount;
+  for(index = 0 ; index < p->_index_waiting ; index++)
+  {
+     send_data(p->_waiting[index], '7zCN', NULL, 0);
+  }
+  p->_index_waiting = 0;
+  release_sem(p->_sem);
+  return 0;
+}
+
+WRes Semaphore_Wait(CSemaphore *p) {
+  acquire_sem(p->_sem);
+  while (p->_count < 1)
+  {
+    thread_id sender;  
+    p->_waiting[p->_index_waiting++] = find_thread(NULL);
+    release_sem(p->_sem);
+    /* int msg = */ receive_data(&sender, NULL, 0);
+    acquire_sem(p->_sem);
+  }
+  p->_count--;
+  release_sem(p->_sem); 
+  return 0;
+}
+
+WRes Semaphore_Close(CSemaphore *p) {
+  if (p->_created)
+  {
+    p->_created = 0;
+    delete_sem(p->_sem);
+  }
+  return 0;
+}
+
+WRes CriticalSection_Init(CCriticalSection * lpCriticalSection)
+{
+  lpCriticalSection->_sem = create_sem(1,"cc");
+  return 0;
+}
+
+#else /* !ENV_BEOS */
+
+WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
+{ 
+	pthread_attr_t attr;
+	int ret;
+
+	thread->_created = 0;
+
+	ret = pthread_attr_init(&attr);
+	if (ret) return ret;
+
+	ret = pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
+	if (ret) return ret;
+
+	ret = pthread_create(&thread->_tid, &attr, (void * (*)(void *))startAddress, parameter);
+
+	/* ret2 = */ pthread_attr_destroy(&attr);
+
+	if (ret) return ret;
+	
+	thread->_created = 1;
+
+	return 0; // SZ_OK;
+}
+
+WRes Thread_Wait(CThread *thread)
+{
+  void *thread_return;
+  int ret;
+
+  if (thread->_created == 0)
+    return EINVAL;
+
+  ret = pthread_join(thread->_tid,&thread_return);
+  thread->_created = 0;
+  
+  return ret;
+}
+
+WRes Thread_Close(CThread *thread)
+{
+    if (!thread->_created) return SZ_OK;
+    
+    pthread_detach(thread->_tid);
+    thread->_tid = 0;
+    thread->_created = 0;
+    return SZ_OK;
+}
+
+#ifdef DEBUG_SYNCHRO
+
+#include <stdio.h>
+
+static void dump_error(int ligne,int ret,const char *text,void *param)
+{
+  printf("\n##T%d#ERROR2 (l=%d) %s : param=%p ret = %d (%s)##\n",(int)pthread_self(),ligne,text,param,ret,strerror(ret));
+    // abort();
+}
+
+WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
+{
+  int ret;
+  pthread_mutexattr_t mutexattr;
+  memset(&mutexattr,0,sizeof(mutexattr));
+  ret = pthread_mutexattr_init(&mutexattr);
+  if (ret != 0) dump_error(__LINE__,ret,"Event_Create::pthread_mutexattr_init",&mutexattr);
+  ret = pthread_mutexattr_settype(&mutexattr,PTHREAD_MUTEX_ERRORCHECK);
+  if (ret != 0) dump_error(__LINE__,ret,"Event_Create::pthread_mutexattr_settype",&mutexattr);
+  ret = pthread_mutex_init(&p->_mutex,&mutexattr);
+  if (ret != 0) dump_error(__LINE__,ret,"Event_Create::pthread_mutexattr_init",&p->_mutex);
+  if (ret == 0)
+  {
+    ret = pthread_cond_init(&p->_cond,0);
+    if (ret != 0) dump_error(__LINE__,ret,"Event_Create::pthread_cond_init",&p->_cond);
+    p->_manual_reset = manualReset;
+    p->_state        = (initialSignaled ? TRUE : FALSE);
+    p->_created = 1;
+  }
+  return ret;
+}
+
+WRes Event_Set(CEvent *p) {
+  int ret = pthread_mutex_lock(&p->_mutex);
+  if (ret != 0) dump_error(__LINE__,ret,"ES::pthread_mutex_lock",&p->_mutex);
+  if (ret == 0)
+  {
+    p->_state = TRUE;
+    ret = pthread_cond_broadcast(&p->_cond);
+    if (ret != 0) dump_error(__LINE__,ret,"ES::pthread_cond_broadcast",&p->_cond);
+    if (ret == 0)
+    {
+       ret = pthread_mutex_unlock(&p->_mutex);
+       if (ret != 0) dump_error(__LINE__,ret,"ES::pthread_mutex_unlock",&p->_mutex);
+    }
+  }
+  return ret;
+}
+
+WRes Event_Reset(CEvent *p) {
+  int ret = pthread_mutex_lock(&p->_mutex);
+  if (ret != 0) dump_error(__LINE__,ret,"ER::pthread_mutex_lock",&p->_mutex);
+  if (ret == 0)
+  {
+    p->_state = FALSE;
+    ret = pthread_mutex_unlock(&p->_mutex);
+    if (ret != 0) dump_error(__LINE__,ret,"ER::pthread_mutex_unlock",&p->_mutex);
+  }
+  return ret;
+}
+ 
+WRes Event_Wait(CEvent *p) {
+  int ret = pthread_mutex_lock(&p->_mutex);
+  if (ret != 0) dump_error(__LINE__,ret,"EW::pthread_mutex_lock",&p->_mutex);
+  if (ret == 0)
+  {
+    while ((p->_state == FALSE) && (ret == 0))
+    {
+       ret = pthread_cond_wait(&p->_cond, &p->_mutex);
+       if (ret != 0) dump_error(__LINE__,ret,"EW::pthread_cond_wait",&p->_mutex);
+    }
+    if (ret == 0)
+    {
+       if (p->_manual_reset == FALSE)
+       {
+         p->_state = FALSE;
+       }
+       ret = pthread_mutex_unlock(&p->_mutex);
+       if (ret != 0) dump_error(__LINE__,ret,"EW::pthread_mutex_unlock",&p->_mutex);
+    }
+  }
+  return ret;
+}
+
+WRes Event_Close(CEvent *p) { 
+  if (p->_created)
+  {
+    int ret;
+    p->_created = 0;
+    ret = pthread_mutex_destroy(&p->_mutex);
+    if (ret != 0) dump_error(__LINE__,ret,"EC::pthread_mutex_destroy",&p->_mutex);
+    ret = pthread_cond_destroy(&p->_cond);
+    if (ret != 0) dump_error(__LINE__,ret,"EC::pthread_cond_destroy",&p->_cond);
+  }
+  return 0;
+}
+
+WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
+{
+  int ret;
+  pthread_mutexattr_t mutexattr;
+  memset(&mutexattr,0,sizeof(mutexattr));
+  ret = pthread_mutexattr_init(&mutexattr);
+  if (ret != 0) dump_error(__LINE__,ret,"SemC::pthread_mutexattr_init",&mutexattr);
+  ret = pthread_mutexattr_settype(&mutexattr,PTHREAD_MUTEX_ERRORCHECK);
+  if (ret != 0) dump_error(__LINE__,ret,"SemC::pthread_mutexattr_settype",&mutexattr);
+  ret = pthread_mutex_init(&p->_mutex,&mutexattr);
+  if (ret != 0) dump_error(__LINE__,ret,"SemC::pthread_mutexattr_init",&p->_mutex);
+  if (ret == 0)
+  {
+    ret = pthread_cond_init(&p->_cond,0);
+    if (ret != 0) dump_error(__LINE__,ret,"SemC::pthread_cond_init",&p->_mutex);
+    p->_count    = initiallyCount;
+    p->_maxCount = maxCount;
+    p->_created = 1;
+  }
+  return ret;
+}
+
+WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
+{
+  int ret;
+  if (releaseCount < 1) return EINVAL;
+
+  ret = pthread_mutex_lock(&p->_mutex);
+  if (ret != 0) dump_error(__LINE__,ret,"SemR::pthread_mutex_lock",&p->_mutex);
+  if (ret == 0)
+  {
+    UInt32 newCount = p->_count + releaseCount;
+    if (newCount > p->_maxCount)
+    {
+      ret = pthread_mutex_unlock(&p->_mutex);
+      if (ret != 0) dump_error(__LINE__,ret,"SemR::pthread_mutex_unlock",&p->_mutex);
+      return EINVAL;
+    }
+    p->_count = newCount;
+    ret = pthread_cond_broadcast(&p->_cond);
+    if (ret != 0) dump_error(__LINE__,ret,"SemR::pthread_cond_broadcast",&p->_cond);
+    if (ret == 0)
+    {
+       ret = pthread_mutex_unlock(&p->_mutex);
+       if (ret != 0) dump_error(__LINE__,ret,"SemR::pthread_mutex_unlock",&p->_mutex);
+    }
+  }
+  return ret;
+}
+
+WRes Semaphore_Wait(CSemaphore *p) {
+  int ret = pthread_mutex_lock(&p->_mutex);
+  if (ret != 0) dump_error(__LINE__,ret,"SemW::pthread_mutex_lock",&p->_mutex);
+  if (ret == 0)
+  {
+    while ((p->_count < 1) && (ret == 0))
+    {
+       ret = pthread_cond_wait(&p->_cond, &p->_mutex);
+       if (ret != 0) dump_error(__LINE__,ret,"SemW::pthread_cond_wait",&p->_mutex);
+    }
+    if (ret == 0)
+    {
+      p->_count--;
+      ret = pthread_mutex_unlock(&p->_mutex);
+      if (ret != 0) dump_error(__LINE__,ret,"SemW::pthread_mutex_unlock",&p->_mutex);
+    }
+  }
+  return ret;
+}
+
+WRes Semaphore_Close(CSemaphore *p) {
+  if (p->_created)
+  {
+    int ret;
+    p->_created = 0;
+    ret = pthread_mutex_destroy(&p->_mutex);
+    if (ret != 0) dump_error(__LINE__,ret,"Semc::pthread_mutex_destroy",&p->_mutex);
+    ret = pthread_cond_destroy(&p->_cond);
+    if (ret != 0) dump_error(__LINE__,ret,"Semc::pthread_cond_destroy",&p->_cond);
+  }
+  return 0;
+}
+
+WRes CriticalSection_Init(CCriticalSection * lpCriticalSection)
+{
+	if (lpCriticalSection)
+	{
+		int ret;
+		pthread_mutexattr_t mutexattr;
+		memset(&mutexattr,0,sizeof(mutexattr));
+		ret = pthread_mutexattr_init(&mutexattr);
+		if (ret != 0) dump_error(__LINE__,ret,"CS I::pthread_mutexattr_init",&mutexattr);
+		ret = pthread_mutexattr_settype(&mutexattr,PTHREAD_MUTEX_ERRORCHECK);
+		if (ret != 0) dump_error(__LINE__,ret,"CS I::pthread_mutexattr_settype",&mutexattr);
+		ret = pthread_mutex_init(&lpCriticalSection->_mutex,&mutexattr);
+		if (ret != 0) dump_error(__LINE__,ret,"CS I::pthread_mutexattr_init",&lpCriticalSection->_mutex);
+		return ret;
+	}
+	return EINTR;
+}
+
+void CriticalSection_Enter(CCriticalSection * lpCriticalSection)
+{
+	if (lpCriticalSection)
+	{
+		int ret = pthread_mutex_lock(&(lpCriticalSection->_mutex));
+                if (ret != 0) dump_error(__LINE__,ret,"CS::pthread_mutex_lock",&(lpCriticalSection->_mutex));
+	}
+}
+
+void CriticalSection_Leave(CCriticalSection * lpCriticalSection)
+{
+	if (lpCriticalSection)
+	{
+		int ret = pthread_mutex_unlock(&(lpCriticalSection->_mutex));
+                if (ret != 0) dump_error(__LINE__,ret,"CS::pthread_mutex_unlock",&(lpCriticalSection->_mutex));
+	}
+}
+
+void CriticalSection_Delete(CCriticalSection * lpCriticalSection)
+{
+	if (lpCriticalSection)
+	{
+		int ret = pthread_mutex_destroy(&(lpCriticalSection->_mutex));
+                if (ret != 0) dump_error(__LINE__,ret,"CS::pthread_mutex_destroy",&(lpCriticalSection->_mutex));
+	}
+}
+
+#else
+
+WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
+{
+  pthread_mutex_init(&p->_mutex,0);
+  pthread_cond_init(&p->_cond,0);
+  p->_manual_reset = manualReset;
+  p->_state        = (initialSignaled ? TRUE : FALSE);
+  p->_created = 1;
+  return 0;
+}
+
+WRes Event_Set(CEvent *p) {
+  pthread_mutex_lock(&p->_mutex);
+  p->_state = TRUE;
+  pthread_cond_broadcast(&p->_cond);
+  pthread_mutex_unlock(&p->_mutex);
+  return 0;
+}
+
+WRes Event_Reset(CEvent *p) {
+  pthread_mutex_lock(&p->_mutex);
+  p->_state = FALSE;
+  pthread_mutex_unlock(&p->_mutex);
+  return 0;
+}
+ 
+WRes Event_Wait(CEvent *p) {
+  pthread_mutex_lock(&p->_mutex);
+  while (p->_state == FALSE)
+  {
+     pthread_cond_wait(&p->_cond, &p->_mutex);
+  }
+  if (p->_manual_reset == FALSE)
+  {
+     p->_state = FALSE;
+  }
+  pthread_mutex_unlock(&p->_mutex);
+  return 0;
+}
+
+WRes Event_Close(CEvent *p) { 
+  if (p->_created)
+  {
+    p->_created = 0;
+    pthread_mutex_destroy(&p->_mutex);
+    pthread_cond_destroy(&p->_cond);
+  }
+  return 0;
+}
+
+WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
+{
+  pthread_mutex_init(&p->_mutex,0);
+  pthread_cond_init(&p->_cond,0);
+  p->_count    = initiallyCount;
+  p->_maxCount = maxCount;
+  p->_created  = 1;
+  return 0;
+}
+
+WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
+{
+  UInt32 newCount;
+
+  if (releaseCount < 1) return EINVAL;
+
+  pthread_mutex_lock(&p->_mutex);
+
+  newCount = p->_count + releaseCount;
+  if (newCount > p->_maxCount)
+  {
+    pthread_mutex_unlock(&p->_mutex);
+    return EINVAL;
+  }
+  p->_count = newCount;
+  pthread_cond_broadcast(&p->_cond);
+  pthread_mutex_unlock(&p->_mutex);
+  return 0;
+}
+
+WRes Semaphore_Wait(CSemaphore *p) {
+  pthread_mutex_lock(&p->_mutex);
+  while (p->_count < 1)
+  {
+     pthread_cond_wait(&p->_cond, &p->_mutex);
+  }
+  p->_count--;
+  pthread_mutex_unlock(&p->_mutex);
+  return 0;
+}
+
+WRes Semaphore_Close(CSemaphore *p) {
+  if (p->_created)
+  {
+    p->_created = 0;
+    pthread_mutex_destroy(&p->_mutex);
+    pthread_cond_destroy(&p->_cond);
+  }
+  return 0;
+}
+
+WRes CriticalSection_Init(CCriticalSection * lpCriticalSection)
+{
+	return pthread_mutex_init(&(lpCriticalSection->_mutex),0);
+}
+
+#endif /* DEBUG_SYNCHRO */
+
+#endif /* ENV_BEOS */
+
+WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)
+  { return Event_Create(p, TRUE, initialSignaled); }
+
+WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) 
+  { return ManualResetEvent_Create(p, 0); }
+
+WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
+  { return Event_Create(p, FALSE, initialSignaled); }
+WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) 
+  { return AutoResetEvent_Create(p, 0); }
+

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Threads.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,123 @@
+/* Threads.h -- multithreading library
+2008-11-22 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_THRESDS_H
+#define __7Z_THRESDS_H
+
+#include "Types.h"
+#include "windows.h"
+
+#ifdef ENV_BEOS
+#include <kernel/OS.h>
+#define MAX_THREAD 256
+#else
+#include <pthread.h>
+#endif
+
+/* #define DEBUG_SYNCHRO 1 */
+
+typedef struct _CThread
+{
+#ifdef ENV_BEOS
+	thread_id _tid;
+#else
+	pthread_t _tid;
+#endif
+	int _created;
+
+} CThread;
+
+#define Thread_Construct(thread) (thread)->_created = 0
+#define Thread_WasCreated(thread) ((thread)->_created != 0)
+
+typedef unsigned THREAD_FUNC_RET_TYPE;
+#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
+#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
+
+typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *);
+
+WRes Thread_Create(CThread *thread, THREAD_FUNC_TYPE startAddress, LPVOID parameter);
+WRes Thread_Wait(CThread *thread);
+WRes Thread_Close(CThread *thread);
+
+typedef struct _CEvent
+{
+  int _created;
+  int _manual_reset;
+  int _state;
+#ifdef ENV_BEOS
+  thread_id _waiting[MAX_THREAD];
+  int       _index_waiting;
+  sem_id    _sem;
+#else
+  pthread_mutex_t _mutex;
+  pthread_cond_t  _cond;
+#endif
+} CEvent;
+
+typedef CEvent CAutoResetEvent;
+typedef CEvent CManualResetEvent;
+
+#define Event_Construct(event) (event)->_created = 0
+#define Event_IsCreated(event) ((event)->_created)
+
+WRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
+WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
+WRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
+WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
+WRes Event_Set(CEvent *event);
+WRes Event_Reset(CEvent *event);
+WRes Event_Wait(CEvent *event);
+WRes Event_Close(CEvent *event);
+
+
+typedef struct _CSemaphore
+{
+  int _created;
+  UInt32 _count;
+  UInt32 _maxCount;
+#ifdef ENV_BEOS
+  thread_id _waiting[MAX_THREAD];
+  int       _index_waiting;
+  sem_id    _sem;
+#else
+  pthread_mutex_t _mutex;
+  pthread_cond_t  _cond;
+#endif
+} CSemaphore;
+
+#define Semaphore_Construct(p) (p)->_created = 0
+
+WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
+WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
+#define Semaphore_Release1(p) Semaphore_ReleaseN(p, 1)
+WRes Semaphore_Wait(CSemaphore *p);
+WRes Semaphore_Close(CSemaphore *p);
+
+typedef struct {
+#ifdef ENV_BEOS
+	sem_id _sem;
+#else
+        pthread_mutex_t _mutex;
+#endif
+} CCriticalSection;
+
+WRes CriticalSection_Init(CCriticalSection *p);
+#ifdef ENV_BEOS
+#define CriticalSection_Delete(p) delete_sem((p)->_sem)
+#define CriticalSection_Enter(p)  acquire_sem((p)->_sem)
+#define CriticalSection_Leave(p)  release_sem((p)->_sem)
+#else
+#ifdef DEBUG_SYNCHRO
+void CriticalSection_Delete(CCriticalSection *);
+void CriticalSection_Enter(CCriticalSection *);
+void CriticalSection_Leave(CCriticalSection *);
+#else
+#define CriticalSection_Delete(p) pthread_mutex_destroy(&((p)->_mutex))
+#define CriticalSection_Enter(p)  pthread_mutex_lock(&((p)->_mutex))
+#define CriticalSection_Leave(p)  pthread_mutex_unlock(&((p)->_mutex))
+#endif
+#endif
+
+#endif
+

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Types.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Types.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Types.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Types.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,254 @@
+/* Types.h -- Basic types
+2010-10-09 : Igor Pavlov : Public domain */
+
+#ifndef __7Z_TYPES_H
+#define __7Z_TYPES_H
+
+#include <stddef.h>
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#ifndef EXTERN_C_BEGIN
+#ifdef __cplusplus
+#define EXTERN_C_BEGIN extern "C" {
+#define EXTERN_C_END }
+#else
+#define EXTERN_C_BEGIN
+#define EXTERN_C_END
+#endif
+#endif
+
+EXTERN_C_BEGIN
+
+#define SZ_OK 0
+
+#define SZ_ERROR_DATA 1
+#define SZ_ERROR_MEM 2
+#define SZ_ERROR_CRC 3
+#define SZ_ERROR_UNSUPPORTED 4
+#define SZ_ERROR_PARAM 5
+#define SZ_ERROR_INPUT_EOF 6
+#define SZ_ERROR_OUTPUT_EOF 7
+#define SZ_ERROR_READ 8
+#define SZ_ERROR_WRITE 9
+#define SZ_ERROR_PROGRESS 10
+#define SZ_ERROR_FAIL 11
+#define SZ_ERROR_THREAD 12
+
+#define SZ_ERROR_ARCHIVE 16
+#define SZ_ERROR_NO_ARCHIVE 17
+
+typedef int SRes;
+
+#ifdef _WIN32
+typedef DWORD WRes;
+#else
+typedef int WRes;
+#endif
+
+#ifndef RINOK
+#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
+#endif
+
+typedef unsigned char Byte;
+typedef short Int16;
+typedef unsigned short UInt16;
+
+#ifdef _LZMA_UINT32_IS_ULONG
+typedef long Int32;
+typedef unsigned long UInt32;
+#else
+typedef int Int32;
+typedef unsigned int UInt32;
+#endif
+
+#ifdef _SZ_NO_INT_64
+
+/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
+   NOTES: Some code will work incorrectly in that case! */
+
+typedef long Int64;
+typedef unsigned long UInt64;
+
+#else
+
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+typedef __int64 Int64;
+typedef unsigned __int64 UInt64;
+#define UINT64_CONST(n) n
+#else
+typedef long long int Int64;
+typedef unsigned long long int UInt64;
+#define UINT64_CONST(n) n ## ULL
+#endif
+
+#endif
+
+#ifdef _LZMA_NO_SYSTEM_SIZE_T
+typedef UInt32 SizeT;
+#else
+typedef size_t SizeT;
+#endif
+
+typedef int Bool;
+#define True 1
+#define False 0
+
+
+#ifdef _WIN32
+#define MY_STD_CALL __stdcall
+#else
+#define MY_STD_CALL
+#endif
+
+#ifdef _MSC_VER
+
+#if _MSC_VER >= 1300
+#define MY_NO_INLINE __declspec(noinline)
+#else
+#define MY_NO_INLINE
+#endif
+
+#define MY_CDECL __cdecl
+#define MY_FAST_CALL __fastcall
+
+#else
+
+#define MY_CDECL
+#define MY_FAST_CALL
+
+#endif
+
+
+/* The following interfaces use first parameter as pointer to structure */
+
+typedef struct
+{
+  Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
+} IByteIn;
+
+typedef struct
+{
+  void (*Write)(void *p, Byte b);
+} IByteOut;
+
+typedef struct
+{
+  SRes (*Read)(void *p, void *buf, size_t *size);
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+       (output(*size) < input(*size)) is allowed */
+} ISeqInStream;
+
+/* it can return SZ_ERROR_INPUT_EOF */
+SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
+SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
+SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
+
+typedef struct
+{
+  size_t (*Write)(void *p, const void *buf, size_t size);
+    /* Returns: result - the number of actually written bytes.
+       (result < size) means error */
+} ISeqOutStream;
+
+typedef enum
+{
+  SZ_SEEK_SET = 0,
+  SZ_SEEK_CUR = 1,
+  SZ_SEEK_END = 2
+} ESzSeek;
+
+typedef struct
+{
+  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
+  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
+} ISeekInStream;
+
+typedef struct
+{
+  SRes (*Look)(void *p, const void **buf, size_t *size);
+    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+       (output(*size) > input(*size)) is not allowed
+       (output(*size) < input(*size)) is allowed */
+  SRes (*Skip)(void *p, size_t offset);
+    /* offset must be <= output(*size) of Look */
+
+  SRes (*Read)(void *p, void *buf, size_t *size);
+    /* reads directly (without buffer). It's same as ISeqInStream::Read */
+  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
+} ILookInStream;
+
+SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
+SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
+
+/* reads via ILookInStream::Read */
+SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
+SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
+
+#define LookToRead_BUF_SIZE (1 << 14)
+
+typedef struct
+{
+  ILookInStream s;
+  ISeekInStream *realStream;
+  size_t pos;
+  size_t size;
+  Byte buf[LookToRead_BUF_SIZE];
+} CLookToRead;
+
+void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
+void LookToRead_Init(CLookToRead *p);
+
+typedef struct
+{
+  ISeqInStream s;
+  ILookInStream *realStream;
+} CSecToLook;
+
+void SecToLook_CreateVTable(CSecToLook *p);
+
+typedef struct
+{
+  ISeqInStream s;
+  ILookInStream *realStream;
+} CSecToRead;
+
+void SecToRead_CreateVTable(CSecToRead *p);
+
+typedef struct
+{
+  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
+    /* Returns: result. (result != SZ_OK) means break.
+       Value (UInt64)(Int64)-1 for size means unknown value. */
+} ICompressProgress;
+
+typedef struct
+{
+  void *(*Alloc)(void *p, size_t size);
+  void (*Free)(void *p, void *address); /* address can be 0 */
+} ISzAlloc;
+
+#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
+#define IAlloc_Free(p, a) (p)->Free((p), a)
+
+#ifdef _WIN32
+
+#define CHAR_PATH_SEPARATOR '\\'
+#define WCHAR_PATH_SEPARATOR L'\\'
+#define STRING_PATH_SEPARATOR "\\"
+#define WSTRING_PATH_SEPARATOR L"\\"
+
+#else
+
+#define CHAR_PATH_SEPARATOR '/'
+#define WCHAR_PATH_SEPARATOR L'/'
+#define STRING_PATH_SEPARATOR "/"
+#define WSTRING_PATH_SEPARATOR L"/"
+
+#endif
+
+EXTERN_C_END
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,88 @@
+/* Xz.c - Xz
+2009-04-15 : Igor Pavlov : Public domain */
+
+#include "7zCrc.h"
+#include "CpuArch.h"
+#include "Xz.h"
+#include "XzCrc64.h"
+
+Byte XZ_SIG[XZ_SIG_SIZE] = { 0xFD, '7', 'z', 'X', 'Z', 0 };
+Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE] = { 'Y', 'Z' };
+
+unsigned Xz_WriteVarInt(Byte *buf, UInt64 v)
+{
+  unsigned i = 0;
+  do
+  {
+    buf[i++] = (Byte)((v & 0x7F) | 0x80);
+    v >>= 7;
+  }
+  while (v != 0);
+  buf[i - 1] &= 0x7F;
+  return i;
+}
+
+void Xz_Construct(CXzStream *p)
+{
+  p->numBlocks = p->numBlocksAllocated = 0;
+  p->blocks = 0;
+  p->flags = 0;
+}
+
+void Xz_Free(CXzStream *p, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, p->blocks);
+  p->numBlocks = p->numBlocksAllocated = 0;
+  p->blocks = 0;
+}
+
+unsigned XzFlags_GetCheckSize(CXzStreamFlags f)
+{
+  int t = XzFlags_GetCheckType(f);
+  return (t == 0) ? 0 : (4 << ((t - 1) / 3));
+}
+
+void XzCheck_Init(CXzCheck *p, int mode)
+{
+  p->mode = mode;
+  switch (mode)
+  {
+    case XZ_CHECK_CRC32: p->crc = CRC_INIT_VAL; break;
+    case XZ_CHECK_CRC64: p->crc64 = CRC64_INIT_VAL; break;
+    case XZ_CHECK_SHA256: Sha256_Init(&p->sha); break;
+  }
+}
+
+void XzCheck_Update(CXzCheck *p, const void *data, size_t size)
+{
+  switch (p->mode)
+  {
+    case XZ_CHECK_CRC32: p->crc = CrcUpdate(p->crc, data, size); break;
+    case XZ_CHECK_CRC64: p->crc64 = Crc64Update(p->crc64, data, size); break;
+    case XZ_CHECK_SHA256: Sha256_Update(&p->sha, (const Byte *)data, size); break;
+  }
+}
+
+int XzCheck_Final(CXzCheck *p, Byte *digest)
+{
+  switch (p->mode)
+  {
+    case XZ_CHECK_CRC32:
+      SetUi32(digest, CRC_GET_DIGEST(p->crc));
+      break;
+    case XZ_CHECK_CRC64:
+    {
+      int i;
+      UInt64 v = CRC64_GET_DIGEST(p->crc64);
+      for (i = 0; i < 8; i++, v >>= 8)
+        digest[i] = (Byte)(v & 0xFF);
+      break;
+    }
+    case XZ_CHECK_SHA256:
+      Sha256_Final(&p->sha, digest);
+      break;
+    default:
+      return 0;
+  }
+  return 1;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/Xz.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,252 @@
+/* Xz.h - Xz interface
+2010-09-17 : Igor Pavlov : Public domain */
+
+#ifndef __XZ_H
+#define __XZ_H
+
+#include "Sha256.h"
+
+EXTERN_C_BEGIN
+
+#define XZ_ID_Subblock 1
+#define XZ_ID_Delta 3
+#define XZ_ID_X86 4
+#define XZ_ID_PPC 5
+#define XZ_ID_IA64 6
+#define XZ_ID_ARM 7
+#define XZ_ID_ARMT 8
+#define XZ_ID_SPARC 9
+#define XZ_ID_LZMA2 0x21
+
+unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value);
+unsigned Xz_WriteVarInt(Byte *buf, UInt64 v);
+
+/* ---------- xz block ---------- */
+
+#define XZ_BLOCK_HEADER_SIZE_MAX 1024
+
+#define XZ_NUM_FILTERS_MAX 4
+#define XZ_BF_NUM_FILTERS_MASK 3
+#define XZ_BF_PACK_SIZE (1 << 6)
+#define XZ_BF_UNPACK_SIZE (1 << 7)
+
+#define XZ_FILTER_PROPS_SIZE_MAX 20
+
+typedef struct
+{
+  UInt64 id;
+  UInt32 propsSize;
+  Byte props[XZ_FILTER_PROPS_SIZE_MAX];
+} CXzFilter;
+
+typedef struct
+{
+  UInt64 packSize;
+  UInt64 unpackSize;
+  Byte flags;
+  CXzFilter filters[XZ_NUM_FILTERS_MAX];
+} CXzBlock;
+
+#define XzBlock_GetNumFilters(p) (((p)->flags & XZ_BF_NUM_FILTERS_MASK) + 1)
+#define XzBlock_HasPackSize(p)   (((p)->flags & XZ_BF_PACK_SIZE) != 0)
+#define XzBlock_HasUnpackSize(p) (((p)->flags & XZ_BF_UNPACK_SIZE) != 0)
+
+SRes XzBlock_Parse(CXzBlock *p, const Byte *header);
+SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes);
+
+/* ---------- xz stream ---------- */
+
+#define XZ_SIG_SIZE 6
+#define XZ_FOOTER_SIG_SIZE 2
+
+extern Byte XZ_SIG[XZ_SIG_SIZE];
+extern Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE];
+
+#define XZ_STREAM_FLAGS_SIZE 2
+#define XZ_STREAM_CRC_SIZE 4
+
+#define XZ_STREAM_HEADER_SIZE (XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE)
+#define XZ_STREAM_FOOTER_SIZE (XZ_FOOTER_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE + 4)
+
+#define XZ_CHECK_MASK 0xF
+#define XZ_CHECK_NO 0
+#define XZ_CHECK_CRC32 1
+#define XZ_CHECK_CRC64 4
+#define XZ_CHECK_SHA256 10
+
+typedef struct
+{
+  int mode;
+  UInt32 crc;
+  UInt64 crc64;
+  CSha256 sha;
+} CXzCheck;
+
+void XzCheck_Init(CXzCheck *p, int mode);
+void XzCheck_Update(CXzCheck *p, const void *data, size_t size);
+int XzCheck_Final(CXzCheck *p, Byte *digest);
+
+typedef UInt16 CXzStreamFlags;
+
+#define XzFlags_IsSupported(f) ((f) <= XZ_CHECK_MASK)
+#define XzFlags_GetCheckType(f) ((f) & XZ_CHECK_MASK)
+#define XzFlags_HasDataCrc32(f) (Xz_GetCheckType(f) == XZ_CHECK_CRC32)
+unsigned XzFlags_GetCheckSize(CXzStreamFlags f);
+
+SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf);
+SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream);
+
+typedef struct
+{
+  UInt64 unpackSize;
+  UInt64 totalSize;
+} CXzBlockSizes;
+
+typedef struct
+{
+  CXzStreamFlags flags;
+  size_t numBlocks;
+  size_t numBlocksAllocated;
+  CXzBlockSizes *blocks;
+  UInt64 startOffset;
+} CXzStream;
+
+void Xz_Construct(CXzStream *p);
+void Xz_Free(CXzStream *p, ISzAlloc *alloc);
+
+#define XZ_SIZE_OVERFLOW ((UInt64)(Int64)-1)
+
+UInt64 Xz_GetUnpackSize(const CXzStream *p);
+UInt64 Xz_GetPackSize(const CXzStream *p);
+
+typedef struct
+{
+  size_t num;
+  size_t numAllocated;
+  CXzStream *streams;
+} CXzs;
+
+void Xzs_Construct(CXzs *p);
+void Xzs_Free(CXzs *p, ISzAlloc *alloc);
+SRes Xzs_ReadBackward(CXzs *p, ILookInStream *inStream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc);
+
+UInt64 Xzs_GetNumBlocks(const CXzs *p);
+UInt64 Xzs_GetUnpackSize(const CXzs *p);
+
+typedef enum
+{
+  CODER_STATUS_NOT_SPECIFIED,               /* use main error code instead */
+  CODER_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */
+  CODER_STATUS_NOT_FINISHED,                /* stream was not finished */
+  CODER_STATUS_NEEDS_MORE_INPUT             /* you must provide more input bytes */
+} ECoderStatus;
+
+typedef enum
+{
+  CODER_FINISH_ANY,   /* finish at any point */
+  CODER_FINISH_END    /* block must be finished at the end */
+} ECoderFinishMode;
+
+typedef struct _IStateCoder
+{
+  void *p;
+  void (*Free)(void *p, ISzAlloc *alloc);
+  SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAlloc *alloc);
+  void (*Init)(void *p);
+  SRes (*Code)(void *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+      int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished);
+} IStateCoder;
+
+#define MIXCODER_NUM_FILTERS_MAX 4
+
+typedef struct
+{
+  ISzAlloc *alloc;
+  Byte *buf;
+  int numCoders;
+  int finished[MIXCODER_NUM_FILTERS_MAX - 1];
+  size_t pos[MIXCODER_NUM_FILTERS_MAX - 1];
+  size_t size[MIXCODER_NUM_FILTERS_MAX - 1];
+  UInt64 ids[MIXCODER_NUM_FILTERS_MAX];
+  IStateCoder coders[MIXCODER_NUM_FILTERS_MAX];
+} CMixCoder;
+
+void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc);
+void MixCoder_Free(CMixCoder *p);
+void MixCoder_Init(CMixCoder *p);
+SRes MixCoder_SetFromMethod(CMixCoder *p, int coderIndex, UInt64 methodId);
+SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,
+    const Byte *src, SizeT *srcLen, int srcWasFinished,
+    ECoderFinishMode finishMode, ECoderStatus *status);
+
+typedef enum
+{
+  XZ_STATE_STREAM_HEADER,
+  XZ_STATE_STREAM_INDEX,
+  XZ_STATE_STREAM_INDEX_CRC,
+  XZ_STATE_STREAM_FOOTER,
+  XZ_STATE_STREAM_PADDING,
+  XZ_STATE_BLOCK_HEADER,
+  XZ_STATE_BLOCK,
+  XZ_STATE_BLOCK_FOOTER
+} EXzState;
+
+typedef struct
+{
+  EXzState state;
+  UInt32 pos;
+  unsigned alignPos;
+  unsigned indexPreSize;
+
+  CXzStreamFlags streamFlags;
+  
+  UInt32 blockHeaderSize;
+  UInt64 packSize;
+  UInt64 unpackSize;
+
+  UInt64 numBlocks;
+  UInt64 indexSize;
+  UInt64 indexPos;
+  UInt64 padSize;
+
+  UInt64 numStreams;
+
+  UInt32 crc;
+  CMixCoder decoder;
+  CXzBlock block;
+  CXzCheck check;
+  CSha256 sha;
+  Byte shaDigest[SHA256_DIGEST_SIZE];
+  Byte buf[XZ_BLOCK_HEADER_SIZE_MAX];
+} CXzUnpacker;
+
+SRes XzUnpacker_Create(CXzUnpacker *p, ISzAlloc *alloc);
+void XzUnpacker_Free(CXzUnpacker *p);
+
+/*
+finishMode:
+  It has meaning only if the decoding reaches output limit (*destLen).
+  LZMA_FINISH_ANY - use smallest number of input bytes
+  LZMA_FINISH_END - read EndOfStream marker after decoding
+
+Returns:
+  SZ_OK
+    status:
+      LZMA_STATUS_FINISHED_WITH_MARK
+      LZMA_STATUS_NOT_FINISHED
+  SZ_ERROR_DATA - Data error
+  SZ_ERROR_MEM  - Memory allocation error
+  SZ_ERROR_UNSUPPORTED - Unsupported properties
+  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
+*/
+
+
+SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
+    const Byte *src, SizeT *srcLen, /* int srcWasFinished, */ int finishMode,
+    ECoderStatus *status);
+
+Bool XzUnpacker_IsStreamWasFinished(CXzUnpacker *p);
+
+EXTERN_C_END
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,33 @@
+/* XzCrc64.c -- CRC64 calculation
+2010-04-16 : Igor Pavlov : Public domain */
+
+#include "XzCrc64.h"
+
+#define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42)
+UInt64 g_Crc64Table[256];
+
+void MY_FAST_CALL Crc64GenerateTable(void)
+{
+  UInt32 i;
+  for (i = 0; i < 256; i++)
+  {
+    UInt64 r = i;
+    int j;
+    for (j = 0; j < 8; j++)
+      r = (r >> 1) ^ ((UInt64)kCrc64Poly & ~((r & 1) - 1));
+    g_Crc64Table[i] = r;
+  }
+}
+
+UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size)
+{
+  const Byte *p = (const Byte *)data;
+  for (; size > 0 ; size--, p++)
+    v = CRC64_UPDATE_BYTE(v, *p);
+  return v;
+}
+
+UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size)
+{
+  return CRC64_GET_DIGEST(Crc64Update(CRC64_INIT_VAL, data, size));
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzCrc64.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,26 @@
+/* XzCrc64.h -- CRC64 calculation
+2010-04-16 : Igor Pavlov : Public domain */
+
+#ifndef __XZ_CRC64_H
+#define __XZ_CRC64_H
+
+#include <stddef.h>
+
+#include "Types.h"
+
+EXTERN_C_BEGIN
+
+extern UInt64 g_Crc64Table[];
+
+void MY_FAST_CALL Crc64GenerateTable(void);
+
+#define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF)
+#define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL)
+#define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+
+UInt64 MY_FAST_CALL Crc64Update(UInt64 crc, const void *data, size_t size);
+UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size);
+
+EXTERN_C_END
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzDec.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzDec.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzDec.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzDec.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,875 @@
+/* XzDec.c -- Xz Decode
+2010-04-16 : Igor Pavlov : Public domain */
+
+/* #define XZ_DUMP */
+
+#ifdef XZ_DUMP
+#include <stdio.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "7zCrc.h"
+#include "Alloc.h"
+#include "Bra.h"
+#include "CpuArch.h"
+#include "Delta.h"
+#include "Lzma2Dec.h"
+
+#ifdef USE_SUBBLOCK
+#include "SbDec.h"
+#endif
+
+#include "Xz.h"
+
+#define XZ_CHECK_SIZE_MAX 64
+
+#define CODER_BUF_SIZE (1 << 17)
+
+unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value)
+{
+  int i, limit;
+  *value = 0;
+  limit = (maxSize > 9) ? 9 : (int)maxSize;
+
+  for (i = 0; i < limit;)
+  {
+    Byte b = p[i];
+    *value |= (UInt64)(b & 0x7F) << (7 * i++);
+    if ((b & 0x80) == 0)
+      return (b == 0 && i != 1) ? 0 : i;
+  }
+  return 0;
+}
+
+/* ---------- BraState ---------- */
+
+#define BRA_BUF_SIZE (1 << 14)
+
+typedef struct
+{
+  size_t bufPos;
+  size_t bufConv;
+  size_t bufTotal;
+
+  UInt32 methodId;
+  int encodeMode;
+  UInt32 delta;
+  UInt32 ip;
+  UInt32 x86State;
+  Byte deltaState[DELTA_STATE_SIZE];
+
+  Byte buf[BRA_BUF_SIZE];
+} CBraState;
+
+void BraState_Free(void *pp, ISzAlloc *alloc)
+{
+  alloc->Free(alloc, pp);
+}
+
+SRes BraState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)
+{
+  CBraState *p = ((CBraState *)pp);
+  alloc = alloc;
+  p->encodeMode = 0;
+  p->ip = 0;
+  if (p->methodId == XZ_ID_Delta)
+  {
+    if (propSize != 1)
+      return SZ_ERROR_UNSUPPORTED;
+    p->delta = (unsigned)props[0] + 1;
+  }
+  else
+  {
+    if (propSize == 4)
+    {
+      UInt32 v = GetUi32(props);
+      switch(p->methodId)
+      {
+        case XZ_ID_PPC:
+        case XZ_ID_ARM:
+        case XZ_ID_SPARC:
+          if ((v & 3) != 0)
+            return SZ_ERROR_UNSUPPORTED;
+          break;
+        case XZ_ID_ARMT:
+          if ((v & 1) != 0)
+            return SZ_ERROR_UNSUPPORTED;
+          break;
+        case XZ_ID_IA64:
+          if ((v & 0xF) != 0)
+            return SZ_ERROR_UNSUPPORTED;
+          break;
+      }
+      p->ip = v;
+    }
+    else if (propSize != 0)
+      return SZ_ERROR_UNSUPPORTED;
+  }
+  return SZ_OK;
+}
+
+void BraState_Init(void *pp)
+{
+  CBraState *p = ((CBraState *)pp);
+  p->bufPos = p->bufConv = p->bufTotal = 0;
+  x86_Convert_Init(p->x86State);
+  if (p->methodId == XZ_ID_Delta)
+    Delta_Init(p->deltaState);
+}
+
+#define CASE_BRA_CONV(isa) case XZ_ID_ ## isa: p->bufConv = isa ## _Convert(p->buf, p->bufTotal, p->ip, p->encodeMode); break;
+
+static SRes BraState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)
+{
+  CBraState *p = ((CBraState *)pp);
+  SizeT destLenOrig = *destLen;
+  SizeT srcLenOrig = *srcLen;
+  *destLen = 0;
+  *srcLen = 0;
+  finishMode = finishMode;
+  *wasFinished = 0;
+  while (destLenOrig > 0)
+  {
+    if (p->bufPos != p->bufConv)
+    {
+      size_t curSize = p->bufConv - p->bufPos;
+      if (curSize > destLenOrig)
+        curSize = destLenOrig;
+      memcpy(dest, p->buf + p->bufPos, curSize);
+      p->bufPos += curSize;
+      *destLen += curSize;
+      dest += curSize;
+      destLenOrig -= curSize;
+      continue;
+    }
+    p->bufTotal -= p->bufPos;
+    memmove(p->buf, p->buf + p->bufPos, p->bufTotal);
+    p->bufPos = 0;
+    p->bufConv = 0;
+    {
+      size_t curSize = BRA_BUF_SIZE - p->bufTotal;
+      if (curSize > srcLenOrig)
+        curSize = srcLenOrig;
+      memcpy(p->buf + p->bufTotal, src, curSize);
+      *srcLen += curSize;
+      src += curSize;
+      srcLenOrig -= curSize;
+      p->bufTotal += curSize;
+    }
+    if (p->bufTotal == 0)
+      break;
+    switch(p->methodId)
+    {
+      case XZ_ID_Delta:
+        if (p->encodeMode)
+          Delta_Encode(p->deltaState, p->delta, p->buf, p->bufTotal);
+        else
+          Delta_Decode(p->deltaState, p->delta, p->buf, p->bufTotal);
+        p->bufConv = p->bufTotal;
+        break;
+      case XZ_ID_X86:
+        p->bufConv = x86_Convert(p->buf, p->bufTotal, p->ip, &p->x86State, p->encodeMode);
+        break;
+      CASE_BRA_CONV(PPC)
+      CASE_BRA_CONV(IA64)
+      CASE_BRA_CONV(ARM)
+      CASE_BRA_CONV(ARMT)
+      CASE_BRA_CONV(SPARC)
+      default:
+        return SZ_ERROR_UNSUPPORTED;
+    }
+    p->ip += (UInt32)p->bufConv;
+
+    if (p->bufConv == 0)
+    {
+      if (!srcWasFinished)
+        break;
+      p->bufConv = p->bufTotal;
+    }
+  }
+  if (p->bufTotal == p->bufPos && srcLenOrig == 0 && srcWasFinished)
+    *wasFinished = 1;
+  return SZ_OK;
+}
+
+SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, ISzAlloc *alloc)
+{
+  CBraState *decoder;
+  if (id != XZ_ID_Delta &&
+      id != XZ_ID_X86 &&
+      id != XZ_ID_PPC &&
+      id != XZ_ID_IA64 &&
+      id != XZ_ID_ARM &&
+      id != XZ_ID_ARMT &&
+      id != XZ_ID_SPARC)
+    return SZ_ERROR_UNSUPPORTED;
+  p->p = 0;
+  decoder = alloc->Alloc(alloc, sizeof(CBraState));
+  if (decoder == 0)
+    return SZ_ERROR_MEM;
+  decoder->methodId = (UInt32)id;
+  p->p = decoder;
+  p->Free = BraState_Free;
+  p->SetProps = BraState_SetProps;
+  p->Init = BraState_Init;
+  p->Code = BraState_Code;
+  return SZ_OK;
+}
+
+/* ---------- SbState ---------- */
+
+#ifdef USE_SUBBLOCK
+
+static void SbState_Free(void *pp, ISzAlloc *alloc)
+{
+  CSubblockDec *p = (CSubblockDec *)pp;
+  SubblockDec_Free(p, alloc);
+  alloc->Free(alloc, pp);
+}
+
+static SRes SbState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)
+{
+  pp = pp;
+  props = props;
+  alloc = alloc;
+  return (propSize == 0) ? SZ_OK : SZ_ERROR_UNSUPPORTED;
+}
+
+static void SbState_Init(void *pp)
+{
+  SubblockDec_Init((CSubblockDec *)pp);
+}
+
+static SRes SbState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)
+{
+  ECoderStatus status;
+  SRes res = SubblockDec_Decode((CSubblockDec *)pp, dest, destLen, src, srcLen, finishMode, &status);
+  srcWasFinished = srcWasFinished;
+  *wasFinished = (status == LZMA_STATUS_FINISHED_WITH_MARK);
+  return res;
+}
+
+SRes SbState_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)
+{
+  CSubblockDec *decoder;
+  p->p = 0;
+  decoder = alloc->Alloc(alloc, sizeof(CSubblockDec));
+  if (decoder == 0)
+    return SZ_ERROR_MEM;
+  p->p = decoder;
+  p->Free = SbState_Free;
+  p->SetProps = SbState_SetProps;
+  p->Init = SbState_Init;
+  p->Code = SbState_Code;
+  SubblockDec_Construct(decoder);
+  return SZ_OK;
+}
+#endif
+
+/* ---------- Lzma2State ---------- */
+
+static void Lzma2State_Free(void *pp, ISzAlloc *alloc)
+{
+  Lzma2Dec_Free((CLzma2Dec *)pp, alloc);
+  alloc->Free(alloc, pp);
+}
+
+static SRes Lzma2State_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)
+{
+  if (propSize != 1)
+    return SZ_ERROR_UNSUPPORTED;
+  return Lzma2Dec_Allocate((CLzma2Dec *)pp, props[0], alloc);
+}
+
+static void Lzma2State_Init(void *pp)
+{
+  Lzma2Dec_Init((CLzma2Dec *)pp);
+}
+
+static SRes Lzma2State_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
+    int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)
+{
+  ELzmaStatus status;
+  /* ELzmaFinishMode fm = (finishMode == LZMA_FINISH_ANY) ? LZMA_FINISH_ANY : LZMA_FINISH_END; */
+  SRes res = Lzma2Dec_DecodeToBuf((CLzma2Dec *)pp, dest, destLen, src, srcLen, finishMode, &status);
+  srcWasFinished = srcWasFinished;
+  *wasFinished = (status == LZMA_STATUS_FINISHED_WITH_MARK);
+  return res;
+}
+
+static SRes Lzma2State_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)
+{
+  CLzma2Dec *decoder = alloc->Alloc(alloc, sizeof(CLzma2Dec));
+  p->p = decoder;
+  if (decoder == 0)
+    return SZ_ERROR_MEM;
+  p->Free = Lzma2State_Free;
+  p->SetProps = Lzma2State_SetProps;
+  p->Init = Lzma2State_Init;
+  p->Code = Lzma2State_Code;
+  Lzma2Dec_Construct(decoder);
+  return SZ_OK;
+}
+
+
+void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc)
+{
+  int i;
+  p->alloc = alloc;
+  p->buf = 0;
+  p->numCoders = 0;
+  for (i = 0; i < MIXCODER_NUM_FILTERS_MAX; i++)
+    p->coders[i].p = NULL;
+}
+
+void MixCoder_Free(CMixCoder *p)
+{
+  int i;
+  for (i = 0; i < p->numCoders; i++)
+  {
+    IStateCoder *sc = &p->coders[i];
+    if (p->alloc && sc->p)
+      sc->Free(sc->p, p->alloc);
+  }
+  p->numCoders = 0;
+  if (p->buf)
+    p->alloc->Free(p->alloc, p->buf);
+}
+
+void MixCoder_Init(CMixCoder *p)
+{
+  int i;
+  for (i = 0; i < p->numCoders - 1; i++)
+  {
+    p->size[i] = 0;
+    p->pos[i] = 0;
+    p->finished[i] = 0;
+  }
+  for (i = 0; i < p->numCoders; i++)
+  {
+    IStateCoder *coder = &p->coders[i];
+    coder->Init(coder->p);
+  }
+}
+
+SRes MixCoder_SetFromMethod(CMixCoder *p, int coderIndex, UInt64 methodId)
+{
+  IStateCoder *sc = &p->coders[coderIndex];
+  p->ids[coderIndex] = methodId;
+  switch(methodId)
+  {
+    case XZ_ID_LZMA2: return Lzma2State_SetFromMethod(sc, p->alloc);
+    #ifdef USE_SUBBLOCK
+    case XZ_ID_Subblock: return SbState_SetFromMethod(sc, p->alloc);
+    #endif
+  }
+  if (coderIndex == 0)
+    return SZ_ERROR_UNSUPPORTED;
+  return BraState_SetFromMethod(sc, methodId, p->alloc);
+}
+
+SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,
+    const Byte *src, SizeT *srcLen, int srcWasFinished,
+    ECoderFinishMode finishMode, ECoderStatus *status)
+{
+  SizeT destLenOrig = *destLen;
+  SizeT srcLenOrig = *srcLen;
+  Bool allFinished = True;
+  *destLen = 0;
+  *srcLen = 0;
+  *status = CODER_STATUS_NOT_FINISHED;
+
+  if (p->buf == 0)
+  {
+    p->buf = p->alloc->Alloc(p->alloc, CODER_BUF_SIZE * (MIXCODER_NUM_FILTERS_MAX - 1));
+    if (p->buf == 0)
+      return SZ_ERROR_MEM;
+  }
+
+  if (p->numCoders != 1)
+    finishMode = CODER_FINISH_ANY;
+
+  for (;;)
+  {
+    Bool processed = False;
+    int i;
+    /*
+    if (p->numCoders == 1 && *destLen == destLenOrig && finishMode == LZMA_FINISH_ANY)
+      break;
+    */
+
+    for (i = 0; i < p->numCoders; i++)
+    {
+      SRes res;
+      IStateCoder *coder = &p->coders[i];
+      Byte *destCur;
+      SizeT destLenCur, srcLenCur;
+      const Byte *srcCur;
+      int srcFinishedCur;
+      int encodingWasFinished;
+      
+      if (i == 0)
+      {
+        srcCur = src;
+        srcLenCur = srcLenOrig - *srcLen;
+        srcFinishedCur = srcWasFinished;
+      }
+      else
+      {
+        srcCur = p->buf + (CODER_BUF_SIZE * (i - 1)) + p->pos[i - 1];
+        srcLenCur = p->size[i - 1] - p->pos[i - 1];
+        srcFinishedCur = p->finished[i - 1];
+      }
+      
+      if (i == p->numCoders - 1)
+      {
+        destCur = dest;
+        destLenCur = destLenOrig - *destLen;
+      }
+      else
+      {
+        if (p->pos[i] != p->size[i])
+          continue;
+        destCur = p->buf + (CODER_BUF_SIZE * i);
+        destLenCur = CODER_BUF_SIZE;
+      }
+      
+      res = coder->Code(coder->p, destCur, &destLenCur, srcCur, &srcLenCur, srcFinishedCur, finishMode, &encodingWasFinished);
+
+      if (!encodingWasFinished)
+        allFinished = False;
+
+      if (i == 0)
+      {
+        *srcLen += srcLenCur;
+        src += srcLenCur;
+      }
+      else
+      {
+        p->pos[i - 1] += srcLenCur;
+      }
+
+      if (i == p->numCoders - 1)
+      {
+        *destLen += destLenCur;
+        dest += destLenCur;
+      }
+      else
+      {
+        p->size[i] = destLenCur;
+        p->pos[i] = 0;
+        p->finished[i] = encodingWasFinished;
+      }
+      
+      if (res != SZ_OK)
+        return res;
+
+      if (destLenCur != 0 || srcLenCur != 0)
+        processed = True;
+    }
+    if (!processed)
+      break;
+  }
+  if (allFinished)
+    *status = CODER_STATUS_FINISHED_WITH_MARK;
+  return SZ_OK;
+}
+
+SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf)
+{
+  *p = (CXzStreamFlags)GetBe16(buf + XZ_SIG_SIZE);
+  if (CrcCalc(buf + XZ_SIG_SIZE, XZ_STREAM_FLAGS_SIZE) !=
+      GetUi32(buf + XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE))
+    return SZ_ERROR_NO_ARCHIVE;
+  return XzFlags_IsSupported(*p) ? SZ_OK : SZ_ERROR_UNSUPPORTED;
+}
+
+static Bool Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *buf)
+{
+  return
+      indexSize == (((UInt64)GetUi32(buf + 4) + 1) << 2) &&
+      (GetUi32(buf) == CrcCalc(buf + 4, 6) &&
+      flags == GetBe16(buf + 8) &&
+      memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) == 0);
+}
+
+#define READ_VARINT_AND_CHECK(buf, pos, size, res) \
+  { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \
+  if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; }
+
+
+SRes XzBlock_Parse(CXzBlock *p, const Byte *header)
+{
+  unsigned pos;
+  int numFilters, i;
+  UInt32 headerSize = (UInt32)header[0] << 2;
+
+  if (CrcCalc(header, headerSize) != GetUi32(header + headerSize))
+    return SZ_ERROR_ARCHIVE;
+
+  pos = 1;
+  if (pos == headerSize)
+    return SZ_ERROR_ARCHIVE;
+  p->flags = header[pos++];
+
+  if (XzBlock_HasPackSize(p))
+  {
+    READ_VARINT_AND_CHECK(header, pos, headerSize, &p->packSize);
+    if (p->packSize == 0 || p->packSize + headerSize >= (UInt64)1 << 63)
+      return SZ_ERROR_ARCHIVE;
+  }
+
+  if (XzBlock_HasUnpackSize(p))
+    READ_VARINT_AND_CHECK(header, pos, headerSize, &p->unpackSize);
+
+  numFilters = XzBlock_GetNumFilters(p);
+  for (i = 0; i < numFilters; i++)
+  {
+    CXzFilter *filter = p->filters + i;
+    UInt64 size;
+    READ_VARINT_AND_CHECK(header, pos, headerSize, &filter->id);
+    READ_VARINT_AND_CHECK(header, pos, headerSize, &size);
+    if (size > headerSize - pos || size > XZ_FILTER_PROPS_SIZE_MAX)
+      return SZ_ERROR_ARCHIVE;
+    filter->propsSize = (UInt32)size;
+    memcpy(filter->props, header + pos, (size_t)size);
+    pos += (unsigned)size;
+
+    #ifdef XZ_DUMP
+    printf("\nf[%d] = %2X: ", i, filter->id);
+    {
+      int i;
+      for (i = 0; i < size; i++)
+        printf(" %2X", filter->props[i]);
+    }
+    #endif
+  }
+
+  while (pos < headerSize)
+    if (header[pos++] != 0)
+      return SZ_ERROR_ARCHIVE;
+  return SZ_OK;
+}
+
+SRes XzDec_Init(CMixCoder *p, const CXzBlock *block)
+{
+  int i;
+  Bool needReInit = True;
+  int numFilters = XzBlock_GetNumFilters(block);
+  if (numFilters == p->numCoders)
+  {
+    for (i = 0; i < numFilters; i++)
+      if (p->ids[i] != block->filters[numFilters - 1 - i].id)
+        break;
+    needReInit = (i != numFilters);
+  }
+  if (needReInit)
+  {
+    MixCoder_Free(p);
+    p->numCoders = numFilters;
+    for (i = 0; i < numFilters; i++)
+    {
+      const CXzFilter *f = &block->filters[numFilters - 1 - i];
+      RINOK(MixCoder_SetFromMethod(p, i, f->id));
+    }
+  }
+  for (i = 0; i < numFilters; i++)
+  {
+    const CXzFilter *f = &block->filters[numFilters - 1 - i];
+    IStateCoder *sc = &p->coders[i];
+    RINOK(sc->SetProps(sc->p, f->props, f->propsSize, p->alloc));
+  }
+  MixCoder_Init(p);
+  return SZ_OK;
+}
+
+SRes XzUnpacker_Create(CXzUnpacker *p, ISzAlloc *alloc)
+{
+  MixCoder_Construct(&p->decoder, alloc);
+  p->state = XZ_STATE_STREAM_HEADER;
+  p->pos = 0;
+  p->numStreams = 0;
+  return SZ_OK;
+}
+
+void XzUnpacker_Free(CXzUnpacker *p)
+{
+  MixCoder_Free(&p->decoder);
+}
+
+SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
+    const Byte *src, SizeT *srcLen, int finishMode, ECoderStatus *status)
+{
+  SizeT destLenOrig = *destLen;
+  SizeT srcLenOrig = *srcLen;
+  *destLen = 0;
+  *srcLen = 0;
+  *status = CODER_STATUS_NOT_SPECIFIED;
+  for (;;)
+  {
+    SizeT srcRem = srcLenOrig - *srcLen;
+
+    if (p->state == XZ_STATE_BLOCK)
+    {
+      SizeT destLen2 = destLenOrig - *destLen;
+      SizeT srcLen2 = srcLenOrig - *srcLen;
+      SRes res;
+      if (srcLen2 == 0 && destLen2 == 0)
+      {
+        *status = CODER_STATUS_NOT_FINISHED;
+        return SZ_OK;
+      }
+      
+      res = MixCoder_Code(&p->decoder, dest, &destLen2, src, &srcLen2, False, finishMode, status);
+      XzCheck_Update(&p->check, dest, destLen2);
+      
+      (*srcLen) += srcLen2;
+      src += srcLen2;
+      p->packSize += srcLen2;
+      
+      (*destLen) += destLen2;
+      dest += destLen2;
+      p->unpackSize += destLen2;
+      
+      RINOK(res);
+      
+      if (*status == CODER_STATUS_FINISHED_WITH_MARK)
+      {
+        Byte temp[32];
+        unsigned num = Xz_WriteVarInt(temp, p->packSize + p->blockHeaderSize + XzFlags_GetCheckSize(p->streamFlags));
+        num += Xz_WriteVarInt(temp + num, p->unpackSize);
+        Sha256_Update(&p->sha, temp, num);
+        p->indexSize += num;
+        p->numBlocks++;
+        
+        p->state = XZ_STATE_BLOCK_FOOTER;
+        p->pos = 0;
+        p->alignPos = 0;
+      }
+      else if (srcLen2 == 0 && destLen2 == 0)
+        return SZ_OK;
+      
+      continue;
+    }
+
+    if (srcRem == 0)
+    {
+      *status = CODER_STATUS_NEEDS_MORE_INPUT;
+      return SZ_OK;
+    }
+
+    switch(p->state)
+    {
+      case XZ_STATE_STREAM_HEADER:
+      {
+        if (p->pos < XZ_STREAM_HEADER_SIZE)
+        {
+          if (p->pos < XZ_SIG_SIZE && *src != XZ_SIG[p->pos])
+            return SZ_ERROR_NO_ARCHIVE;
+          p->buf[p->pos++] = *src++;
+          (*srcLen)++;
+        }
+        else
+        {
+          RINOK(Xz_ParseHeader(&p->streamFlags, p->buf));
+          p->state = XZ_STATE_BLOCK_HEADER;
+          Sha256_Init(&p->sha);
+          p->indexSize = 0;
+          p->numBlocks = 0;
+          p->pos = 0;
+        }
+        break;
+      }
+
+      case XZ_STATE_BLOCK_HEADER:
+      {
+        if (p->pos == 0)
+        {
+          p->buf[p->pos++] = *src++;
+          (*srcLen)++;
+          if (p->buf[0] == 0)
+          {
+            p->indexPreSize = 1 + Xz_WriteVarInt(p->buf + 1, p->numBlocks);
+            p->indexPos = p->indexPreSize;
+            p->indexSize += p->indexPreSize;
+            Sha256_Final(&p->sha, p->shaDigest);
+            Sha256_Init(&p->sha);
+            p->crc = CrcUpdate(CRC_INIT_VAL, p->buf, p->indexPreSize);
+            p->state = XZ_STATE_STREAM_INDEX;
+          }
+          p->blockHeaderSize = ((UInt32)p->buf[0] << 2) + 4;
+        }
+        else if (p->pos != p->blockHeaderSize)
+        {
+          UInt32 cur = p->blockHeaderSize - p->pos;
+          if (cur > srcRem)
+            cur = (UInt32)srcRem;
+          memcpy(p->buf + p->pos, src, cur);
+          p->pos += cur;
+          (*srcLen) += cur;
+          src += cur;
+        }
+        else
+        {
+          RINOK(XzBlock_Parse(&p->block, p->buf));
+          p->state = XZ_STATE_BLOCK;
+          p->packSize = 0;
+          p->unpackSize = 0;
+          XzCheck_Init(&p->check, XzFlags_GetCheckType(p->streamFlags));
+          RINOK(XzDec_Init(&p->decoder, &p->block));
+        }
+        break;
+      }
+
+      case XZ_STATE_BLOCK_FOOTER:
+      {
+        if (((p->packSize + p->alignPos) & 3) != 0)
+        {
+          (*srcLen)++;
+          p->alignPos++;
+          if (*src++ != 0)
+            return SZ_ERROR_CRC;
+        }
+        else
+        {
+          UInt32 checkSize = XzFlags_GetCheckSize(p->streamFlags);
+          UInt32 cur = checkSize - p->pos;
+          if (cur != 0)
+          {
+            if (cur > srcRem)
+              cur = (UInt32)srcRem;
+            memcpy(p->buf + p->pos, src, cur);
+            p->pos += cur;
+            (*srcLen) += cur;
+            src += cur;
+          }
+          else
+          {
+            Byte digest[XZ_CHECK_SIZE_MAX];
+            p->state = XZ_STATE_BLOCK_HEADER;
+            p->pos = 0;
+            if (XzCheck_Final(&p->check, digest) && memcmp(digest, p->buf, checkSize) != 0)
+              return SZ_ERROR_CRC;
+          }
+        }
+        break;
+      }
+
+      case XZ_STATE_STREAM_INDEX:
+      {
+        if (p->pos < p->indexPreSize)
+        {
+          (*srcLen)++;
+          if (*src++ != p->buf[p->pos++])
+            return SZ_ERROR_CRC;
+        }
+        else
+        {
+          if (p->indexPos < p->indexSize)
+          {
+            UInt64 cur = p->indexSize - p->indexPos;
+            if (srcRem > cur)
+              srcRem = (SizeT)cur;
+            p->crc = CrcUpdate(p->crc, src, srcRem);
+            Sha256_Update(&p->sha, src, srcRem);
+            (*srcLen) += srcRem;
+            src += srcRem;
+            p->indexPos += srcRem;
+          }
+          else if ((p->indexPos & 3) != 0)
+          {
+            Byte b = *src++;
+            p->crc = CRC_UPDATE_BYTE(p->crc, b);
+            (*srcLen)++;
+            p->indexPos++;
+            p->indexSize++;
+            if (b != 0)
+              return SZ_ERROR_CRC;
+          }
+          else
+          {
+            Byte digest[SHA256_DIGEST_SIZE];
+            p->state = XZ_STATE_STREAM_INDEX_CRC;
+            p->indexSize += 4;
+            p->pos = 0;
+            Sha256_Final(&p->sha, digest);
+            if (memcmp(digest, p->shaDigest, SHA256_DIGEST_SIZE) != 0)
+              return SZ_ERROR_CRC;
+          }
+        }
+        break;
+      }
+
+      case XZ_STATE_STREAM_INDEX_CRC:
+      {
+        if (p->pos < 4)
+        {
+          (*srcLen)++;
+          p->buf[p->pos++] = *src++;
+        }
+        else
+        {
+          p->state = XZ_STATE_STREAM_FOOTER;
+          p->pos = 0;
+          if (CRC_GET_DIGEST(p->crc) != GetUi32(p->buf))
+            return SZ_ERROR_CRC;
+        }
+        break;
+      }
+
+      case XZ_STATE_STREAM_FOOTER:
+      {
+        UInt32 cur = XZ_STREAM_FOOTER_SIZE - p->pos;
+        if (cur > srcRem)
+          cur = (UInt32)srcRem;
+        memcpy(p->buf + p->pos, src, cur);
+        p->pos += cur;
+        (*srcLen) += cur;
+        src += cur;
+        if (p->pos == XZ_STREAM_FOOTER_SIZE)
+        {
+          p->state = XZ_STATE_STREAM_PADDING;
+          p->numStreams++;
+          p->padSize = 0;
+          if (!Xz_CheckFooter(p->streamFlags, p->indexSize, p->buf))
+            return SZ_ERROR_CRC;
+        }
+        break;
+      }
+
+      case XZ_STATE_STREAM_PADDING:
+      {
+        if (*src != 0)
+        {
+          if (((UInt32)p->padSize & 3) != 0)
+            return SZ_ERROR_NO_ARCHIVE;
+          p->pos = 0;
+          p->state = XZ_STATE_STREAM_HEADER;
+        }
+        else
+        {
+          (*srcLen)++;
+          src++;
+          p->padSize++;
+        }
+        break;
+      }
+      
+      case XZ_STATE_BLOCK: break; /* to disable GCC warning */
+    }
+  }
+  /*
+  if (p->state == XZ_STATE_FINISHED)
+    *status = CODER_STATUS_FINISHED_WITH_MARK;
+  return SZ_OK;
+  */
+}
+
+Bool XzUnpacker_IsStreamWasFinished(CXzUnpacker *p)
+{
+  return (p->state == XZ_STATE_STREAM_PADDING) && (((UInt32)p->padSize & 3) == 0);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,497 @@
+/* XzEnc.c -- Xz Encode
+2009-06-04 : Igor Pavlov : Public domain */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "7zCrc.h"
+#include "Alloc.h"
+#include "Bra.h"
+#include "CpuArch.h"
+#ifdef USE_SUBBLOCK
+#include "SbEnc.h"
+#endif
+
+#include "XzEnc.h"
+
+static void *SzBigAlloc(void *p, size_t size) { p = p; return BigAlloc(size); }
+static void SzBigFree(void *p, void *address) { p = p; BigFree(address); }
+static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+#define XzBlock_ClearFlags(p)       (p)->flags = 0;
+#define XzBlock_SetNumFilters(p, n) (p)->flags |= ((n) - 1);
+#define XzBlock_SetHasPackSize(p)   (p)->flags |= XZ_BF_PACK_SIZE;
+#define XzBlock_SetHasUnpackSize(p) (p)->flags |= XZ_BF_UNPACK_SIZE;
+
+static SRes WriteBytes(ISeqOutStream *s, const void *buf, UInt32 size)
+{
+  return (s->Write(s, buf, size) == size) ? SZ_OK : SZ_ERROR_WRITE;
+}
+
+static SRes WriteBytesAndCrc(ISeqOutStream *s, const void *buf, UInt32 size, UInt32 *crc)
+{
+  *crc = CrcUpdate(*crc, buf, size);
+  return WriteBytes(s, buf, size);
+}
+
+SRes Xz_WriteHeader(CXzStreamFlags f, ISeqOutStream *s)
+{
+  UInt32 crc;
+  Byte header[XZ_STREAM_HEADER_SIZE];
+  memcpy(header, XZ_SIG, XZ_SIG_SIZE);
+  header[XZ_SIG_SIZE] = (Byte)(f >> 8);
+  header[XZ_SIG_SIZE + 1] = (Byte)(f & 0xFF);
+  crc = CrcCalc(header + XZ_SIG_SIZE, XZ_STREAM_FLAGS_SIZE);
+  SetUi32(header + XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE, crc);
+  return WriteBytes(s, header, XZ_STREAM_HEADER_SIZE);
+}
+
+SRes XzBlock_WriteHeader(const CXzBlock *p, ISeqOutStream *s)
+{
+  Byte header[XZ_BLOCK_HEADER_SIZE_MAX];
+
+  unsigned pos = 1;
+  int numFilters, i;
+  header[pos++] = p->flags;
+
+  if (XzBlock_HasPackSize(p)) pos += Xz_WriteVarInt(header + pos, p->packSize);
+  if (XzBlock_HasUnpackSize(p)) pos += Xz_WriteVarInt(header + pos, p->unpackSize);
+  numFilters = XzBlock_GetNumFilters(p);
+  for (i = 0; i < numFilters; i++)
+  {
+    const CXzFilter *f = &p->filters[i];
+    pos += Xz_WriteVarInt(header + pos, f->id);
+    pos += Xz_WriteVarInt(header + pos, f->propsSize);
+    memcpy(header + pos, f->props, f->propsSize);
+    pos += f->propsSize;
+  }
+  while((pos & 3) != 0)
+    header[pos++] = 0;
+  header[0] = (Byte)(pos >> 2);
+  SetUi32(header + pos, CrcCalc(header, pos));
+  return WriteBytes(s, header, pos + 4);
+}
+
+SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)
+{
+  Byte buf[32];
+  UInt64 globalPos;
+  {
+    UInt32 crc = CRC_INIT_VAL;
+    unsigned pos = 1 + Xz_WriteVarInt(buf + 1, p->numBlocks);
+    size_t i;
+
+    globalPos = pos;
+    buf[0] = 0;
+    RINOK(WriteBytesAndCrc(s, buf, pos, &crc));
+    for (i = 0; i < p->numBlocks; i++)
+    {
+      const CXzBlockSizes *block = &p->blocks[i];
+      pos = Xz_WriteVarInt(buf, block->totalSize);
+      pos += Xz_WriteVarInt(buf + pos, block->unpackSize);
+      globalPos += pos;
+      RINOK(WriteBytesAndCrc(s, buf, pos, &crc));
+    }
+    pos = ((unsigned)globalPos & 3);
+    if (pos != 0)
+    {
+      buf[0] = buf[1] = buf[2] = 0;
+      RINOK(WriteBytesAndCrc(s, buf, 4 - pos, &crc));
+      globalPos += 4 - pos;
+    }
+    {
+      SetUi32(buf, CRC_GET_DIGEST(crc));
+      RINOK(WriteBytes(s, buf, 4));
+      globalPos += 4;
+    }
+  }
+
+  {
+    UInt32 indexSize = (UInt32)((globalPos >> 2) - 1);
+    SetUi32(buf + 4, indexSize);
+    buf[8] = (Byte)(p->flags >> 8);
+    buf[9] = (Byte)(p->flags & 0xFF);
+    SetUi32(buf, CrcCalc(buf + 4, 6));
+    memcpy(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE);
+    return WriteBytes(s, buf, 12);
+  }
+}
+
+SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize, ISzAlloc *alloc)
+{
+  if (p->blocks == 0 || p->numBlocksAllocated == p->numBlocks)
+  {
+    size_t num = (p->numBlocks + 1) * 2;
+    size_t newSize = sizeof(CXzBlockSizes) * num;
+    CXzBlockSizes *blocks;
+    if (newSize / sizeof(CXzBlockSizes) != num)
+      return SZ_ERROR_MEM;
+    blocks = alloc->Alloc(alloc, newSize);
+    if (blocks == 0)
+      return SZ_ERROR_MEM;
+    if (p->numBlocks != 0)
+    {
+      memcpy(blocks, p->blocks, p->numBlocks * sizeof(CXzBlockSizes));
+      Xz_Free(p, alloc);
+    }
+    p->blocks = blocks;
+    p->numBlocksAllocated = num;
+  }
+  {
+    CXzBlockSizes *block = &p->blocks[p->numBlocks++];
+    block->totalSize = totalSize;
+    block->unpackSize = unpackSize;
+  }
+  return SZ_OK;
+}
+
+/* ---------- CSeqCheckInStream ---------- */
+
+typedef struct
+{
+  ISeqInStream p;
+  ISeqInStream *realStream;
+  UInt64 processed;
+  CXzCheck check;
+} CSeqCheckInStream;
+
+void SeqCheckInStream_Init(CSeqCheckInStream *p, int mode)
+{
+  p->processed = 0;
+  XzCheck_Init(&p->check, mode);
+}
+
+void SeqCheckInStream_GetDigest(CSeqCheckInStream *p, Byte *digest)
+{
+  XzCheck_Final(&p->check, digest);
+}
+
+static SRes SeqCheckInStream_Read(void *pp, void *data, size_t *size)
+{
+  CSeqCheckInStream *p = (CSeqCheckInStream *)pp;
+  SRes res = p->realStream->Read(p->realStream, data, size);
+  XzCheck_Update(&p->check, data, *size);
+  p->processed += *size;
+  return res;
+}
+
+/* ---------- CSeqSizeOutStream ---------- */
+
+typedef struct
+{
+  ISeqOutStream p;
+  ISeqOutStream *realStream;
+  UInt64 processed;
+} CSeqSizeOutStream;
+
+static size_t MyWrite(void *pp, const void *data, size_t size)
+{
+  CSeqSizeOutStream *p = (CSeqSizeOutStream *)pp;
+  size = p->realStream->Write(p->realStream, data, size);
+  p->processed += size;
+  return size;
+}
+
+/* ---------- CSeqInFilter ---------- */
+
+/*
+typedef struct _IFilter
+{
+  void *p;
+  void (*Free)(void *p, ISzAlloc *alloc);
+  SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAlloc *alloc);
+  void (*Init)(void *p);
+  size_t (*Filter)(void *p, Byte *data, SizeT destLen);
+} IFilter;
+
+#define FILT_BUF_SIZE (1 << 19)
+
+typedef struct
+{
+  ISeqInStream p;
+  ISeqInStream *realStream;
+  UInt32 x86State;
+  UInt32 ip;
+  UInt64 processed;
+  CXzCheck check;
+  Byte buf[FILT_BUF_SIZE];
+  UInt32 bufferPos;
+  UInt32 convertedPosBegin;
+  UInt32 convertedPosEnd;
+  IFilter *filter;
+} CSeqInFilter;
+
+static SRes SeqInFilter_Read(void *pp, void *data, size_t *size)
+{
+  CSeqInFilter *p = (CSeqInFilter *)pp;
+  size_t remSize = *size;
+  *size = 0;
+
+  while (remSize > 0)
+  {
+    int i;
+    if (p->convertedPosBegin != p->convertedPosEnd)
+    {
+      UInt32 sizeTemp = p->convertedPosEnd - p->convertedPosBegin;
+      if (remSize < sizeTemp)
+        sizeTemp = (UInt32)remSize;
+      memmove(data, p->buf + p->convertedPosBegin, sizeTemp);
+      p->convertedPosBegin += sizeTemp;
+      data = (void *)((Byte *)data + sizeTemp);
+      remSize -= sizeTemp;
+      *size += sizeTemp;
+      break;
+    }
+    for (i = 0; p->convertedPosEnd + i < p->bufferPos; i++)
+      p->buf[i] = p->buf[i + p->convertedPosEnd];
+    p->bufferPos = i;
+    p->convertedPosBegin = p->convertedPosEnd = 0;
+    {
+      size_t processedSizeTemp = FILT_BUF_SIZE - p->bufferPos;
+      RINOK(p->realStream->Read(p->realStream, p->buf + p->bufferPos, &processedSizeTemp));
+      p->bufferPos = p->bufferPos + (UInt32)processedSizeTemp;
+    }
+    p->convertedPosEnd = (UInt32)p->filter->Filter(p->filter->p, p->buf, p->bufferPos);
+    if (p->convertedPosEnd == 0)
+    {
+      if (p->bufferPos == 0)
+        break;
+      else
+      {
+        p->convertedPosEnd = p->bufferPos;
+        continue;
+      }
+    }
+    if (p->convertedPosEnd > p->bufferPos)
+    {
+      for (; p->bufferPos < p->convertedPosEnd; p->bufferPos++)
+        p->buf[p->bufferPos] = 0;
+      p->convertedPosEnd = (UInt32)p->filter->Filter(p->filter->p, p->buf, p->bufferPos);
+    }
+  }
+  return SZ_OK;
+}
+*/
+
+/*
+typedef struct
+{
+  ISeqInStream p;
+  ISeqInStream *realStream;
+  CMixCoder mixCoder;
+  Byte buf[FILT_BUF_SIZE];
+  UInt32 bufPos;
+  UInt32 bufSize;
+} CMixCoderSeqInStream;
+
+static SRes CMixCoderSeqInStream_Read(void *pp, void *data, size_t *size)
+{
+  CMixCoderSeqInStream *p = (CMixCoderSeqInStream *)pp;
+  SRes res = SZ_OK;
+  size_t remSize = *size;
+  *size = 0;
+  while (remSize > 0)
+  {
+    if (p->bufPos == p->bufSize)
+    {
+      size_t curSize;
+      p->bufPos = p->bufSize = 0;
+      if (*size != 0)
+        break;
+      curSize = FILT_BUF_SIZE;
+      RINOK(p->realStream->Read(p->realStream, p->buf, &curSize));
+      p->bufSize = (UInt32)curSize;
+    }
+    {
+      SizeT destLen = remSize;
+      SizeT srcLen = p->bufSize - p->bufPos;
+      res = MixCoder_Code(&p->mixCoder, data, &destLen, p->buf + p->bufPos, &srcLen, 0);
+      data = (void *)((Byte *)data + destLen);
+      remSize -= destLen;
+      *size += destLen;
+      p->bufPos += srcLen;
+    }
+  }
+  return res;
+}
+*/
+
+#ifdef USE_SUBBLOCK
+typedef struct
+{
+  ISeqInStream p;
+  CSubblockEnc sb;
+  UInt64 processed;
+} CSbEncInStream;
+
+void SbEncInStream_Init(CSbEncInStream *p)
+{
+  p->processed = 0;
+  SubblockEnc_Init(&p->sb);
+}
+
+static SRes SbEncInStream_Read(void *pp, void *data, size_t *size)
+{
+  CSbEncInStream *p = (CSbEncInStream *)pp;
+  SRes res = SubblockEnc_Read(&p->sb, data, size);
+  p->processed += *size;
+  return res;
+}
+#endif
+
+typedef struct
+{
+  /* CMixCoderSeqInStream inStream; */
+  CLzma2EncHandle lzma2;
+  #ifdef USE_SUBBLOCK
+  CSbEncInStream sb;
+  #endif
+  ISzAlloc *alloc;
+  ISzAlloc *bigAlloc;
+} CLzma2WithFilters;
+
+
+static void Lzma2WithFilters_Construct(CLzma2WithFilters *p, ISzAlloc *alloc, ISzAlloc *bigAlloc)
+{
+  p->alloc = alloc;
+  p->bigAlloc = bigAlloc;
+  p->lzma2 = NULL;
+  #ifdef USE_SUBBLOCK
+  p->sb.p.Read = SbEncInStream_Read;
+  SubblockEnc_Construct(&p->sb.sb, p->alloc);
+  #endif
+}
+
+static SRes Lzma2WithFilters_Create(CLzma2WithFilters *p)
+{
+  p->lzma2 = Lzma2Enc_Create(p->alloc, p->bigAlloc);
+  if (p->lzma2 == 0)
+    return SZ_ERROR_MEM;
+  return SZ_OK;
+}
+
+static void Lzma2WithFilters_Free(CLzma2WithFilters *p)
+{
+  #ifdef USE_SUBBLOCK
+  SubblockEnc_Free(&p->sb.sb);
+  #endif
+  if (p->lzma2)
+  {
+    Lzma2Enc_Destroy(p->lzma2);
+    p->lzma2 = NULL;
+  }
+}
+
+static SRes Xz_Compress(CXzStream *xz,
+    CLzma2WithFilters *lzmaf,
+    ISeqOutStream *outStream,
+    ISeqInStream *inStream,
+    const CLzma2EncProps *lzma2Props,
+    Bool useSubblock,
+    ICompressProgress *progress)
+{
+  xz->flags = XZ_CHECK_CRC32;
+
+  RINOK(Lzma2Enc_SetProps(lzmaf->lzma2, lzma2Props));
+  RINOK(Xz_WriteHeader(xz->flags, outStream));
+
+  {
+    CSeqCheckInStream checkInStream;
+    CSeqSizeOutStream seqSizeOutStream;
+    CXzBlock block;
+    int filterIndex = 0;
+    
+    XzBlock_ClearFlags(&block);
+    XzBlock_SetNumFilters(&block, 1 + (useSubblock ? 1 : 0));
+    
+    if (useSubblock)
+    {
+      CXzFilter *f = &block.filters[filterIndex++];
+      f->id = XZ_ID_Subblock;
+      f->propsSize = 0;
+    }
+
+    {
+      CXzFilter *f = &block.filters[filterIndex++];
+      f->id = XZ_ID_LZMA2;
+      f->propsSize = 1;
+      f->props[0] = Lzma2Enc_WriteProperties(lzmaf->lzma2);
+    }
+
+    seqSizeOutStream.p.Write = MyWrite;
+    seqSizeOutStream.realStream = outStream;
+    seqSizeOutStream.processed = 0;
+    
+    RINOK(XzBlock_WriteHeader(&block, &seqSizeOutStream.p));
+    
+    checkInStream.p.Read = SeqCheckInStream_Read;
+    checkInStream.realStream = inStream;
+    SeqCheckInStream_Init(&checkInStream, XzFlags_GetCheckType(xz->flags));
+    
+    #ifdef USE_SUBBLOCK
+    if (useSubblock)
+    {
+      lzmaf->sb.sb.inStream = &checkInStream.p;
+      SubblockEnc_Init(&lzmaf->sb.sb);
+    }
+    #endif
+    
+    {
+      UInt64 packPos = seqSizeOutStream.processed;
+      SRes res = Lzma2Enc_Encode(lzmaf->lzma2, &seqSizeOutStream.p,
+        #ifdef USE_SUBBLOCK
+        useSubblock ? &lzmaf->sb.p:
+        #endif
+        &checkInStream.p,
+        progress);
+      RINOK(res);
+      block.unpackSize = checkInStream.processed;
+      block.packSize = seqSizeOutStream.processed - packPos;
+    }
+
+    {
+      unsigned padSize = 0;
+      Byte buf[128];
+      while((((unsigned)block.packSize + padSize) & 3) != 0)
+        buf[padSize++] = 0;
+      SeqCheckInStream_GetDigest(&checkInStream, buf + padSize);
+      RINOK(WriteBytes(&seqSizeOutStream.p, buf, padSize + XzFlags_GetCheckSize(xz->flags)));
+      RINOK(Xz_AddIndexRecord(xz, block.unpackSize, seqSizeOutStream.processed - padSize, &g_Alloc));
+    }
+  }
+  return Xz_WriteFooter(xz, outStream);
+}
+
+SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
+    const CLzma2EncProps *lzma2Props, Bool useSubblock,
+    ICompressProgress *progress)
+{
+  SRes res;
+  CXzStream xz;
+  CLzma2WithFilters lzmaf;
+  Xz_Construct(&xz);
+  Lzma2WithFilters_Construct(&lzmaf, &g_Alloc, &g_BigAlloc);
+  res = Lzma2WithFilters_Create(&lzmaf);
+  if (res == SZ_OK)
+    res = Xz_Compress(&xz, &lzmaf, outStream, inStream,
+        lzma2Props, useSubblock, progress);
+  Lzma2WithFilters_Free(&lzmaf);
+  Xz_Free(&xz, &g_Alloc);
+  return res;
+}
+
+SRes Xz_EncodeEmpty(ISeqOutStream *outStream)
+{
+  SRes res;
+  CXzStream xz;
+  Xz_Construct(&xz);
+  res = Xz_WriteHeader(xz.flags, outStream);
+  if (res == SZ_OK)
+    res = Xz_WriteFooter(&xz, outStream);
+  Xz_Free(&xz, &g_Alloc);
+  return res;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzEnc.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,25 @@
+/* XzEnc.h -- Xz Encode
+2009-04-15 : Igor Pavlov : Public domain */
+
+#ifndef __XZ_ENC_H
+#define __XZ_ENC_H
+
+#include "Lzma2Enc.h"
+
+#include "Xz.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
+    const CLzma2EncProps *lzma2Props, Bool useSubblock,
+    ICompressProgress *progress);
+
+SRes Xz_EncodeEmpty(ISeqOutStream *outStream);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzIn.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzIn.c?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzIn.c (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/C/XzIn.c Sun Dec 16 23:23:25 2012
@@ -0,0 +1,306 @@
+/* XzIn.c - Xz input
+2009-06-19 : Igor Pavlov : Public domain */
+
+#include <string.h>
+
+#include "7zCrc.h"
+#include "CpuArch.h"
+#include "Xz.h"
+
+SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream)
+{
+  Byte sig[XZ_STREAM_HEADER_SIZE];
+  RINOK(SeqInStream_Read2(inStream, sig, XZ_STREAM_HEADER_SIZE, SZ_ERROR_NO_ARCHIVE));
+  if (memcmp(sig, XZ_SIG, XZ_SIG_SIZE) != 0)
+    return SZ_ERROR_NO_ARCHIVE;
+  return Xz_ParseHeader(p, sig);
+}
+
+#define READ_VARINT_AND_CHECK(buf, pos, size, res) \
+  { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \
+  if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; }
+
+SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes)
+{
+  Byte header[XZ_BLOCK_HEADER_SIZE_MAX];
+  unsigned headerSize;
+  *headerSizeRes = 0;
+  RINOK(SeqInStream_ReadByte(inStream, &header[0]));
+  headerSize = ((unsigned)header[0] << 2) + 4;
+  if (headerSize == 0)
+  {
+    *headerSizeRes = 1;
+    *isIndex = True;
+    return SZ_OK;
+  }
+
+  *isIndex = False;
+  *headerSizeRes = headerSize;
+  RINOK(SeqInStream_Read(inStream, header + 1, headerSize - 1));
+  return XzBlock_Parse(p, header);
+}
+
+#define ADD_SIZE_CHECH(size, val) \
+  { UInt64 newSize = size + (val); if (newSize < size) return XZ_SIZE_OVERFLOW; size = newSize; }
+
+UInt64 Xz_GetUnpackSize(const CXzStream *p)
+{
+  UInt64 size = 0;
+  size_t i;
+  for (i = 0; i < p->numBlocks; i++)
+    ADD_SIZE_CHECH(size, p->blocks[i].unpackSize);
+  return size;
+}
+
+UInt64 Xz_GetPackSize(const CXzStream *p)
+{
+  UInt64 size = 0;
+  size_t i;
+  for (i = 0; i < p->numBlocks; i++)
+    ADD_SIZE_CHECH(size, (p->blocks[i].totalSize + 3) & ~(UInt64)3);
+  return size;
+}
+
+/*
+SRes XzBlock_ReadFooter(CXzBlock *p, CXzStreamFlags f, ISeqInStream *inStream)
+{
+  return SeqInStream_Read(inStream, p->check, XzFlags_GetCheckSize(f));
+}
+*/
+
+static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc *alloc)
+{
+  size_t i, numBlocks, crcStartPos, pos = 1;
+  UInt32 crc;
+
+  if (size < 5 || buf[0] != 0)
+    return SZ_ERROR_ARCHIVE;
+
+  size -= 4;
+  crc = CrcCalc(buf, size);
+  if (crc != GetUi32(buf + size))
+    return SZ_ERROR_ARCHIVE;
+
+  {
+    UInt64 numBlocks64;
+    READ_VARINT_AND_CHECK(buf, pos, size, &numBlocks64);
+    numBlocks = (size_t)numBlocks64;
+    if (numBlocks != numBlocks64 || numBlocks * 2 > size)
+      return SZ_ERROR_ARCHIVE;
+  }
+  
+  crcStartPos = pos;
+  Xz_Free(p, alloc);
+  if (numBlocks != 0)
+  {
+    p->numBlocks = numBlocks;
+    p->numBlocksAllocated = numBlocks;
+    p->blocks = alloc->Alloc(alloc, sizeof(CXzBlockSizes) * numBlocks);
+    if (p->blocks == 0)
+      return SZ_ERROR_MEM;
+    for (i = 0; i < numBlocks; i++)
+    {
+      CXzBlockSizes *block = &p->blocks[i];
+      READ_VARINT_AND_CHECK(buf, pos, size, &block->totalSize);
+      READ_VARINT_AND_CHECK(buf, pos, size, &block->unpackSize);
+      if (block->totalSize == 0)
+        return SZ_ERROR_ARCHIVE;
+    }
+  }
+  while ((pos & 3) != 0)
+    if (buf[pos++] != 0)
+      return SZ_ERROR_ARCHIVE;
+  return (pos == size) ? SZ_OK : SZ_ERROR_ARCHIVE;
+}
+
+static SRes Xz_ReadIndex(CXzStream *p, ILookInStream *stream, UInt64 indexSize, ISzAlloc *alloc)
+{
+  SRes res;
+  size_t size;
+  Byte *buf;
+  if (indexSize > ((UInt32)1 << 31))
+    return SZ_ERROR_UNSUPPORTED;
+  size = (size_t)indexSize;
+  if (size != indexSize)
+    return SZ_ERROR_UNSUPPORTED;
+  buf = alloc->Alloc(alloc, size);
+  if (buf == 0)
+    return SZ_ERROR_MEM;
+  res = LookInStream_Read2(stream, buf, size, SZ_ERROR_UNSUPPORTED);
+  if (res == SZ_OK)
+    res = Xz_ReadIndex2(p, buf, size, alloc);
+  alloc->Free(alloc, buf);
+  return res;
+}
+
+static SRes SeekFromCur(ILookInStream *inStream, Int64 *res)
+{
+  return inStream->Seek(inStream, res, SZ_SEEK_CUR);
+}
+
+static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOffset, ISzAlloc *alloc)
+{
+  UInt64 indexSize;
+  Byte buf[XZ_STREAM_FOOTER_SIZE];
+
+  if ((*startOffset & 3) != 0 || *startOffset < XZ_STREAM_FOOTER_SIZE)
+    return SZ_ERROR_NO_ARCHIVE;
+  *startOffset = -XZ_STREAM_FOOTER_SIZE;
+  RINOK(SeekFromCur(stream, startOffset));
+
+  RINOK(LookInStream_Read2(stream, buf, XZ_STREAM_FOOTER_SIZE, SZ_ERROR_NO_ARCHIVE));
+  
+  if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
+  {
+    Int64 i = 0;
+    *startOffset += XZ_STREAM_FOOTER_SIZE;
+    for (;;)
+    {
+      int j;
+      size_t processedSize;
+      #define TEMP_BUF_SIZE (1 << 10)
+      Byte tempBuf[TEMP_BUF_SIZE];
+      if (*startOffset < XZ_STREAM_FOOTER_SIZE || i > (1 << 16))
+        return SZ_ERROR_NO_ARCHIVE;
+      processedSize = (*startOffset > TEMP_BUF_SIZE) ? TEMP_BUF_SIZE : (size_t)*startOffset;
+      i += processedSize;
+      *startOffset = -(Int64)processedSize;
+      RINOK(SeekFromCur(stream, startOffset));
+      RINOK(LookInStream_Read2(stream, tempBuf, processedSize, SZ_ERROR_NO_ARCHIVE));
+      for (j = (int)processedSize; j >= 1; j--) // FIXED j >= 0 => j >= 1
+        if (tempBuf[j -1] != 0)
+          break;
+      if (j != 0)
+      {
+        if ((j & 3) != 0)
+          return SZ_ERROR_NO_ARCHIVE;
+        *startOffset += j;
+        if (*startOffset < XZ_STREAM_FOOTER_SIZE)
+          return SZ_ERROR_NO_ARCHIVE;
+        *startOffset -= XZ_STREAM_FOOTER_SIZE;
+        RINOK(stream->Seek(stream, startOffset, SZ_SEEK_SET));
+        RINOK(LookInStream_Read2(stream, buf, XZ_STREAM_FOOTER_SIZE, SZ_ERROR_NO_ARCHIVE));
+        if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
+          return SZ_ERROR_NO_ARCHIVE;
+        break;
+      }
+    }
+  }
+  
+  p->flags = (CXzStreamFlags)GetBe16(buf + 8);
+
+  if (!XzFlags_IsSupported(p->flags))
+    return SZ_ERROR_UNSUPPORTED;
+
+  if (GetUi32(buf) != CrcCalc(buf + 4, 6))
+    return SZ_ERROR_ARCHIVE;
+
+  indexSize = ((UInt64)GetUi32(buf + 4) + 1) << 2;
+
+  *startOffset = -(Int64)(indexSize + XZ_STREAM_FOOTER_SIZE);
+  RINOK(SeekFromCur(stream, startOffset));
+
+  RINOK(Xz_ReadIndex(p, stream, indexSize, alloc));
+
+  {
+    UInt64 totalSize = Xz_GetPackSize(p);
+    UInt64 sum = XZ_STREAM_HEADER_SIZE + totalSize + indexSize;
+    if (totalSize == XZ_SIZE_OVERFLOW ||
+      sum >= ((UInt64)1 << 63) ||
+      totalSize >= ((UInt64)1 << 63))
+      return SZ_ERROR_ARCHIVE;
+    *startOffset = -(Int64)sum;
+    RINOK(SeekFromCur(stream, startOffset));
+  }
+  {
+    CXzStreamFlags headerFlags;
+    CSecToRead secToRead;
+    SecToRead_CreateVTable(&secToRead);
+    secToRead.realStream = stream;
+
+    RINOK(Xz_ReadHeader(&headerFlags, &secToRead.s));
+    return (p->flags == headerFlags) ? SZ_OK : SZ_ERROR_ARCHIVE;
+  }
+}
+
+
+/* ---------- Xz Streams ---------- */
+
+void Xzs_Construct(CXzs *p)
+{
+  p->num = p->numAllocated = 0;
+  p->streams = 0;
+}
+
+void Xzs_Free(CXzs *p, ISzAlloc *alloc)
+{
+  size_t i;
+  for (i = 0; i < p->num; i++)
+    Xz_Free(&p->streams[i], alloc);
+  alloc->Free(alloc, p->streams);
+  p->num = p->numAllocated = 0;
+  p->streams = 0;
+}
+
+UInt64 Xzs_GetNumBlocks(const CXzs *p)
+{
+  UInt64 num = 0;
+  size_t i;
+  for (i = 0; i < p->num; i++)
+    num += p->streams[i].numBlocks;
+  return num;
+}
+
+UInt64 Xzs_GetUnpackSize(const CXzs *p)
+{
+  UInt64 size = 0;
+  size_t i;
+  for (i = 0; i < p->num; i++)
+    ADD_SIZE_CHECH(size, Xz_GetUnpackSize(&p->streams[i]));
+  return size;
+}
+
+/*
+UInt64 Xzs_GetPackSize(const CXzs *p)
+{
+  UInt64 size = 0;
+  size_t i;
+  for (i = 0; i < p->num; i++)
+    ADD_SIZE_CHECH(size, Xz_GetTotalSize(&p->streams[i]));
+  return size;
+}
+*/
+
+SRes Xzs_ReadBackward(CXzs *p, ILookInStream *stream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc)
+{
+  Int64 endOffset = 0;
+  RINOK(stream->Seek(stream, &endOffset, SZ_SEEK_END));
+  *startOffset = endOffset;
+  for (;;)
+  {
+    CXzStream st;
+    SRes res;
+    Xz_Construct(&st);
+    res = Xz_ReadBackward(&st, stream, startOffset, alloc);
+    st.startOffset = *startOffset;
+    RINOK(res);
+    if (p->num == p->numAllocated)
+    {
+      size_t newNum = p->num + p->num / 4 + 1;
+      Byte *data = (Byte *)alloc->Alloc(alloc, newNum * sizeof(CXzStream));
+      if (data == 0)
+        return SZ_ERROR_MEM;
+      p->numAllocated = newNum;
+      memcpy(data, p->streams, p->num * sizeof(CXzStream));
+      alloc->Free(alloc, p->streams);
+      p->streams = (CXzStream *)data;
+    }
+    p->streams[p->num++] = st;
+    if (*startOffset == 0)
+      break;
+    RINOK(stream->Seek(stream, startOffset, SZ_SEEK_SET));
+    if (progress && progress->Progress(progress, endOffset - *startOffset, (UInt64)(Int64)-1) != SZ_OK)
+      return SZ_ERROR_PROGRESS;
+  }
+  return SZ_OK;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,3 @@
+// CompressionMethod.cpp
+
+#include "StdAfx.h"

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zCompressionMode.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,50 @@
+// 7zCompressionMode.h
+
+#ifndef __7Z_COMPRESSION_MODE_H
+#define __7Z_COMPRESSION_MODE_H
+
+#include "../../../Common/MyString.h"
+
+#include "../../../Windows/PropVariant.h"
+
+#include "../../Common/MethodProps.h"
+
+namespace NArchive {
+namespace N7z {
+
+struct CMethodFull: public CMethod
+{
+  UInt32 NumInStreams;
+  UInt32 NumOutStreams;
+  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
+};
+
+struct CBind
+{
+  UInt32 InCoder;
+  UInt32 InStream;
+  UInt32 OutCoder;
+  UInt32 OutStream;
+};
+
+struct CCompressionMethodMode
+{
+  CObjectVector<CMethodFull> Methods;
+  CRecordVector<CBind> Binds;
+  #ifndef _7ZIP_ST
+  UInt32 NumThreads;
+  #endif
+  bool PasswordIsDefined;
+  UString Password;
+
+  bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }
+  CCompressionMethodMode(): PasswordIsDefined(false)
+      #ifndef _7ZIP_ST
+      , NumThreads(1)
+      #endif
+  {}
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,332 @@
+// 7zDecode.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/LimitedStreams.h"
+#include "../../Common/LockedStream.h"
+#include "../../Common/ProgressUtils.h"
+#include "../../Common/StreamObjects.h"
+
+#include "7zDecode.h"
+
+namespace NArchive {
+namespace N7z {
+
+static void ConvertFolderItemInfoToBindInfo(const CFolder &folder,
+    CBindInfoEx &bindInfo)
+{
+  bindInfo.Clear();
+  int i;
+  for (i = 0; i < folder.BindPairs.Size(); i++)
+  {
+    NCoderMixer::CBindPair bindPair;
+    bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;
+    bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;
+    bindInfo.BindPairs.Add(bindPair);
+  }
+  UInt32 outStreamIndex = 0;
+  for (i = 0; i < folder.Coders.Size(); i++)
+  {
+    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
+    const CCoderInfo &coderInfo = folder.Coders[i];
+    coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;
+    coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;
+    bindInfo.Coders.Add(coderStreamsInfo);
+    bindInfo.CoderMethodIDs.Add(coderInfo.MethodID);
+    for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)
+      if (folder.FindBindPairForOutStream(outStreamIndex) < 0)
+        bindInfo.OutStreams.Add(outStreamIndex);
+  }
+  for (i = 0; i < folder.PackStreams.Size(); i++)
+    bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]);
+}
+
+static bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,
+    const NCoderMixer::CCoderStreamsInfo &a2)
+{
+  return (a1.NumInStreams == a2.NumInStreams) &&
+    (a1.NumOutStreams == a2.NumOutStreams);
+}
+
+static bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)
+{
+  return (a1.InIndex == a2.InIndex) &&
+    (a1.OutIndex == a2.OutIndex);
+}
+
+static bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)
+{
+  if (a1.Coders.Size() != a2.Coders.Size())
+    return false;
+  int i;
+  for (i = 0; i < a1.Coders.Size(); i++)
+    if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))
+      return false;
+  if (a1.BindPairs.Size() != a2.BindPairs.Size())
+    return false;
+  for (i = 0; i < a1.BindPairs.Size(); i++)
+    if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))
+      return false;
+  for (i = 0; i < a1.CoderMethodIDs.Size(); i++)
+    if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])
+      return false;
+  if (a1.InStreams.Size() != a2.InStreams.Size())
+    return false;
+  if (a1.OutStreams.Size() != a2.OutStreams.Size())
+    return false;
+  return true;
+}
+
+CDecoder::CDecoder(bool multiThread)
+{
+  #ifndef _ST_MODE
+  multiThread = true;
+  #endif
+  _multiThread = multiThread;
+  _bindInfoExPrevIsDefined = false;
+}
+
+HRESULT CDecoder::Decode(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    IInStream *inStream,
+    UInt64 startPos,
+    const UInt64 *packSizes,
+    const CFolder &folderInfo,
+    ISequentialOutStream *outStream,
+    ICompressProgressInfo *compressProgress
+    #ifndef _NO_CRYPTO
+    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+    #endif
+    #if !defined(_7ZIP_ST) && !defined(_SFX)
+    , bool mtMode, UInt32 numThreads
+    #endif
+    )
+{
+  if (!folderInfo.CheckStructure())
+    return E_NOTIMPL;
+  #ifndef _NO_CRYPTO
+  passwordIsDefined = false;
+  #endif
+  CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;
+  
+  CLockedInStream lockedInStream;
+  lockedInStream.Init(inStream);
+  
+  for (int j = 0; j < folderInfo.PackStreams.Size(); j++)
+  {
+    CLockedSequentialInStreamImp *lockedStreamImpSpec = new
+        CLockedSequentialInStreamImp;
+    CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;
+    lockedStreamImpSpec->Init(&lockedInStream, startPos);
+    startPos += packSizes[j];
+    
+    CLimitedSequentialInStream *streamSpec = new
+        CLimitedSequentialInStream;
+    CMyComPtr<ISequentialInStream> inStream = streamSpec;
+    streamSpec->SetStream(lockedStreamImp);
+    streamSpec->Init(packSizes[j]);
+    inStreams.Add(inStream);
+  }
+  
+  int numCoders = folderInfo.Coders.Size();
+  
+  CBindInfoEx bindInfo;
+  ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);
+  bool createNewCoders;
+  if (!_bindInfoExPrevIsDefined)
+    createNewCoders = true;
+  else
+    createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);
+  if (createNewCoders)
+  {
+    int i;
+    _decoders.Clear();
+    // _decoders2.Clear();
+    
+    _mixerCoder.Release();
+
+    if (_multiThread)
+    {
+      _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;
+      _mixerCoder = _mixerCoderMTSpec;
+      _mixerCoderCommon = _mixerCoderMTSpec;
+    }
+    else
+    {
+      #ifdef _ST_MODE
+      _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;
+      _mixerCoder = _mixerCoderSTSpec;
+      _mixerCoderCommon = _mixerCoderSTSpec;
+      #endif
+    }
+    RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));
+    
+    for (i = 0; i < numCoders; i++)
+    {
+      const CCoderInfo &coderInfo = folderInfo.Coders[i];
+
+  
+      CMyComPtr<ICompressCoder> decoder;
+      CMyComPtr<ICompressCoder2> decoder2;
+      RINOK(CreateCoder(
+          EXTERNAL_CODECS_LOC_VARS
+          coderInfo.MethodID, decoder, decoder2, false));
+      CMyComPtr<IUnknown> decoderUnknown;
+      if (coderInfo.IsSimpleCoder())
+      {
+        if (decoder == 0)
+          return E_NOTIMPL;
+
+        decoderUnknown = (IUnknown *)decoder;
+        
+        if (_multiThread)
+          _mixerCoderMTSpec->AddCoder(decoder);
+        #ifdef _ST_MODE
+        else
+          _mixerCoderSTSpec->AddCoder(decoder, false);
+        #endif
+      }
+      else
+      {
+        if (decoder2 == 0)
+          return E_NOTIMPL;
+        decoderUnknown = (IUnknown *)decoder2;
+        if (_multiThread)
+          _mixerCoderMTSpec->AddCoder2(decoder2);
+        #ifdef _ST_MODE
+        else
+          _mixerCoderSTSpec->AddCoder2(decoder2, false);
+        #endif
+      }
+      _decoders.Add(decoderUnknown);
+      #ifdef EXTERNAL_CODECS
+      CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
+      decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
+      if (setCompressCodecsInfo)
+      {
+        RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));
+      }
+      #endif
+    }
+    _bindInfoExPrev = bindInfo;
+    _bindInfoExPrevIsDefined = true;
+  }
+  int i;
+  _mixerCoderCommon->ReInit();
+  
+  UInt32 packStreamIndex = 0, unpackStreamIndex = 0;
+  UInt32 coderIndex = 0;
+  // UInt32 coder2Index = 0;
+  
+  for (i = 0; i < numCoders; i++)
+  {
+    const CCoderInfo &coderInfo = folderInfo.Coders[i];
+    CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];
+    
+    {
+      CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
+      decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
+      if (setDecoderProperties)
+      {
+        const CByteBuffer &props = coderInfo.Props;
+        size_t size = props.GetCapacity();
+        if (size > 0xFFFFFFFF)
+          return E_NOTIMPL;
+        // if (size > 0)
+        {
+          RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));
+        }
+      }
+    }
+
+    #if !defined(_7ZIP_ST) && !defined(_SFX)
+    if (mtMode)
+    {
+      CMyComPtr<ICompressSetCoderMt> setCoderMt;
+      decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
+      if (setCoderMt)
+      {
+        RINOK(setCoderMt->SetNumberOfThreads(numThreads));
+      }
+    }
+    #endif
+
+    #ifndef _NO_CRYPTO
+    {
+      CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
+      decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);
+      if (cryptoSetPassword)
+      {
+        if (getTextPassword == 0)
+          return E_FAIL;
+        CMyComBSTR passwordBSTR;
+        RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));
+        CByteBuffer buffer;
+        passwordIsDefined = true;
+        const UString password(passwordBSTR);
+        const UInt32 sizeInBytes = password.Length() * 2;
+        buffer.SetCapacity(sizeInBytes);
+        for (int i = 0; i < password.Length(); i++)
+        {
+          wchar_t c = password[i];
+          ((Byte *)buffer)[i * 2] = (Byte)c;
+          ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
+        }
+        RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));
+      }
+    }
+    #endif
+
+    coderIndex++;
+    
+    UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;
+    UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;
+    CRecordVector<const UInt64 *> packSizesPointers;
+    CRecordVector<const UInt64 *> unpackSizesPointers;
+    packSizesPointers.Reserve(numInStreams);
+    unpackSizesPointers.Reserve(numOutStreams);
+    UInt32 j;
+    for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)
+      unpackSizesPointers.Add(&folderInfo.UnpackSizes[unpackStreamIndex]);
+    
+    for (j = 0; j < numInStreams; j++, packStreamIndex++)
+    {
+      int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);
+      if (bindPairIndex >= 0)
+        packSizesPointers.Add(
+        &folderInfo.UnpackSizes[(UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex]);
+      else
+      {
+        int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);
+        if (index < 0)
+          return E_FAIL;
+        packSizesPointers.Add(&packSizes[index]);
+      }
+    }
+    
+    _mixerCoderCommon->SetCoderInfo(i,
+        &packSizesPointers.Front(),
+        &unpackSizesPointers.Front());
+  }
+  UInt32 mainCoder, temp;
+  bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);
+
+  if (_multiThread)
+    _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);
+  /*
+  else
+    _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;
+  */
+  
+  if (numCoders == 0)
+    return 0;
+  CRecordVector<ISequentialInStream *> inStreamPointers;
+  inStreamPointers.Reserve(inStreams.Size());
+  for (i = 0; i < inStreams.Size(); i++)
+    inStreamPointers.Add(inStreams[i]);
+  ISequentialOutStream *outStreamPointer = outStream;
+  return _mixerCoder->Code(&inStreamPointers.Front(), NULL,
+    inStreams.Size(), &outStreamPointer, NULL, 1, compressProgress);
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zDecode.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,68 @@
+// 7zDecode.h
+
+#ifndef __7Z_DECODE_H
+#define __7Z_DECODE_H
+
+#include "../../IStream.h"
+#include "../../IPassword.h"
+
+#include "../Common/CoderMixer2.h"
+#include "../Common/CoderMixer2MT.h"
+#ifdef _ST_MODE
+#include "../Common/CoderMixer2ST.h"
+#endif
+
+#include "../../Common/CreateCoder.h"
+
+#include "7zItem.h"
+
+namespace NArchive {
+namespace N7z {
+
+struct CBindInfoEx: public NCoderMixer::CBindInfo
+{
+  CRecordVector<CMethodId> CoderMethodIDs;
+  void Clear()
+  {
+    CBindInfo::Clear();
+    CoderMethodIDs.Clear();
+  }
+};
+
+class CDecoder
+{
+  bool _bindInfoExPrevIsDefined;
+  CBindInfoEx _bindInfoExPrev;
+  
+  bool _multiThread;
+  #ifdef _ST_MODE
+  NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;
+  #endif
+  NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;
+  NCoderMixer::CCoderMixer2 *_mixerCoderCommon;
+  
+  CMyComPtr<ICompressCoder2> _mixerCoder;
+  CObjectVector<CMyComPtr<IUnknown> > _decoders;
+  // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;
+public:
+  CDecoder(bool multiThread);
+  HRESULT Decode(
+      DECL_EXTERNAL_CODECS_LOC_VARS
+      IInStream *inStream,
+      UInt64 startPos,
+      const UInt64 *packSizes,
+      const CFolder &folder,
+      ISequentialOutStream *outStream,
+      ICompressProgressInfo *compressProgress
+      #ifndef _NO_CRYPTO
+      , ICryptoGetTextPassword *getTextPasswordSpec, bool &passwordIsDefined
+      #endif
+      #if !defined(_7ZIP_ST) && !defined(_SFX)
+      , bool mtMode, UInt32 numThreads
+      #endif
+      );
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,444 @@
+// 7zEncode.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/CreateCoder.h"
+#include "../../Common/FilterCoder.h"
+#include "../../Common/LimitedStreams.h"
+#include "../../Common/InOutTempBuffer.h"
+#include "../../Common/ProgressUtils.h"
+#include "../../Common/StreamObjects.h"
+
+#include "7zEncode.h"
+#include "7zSpecStream.h"
+
+static const UInt64 k_Delta = 0x03;
+static const UInt64 k_BCJ = 0x03030103;
+static const UInt64 k_BCJ2 = 0x0303011B;
+
+namespace NArchive {
+namespace N7z {
+
+static void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,
+    const CRecordVector<CMethodId> decompressionMethods,
+    CFolder &folder)
+{
+  folder.Coders.Clear();
+  // bindInfo.CoderMethodIDs.Clear();
+  // folder.OutStreams.Clear();
+  folder.PackStreams.Clear();
+  folder.BindPairs.Clear();
+  int i;
+  for (i = 0; i < bindInfo.BindPairs.Size(); i++)
+  {
+    CBindPair bindPair;
+    bindPair.InIndex = bindInfo.BindPairs[i].InIndex;
+    bindPair.OutIndex = bindInfo.BindPairs[i].OutIndex;
+    folder.BindPairs.Add(bindPair);
+  }
+  for (i = 0; i < bindInfo.Coders.Size(); i++)
+  {
+    CCoderInfo coderInfo;
+    const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];
+    coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;
+    coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;
+    coderInfo.MethodID = decompressionMethods[i];
+    folder.Coders.Add(coderInfo);
+  }
+  for (i = 0; i < bindInfo.InStreams.Size(); i++)
+    folder.PackStreams.Add(bindInfo.InStreams[i]);
+}
+
+HRESULT CEncoder::CreateMixerCoder(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    const UInt64 *inSizeForReduce)
+{
+  _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;
+  _mixerCoder = _mixerCoderSpec;
+  RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));
+  for (int i = 0; i < _options.Methods.Size(); i++)
+  {
+    const CMethodFull &methodFull = _options.Methods[i];
+    _codersInfo.Add(CCoderInfo());
+    CCoderInfo &encodingInfo = _codersInfo.Back();
+    encodingInfo.MethodID = methodFull.Id;
+    CMyComPtr<ICompressCoder> encoder;
+    CMyComPtr<ICompressCoder2> encoder2;
+    
+
+    RINOK(CreateCoder(
+        EXTERNAL_CODECS_LOC_VARS
+        methodFull.Id, encoder, encoder2, true));
+
+    if (!encoder && !encoder2)
+      return E_FAIL;
+
+    CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;
+   
+    #ifndef _7ZIP_ST
+    {
+      CMyComPtr<ICompressSetCoderMt> setCoderMt;
+      encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
+      if (setCoderMt)
+      {
+        RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));
+      }
+    }
+    #endif
+        
+
+    RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon));
+
+    /*
+    CMyComPtr<ICryptoResetSalt> resetSalt;
+    encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);
+    if (resetSalt != NULL)
+    {
+      resetSalt->ResetSalt();
+    }
+    */
+
+    #ifdef EXTERNAL_CODECS
+    CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
+    encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
+    if (setCompressCodecsInfo)
+    {
+      RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecsInfo));
+    }
+    #endif
+    
+    CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
+    encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);
+
+    if (cryptoSetPassword)
+    {
+      CByteBuffer buffer;
+      const UInt32 sizeInBytes = _options.Password.Length() * 2;
+      buffer.SetCapacity(sizeInBytes);
+      for (int i = 0; i < _options.Password.Length(); i++)
+      {
+        wchar_t c = _options.Password[i];
+        ((Byte *)buffer)[i * 2] = (Byte)c;
+        ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
+      }
+      RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));
+    }
+
+    if (encoder)
+      _mixerCoderSpec->AddCoder(encoder);
+    else
+      _mixerCoderSpec->AddCoder2(encoder2);
+  }
+  return S_OK;
+}
+
+HRESULT CEncoder::Encode(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    ISequentialInStream *inStream,
+    const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,
+    CFolder &folderItem,
+    ISequentialOutStream *outStream,
+    CRecordVector<UInt64> &packSizes,
+    ICompressProgressInfo *compressProgress)
+{
+  RINOK(EncoderConstr());
+
+  if (_mixerCoderSpec == NULL)
+  {
+    RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));
+  }
+  _mixerCoderSpec->ReInit();
+  // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);
+
+  CObjectVector<CInOutTempBuffer> inOutTempBuffers;
+  CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;
+  CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;
+  int numMethods = _bindInfo.Coders.Size();
+  int i;
+  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)
+  {
+    inOutTempBuffers.Add(CInOutTempBuffer());
+    inOutTempBuffers.Back().Create();
+    inOutTempBuffers.Back().InitWriting();
+  }
+  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)
+  {
+    CSequentialOutTempBufferImp *tempBufferSpec = new CSequentialOutTempBufferImp;
+    CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;
+    tempBufferSpec->Init(&inOutTempBuffers[i - 1]);
+    tempBuffers.Add(tempBuffer);
+    tempBufferSpecs.Add(tempBufferSpec);
+  }
+
+  for (i = 0; i < numMethods; i++)
+    _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);
+
+  if (_bindInfo.InStreams.IsEmpty())
+    return E_FAIL;
+  UInt32 mainCoderIndex, mainStreamIndex;
+  _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);
+  
+  if (inStreamSize != NULL)
+  {
+    CRecordVector<const UInt64 *> sizePointers;
+    for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)
+      if (i == mainStreamIndex)
+        sizePointers.Add(inStreamSize);
+      else
+        sizePointers.Add(NULL);
+    _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);
+  }
+
+  
+  // UInt64 outStreamStartPos;
+  // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));
+  
+  CSequentialInStreamSizeCount2 *inStreamSizeCountSpec = new CSequentialInStreamSizeCount2;
+  CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;
+  CSequentialOutStreamSizeCount *outStreamSizeCountSpec = new CSequentialOutStreamSizeCount;
+  CMyComPtr<ISequentialOutStream> outStreamSizeCount = outStreamSizeCountSpec;
+
+  inStreamSizeCountSpec->Init(inStream);
+  outStreamSizeCountSpec->SetStream(outStream);
+  outStreamSizeCountSpec->Init();
+
+  CRecordVector<ISequentialInStream *> inStreamPointers;
+  CRecordVector<ISequentialOutStream *> outStreamPointers;
+  inStreamPointers.Add(inStreamSizeCount);
+  outStreamPointers.Add(outStreamSizeCount);
+  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)
+    outStreamPointers.Add(tempBuffers[i - 1]);
+
+  for (i = 0; i < _codersInfo.Size(); i++)
+  {
+    CCoderInfo &encodingInfo = _codersInfo[i];
+    
+    CMyComPtr<ICryptoResetInitVector> resetInitVector;
+    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);
+    if (resetInitVector != NULL)
+    {
+      resetInitVector->ResetInitVector();
+    }
+
+    CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
+    _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);
+    if (writeCoderProperties != NULL)
+    {
+      CDynBufSeqOutStream *outStreamSpec = new CDynBufSeqOutStream;
+      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
+      outStreamSpec->Init();
+      writeCoderProperties->WriteCoderProperties(outStream);
+      outStreamSpec->CopyToBuffer(encodingInfo.Props);
+    }
+  }
+
+  UInt32 progressIndex = mainCoderIndex;
+
+  for (i = 0; i + 1 < _codersInfo.Size(); i++)
+  {
+    UInt64 m = _codersInfo[i].MethodID;
+    if (m == k_Delta || m == k_BCJ || m == k_BCJ2)
+      progressIndex = i + 1;
+  }
+
+  _mixerCoderSpec->SetProgressCoderIndex(progressIndex);
+  
+  RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,
+    &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));
+  
+  ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods, folderItem);
+  
+  packSizes.Add(outStreamSizeCountSpec->GetSize());
+  
+  for (i = 1; i < _bindInfo.OutStreams.Size(); i++)
+  {
+    CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];
+    RINOK(inOutTempBuffer.WriteToStream(outStream));
+    packSizes.Add(inOutTempBuffer.GetDataSize());
+  }
+  
+  for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)
+  {
+    int binder = _bindInfo.FindBinderForInStream(
+        _bindReverseConverter->DestOutToSrcInMap[i]);
+    UInt64 streamSize;
+    if (binder < 0)
+      streamSize = inStreamSizeCountSpec->GetSize();
+    else
+      streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);
+    folderItem.UnpackSizes.Add(streamSize);
+  }
+  for (i = numMethods - 1; i >= 0; i--)
+    folderItem.Coders[numMethods - 1 - i].Props = _codersInfo[i].Props;
+  return S_OK;
+}
+
+
+CEncoder::CEncoder(const CCompressionMethodMode &options):
+  _bindReverseConverter(0),
+  _constructed(false)
+{
+  if (options.IsEmpty())
+    throw 1;
+
+  _options = options;
+  _mixerCoderSpec = NULL;
+}
+
+HRESULT CEncoder::EncoderConstr()
+{
+  if (_constructed)
+    return S_OK;
+  if (_options.Methods.IsEmpty())
+  {
+    // it has only password method;
+    if (!_options.PasswordIsDefined)
+      throw 1;
+    if (!_options.Binds.IsEmpty())
+      throw 1;
+    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
+    CMethodFull method;
+    
+    method.NumInStreams = 1;
+    method.NumOutStreams = 1;
+    coderStreamsInfo.NumInStreams = 1;
+    coderStreamsInfo.NumOutStreams = 1;
+    method.Id = k_AES;
+    
+    _options.Methods.Add(method);
+    _bindInfo.Coders.Add(coderStreamsInfo);
+  
+    _bindInfo.InStreams.Add(0);
+    _bindInfo.OutStreams.Add(0);
+  }
+  else
+  {
+
+  UInt32 numInStreams = 0, numOutStreams = 0;
+  int i;
+  for (i = 0; i < _options.Methods.Size(); i++)
+  {
+    const CMethodFull &methodFull = _options.Methods[i];
+    NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
+    coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;
+    coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;
+    if (_options.Binds.IsEmpty())
+    {
+      if (i < _options.Methods.Size() - 1)
+      {
+        NCoderMixer::CBindPair bindPair;
+        bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;
+        bindPair.OutIndex = numOutStreams;
+        _bindInfo.BindPairs.Add(bindPair);
+      }
+      else
+        _bindInfo.OutStreams.Insert(0, numOutStreams);
+      for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)
+        _bindInfo.OutStreams.Add(numOutStreams + j);
+    }
+    
+    numInStreams += coderStreamsInfo.NumInStreams;
+    numOutStreams += coderStreamsInfo.NumOutStreams;
+
+    _bindInfo.Coders.Add(coderStreamsInfo);
+  }
+
+  if (!_options.Binds.IsEmpty())
+  {
+    for (i = 0; i < _options.Binds.Size(); i++)
+    {
+      NCoderMixer::CBindPair bindPair;
+      const CBind &bind = _options.Binds[i];
+      bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;
+      bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;
+      _bindInfo.BindPairs.Add(bindPair);
+    }
+    for (i = 0; i < (int)numOutStreams; i++)
+      if (_bindInfo.FindBinderForOutStream(i) == -1)
+        _bindInfo.OutStreams.Add(i);
+  }
+
+  for (i = 0; i < (int)numInStreams; i++)
+    if (_bindInfo.FindBinderForInStream(i) == -1)
+      _bindInfo.InStreams.Add(i);
+
+  if (_bindInfo.InStreams.IsEmpty())
+    throw 1; // this is error
+
+  // Make main stream first in list
+  int inIndex = _bindInfo.InStreams[0];
+  for (;;)
+  {
+    UInt32 coderIndex, coderStreamIndex;
+    _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);
+    UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);
+    int binder = _bindInfo.FindBinderForOutStream(outIndex);
+    if (binder >= 0)
+    {
+      inIndex = _bindInfo.BindPairs[binder].InIndex;
+      continue;
+    }
+    for (i = 0; i < _bindInfo.OutStreams.Size(); i++)
+      if (_bindInfo.OutStreams[i] == outIndex)
+      {
+        _bindInfo.OutStreams.Delete(i);
+        _bindInfo.OutStreams.Insert(0, outIndex);
+        break;
+      }
+    break;
+  }
+
+  if (_options.PasswordIsDefined)
+  {
+    int numCryptoStreams = _bindInfo.OutStreams.Size();
+
+    for (i = 0; i < numCryptoStreams; i++)
+    {
+      NCoderMixer::CBindPair bindPair;
+      bindPair.InIndex = numInStreams + i;
+      bindPair.OutIndex = _bindInfo.OutStreams[i];
+      _bindInfo.BindPairs.Add(bindPair);
+    }
+    _bindInfo.OutStreams.Clear();
+
+    /*
+    if (numCryptoStreams == 0)
+      numCryptoStreams = 1;
+    */
+
+    for (i = 0; i < numCryptoStreams; i++)
+    {
+      NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
+      CMethodFull method;
+      method.NumInStreams = 1;
+      method.NumOutStreams = 1;
+      coderStreamsInfo.NumInStreams = method.NumOutStreams;
+      coderStreamsInfo.NumOutStreams = method.NumInStreams;
+      method.Id = k_AES;
+
+      _options.Methods.Add(method);
+      _bindInfo.Coders.Add(coderStreamsInfo);
+      _bindInfo.OutStreams.Add(numOutStreams + i);
+    }
+  }
+
+  }
+
+  for (int i = _options.Methods.Size() - 1; i >= 0; i--)
+  {
+    const CMethodFull &methodFull = _options.Methods[i];
+    _decompressionMethods.Add(methodFull.Id);
+  }
+
+  _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);
+  _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);
+  _constructed = true;
+  return S_OK;
+}
+
+CEncoder::~CEncoder()
+{
+  delete _bindReverseConverter;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zEncode.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,55 @@
+// 7zEncode.h
+
+#ifndef __7Z_ENCODE_H
+#define __7Z_ENCODE_H
+
+// #include "../../Common/StreamObjects.h"
+
+#include "7zCompressionMode.h"
+
+#include "../Common/CoderMixer2.h"
+#include "../Common/CoderMixer2MT.h"
+#ifdef _ST_MODE
+#include "../Common/CoderMixer2ST.h"
+#endif
+#include "7zItem.h"
+
+#include "../../Common/CreateCoder.h"
+
+namespace NArchive {
+namespace N7z {
+
+class CEncoder
+{
+  NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;
+  CMyComPtr<ICompressCoder2> _mixerCoder;
+
+  CObjectVector<CCoderInfo> _codersInfo;
+
+  CCompressionMethodMode _options;
+  NCoderMixer::CBindInfo _bindInfo;
+  NCoderMixer::CBindInfo _decompressBindInfo;
+  NCoderMixer::CBindReverseConverter *_bindReverseConverter;
+  CRecordVector<CMethodId> _decompressionMethods;
+
+  HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS
+      const UInt64 *inSizeForReduce);
+
+  bool _constructed;
+public:
+  CEncoder(const CCompressionMethodMode &options);
+  ~CEncoder();
+  HRESULT EncoderConstr();
+  HRESULT Encode(
+      DECL_EXTERNAL_CODECS_LOC_VARS
+      ISequentialInStream *inStream,
+      const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,
+      CFolder &folderItem,
+      ISequentialOutStream *outStream,
+      CRecordVector<UInt64> &packSizes,
+      ICompressProgressInfo *compressProgress);
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zExtract.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zExtract.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zExtract.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zExtract.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,270 @@
+// 7zExtract.cpp
+
+#include "StdAfx.h"
+
+#include "../../../Common/ComTry.h"
+
+#include "../../Common/ProgressUtils.h"
+
+#include "7zDecode.h"
+// #include "7z1Decode.h"
+#include "7zFolderOutStream.h"
+#include "7zHandler.h"
+
+namespace NArchive {
+namespace N7z {
+
+struct CExtractFolderInfo
+{
+  #ifdef _7Z_VOL
+  int VolumeIndex;
+  #endif
+  CNum FileIndex;
+  CNum FolderIndex;
+  CBoolVector ExtractStatuses;
+  UInt64 UnpackSize;
+  CExtractFolderInfo(
+    #ifdef _7Z_VOL
+    int volumeIndex,
+    #endif
+    CNum fileIndex, CNum folderIndex):
+    #ifdef _7Z_VOL
+    VolumeIndex(volumeIndex),
+    #endif
+    FileIndex(fileIndex),
+    FolderIndex(folderIndex),
+    UnpackSize(0)
+  {
+    if (fileIndex != kNumNoIndex)
+    {
+      ExtractStatuses.Reserve(1);
+      ExtractStatuses.Add(true);
+    }
+  };
+};
+
+STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+    Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)
+{
+  COM_TRY_BEGIN
+  bool testMode = (testModeSpec != 0);
+  CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
+  UInt64 importantTotalUnpacked = 0;
+
+  bool allFilesMode = (numItems == (UInt32)-1);
+  if (allFilesMode)
+    numItems =
+    #ifdef _7Z_VOL
+    _refs.Size();
+    #else
+    _db.Files.Size();
+    #endif
+
+  if(numItems == 0)
+    return S_OK;
+
+  /*
+  if(_volumes.Size() != 1)
+    return E_FAIL;
+  const CVolume &volume = _volumes.Front();
+  const CArchiveDatabaseEx &_db = volume.Database;
+  IInStream *_inStream = volume.Stream;
+  */
+  
+  CObjectVector<CExtractFolderInfo> extractFolderInfoVector;
+  for (UInt32 ii = 0; ii < numItems; ii++)
+  {
+    // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];
+    UInt32 ref2Index = allFilesMode ? ii : indices[ii];
+    // const CRef2 &ref2 = _refs[ref2Index];
+
+    // for (UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)
+    {
+      #ifdef _7Z_VOL
+      // const CRef &ref = ref2.Refs[ri];
+      const CRef &ref = _refs[ref2Index];
+
+      int volumeIndex = ref.VolumeIndex;
+      const CVolume &volume = _volumes[volumeIndex];
+      const CArchiveDatabaseEx &db = volume.Database;
+      UInt32 fileIndex = ref.ItemIndex;
+      #else
+      const CArchiveDatabaseEx &db = _db;
+      UInt32 fileIndex = ref2Index;
+      #endif
+
+      CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];
+      if (folderIndex == kNumNoIndex)
+      {
+        extractFolderInfoVector.Add(CExtractFolderInfo(
+            #ifdef _7Z_VOL
+            volumeIndex,
+            #endif
+            fileIndex, kNumNoIndex));
+        continue;
+      }
+      if (extractFolderInfoVector.IsEmpty() ||
+        folderIndex != extractFolderInfoVector.Back().FolderIndex
+        #ifdef _7Z_VOL
+        || volumeIndex != extractFolderInfoVector.Back().VolumeIndex
+        #endif
+        )
+      {
+        extractFolderInfoVector.Add(CExtractFolderInfo(
+            #ifdef _7Z_VOL
+            volumeIndex,
+            #endif
+            kNumNoIndex, folderIndex));
+        const CFolder &folderInfo = db.Folders[folderIndex];
+        UInt64 unpackSize = folderInfo.GetUnpackSize();
+        importantTotalUnpacked += unpackSize;
+        extractFolderInfoVector.Back().UnpackSize = unpackSize;
+      }
+      
+      CExtractFolderInfo &efi = extractFolderInfoVector.Back();
+      
+      // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];
+      CNum startIndex = db.FolderStartFileIndex[folderIndex];
+      for (CNum index = efi.ExtractStatuses.Size();
+          index <= fileIndex - startIndex; index++)
+      {
+        // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;
+        // Count partial_folder_size
+        // efi.UnpackSize += unpackSize;
+        // importantTotalUnpacked += unpackSize;
+        efi.ExtractStatuses.Add(index == fileIndex - startIndex);
+      }
+    }
+  }
+
+  RINOK(extractCallback->SetTotal(importantTotalUnpacked));
+
+  CDecoder decoder(
+    #ifdef _ST_MODE
+    false
+    #else
+    true
+    #endif
+    );
+  // CDecoder1 decoder;
+
+  UInt64 totalPacked = 0;
+  UInt64 totalUnpacked = 0;
+  UInt64 curPacked, curUnpacked;
+
+  CLocalProgress *lps = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> progress = lps;
+  lps->Init(extractCallback, false);
+
+  for (int i = 0;; i++, totalUnpacked += curUnpacked, totalPacked += curPacked)
+  {
+    lps->OutSize = totalUnpacked;
+    lps->InSize = totalPacked;
+    RINOK(lps->SetCur());
+
+    if (i >= extractFolderInfoVector.Size())
+      break;
+    
+    const CExtractFolderInfo &efi = extractFolderInfoVector[i];
+    curUnpacked = efi.UnpackSize;
+    curPacked = 0;
+
+    CFolderOutStream *folderOutStream = new CFolderOutStream;
+    CMyComPtr<ISequentialOutStream> outStream(folderOutStream);
+
+    #ifdef _7Z_VOL
+    const CVolume &volume = _volumes[efi.VolumeIndex];
+    const CArchiveDatabaseEx &db = volume.Database;
+    #else
+    const CArchiveDatabaseEx &db = _db;
+    #endif
+
+    CNum startIndex;
+    if (efi.FileIndex != kNumNoIndex)
+      startIndex = efi.FileIndex;
+    else
+      startIndex = db.FolderStartFileIndex[efi.FolderIndex];
+
+    HRESULT result = folderOutStream->Init(&db,
+        #ifdef _7Z_VOL
+        volume.StartRef2Index,
+        #else
+        0,
+        #endif
+        startIndex,
+        &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);
+
+    RINOK(result);
+
+    if (efi.FileIndex != kNumNoIndex)
+      continue;
+
+    CNum folderIndex = efi.FolderIndex;
+    const CFolder &folderInfo = db.Folders[folderIndex];
+
+    curPacked = _db.GetFolderFullPackSize(folderIndex);
+
+    CNum packStreamIndex = db.FolderStartPackStreamIndex[folderIndex];
+    UInt64 folderStartPackPos = db.GetFolderStreamPos(folderIndex, 0);
+
+    #ifndef _NO_CRYPTO
+    CMyComPtr<ICryptoGetTextPassword> getTextPassword;
+    if (extractCallback)
+      extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
+    #endif
+
+    try
+    {
+      #ifndef _NO_CRYPTO
+      bool passwordIsDefined;
+      #endif
+
+      HRESULT result = decoder.Decode(
+          EXTERNAL_CODECS_VARS
+          #ifdef _7Z_VOL
+          volume.Stream,
+          #else
+          _inStream,
+          #endif
+          folderStartPackPos,
+          &db.PackSizes[packStreamIndex],
+          folderInfo,
+          outStream,
+          progress
+          #ifndef _NO_CRYPTO
+          , getTextPassword, passwordIsDefined
+          #endif
+          #if !defined(_7ZIP_ST) && !defined(_SFX)
+          , true, _numThreads
+          #endif
+          );
+
+      if (result == S_FALSE)
+      {
+        RINOK(folderOutStream->FlushCorrupted(NExtract::NOperationResult::kDataError));
+        continue;
+      }
+      if (result == E_NOTIMPL)
+      {
+        RINOK(folderOutStream->FlushCorrupted(NExtract::NOperationResult::kUnSupportedMethod));
+        continue;
+      }
+      if (result != S_OK)
+        return result;
+      if (folderOutStream->WasWritingFinished() != S_OK)
+      {
+        RINOK(folderOutStream->FlushCorrupted(NExtract::NOperationResult::kDataError));
+        continue;
+      }
+    }
+    catch(...)
+    {
+      RINOK(folderOutStream->FlushCorrupted(NExtract::NOperationResult::kDataError));
+      continue;
+    }
+  }
+  return S_OK;
+  COM_TRY_END
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,123 @@
+// 7zFolderInStream.cpp
+
+#include "StdAfx.h"
+
+#include "7zFolderInStream.h"
+
+namespace NArchive {
+namespace N7z {
+
+CFolderInStream::CFolderInStream()
+{
+  _inStreamWithHashSpec = new CSequentialInStreamWithCRC;
+  _inStreamWithHash = _inStreamWithHashSpec;
+}
+
+void CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,
+    const UInt32 *fileIndices, UInt32 numFiles)
+{
+  _updateCallback = updateCallback;
+  _numFiles = numFiles;
+  _fileIndex = 0;
+  _fileIndices = fileIndices;
+  Processed.Clear();
+  CRCs.Clear();
+  Sizes.Clear();
+  _fileIsOpen = false;
+  _currentSizeIsDefined = false;
+}
+
+HRESULT CFolderInStream::OpenStream()
+{
+  _filePos = 0;
+  while (_fileIndex < _numFiles)
+  {
+    CMyComPtr<ISequentialInStream> stream;
+    HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);
+    if (result != S_OK && result != S_FALSE)
+      return result;
+    _fileIndex++;
+    _inStreamWithHashSpec->SetStream(stream);
+    _inStreamWithHashSpec->Init();
+    if (stream)
+    {
+      _fileIsOpen = true;
+      CMyComPtr<IStreamGetSize> streamGetSize;
+      stream.QueryInterface(IID_IStreamGetSize, &streamGetSize);
+      if (streamGetSize)
+      {
+        RINOK(streamGetSize->GetSize(&_currentSize));
+        _currentSizeIsDefined = true;
+      }
+      return S_OK;
+    }
+    RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
+    Sizes.Add(0);
+    Processed.Add(result == S_OK);
+    AddDigest();
+  }
+  return S_OK;
+}
+
+void CFolderInStream::AddDigest()
+{
+  CRCs.Add(_inStreamWithHashSpec->GetCRC());
+}
+
+HRESULT CFolderInStream::CloseStream()
+{
+  RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
+  _inStreamWithHashSpec->ReleaseStream();
+  _fileIsOpen = false;
+  _currentSizeIsDefined = false;
+  Processed.Add(true);
+  Sizes.Add(_filePos);
+  AddDigest();
+  return S_OK;
+}
+
+STDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+  if (processedSize != 0)
+    *processedSize = 0;
+  while (size > 0)
+  {
+    if (_fileIsOpen)
+    {
+      UInt32 processed2;
+      RINOK(_inStreamWithHash->Read(data, size, &processed2));
+      if (processed2 == 0)
+      {
+        RINOK(CloseStream());
+        continue;
+      }
+      if (processedSize != 0)
+        *processedSize = processed2;
+      _filePos += processed2;
+      break;
+    }
+    if (_fileIndex >= _numFiles)
+      break;
+    RINOK(OpenStream());
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)
+{
+  *value = 0;
+  int index2 = (int)subStream;
+  if (index2 < 0 || subStream > Sizes.Size())
+    return E_FAIL;
+  if (index2 < Sizes.Size())
+  {
+    *value = Sizes[index2];
+    return S_OK;
+  }
+  if (!_currentSizeIsDefined)
+    return S_FALSE;
+  *value = _currentSize;
+  return S_OK;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderInStream.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,58 @@
+// 7zFolderInStream.h
+
+#ifndef __7Z_FOLDER_IN_STREAM_H
+#define __7Z_FOLDER_IN_STREAM_H
+
+#include "../../ICoder.h"
+#include "../IArchive.h"
+#include "../Common/InStreamWithCRC.h"
+
+#include "7zItem.h"
+
+namespace NArchive {
+namespace N7z {
+
+class CFolderInStream:
+  public ISequentialInStream,
+  public ICompressGetSubStreamSize,
+  public CMyUnknownImp
+{
+  CSequentialInStreamWithCRC *_inStreamWithHashSpec;
+  CMyComPtr<ISequentialInStream> _inStreamWithHash;
+  CMyComPtr<IArchiveUpdateCallback> _updateCallback;
+
+  bool _currentSizeIsDefined;
+  bool _fileIsOpen;
+  UInt64 _currentSize;
+  UInt64 _filePos;
+  const UInt32 *_fileIndices;
+  UInt32 _numFiles;
+  UInt32 _fileIndex;
+
+  HRESULT OpenStream();
+  HRESULT CloseStream();
+  void AddDigest();
+
+public:
+  CRecordVector<bool> Processed;
+  CRecordVector<UInt32> CRCs;
+  CRecordVector<UInt64> Sizes;
+
+  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
+  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
+
+  CFolderInStream();
+  void Init(IArchiveUpdateCallback *updateCallback, const UInt32 *fileIndices, UInt32 numFiles);
+  UInt64 GetFullSize() const
+  {
+    UInt64 size = 0;
+    for (int i = 0; i < Sizes.Size(); i++)
+      size += Sizes[i];
+    return size;
+  }
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,149 @@
+// 7zFolderOutStream.cpp
+
+#include "StdAfx.h"
+
+#include "7zFolderOutStream.h"
+
+namespace NArchive {
+namespace N7z {
+
+CFolderOutStream::CFolderOutStream()
+{
+  _crcStreamSpec = new COutStreamWithCRC;
+  _crcStream = _crcStreamSpec;
+}
+
+HRESULT CFolderOutStream::Init(
+    const CArchiveDatabaseEx *db,
+    UInt32 ref2Offset, UInt32 startIndex,
+    const CBoolVector *extractStatuses,
+    IArchiveExtractCallback *extractCallback,
+    bool testMode, bool checkCrc)
+{
+  _db = db;
+  _ref2Offset = ref2Offset;
+  _startIndex = startIndex;
+
+  _extractStatuses = extractStatuses;
+  _extractCallback = extractCallback;
+  _testMode = testMode;
+  _checkCrc = checkCrc;
+
+  _currentIndex = 0;
+  _fileIsOpen = false;
+  return ProcessEmptyFiles();
+}
+
+HRESULT CFolderOutStream::OpenFile()
+{
+  Int32 askMode = ((*_extractStatuses)[_currentIndex]) ? (_testMode ?
+      NExtract::NAskMode::kTest :
+      NExtract::NAskMode::kExtract) :
+      NExtract::NAskMode::kSkip;
+  CMyComPtr<ISequentialOutStream> realOutStream;
+  UInt32 index = _startIndex + _currentIndex;
+  RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));
+  _crcStreamSpec->SetStream(realOutStream);
+  _crcStreamSpec->Init(_checkCrc);
+  _fileIsOpen = true;
+  const CFileItem &fi = _db->Files[index];
+  _rem = fi.Size;
+  if (askMode == NExtract::NAskMode::kExtract && !realOutStream &&
+      !_db->IsItemAnti(index) && !fi.IsDir)
+    askMode = NExtract::NAskMode::kSkip;
+  return _extractCallback->PrepareOperation(askMode);
+}
+
+HRESULT CFolderOutStream::CloseFileAndSetResult(Int32 res)
+{
+  _crcStreamSpec->ReleaseStream();
+  _fileIsOpen = false;
+  _currentIndex++;
+  return _extractCallback->SetOperationResult(res);
+}
+
+HRESULT CFolderOutStream::CloseFileAndSetResult()
+{
+  const CFileItem &fi = _db->Files[_startIndex + _currentIndex];
+  return CloseFileAndSetResult(
+      (fi.IsDir || !fi.CrcDefined || !_checkCrc || fi.Crc == _crcStreamSpec->GetCRC()) ?
+      NExtract::NOperationResult::kOK :
+      NExtract::NOperationResult::kCRCError);
+}
+
+HRESULT CFolderOutStream::ProcessEmptyFiles()
+{
+  while (_currentIndex < _extractStatuses->Size() && _db->Files[_startIndex + _currentIndex].Size == 0)
+  {
+    RINOK(OpenFile());
+    RINOK(CloseFileAndSetResult());
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+  if (processedSize != NULL)
+    *processedSize = 0;
+  while (size != 0)
+  {
+    if (_fileIsOpen)
+    {
+      UInt32 cur = size < _rem ? size : (UInt32)_rem;
+      RINOK(_crcStream->Write(data, cur, &cur));
+      if (cur == 0)
+        break;
+      data = (const Byte *)data + cur;
+      size -= cur;
+      _rem -= cur;
+      if (processedSize != NULL)
+        *processedSize += cur;
+      if (_rem == 0)
+      {
+        RINOK(CloseFileAndSetResult());
+        RINOK(ProcessEmptyFiles());
+        continue;
+      }
+    }
+    else
+    {
+      RINOK(ProcessEmptyFiles());
+      if (_currentIndex == _extractStatuses->Size())
+      {
+        // we support partial extracting
+        if (processedSize != NULL)
+          *processedSize += size;
+        break;
+      }
+      RINOK(OpenFile());
+    }
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CFolderOutStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)
+{
+  *value = 0;
+  if ((int)subStream >= _extractStatuses->Size())
+    return S_FALSE;
+  *value = _db->Files[_startIndex + (int)subStream].Size;
+  return S_OK;
+}
+
+HRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)
+{
+  while (_currentIndex < _extractStatuses->Size())
+  {
+    if (_fileIsOpen)
+    {
+      RINOK(CloseFileAndSetResult(resultEOperationResult));
+    }
+    else
+    {
+      RINOK(OpenFile());
+    }
+  }
+  return S_OK;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,58 @@
+// 7zFolderOutStream.h
+
+#ifndef __7Z_FOLDER_OUT_STREAM_H
+#define __7Z_FOLDER_OUT_STREAM_H
+
+#include "../../IStream.h"
+#include "../IArchive.h"
+#include "../Common/OutStreamWithCRC.h"
+
+#include "7zIn.h"
+
+namespace NArchive {
+namespace N7z {
+
+class CFolderOutStream:
+  public ISequentialOutStream,
+  public ICompressGetSubStreamSize,
+  public CMyUnknownImp
+{
+  COutStreamWithCRC *_crcStreamSpec;
+  CMyComPtr<ISequentialOutStream> _crcStream;
+  const CArchiveDatabaseEx *_db;
+  const CBoolVector *_extractStatuses;
+  CMyComPtr<IArchiveExtractCallback> _extractCallback;
+  UInt32 _ref2Offset;
+  UInt32 _startIndex;
+  int _currentIndex;
+  bool _testMode;
+  bool _checkCrc;
+  bool _fileIsOpen;
+  UInt64 _rem;
+
+  HRESULT OpenFile();
+  HRESULT CloseFileAndSetResult(Int32 res);
+  HRESULT CloseFileAndSetResult();
+  HRESULT ProcessEmptyFiles();
+public:
+  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
+
+  CFolderOutStream();
+
+  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
+
+  HRESULT Init(
+      const CArchiveDatabaseEx *db,
+      UInt32 ref2Offset, UInt32 startIndex,
+      const CBoolVector *extractStatuses,
+      IArchiveExtractCallback *extractCallback,
+      bool testMode, bool checkCrc);
+  HRESULT FlushCorrupted(Int32 resultEOperationResult);
+  HRESULT WasWritingFinished() const
+      { return (_currentIndex == _extractStatuses->Size()) ? S_OK: E_FAIL; }
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,482 @@
+// 7zHandler.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/CpuArch.h"
+
+#include "../../../Common/ComTry.h"
+#include "../../../Common/IntToString.h"
+
+#ifndef __7Z_SET_PROPERTIES
+#include "../../../Windows/System.h"
+#endif
+
+#include "../Common/ItemNameUtils.h"
+
+#include "7zHandler.h"
+#include "7zProperties.h"
+
+#ifdef __7Z_SET_PROPERTIES
+#ifdef EXTRACT_ONLY
+#include "../Common/ParseProperties.h"
+#endif
+#endif
+
+using namespace NWindows;
+
+extern UString ConvertMethodIdToString(UInt64 id);
+
+namespace NArchive {
+namespace N7z {
+
+CHandler::CHandler()
+{
+  _crcSize = 4;
+
+  #ifndef _NO_CRYPTO
+  _passwordIsDefined = false;
+  #endif
+
+  #ifdef EXTRACT_ONLY
+  #ifdef __7Z_SET_PROPERTIES
+  _numThreads = NSystem::GetNumberOfProcessors();
+  #endif
+  #else
+  Init();
+  #endif
+}
+
+STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+{
+  *numItems = _db.Files.Size();
+  return S_OK;
+}
+
+#ifdef _SFX
+
+IMP_IInArchive_ArcProps_NO
+
+STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */)
+{
+  return E_NOTIMPL;
+}
+
+STDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,
+      BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)
+{
+  return E_NOTIMPL;
+}
+
+
+#else
+
+STATPROPSTG kArcProps[] =
+{
+  { NULL, kpidMethod, VT_BSTR},
+  { NULL, kpidSolid, VT_BOOL},
+  { NULL, kpidNumBlocks, VT_UI4},
+  { NULL, kpidPhySize, VT_UI8},
+  { NULL, kpidHeadersSize, VT_UI8},
+  { NULL, kpidOffset, VT_UI8}
+};
+
+STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case kpidMethod:
+    {
+      UString resString;
+      CRecordVector<UInt64> ids;
+      int i;
+      for (i = 0; i < _db.Folders.Size(); i++)
+      {
+        const CFolder &f = _db.Folders[i];
+        for (int j = f.Coders.Size() - 1; j >= 0; j--)
+          ids.AddToUniqueSorted(f.Coders[j].MethodID);
+      }
+
+      for (i = 0; i < ids.Size(); i++)
+      {
+        UInt64 id = ids[i];
+        UString methodName;
+        /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName);
+        if (methodName.IsEmpty())
+          methodName = ConvertMethodIdToString(id);
+        if (!resString.IsEmpty())
+          resString += L' ';
+        resString += methodName;
+      }
+      prop = resString;
+      break;
+    }
+    case kpidSolid: prop = _db.IsSolid(); break;
+    case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break;
+    case kpidHeadersSize:  prop = _db.HeadersSize; break;
+    case kpidPhySize:  prop = _db.PhySize; break;
+    case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break;
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+IMP_IInArchive_ArcProps
+
+#endif
+
+static void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop)
+{
+  UInt64 value;
+  if (v.GetItem(index, value))
+  {
+    FILETIME ft;
+    ft.dwLowDateTime = (DWORD)value;
+    ft.dwHighDateTime = (DWORD)(value >> 32);
+    prop = ft;
+  }
+}
+
+#ifndef _SFX
+
+static UString ConvertUInt32ToString(UInt32 value)
+{
+  wchar_t buffer[32];
+  ConvertUInt64ToString(value, buffer);
+  return buffer;
+}
+
+static UString GetStringForSizeValue(UInt32 value)
+{
+  for (int i = 31; i >= 0; i--)
+    if ((UInt32(1) << i) == value)
+      return ConvertUInt32ToString(i);
+  UString result;
+  if (value % (1 << 20) == 0)
+  {
+    result += ConvertUInt32ToString(value >> 20);
+    result += L"m";
+  }
+  else if (value % (1 << 10) == 0)
+  {
+    result += ConvertUInt32ToString(value >> 10);
+    result += L"k";
+  }
+  else
+  {
+    result += ConvertUInt32ToString(value);
+    result += L"b";
+  }
+  return result;
+}
+
+static const UInt64 k_Copy = 0x0;
+static const UInt64 k_Delta = 3;
+static const UInt64 k_LZMA2 = 0x21;
+static const UInt64 k_LZMA  = 0x030101;
+static const UInt64 k_PPMD  = 0x030401;
+
+static wchar_t GetHex(Byte value)
+{
+  return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10)));
+}
+static inline void AddHexToString(UString &res, Byte value)
+{
+  res += GetHex((Byte)(value >> 4));
+  res += GetHex((Byte)(value & 0xF));
+}
+
+#endif
+
+bool CHandler::IsEncrypted(UInt32 index2) const
+{
+  CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
+  if (folderIndex != kNumNoIndex)
+    return _db.Folders[folderIndex].IsEncrypted();
+  return false;
+}
+
+STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NCOM::CPropVariant prop;
+  
+  /*
+  const CRef2 &ref2 = _refs[index];
+  if (ref2.Refs.IsEmpty())
+    return E_FAIL;
+  const CRef &ref = ref2.Refs.Front();
+  */
+  
+  const CFileItem &item = _db.Files[index];
+  UInt32 index2 = index;
+
+  switch(propID)
+  {
+    case kpidPath:
+      if (!item.Name.IsEmpty())
+        prop = NItemName::GetOSName(item.Name);
+      break;
+    case kpidIsDir:  prop = item.IsDir; break;
+    case kpidSize:
+    {
+      prop = item.Size;
+      // prop = ref2.Size;
+      break;
+    }
+    case kpidPackSize:
+    {
+      // prop = ref2.PackSize;
+      {
+        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
+        if (folderIndex != kNumNoIndex)
+        {
+          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)
+            prop = _db.GetFolderFullPackSize(folderIndex);
+          /*
+          else
+            prop = (UInt64)0;
+          */
+        }
+        else
+          prop = (UInt64)0;
+      }
+      break;
+    }
+    case kpidPosition:  { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; }
+    case kpidCTime:  SetPropFromUInt64Def(_db.CTime, index2, prop); break;
+    case kpidATime:  SetPropFromUInt64Def(_db.ATime, index2, prop); break;
+    case kpidMTime:  SetPropFromUInt64Def(_db.MTime, index2, prop); break;
+    case kpidAttrib:  if (item.AttribDefined) prop = item.Attrib; break;
+    case kpidCRC:  if (item.CrcDefined) prop = item.Crc; break;
+    case kpidEncrypted:  prop = IsEncrypted(index2); break;
+    case kpidIsAnti:  prop = _db.IsItemAnti(index2); break;
+    #ifndef _SFX
+    case kpidMethod:
+      {
+        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
+        if (folderIndex != kNumNoIndex)
+        {
+          const CFolder &folderInfo = _db.Folders[folderIndex];
+          UString methodsString;
+          for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--)
+          {
+            const CCoderInfo &coder = folderInfo.Coders[i];
+            if (!methodsString.IsEmpty())
+              methodsString += L' ';
+
+            UString methodName, propsString;
+            bool methodIsKnown = FindMethod(
+              EXTERNAL_CODECS_VARS
+              coder.MethodID, methodName);
+            
+            if (!methodIsKnown)
+              methodsString += ConvertMethodIdToString(coder.MethodID);
+            else
+            {
+              methodsString += methodName;
+              if (coder.MethodID == k_Delta && coder.Props.GetCapacity() == 1)
+                propsString = ConvertUInt32ToString((UInt32)coder.Props[0] + 1);
+              else if (coder.MethodID == k_LZMA && coder.Props.GetCapacity() == 5)
+              {
+                UInt32 dicSize = GetUi32((const Byte *)coder.Props + 1);
+                propsString = GetStringForSizeValue(dicSize);
+              }
+              else if (coder.MethodID == k_LZMA2 && coder.Props.GetCapacity() == 1)
+              {
+                Byte p = coder.Props[0];
+                UInt32 dicSize = (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11));
+                propsString = GetStringForSizeValue(dicSize);
+              }
+              else if (coder.MethodID == k_PPMD && coder.Props.GetCapacity() == 5)
+              {
+                Byte order = *(const Byte *)coder.Props;
+                propsString = L'o';
+                propsString += ConvertUInt32ToString(order);
+                propsString += L":mem";
+                UInt32 dicSize = GetUi32((const Byte *)coder.Props + 1);
+                propsString += GetStringForSizeValue(dicSize);
+              }
+              else if (coder.MethodID == k_AES && coder.Props.GetCapacity() >= 1)
+              {
+                const Byte *data = (const Byte *)coder.Props;
+                Byte firstByte = *data++;
+                UInt32 numCyclesPower = firstByte & 0x3F;
+                propsString = ConvertUInt32ToString(numCyclesPower);
+                /*
+                if ((firstByte & 0xC0) != 0)
+                {
+                  UInt32 saltSize = (firstByte >> 7) & 1;
+                  UInt32 ivSize = (firstByte >> 6) & 1;
+                  if (coder.Props.GetCapacity() >= 2)
+                  {
+                    Byte secondByte = *data++;
+                    saltSize += (secondByte >> 4);
+                    ivSize += (secondByte & 0x0F);
+                  }
+                }
+                */
+              }
+            }
+            if (!propsString.IsEmpty())
+            {
+              methodsString += L':';
+              methodsString += propsString;
+            }
+            else if (coder.Props.GetCapacity() > 0)
+            {
+              methodsString += L":[";
+              for (size_t bi = 0; bi < coder.Props.GetCapacity(); bi++)
+              {
+                if (bi > 5 && bi + 1 < coder.Props.GetCapacity())
+                {
+                  methodsString += L"..";
+                  break;
+                }
+                else
+                  AddHexToString(methodsString, coder.Props[bi]);
+              }
+              methodsString += L']';
+            }
+          }
+          prop = methodsString;
+        }
+      }
+      break;
+    case kpidBlock:
+      {
+        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
+        if (folderIndex != kNumNoIndex)
+          prop = (UInt32)folderIndex;
+      }
+      break;
+    case kpidPackedSize0:
+    case kpidPackedSize1:
+    case kpidPackedSize2:
+    case kpidPackedSize3:
+    case kpidPackedSize4:
+      {
+        CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
+        if (folderIndex != kNumNoIndex)
+        {
+          const CFolder &folderInfo = _db.Folders[folderIndex];
+          if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&
+              folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))
+          {
+            prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);
+          }
+          else
+            prop = (UInt64)0;
+        }
+        else
+          prop = (UInt64)0;
+      }
+      break;
+    #endif
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::Open(IInStream *stream,
+    const UInt64 *maxCheckStartPosition,
+    IArchiveOpenCallback *openArchiveCallback)
+{
+  COM_TRY_BEGIN
+  Close();
+  #ifndef _SFX
+  _fileInfoPopIDs.Clear();
+  #endif
+  try
+  {
+    CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;
+
+    #ifndef _NO_CRYPTO
+    CMyComPtr<ICryptoGetTextPassword> getTextPassword;
+    if (openArchiveCallback)
+    {
+      openArchiveCallbackTemp.QueryInterface(
+          IID_ICryptoGetTextPassword, &getTextPassword);
+    }
+    #endif
+    CInArchive archive;
+    RINOK(archive.Open(stream, maxCheckStartPosition));
+    #ifndef _NO_CRYPTO
+    _passwordIsDefined = false;
+    UString password;
+    #endif
+    HRESULT result = archive.ReadDatabase(
+      EXTERNAL_CODECS_VARS
+      _db
+      #ifndef _NO_CRYPTO
+      , getTextPassword, _passwordIsDefined
+      #endif
+      );
+    RINOK(result);
+    _db.Fill();
+    _inStream = stream;
+  }
+  catch(...)
+  {
+    Close();
+    return S_FALSE;
+  }
+  // _inStream = stream;
+  #ifndef _SFX
+  FillPopIDs();
+  #endif
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::Close()
+{
+  COM_TRY_BEGIN
+  _inStream.Release();
+  _db.Clear();
+  return S_OK;
+  COM_TRY_END
+}
+
+#ifdef __7Z_SET_PROPERTIES
+#ifdef EXTRACT_ONLY
+
+STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)
+{
+  COM_TRY_BEGIN
+  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();
+  _numThreads = numProcessors;
+
+  for (int i = 0; i < numProperties; i++)
+  {
+    UString name = names[i];
+    name.MakeUpper();
+    if (name.IsEmpty())
+      return E_INVALIDARG;
+    const PROPVARIANT &value = values[i];
+    UInt32 number;
+    int index = ParseStringToUInt32(name, number);
+    if (index == 0)
+    {
+      if(name.Left(2).CompareNoCase(L"MT") == 0)
+      {
+        RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));
+        continue;
+      }
+      else
+        return E_INVALIDARG;
+    }
+  }
+  return S_OK;
+  COM_TRY_END
+}
+
+#endif
+#endif
+
+IMPL_ISetCompressCodecsInfo
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandler.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,119 @@
+// 7z/Handler.h
+
+#ifndef __7Z_HANDLER_H
+#define __7Z_HANDLER_H
+
+#include "../../ICoder.h"
+#include "../IArchive.h"
+
+#include "../../Common/CreateCoder.h"
+
+#ifndef EXTRACT_ONLY
+#include "../Common/HandlerOut.h"
+#endif
+
+#include "7zCompressionMode.h"
+#include "7zIn.h"
+
+namespace NArchive {
+namespace N7z {
+
+#ifndef __7Z_SET_PROPERTIES
+
+#ifdef EXTRACT_ONLY
+#if !defined(_7ZIP_ST) && !defined(_SFX)
+#define __7Z_SET_PROPERTIES
+#endif
+#else
+#define __7Z_SET_PROPERTIES
+#endif
+
+#endif
+
+
+class CHandler:
+  #ifndef EXTRACT_ONLY
+  public NArchive::COutHandler,
+  #endif
+  public IInArchive,
+  #ifdef __7Z_SET_PROPERTIES
+  public ISetProperties,
+  #endif
+  #ifndef EXTRACT_ONLY
+  public IOutArchive,
+  #endif
+  PUBLIC_ISetCompressCodecsInfo
+  public CMyUnknownImp
+{
+public:
+  MY_QUERYINTERFACE_BEGIN2(IInArchive)
+  #ifdef __7Z_SET_PROPERTIES
+  MY_QUERYINTERFACE_ENTRY(ISetProperties)
+  #endif
+  #ifndef EXTRACT_ONLY
+  MY_QUERYINTERFACE_ENTRY(IOutArchive)
+  #endif
+  QUERY_ENTRY_ISetCompressCodecsInfo
+  MY_QUERYINTERFACE_END
+  MY_ADDREF_RELEASE
+
+  INTERFACE_IInArchive(;)
+
+  #ifdef __7Z_SET_PROPERTIES
+  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
+  #endif
+
+  #ifndef EXTRACT_ONLY
+  INTERFACE_IOutArchive(;)
+  #endif
+
+  DECL_ISetCompressCodecsInfo
+
+  CHandler();
+
+private:
+  CMyComPtr<IInStream> _inStream;
+  NArchive::N7z::CArchiveDatabaseEx _db;
+  #ifndef _NO_CRYPTO
+  bool _passwordIsDefined;
+  #endif
+
+  #ifdef EXTRACT_ONLY
+  
+  #ifdef __7Z_SET_PROPERTIES
+  UInt32 _numThreads;
+  #endif
+
+  UInt32 _crcSize;
+
+  #else
+  
+  CRecordVector<CBind> _binds;
+
+  HRESULT SetCompressionMethod(CCompressionMethodMode &method,
+      CObjectVector<COneMethodInfo> &methodsInfo
+      #ifndef _7ZIP_ST
+      , UInt32 numThreads
+      #endif
+      );
+
+  HRESULT SetCompressionMethod(
+      CCompressionMethodMode &method,
+      CCompressionMethodMode &headerMethod);
+
+  #endif
+
+  bool IsEncrypted(UInt32 index2) const;
+  #ifndef _SFX
+
+  CRecordVector<UInt64> _fileInfoPopIDs;
+  void FillPopIDs();
+
+  #endif
+
+  DECL_EXTERNAL_CODECS_VARS
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,483 @@
+// 7zHandlerOut.cpp
+
+#include "StdAfx.h"
+
+#include "../../../Windows/PropVariant.h"
+
+#include "../../../Common/ComTry.h"
+#include "../../../Common/StringToInt.h"
+
+#include "../../ICoder.h"
+
+#include "../Common/ItemNameUtils.h"
+#include "../Common/ParseProperties.h"
+
+#include "7zHandler.h"
+#include "7zOut.h"
+#include "7zUpdate.h"
+
+using namespace NWindows;
+
+namespace NArchive {
+namespace N7z {
+
+static const wchar_t *kLZMAMethodName = L"LZMA";
+static const wchar_t *kCopyMethod = L"Copy";
+static const wchar_t *kDefaultMethodName = kLZMAMethodName;
+
+static const UInt32 kLzmaAlgorithmX5 = 1;
+static const wchar_t *kLzmaMatchFinderForHeaders = L"BT2";
+static const UInt32 kDictionaryForHeaders =
+  #ifdef UNDER_CE
+  1 << 18
+  #else
+  1 << 20
+  #endif
+;
+static const UInt32 kNumFastBytesForHeaders = 273;
+static const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5;
+
+static inline bool IsCopyMethod(const UString &methodName)
+  { return (methodName.CompareNoCase(kCopyMethod) == 0); }
+
+STDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)
+{
+  *type = NFileTimeType::kWindows;
+  return S_OK;
+}
+
+HRESULT CHandler::SetCompressionMethod(
+    CCompressionMethodMode &methodMode,
+    CCompressionMethodMode &headerMethod)
+{
+  HRESULT res = SetCompressionMethod(methodMode, _methods
+  #ifndef _7ZIP_ST
+  , _numThreads
+  #endif
+  );
+  RINOK(res);
+  methodMode.Binds = _binds;
+
+  if (_compressHeaders)
+  {
+    // headerMethod.Methods.Add(methodMode.Methods.Back());
+
+    CObjectVector<COneMethodInfo> headerMethodInfoVector;
+    COneMethodInfo oneMethodInfo;
+    oneMethodInfo.MethodName = kLZMAMethodName;
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kMatchFinder;
+      prop.Value = kLzmaMatchFinderForHeaders;
+      oneMethodInfo.Props.Add(prop);
+    }
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kAlgorithm;
+      prop.Value = kAlgorithmForHeaders;
+      oneMethodInfo.Props.Add(prop);
+    }
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kNumFastBytes;
+      prop.Value = (UInt32)kNumFastBytesForHeaders;
+      oneMethodInfo.Props.Add(prop);
+    }
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kDictionarySize;
+      prop.Value = (UInt32)kDictionaryForHeaders;
+      oneMethodInfo.Props.Add(prop);
+    }
+    headerMethodInfoVector.Add(oneMethodInfo);
+    HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector
+      #ifndef _7ZIP_ST
+      , 1
+      #endif
+    );
+    RINOK(res);
+  }
+  return S_OK;
+}
+
+HRESULT CHandler::SetCompressionMethod(
+    CCompressionMethodMode &methodMode,
+    CObjectVector<COneMethodInfo> &methodsInfo
+    #ifndef _7ZIP_ST
+    , UInt32 numThreads
+    #endif
+    )
+{
+  UInt32 level = _level;
+  
+  if (methodsInfo.IsEmpty())
+  {
+    COneMethodInfo oneMethodInfo;
+    oneMethodInfo.MethodName = ((level == 0) ? kCopyMethod : kDefaultMethodName);
+    methodsInfo.Add(oneMethodInfo);
+  }
+
+  bool needSolid = false;
+  for(int i = 0; i < methodsInfo.Size(); i++)
+  {
+    COneMethodInfo &oneMethodInfo = methodsInfo[i];
+    SetCompressionMethod2(oneMethodInfo
+      #ifndef _7ZIP_ST
+      , numThreads
+      #endif
+      );
+
+    if (!IsCopyMethod(oneMethodInfo.MethodName))
+      needSolid = true;
+
+    CMethodFull methodFull;
+
+    if (!FindMethod(
+        EXTERNAL_CODECS_VARS
+        oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams))
+      return E_INVALIDARG;
+    methodFull.Props = oneMethodInfo.Props;
+    methodMode.Methods.Add(methodFull);
+
+    if (!_numSolidBytesDefined)
+    {
+      for (int j = 0; j < methodFull.Props.Size(); j++)
+      {
+        const CProp &prop = methodFull.Props[j];
+        if ((prop.Id == NCoderPropID::kDictionarySize ||
+             prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4)
+        {
+          _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7;
+          const UInt64 kMinSize = (1 << 24);
+          if (_numSolidBytes < kMinSize)
+            _numSolidBytes = kMinSize;
+          _numSolidBytesDefined = true;
+          break;
+        }
+      }
+    }
+  }
+
+  if (!needSolid && !_numSolidBytesDefined)
+  {
+    _numSolidBytesDefined = true;
+    _numSolidBytes  = 0;
+  }
+  return S_OK;
+}
+
+static HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, bool writeTime, PROPID propID, UInt64 &ft, bool &ftDefined)
+{
+  ft = 0;
+  ftDefined = false;
+  if (!writeTime)
+    return S_OK;
+  NCOM::CPropVariant prop;
+  RINOK(updateCallback->GetProperty(index, propID, &prop));
+  if (prop.vt == VT_FILETIME)
+  {
+    ft = prop.filetime.dwLowDateTime | ((UInt64)prop.filetime.dwHighDateTime << 32);
+    ftDefined = true;
+  }
+  else if (prop.vt != VT_EMPTY)
+    return E_INVALIDARG;
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
+    IArchiveUpdateCallback *updateCallback)
+{
+  COM_TRY_BEGIN
+
+  const CArchiveDatabaseEx *db = 0;
+  #ifdef _7Z_VOL
+  if (_volumes.Size() > 1)
+    return E_FAIL;
+  const CVolume *volume = 0;
+  if (_volumes.Size() == 1)
+  {
+    volume = &_volumes.Front();
+    db = &volume->Database;
+  }
+  #else
+  if (_inStream != 0)
+    db = &_db;
+  #endif
+
+  CObjectVector<CUpdateItem> updateItems;
+  
+  for (UInt32 i = 0; i < numItems; i++)
+  {
+    Int32 newData, newProps;
+    UInt32 indexInArchive;
+    if (!updateCallback)
+      return E_FAIL;
+    RINOK(updateCallback->GetUpdateItemInfo(i, &newData, &newProps, &indexInArchive));
+    CUpdateItem ui;
+    ui.NewProps = IntToBool(newProps);
+    ui.NewData = IntToBool(newData);
+    ui.IndexInArchive = indexInArchive;
+    ui.IndexInClient = i;
+    ui.IsAnti = false;
+    ui.Size = 0;
+
+    if (ui.IndexInArchive != -1)
+    {
+      if (db == 0 || ui.IndexInArchive >= db->Files.Size())
+        return E_INVALIDARG;
+      const CFileItem &fi = db->Files[ui.IndexInArchive];
+      ui.Name = fi.Name;
+      ui.IsDir = fi.IsDir;
+      ui.Size = fi.Size;
+      ui.IsAnti = db->IsItemAnti(ui.IndexInArchive);
+      
+      ui.CTimeDefined = db->CTime.GetItem(ui.IndexInArchive, ui.CTime);
+      ui.ATimeDefined = db->ATime.GetItem(ui.IndexInArchive, ui.ATime);
+      ui.MTimeDefined = db->MTime.GetItem(ui.IndexInArchive, ui.MTime);
+    }
+
+    if (ui.NewProps)
+    {
+      bool nameIsDefined;
+      bool folderStatusIsDefined;
+      {
+        NCOM::CPropVariant prop;
+        RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop));
+        if (prop.vt == VT_EMPTY)
+          ui.AttribDefined = false;
+        else if (prop.vt != VT_UI4)
+          return E_INVALIDARG;
+        else
+        {
+          ui.Attrib = prop.ulVal;
+          ui.AttribDefined = true;
+        }
+      }
+      
+      // we need MTime to sort files.
+      RINOK(GetTime(updateCallback, i, WriteCTime, kpidCTime, ui.CTime, ui.CTimeDefined));
+      RINOK(GetTime(updateCallback, i, WriteATime, kpidATime, ui.ATime, ui.ATimeDefined));
+      RINOK(GetTime(updateCallback, i, true,       kpidMTime, ui.MTime, ui.MTimeDefined));
+
+      {
+        NCOM::CPropVariant prop;
+        RINOK(updateCallback->GetProperty(i, kpidPath, &prop));
+        if (prop.vt == VT_EMPTY)
+          nameIsDefined = false;
+        else if (prop.vt != VT_BSTR)
+          return E_INVALIDARG;
+        else
+        {
+          ui.Name = NItemName::MakeLegalName(prop.bstrVal);
+          nameIsDefined = true;
+        }
+      }
+      {
+        NCOM::CPropVariant prop;
+        RINOK(updateCallback->GetProperty(i, kpidIsDir, &prop));
+        if (prop.vt == VT_EMPTY)
+          folderStatusIsDefined = false;
+        else if (prop.vt != VT_BOOL)
+          return E_INVALIDARG;
+        else
+        {
+          ui.IsDir = (prop.boolVal != VARIANT_FALSE);
+          folderStatusIsDefined = true;
+        }
+      }
+
+      {
+        NCOM::CPropVariant prop;
+        RINOK(updateCallback->GetProperty(i, kpidIsAnti, &prop));
+        if (prop.vt == VT_EMPTY)
+          ui.IsAnti = false;
+        else if (prop.vt != VT_BOOL)
+          return E_INVALIDARG;
+        else
+          ui.IsAnti = (prop.boolVal != VARIANT_FALSE);
+      }
+
+      if (ui.IsAnti)
+      {
+        ui.AttribDefined = false;
+
+        ui.CTimeDefined = false;
+        ui.ATimeDefined = false;
+        ui.MTimeDefined = false;
+        
+        ui.Size = 0;
+      }
+
+      if (!folderStatusIsDefined && ui.AttribDefined)
+        ui.SetDirStatusFromAttrib();
+    }
+
+    if (ui.NewData)
+    {
+      NCOM::CPropVariant prop;
+      RINOK(updateCallback->GetProperty(i, kpidSize, &prop));
+      if (prop.vt != VT_UI8)
+        return E_INVALIDARG;
+      ui.Size = (UInt64)prop.uhVal.QuadPart;
+      if (ui.Size != 0 && ui.IsAnti)
+        return E_INVALIDARG;
+    }
+    updateItems.Add(ui);
+  }
+
+  CCompressionMethodMode methodMode, headerMethod;
+  RINOK(SetCompressionMethod(methodMode, headerMethod));
+  #ifndef _7ZIP_ST
+  methodMode.NumThreads = _numThreads;
+  headerMethod.NumThreads = 1;
+  #endif
+
+  CMyComPtr<ICryptoGetTextPassword2> getPassword2;
+  updateCallback->QueryInterface(IID_ICryptoGetTextPassword2, (void **)&getPassword2);
+
+  if (getPassword2)
+  {
+    CMyComBSTR password;
+    Int32 passwordIsDefined;
+    RINOK(getPassword2->CryptoGetTextPassword2(&passwordIsDefined, &password));
+    methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);
+    if (methodMode.PasswordIsDefined)
+      methodMode.Password = password;
+  }
+  else
+    methodMode.PasswordIsDefined = false;
+
+  bool compressMainHeader = _compressHeaders;  // check it
+
+  bool encryptHeaders = false;
+
+  if (methodMode.PasswordIsDefined)
+  {
+    if (_encryptHeadersSpecified)
+      encryptHeaders = _encryptHeaders;
+    #ifndef _NO_CRYPTO
+    else
+      encryptHeaders = _passwordIsDefined;
+    #endif
+    compressMainHeader = true;
+    if (encryptHeaders)
+    {
+      headerMethod.PasswordIsDefined = methodMode.PasswordIsDefined;
+      headerMethod.Password = methodMode.Password;
+    }
+  }
+
+  if (numItems < 2)
+    compressMainHeader = false;
+
+  CUpdateOptions options;
+  options.Method = &methodMode;
+  options.HeaderMethod = (_compressHeaders || encryptHeaders) ? &headerMethod : 0;
+  options.UseFilters = _level != 0 && _autoFilter;
+  options.MaxFilter = _level >= 8;
+
+  options.HeaderOptions.CompressMainHeader = compressMainHeader;
+  options.HeaderOptions.WriteCTime = WriteCTime;
+  options.HeaderOptions.WriteATime = WriteATime;
+  options.HeaderOptions.WriteMTime = WriteMTime;
+  
+  options.NumSolidFiles = _numSolidFiles;
+  options.NumSolidBytes = _numSolidBytes;
+  options.SolidExtension = _solidExtension;
+  options.RemoveSfxBlock = _removeSfxBlock;
+  options.VolumeMode = _volumeMode;
+
+  COutArchive archive;
+  CArchiveDatabase newDatabase;
+
+  CMyComPtr<ICryptoGetTextPassword> getPassword;
+  updateCallback->QueryInterface(IID_ICryptoGetTextPassword, (void **)&getPassword);
+  
+  HRESULT res = Update(
+      EXTERNAL_CODECS_VARS
+      #ifdef _7Z_VOL
+      volume ? volume->Stream: 0,
+      volume ? db : 0,
+      #else
+      _inStream,
+      db,
+      #endif
+      updateItems,
+      archive, newDatabase, outStream, updateCallback, options
+      #ifndef _NO_CRYPTO
+      , getPassword
+      #endif
+      );
+
+  RINOK(res);
+
+  updateItems.ClearAndFree();
+
+  return archive.WriteDatabase(EXTERNAL_CODECS_VARS
+      newDatabase, options.HeaderMethod, options.HeaderOptions);
+
+  COM_TRY_END
+}
+
+static HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)
+{
+  stream = 0;
+  int index = ParseStringToUInt32(srcString, coder);
+  if (index == 0)
+    return E_INVALIDARG;
+  srcString.Delete(0, index);
+  if (srcString[0] == 'S')
+  {
+    srcString.Delete(0);
+    int index = ParseStringToUInt32(srcString, stream);
+    if (index == 0)
+      return E_INVALIDARG;
+    srcString.Delete(0, index);
+  }
+  return S_OK;
+}
+
+static HRESULT GetBindInfo(UString &srcString, CBind &bind)
+{
+  RINOK(GetBindInfoPart(srcString, bind.OutCoder, bind.OutStream));
+  if (srcString[0] != ':')
+    return E_INVALIDARG;
+  srcString.Delete(0);
+  RINOK(GetBindInfoPart(srcString, bind.InCoder, bind.InStream));
+  if (!srcString.IsEmpty())
+    return E_INVALIDARG;
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties)
+{
+  COM_TRY_BEGIN
+  _binds.Clear();
+  BeforeSetProperty();
+
+  for (int i = 0; i < numProperties; i++)
+  {
+    UString name = names[i];
+    name.MakeUpper();
+    if (name.IsEmpty())
+      return E_INVALIDARG;
+
+    const PROPVARIANT &value = values[i];
+
+    if (name[0] == 'B')
+    {
+      name.Delete(0);
+      CBind bind;
+      RINOK(GetBindInfo(name, bind));
+      _binds.Add(bind);
+      continue;
+    }
+
+    RINOK(SetProperty(name, value));
+  }
+
+  return S_OK;
+  COM_TRY_END
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,14 @@
+// 7zHeader.cpp
+
+#include "StdAfx.h"
+#include "7zHeader.h"
+
+namespace NArchive {
+namespace N7z {
+
+Byte kSignature[kSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
+#ifdef _7Z_VOL
+Byte kFinishSignature[kSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};
+#endif
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zHeader.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,97 @@
+// 7z/7zHeader.h
+
+#ifndef __7Z_HEADER_H
+#define __7Z_HEADER_H
+
+#include "../../../Common/Types.h"
+
+namespace NArchive {
+namespace N7z {
+
+const int kSignatureSize = 6;
+extern Byte kSignature[kSignatureSize];
+
+// #define _7Z_VOL
+// 7z-MultiVolume is not finished yet.
+// It can work already, but I still do not like some
+// things of that new multivolume format.
+// So please keep it commented.
+
+#ifdef _7Z_VOL
+extern Byte kFinishSignature[kSignatureSize];
+#endif
+
+struct CArchiveVersion
+{
+  Byte Major;
+  Byte Minor;
+};
+
+const Byte kMajorVersion = 0;
+
+struct CStartHeader
+{
+  UInt64 NextHeaderOffset;
+  UInt64 NextHeaderSize;
+  UInt32 NextHeaderCRC;
+};
+
+const UInt32 kStartHeaderSize = 20;
+
+#ifdef _7Z_VOL
+struct CFinishHeader: public CStartHeader
+{
+  UInt64 ArchiveStartOffset;  // data offset from end if that struct
+  UInt64 AdditionalStartBlockSize; // start  signature & start header size
+};
+
+const UInt32 kFinishHeaderSize = kStartHeaderSize + 16;
+#endif
+
+namespace NID
+{
+  enum EEnum
+  {
+    kEnd,
+
+    kHeader,
+
+    kArchiveProperties,
+    
+    kAdditionalStreamsInfo,
+    kMainStreamsInfo,
+    kFilesInfo,
+    
+    kPackInfo,
+    kUnpackInfo,
+    kSubStreamsInfo,
+
+    kSize,
+    kCRC,
+
+    kFolder,
+
+    kCodersUnpackSize,
+    kNumUnpackStream,
+
+    kEmptyStream,
+    kEmptyFile,
+    kAnti,
+
+    kName,
+    kCTime,
+    kATime,
+    kMTime,
+    kWinAttributes,
+    kComment,
+
+    kEncodedHeader,
+
+    kStartPos,
+    kDummy
+  };
+}
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,1276 @@
+// 7zIn.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/7zCrc.h"
+#include "../../../../C/CpuArch.h"
+
+#include "../../Common/StreamObjects.h"
+#include "../../Common/StreamUtils.h"
+
+#include "7zDecode.h"
+#include "7zIn.h"
+
+#define Get16(p) GetUi16(p)
+#define Get32(p) GetUi32(p)
+#define Get64(p) GetUi64(p)
+
+// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader
+#ifndef _SFX
+#define FORMAT_7Z_RECOVERY
+#endif
+
+namespace NArchive {
+namespace N7z {
+
+static void BoolVector_Fill_False(CBoolVector &v, int size)
+{
+  v.Clear();
+  v.Reserve(size);
+  for (int i = 0; i < size; i++)
+    v.Add(false);
+}
+
+static bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)
+{
+  if (index >= (UInt32)v.Size())
+    return true;
+  bool res = v[index];
+  v[index] = true;
+  return res;
+}
+
+bool CFolder::CheckStructure() const
+{
+  const int kNumCodersMax = sizeof(UInt32) * 8; // don't change it
+  const int kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax
+  const int kNumBindsMax = 32;
+
+  if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)
+    return false;
+
+  {
+    CBoolVector v;
+    BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());
+    
+    int i;
+    for (i = 0; i < BindPairs.Size(); i++)
+      if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))
+        return false;
+    for (i = 0; i < PackStreams.Size(); i++)
+      if (BoolVector_GetAndSet(v, PackStreams[i]))
+        return false;
+    
+    BoolVector_Fill_False(v, UnpackSizes.Size());
+    for (i = 0; i < BindPairs.Size(); i++)
+      if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))
+        return false;
+  }
+  
+  UInt32 mask[kMaskSize];
+  int i;
+  for (i = 0; i < kMaskSize; i++)
+    mask[i] = 0;
+
+  {
+    CIntVector inStreamToCoder, outStreamToCoder;
+    for (i = 0; i < Coders.Size(); i++)
+    {
+      CNum j;
+      const CCoderInfo &coder = Coders[i];
+      for (j = 0; j < coder.NumInStreams; j++)
+        inStreamToCoder.Add(i);
+      for (j = 0; j < coder.NumOutStreams; j++)
+        outStreamToCoder.Add(i);
+    }
+    
+    for (i = 0; i < BindPairs.Size(); i++)
+    {
+      const CBindPair &bp = BindPairs[i];
+      mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);
+    }
+  }
+  
+  for (i = 0; i < kMaskSize; i++)
+    for (int j = 0; j < kMaskSize; j++)
+      if (((1 << j) & mask[i]) != 0)
+        mask[i] |= mask[j];
+
+  for (i = 0; i < kMaskSize; i++)
+    if (((1 << i) & mask[i]) != 0)
+      return false;
+
+  return true;
+}
+
+class CInArchiveException {};
+
+static void ThrowException() { throw CInArchiveException(); }
+static inline void ThrowEndOfData()   { ThrowException(); }
+static inline void ThrowUnsupported() { ThrowException(); }
+static inline void ThrowIncorrect()   { ThrowException(); }
+static inline void ThrowUnsupportedVersion() { ThrowException(); }
+
+/*
+class CInArchiveException
+{
+public:
+  enum CCauseType
+  {
+    kUnsupportedVersion = 0,
+    kUnsupported,
+    kIncorrect,
+    kEndOfData
+  } Cause;
+  CInArchiveException(CCauseType cause): Cause(cause) {};
+};
+
+static void ThrowException(CInArchiveException::CCauseType c) { throw CInArchiveException(c); }
+static void ThrowEndOfData()   { ThrowException(CInArchiveException::kEndOfData); }
+static void ThrowUnsupported() { ThrowException(CInArchiveException::kUnsupported); }
+static void ThrowIncorrect()   { ThrowException(CInArchiveException::kIncorrect); }
+static void ThrowUnsupportedVersion() { ThrowException(CInArchiveException::kUnsupportedVersion); }
+*/
+
+class CStreamSwitch
+{
+  CInArchive *_archive;
+  bool _needRemove;
+public:
+  CStreamSwitch(): _needRemove(false) {}
+  ~CStreamSwitch() { Remove(); }
+  void Remove();
+  void Set(CInArchive *archive, const Byte *data, size_t size);
+  void Set(CInArchive *archive, const CByteBuffer &byteBuffer);
+  void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);
+};
+
+void CStreamSwitch::Remove()
+{
+  if (_needRemove)
+  {
+    _archive->DeleteByteStream();
+    _needRemove = false;
+  }
+}
+
+void CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size)
+{
+  Remove();
+  _archive = archive;
+  _archive->AddByteStream(data, size);
+  _needRemove = true;
+}
+
+void CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)
+{
+  Set(archive, byteBuffer, byteBuffer.GetCapacity());
+}
+
+void CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)
+{
+  Remove();
+  Byte external = archive->ReadByte();
+  if (external != 0)
+  {
+    int dataIndex = (int)archive->ReadNum();
+    if (dataIndex < 0 || dataIndex >= dataVector->Size())
+      ThrowIncorrect();
+    Set(archive, (*dataVector)[dataIndex]);
+  }
+}
+
+Byte CInByte2::ReadByte()
+{
+  if (_pos >= _size)
+    ThrowEndOfData();
+  return _buffer[_pos++];
+}
+
+void CInByte2::ReadBytes(Byte *data, size_t size)
+{
+  if (size > _size - _pos)
+    ThrowEndOfData();
+  for (size_t i = 0; i < size; i++)
+    data[i] = _buffer[_pos++];
+}
+
+void CInByte2::SkipData(UInt64 size)
+{
+  if (size > _size - _pos)
+    ThrowEndOfData();
+  _pos += (size_t)size;
+}
+
+void CInByte2::SkipData()
+{
+  SkipData(ReadNumber());
+}
+
+UInt64 CInByte2::ReadNumber()
+{
+  if (_pos >= _size)
+    ThrowEndOfData();
+  Byte firstByte = _buffer[_pos++];
+  Byte mask = 0x80;
+  UInt64 value = 0;
+  for (int i = 0; i < 8; i++)
+  {
+    if ((firstByte & mask) == 0)
+    {
+      UInt64 highPart = firstByte & (mask - 1);
+      value += (highPart << (i * 8));
+      return value;
+    }
+    if (_pos >= _size)
+      ThrowEndOfData();
+    value |= ((UInt64)_buffer[_pos++] << (8 * i));
+    mask >>= 1;
+  }
+  return value;
+}
+
+CNum CInByte2::ReadNum()
+{
+  UInt64 value = ReadNumber();
+  if (value > kNumMax)
+    ThrowUnsupported();
+  return (CNum)value;
+}
+
+UInt32 CInByte2::ReadUInt32()
+{
+  if (_pos + 4 > _size)
+    ThrowEndOfData();
+  UInt32 res = Get32(_buffer + _pos);
+  _pos += 4;
+  return res;
+}
+
+UInt64 CInByte2::ReadUInt64()
+{
+  if (_pos + 8 > _size)
+    ThrowEndOfData();
+  UInt64 res = Get64(_buffer + _pos);
+  _pos += 8;
+  return res;
+}
+
+void CInByte2::ReadString(UString &s)
+{
+  const Byte *buf = _buffer + _pos;
+  size_t rem = (_size - _pos) / 2 * 2;
+  {
+    size_t i;
+    for (i = 0; i < rem; i += 2)
+      if (buf[i] == 0 && buf[i + 1] == 0)
+        break;
+    if (i == rem)
+      ThrowEndOfData();
+    rem = i;
+  }
+  int len = (int)(rem / 2);
+  if (len < 0 || (size_t)len * 2 != rem)
+    ThrowUnsupported();
+  wchar_t *p = s.GetBuffer(len);
+  int i;
+  for (i = 0; i < len; i++, buf += 2)
+    p[i] = (wchar_t)Get16(buf);
+  s.ReleaseBuffer(len);
+  _pos += rem + 2;
+}
+
+static inline bool TestSignature(const Byte *p)
+{
+  for (int i = 0; i < kSignatureSize; i++)
+    if (p[i] != kSignature[i])
+      return false;
+  return CrcCalc(p + 12, 20) == GetUi32(p + 8);
+}
+
+#ifdef FORMAT_7Z_RECOVERY
+static inline bool TestSignature2(const Byte *p)
+{
+  int i;
+  for (i = 0; i < kSignatureSize; i++)
+    if (p[i] != kSignature[i])
+      return false;
+  if (CrcCalc(p + 12, 20) == GetUi32(p + 8))
+    return true;
+  for (i = 8; i < kHeaderSize; i++)
+    if (p[i] != 0)
+      return false;
+  return (p[6] != 0 || p[7] != 0);
+}
+#else
+#define TestSignature2(p) TestSignature(p)
+#endif
+
+HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
+{
+  RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));
+
+  if (TestSignature2(_header))
+    return S_OK;
+
+  CByteBuffer byteBuffer;
+  const UInt32 kBufferSize = (1 << 16);
+  byteBuffer.SetCapacity(kBufferSize);
+  Byte *buffer = byteBuffer;
+  UInt32 numPrevBytes = kHeaderSize;
+  memcpy(buffer, _header, kHeaderSize);
+  UInt64 curTestPos = _arhiveBeginStreamPosition;
+  for (;;)
+  {
+    if (searchHeaderSizeLimit != NULL)
+      if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit)
+        break;
+    do
+    {
+      UInt32 numReadBytes = kBufferSize - numPrevBytes;
+      UInt32 processedSize;
+      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
+      numPrevBytes += processedSize;
+      if (processedSize == 0)
+        return S_FALSE;
+    }
+    while (numPrevBytes <= kHeaderSize);
+    UInt32 numTests = numPrevBytes - kHeaderSize;
+    for (UInt32 pos = 0; pos < numTests; pos++)
+    {
+      for (; buffer[pos] != '7' && pos < numTests; pos++);
+      if (pos == numTests)
+        break;
+      if (TestSignature(buffer + pos))
+      {
+        memcpy(_header, buffer + pos, kHeaderSize);
+        curTestPos += pos;
+        _arhiveBeginStreamPosition = curTestPos;
+        return stream->Seek(curTestPos + kHeaderSize, STREAM_SEEK_SET, NULL);
+      }
+    }
+    curTestPos += numTests;
+    numPrevBytes -= numTests;
+    memmove(buffer, buffer + numTests, numPrevBytes);
+  }
+  return S_FALSE;
+}
+
+// S_FALSE means that file is not archive
+HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
+{
+  HeadersSize = 0;
+  Close();
+  RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))
+  RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));
+  _stream = stream;
+  return S_OK;
+}
+  
+void CInArchive::Close()
+{
+  _stream.Release();
+}
+
+void CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)
+{
+  for (;;)
+  {
+    if (ReadID() == NID::kEnd)
+      break;
+    SkipData();
+  }
+}
+
+void CInArchive::GetNextFolderItem(CFolder &folder)
+{
+  CNum numCoders = ReadNum();
+
+  folder.Coders.Clear();
+  folder.Coders.Reserve((int)numCoders);
+  CNum numInStreams = 0;
+  CNum numOutStreams = 0;
+  CNum i;
+  for (i = 0; i < numCoders; i++)
+  {
+    folder.Coders.Add(CCoderInfo());
+    CCoderInfo &coder = folder.Coders.Back();
+
+    {
+      Byte mainByte = ReadByte();
+      int idSize = (mainByte & 0xF);
+      Byte longID[15];
+      ReadBytes(longID, idSize);
+      if (idSize > 8)
+        ThrowUnsupported();
+      UInt64 id = 0;
+      for (int j = 0; j < idSize; j++)
+        id |= (UInt64)longID[idSize - 1 - j] << (8 * j);
+      coder.MethodID = id;
+
+      if ((mainByte & 0x10) != 0)
+      {
+        coder.NumInStreams = ReadNum();
+        coder.NumOutStreams = ReadNum();
+      }
+      else
+      {
+        coder.NumInStreams = 1;
+        coder.NumOutStreams = 1;
+      }
+      if ((mainByte & 0x20) != 0)
+      {
+        CNum propsSize = ReadNum();
+        coder.Props.SetCapacity((size_t)propsSize);
+        ReadBytes((Byte *)coder.Props, (size_t)propsSize);
+      }
+      if ((mainByte & 0x80) != 0)
+        ThrowUnsupported();
+    }
+    numInStreams += coder.NumInStreams;
+    numOutStreams += coder.NumOutStreams;
+  }
+
+  CNum numBindPairs = numOutStreams - 1;
+  folder.BindPairs.Clear();
+  folder.BindPairs.Reserve(numBindPairs);
+  for (i = 0; i < numBindPairs; i++)
+  {
+    CBindPair bp;
+    bp.InIndex = ReadNum();
+    bp.OutIndex = ReadNum();
+    folder.BindPairs.Add(bp);
+  }
+
+  if (numInStreams < numBindPairs)
+    ThrowUnsupported();
+  CNum numPackStreams = numInStreams - numBindPairs;
+  folder.PackStreams.Reserve(numPackStreams);
+  if (numPackStreams == 1)
+  {
+    for (i = 0; i < numInStreams; i++)
+      if (folder.FindBindPairForInStream(i) < 0)
+      {
+        folder.PackStreams.Add(i);
+        break;
+      }
+    if (folder.PackStreams.Size() != 1)
+      ThrowUnsupported();
+  }
+  else
+    for (i = 0; i < numPackStreams; i++)
+      folder.PackStreams.Add(ReadNum());
+}
+
+void CInArchive::WaitAttribute(UInt64 attribute)
+{
+  for (;;)
+  {
+    UInt64 type = ReadID();
+    if (type == attribute)
+      return;
+    if (type == NID::kEnd)
+      ThrowIncorrect();
+    SkipData();
+  }
+}
+
+void CInArchive::ReadHashDigests(int numItems,
+    CBoolVector &digestsDefined,
+    CRecordVector<UInt32> &digests)
+{
+  ReadBoolVector2(numItems, digestsDefined);
+  digests.Clear();
+  digests.Reserve(numItems);
+  for (int i = 0; i < numItems; i++)
+  {
+    UInt32 crc = 0;
+    if (digestsDefined[i])
+      crc = ReadUInt32();
+    digests.Add(crc);
+  }
+}
+
+void CInArchive::ReadPackInfo(
+    UInt64 &dataOffset,
+    CRecordVector<UInt64> &packSizes,
+    CBoolVector &packCRCsDefined,
+    CRecordVector<UInt32> &packCRCs)
+{
+  dataOffset = ReadNumber();
+  CNum numPackStreams = ReadNum();
+
+  WaitAttribute(NID::kSize);
+  packSizes.Clear();
+  packSizes.Reserve(numPackStreams);
+  for (CNum i = 0; i < numPackStreams; i++)
+    packSizes.Add(ReadNumber());
+
+  UInt64 type;
+  for (;;)
+  {
+    type = ReadID();
+    if (type == NID::kEnd)
+      break;
+    if (type == NID::kCRC)
+    {
+      ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);
+      continue;
+    }
+    SkipData();
+  }
+  if (packCRCsDefined.IsEmpty())
+  {
+    BoolVector_Fill_False(packCRCsDefined, numPackStreams);
+    packCRCs.Reserve(numPackStreams);
+    packCRCs.Clear();
+    for (CNum i = 0; i < numPackStreams; i++)
+      packCRCs.Add(0);
+  }
+}
+
+void CInArchive::ReadUnpackInfo(
+    const CObjectVector<CByteBuffer> *dataVector,
+    CObjectVector<CFolder> &folders)
+{
+  WaitAttribute(NID::kFolder);
+  CNum numFolders = ReadNum();
+
+  {
+    CStreamSwitch streamSwitch;
+    streamSwitch.Set(this, dataVector);
+    folders.Clear();
+    folders.Reserve(numFolders);
+    for (CNum i = 0; i < numFolders; i++)
+    {
+      folders.Add(CFolder());
+      GetNextFolderItem(folders.Back());
+    }
+  }
+
+  WaitAttribute(NID::kCodersUnpackSize);
+
+  CNum i;
+  for (i = 0; i < numFolders; i++)
+  {
+    CFolder &folder = folders[i];
+    CNum numOutStreams = folder.GetNumOutStreams();
+    folder.UnpackSizes.Reserve(numOutStreams);
+    for (CNum j = 0; j < numOutStreams; j++)
+      folder.UnpackSizes.Add(ReadNumber());
+  }
+
+  for (;;)
+  {
+    UInt64 type = ReadID();
+    if (type == NID::kEnd)
+      return;
+    if (type == NID::kCRC)
+    {
+      CBoolVector crcsDefined;
+      CRecordVector<UInt32> crcs;
+      ReadHashDigests(numFolders, crcsDefined, crcs);
+      for (i = 0; i < numFolders; i++)
+      {
+        CFolder &folder = folders[i];
+        folder.UnpackCRCDefined = crcsDefined[i];
+        folder.UnpackCRC = crcs[i];
+      }
+      continue;
+    }
+    SkipData();
+  }
+}
+
+void CInArchive::ReadSubStreamsInfo(
+    const CObjectVector<CFolder> &folders,
+    CRecordVector<CNum> &numUnpackStreamsInFolders,
+    CRecordVector<UInt64> &unpackSizes,
+    CBoolVector &digestsDefined,
+    CRecordVector<UInt32> &digests)
+{
+  numUnpackStreamsInFolders.Clear();
+  numUnpackStreamsInFolders.Reserve(folders.Size());
+  UInt64 type;
+  for (;;)
+  {
+    type = ReadID();
+    if (type == NID::kNumUnpackStream)
+    {
+      for (int i = 0; i < folders.Size(); i++)
+        numUnpackStreamsInFolders.Add(ReadNum());
+      continue;
+    }
+    if (type == NID::kCRC || type == NID::kSize)
+      break;
+    if (type == NID::kEnd)
+      break;
+    SkipData();
+  }
+
+  if (numUnpackStreamsInFolders.IsEmpty())
+    for (int i = 0; i < folders.Size(); i++)
+      numUnpackStreamsInFolders.Add(1);
+
+  int i;
+  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)
+  {
+    // v3.13 incorrectly worked with empty folders
+    // v4.07: we check that folder is empty
+    CNum numSubstreams = numUnpackStreamsInFolders[i];
+    if (numSubstreams == 0)
+      continue;
+    UInt64 sum = 0;
+    for (CNum j = 1; j < numSubstreams; j++)
+      if (type == NID::kSize)
+      {
+        UInt64 size = ReadNumber();
+        unpackSizes.Add(size);
+        sum += size;
+      }
+    unpackSizes.Add(folders[i].GetUnpackSize() - sum);
+  }
+  if (type == NID::kSize)
+    type = ReadID();
+
+  int numDigests = 0;
+  int numDigestsTotal = 0;
+  for (i = 0; i < folders.Size(); i++)
+  {
+    CNum numSubstreams = numUnpackStreamsInFolders[i];
+    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)
+      numDigests += numSubstreams;
+    numDigestsTotal += numSubstreams;
+  }
+
+  for (;;)
+  {
+    if (type == NID::kCRC)
+    {
+      CBoolVector digestsDefined2;
+      CRecordVector<UInt32> digests2;
+      ReadHashDigests(numDigests, digestsDefined2, digests2);
+      int digestIndex = 0;
+      for (i = 0; i < folders.Size(); i++)
+      {
+        CNum numSubstreams = numUnpackStreamsInFolders[i];
+        const CFolder &folder = folders[i];
+        if (numSubstreams == 1 && folder.UnpackCRCDefined)
+        {
+          digestsDefined.Add(true);
+          digests.Add(folder.UnpackCRC);
+        }
+        else
+          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)
+          {
+            digestsDefined.Add(digestsDefined2[digestIndex]);
+            digests.Add(digests2[digestIndex]);
+          }
+      }
+    }
+    else if (type == NID::kEnd)
+    {
+      if (digestsDefined.IsEmpty())
+      {
+        BoolVector_Fill_False(digestsDefined, numDigestsTotal);
+        digests.Clear();
+        for (int i = 0; i < numDigestsTotal; i++)
+          digests.Add(0);
+      }
+      return;
+    }
+    else
+      SkipData();
+    type = ReadID();
+  }
+}
+
+void CInArchive::ReadStreamsInfo(
+    const CObjectVector<CByteBuffer> *dataVector,
+    UInt64 &dataOffset,
+    CRecordVector<UInt64> &packSizes,
+    CBoolVector &packCRCsDefined,
+    CRecordVector<UInt32> &packCRCs,
+    CObjectVector<CFolder> &folders,
+    CRecordVector<CNum> &numUnpackStreamsInFolders,
+    CRecordVector<UInt64> &unpackSizes,
+    CBoolVector &digestsDefined,
+    CRecordVector<UInt32> &digests)
+{
+  for (;;)
+  {
+    UInt64 type = ReadID();
+    if (type > ((UInt32)1 << 30))
+      ThrowIncorrect();
+    switch((UInt32)type)
+    {
+      case NID::kEnd:
+        return;
+      case NID::kPackInfo:
+      {
+        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);
+        break;
+      }
+      case NID::kUnpackInfo:
+      {
+        ReadUnpackInfo(dataVector, folders);
+        break;
+      }
+      case NID::kSubStreamsInfo:
+      {
+        ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,
+            unpackSizes, digestsDefined, digests);
+        break;
+      }
+      default:
+        ThrowIncorrect();
+    }
+  }
+}
+
+void CInArchive::ReadBoolVector(int numItems, CBoolVector &v)
+{
+  v.Clear();
+  v.Reserve(numItems);
+  Byte b = 0;
+  Byte mask = 0;
+  for (int i = 0; i < numItems; i++)
+  {
+    if (mask == 0)
+    {
+      b = ReadByte();
+      mask = 0x80;
+    }
+    v.Add((b & mask) != 0);
+    mask >>= 1;
+  }
+}
+
+void CInArchive::ReadBoolVector2(int numItems, CBoolVector &v)
+{
+  Byte allAreDefined = ReadByte();
+  if (allAreDefined == 0)
+  {
+    ReadBoolVector(numItems, v);
+    return;
+  }
+  v.Clear();
+  v.Reserve(numItems);
+  for (int i = 0; i < numItems; i++)
+    v.Add(true);
+}
+
+void CInArchive::ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,
+    CUInt64DefVector &v, int numFiles)
+{
+  ReadBoolVector2(numFiles, v.Defined);
+
+  CStreamSwitch streamSwitch;
+  streamSwitch.Set(this, &dataVector);
+  v.Values.Reserve(numFiles);
+
+  for (int i = 0; i < numFiles; i++)
+  {
+    UInt64 t = 0;
+    if (v.Defined[i])
+      t = ReadUInt64();
+    v.Values.Add(t);
+  }
+}
+
+HRESULT CInArchive::ReadAndDecodePackedStreams(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    UInt64 baseOffset,
+    UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector
+    #ifndef _NO_CRYPTO
+    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+    #endif
+    )
+{
+  CRecordVector<UInt64> packSizes;
+  CBoolVector packCRCsDefined;
+  CRecordVector<UInt32> packCRCs;
+  CObjectVector<CFolder> folders;
+  
+  CRecordVector<CNum> numUnpackStreamsInFolders;
+  CRecordVector<UInt64> unpackSizes;
+  CBoolVector digestsDefined;
+  CRecordVector<UInt32> digests;
+  
+  ReadStreamsInfo(NULL,
+    dataOffset,
+    packSizes,
+    packCRCsDefined,
+    packCRCs,
+    folders,
+    numUnpackStreamsInFolders,
+    unpackSizes,
+    digestsDefined,
+    digests);
+  
+  // db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;
+  
+  CNum packIndex = 0;
+  CDecoder decoder(
+    #ifdef _ST_MODE
+    false
+    #else
+    true
+    #endif
+    );
+  UInt64 dataStartPos = baseOffset + dataOffset;
+  for (int i = 0; i < folders.Size(); i++)
+  {
+    const CFolder &folder = folders[i];
+    dataVector.Add(CByteBuffer());
+    CByteBuffer &data = dataVector.Back();
+    UInt64 unpackSize64 = folder.GetUnpackSize();
+    size_t unpackSize = (size_t)unpackSize64;
+    if (unpackSize != unpackSize64)
+      ThrowUnsupported();
+    data.SetCapacity(unpackSize);
+    
+    CBufPtrSeqOutStream *outStreamSpec = new CBufPtrSeqOutStream;
+    CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
+    outStreamSpec->Init(data, unpackSize);
+    
+    HRESULT result = decoder.Decode(
+      EXTERNAL_CODECS_LOC_VARS
+      _stream, dataStartPos,
+      &packSizes[packIndex], folder, outStream, NULL
+      #ifndef _NO_CRYPTO
+      , getTextPassword, passwordIsDefined
+      #endif
+      #if !defined(_7ZIP_ST) && !defined(_SFX)
+      , false, 1
+      #endif
+      );
+    RINOK(result);
+    
+    if (folder.UnpackCRCDefined)
+      if (CrcCalc(data, unpackSize) != folder.UnpackCRC)
+        ThrowIncorrect();
+    for (int j = 0; j < folder.PackStreams.Size(); j++)
+    {
+      UInt64 packSize = packSizes[packIndex++];
+      dataStartPos += packSize;
+      HeadersSize += packSize;
+    }
+  }
+  return S_OK;
+}
+
+HRESULT CInArchive::ReadHeader(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    CArchiveDatabaseEx &db
+    #ifndef _NO_CRYPTO
+    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+    #endif
+    )
+{
+  UInt64 type = ReadID();
+
+  if (type == NID::kArchiveProperties)
+  {
+    ReadArchiveProperties(db.ArchiveInfo);
+    type = ReadID();
+  }
+ 
+  CObjectVector<CByteBuffer> dataVector;
+  
+  if (type == NID::kAdditionalStreamsInfo)
+  {
+    HRESULT result = ReadAndDecodePackedStreams(
+        EXTERNAL_CODECS_LOC_VARS
+        db.ArchiveInfo.StartPositionAfterHeader,
+        db.ArchiveInfo.DataStartPosition2,
+        dataVector
+        #ifndef _NO_CRYPTO
+        , getTextPassword, passwordIsDefined
+        #endif
+        );
+    RINOK(result);
+    db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;
+    type = ReadID();
+  }
+
+  CRecordVector<UInt64> unpackSizes;
+  CBoolVector digestsDefined;
+  CRecordVector<UInt32> digests;
+  
+  if (type == NID::kMainStreamsInfo)
+  {
+    ReadStreamsInfo(&dataVector,
+        db.ArchiveInfo.DataStartPosition,
+        db.PackSizes,
+        db.PackCRCsDefined,
+        db.PackCRCs,
+        db.Folders,
+        db.NumUnpackStreamsVector,
+        unpackSizes,
+        digestsDefined,
+        digests);
+    db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;
+    type = ReadID();
+  }
+  else
+  {
+    for (int i = 0; i < db.Folders.Size(); i++)
+    {
+      db.NumUnpackStreamsVector.Add(1);
+      CFolder &folder = db.Folders[i];
+      unpackSizes.Add(folder.GetUnpackSize());
+      digestsDefined.Add(folder.UnpackCRCDefined);
+      digests.Add(folder.UnpackCRC);
+    }
+  }
+
+  db.Files.Clear();
+
+  if (type == NID::kEnd)
+    return S_OK;
+  if (type != NID::kFilesInfo)
+    ThrowIncorrect();
+  
+  CNum numFiles = ReadNum();
+  db.Files.Reserve(numFiles);
+  CNum i;
+  for (i = 0; i < numFiles; i++)
+    db.Files.Add(CFileItem());
+
+  db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);
+  if (!db.PackSizes.IsEmpty())
+    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);
+  if (numFiles > 0  && !digests.IsEmpty())
+    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);
+
+  CBoolVector emptyStreamVector;
+  BoolVector_Fill_False(emptyStreamVector, (int)numFiles);
+  CBoolVector emptyFileVector;
+  CBoolVector antiFileVector;
+  CNum numEmptyStreams = 0;
+
+  for (;;)
+  {
+    UInt64 type = ReadID();
+    if (type == NID::kEnd)
+      break;
+    UInt64 size = ReadNumber();
+    size_t ppp = _inByteBack->_pos;
+    bool addPropIdToList = true;
+    bool isKnownType = true;
+    if (type > ((UInt32)1 << 30))
+      isKnownType = false;
+    else switch((UInt32)type)
+    {
+      case NID::kName:
+      {
+        CStreamSwitch streamSwitch;
+        streamSwitch.Set(this, &dataVector);
+        for (int i = 0; i < db.Files.Size(); i++)
+          _inByteBack->ReadString(db.Files[i].Name);
+        break;
+      }
+      case NID::kWinAttributes:
+      {
+        CBoolVector boolVector;
+        ReadBoolVector2(db.Files.Size(), boolVector);
+        CStreamSwitch streamSwitch;
+        streamSwitch.Set(this, &dataVector);
+        for (i = 0; i < numFiles; i++)
+        {
+          CFileItem &file = db.Files[i];
+          file.AttribDefined = boolVector[i];
+          if (file.AttribDefined)
+            file.Attrib = ReadUInt32();
+        }
+        break;
+      }
+      case NID::kEmptyStream:
+      {
+        ReadBoolVector(numFiles, emptyStreamVector);
+        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)
+          if (emptyStreamVector[i])
+            numEmptyStreams++;
+
+        BoolVector_Fill_False(emptyFileVector, numEmptyStreams);
+        BoolVector_Fill_False(antiFileVector, numEmptyStreams);
+
+        break;
+      }
+      case NID::kEmptyFile:  ReadBoolVector(numEmptyStreams, emptyFileVector); break;
+      case NID::kAnti:  ReadBoolVector(numEmptyStreams, antiFileVector); break;
+      case NID::kStartPos:  ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;
+      case NID::kCTime:  ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;
+      case NID::kATime:  ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;
+      case NID::kMTime:  ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;
+      case NID::kDummy:
+      {
+        for (UInt64 j = 0; j < size; j++)
+          if (ReadByte() != 0)
+            ThrowIncorrect();
+        addPropIdToList = false;
+        break;
+      }
+      default:
+        addPropIdToList = isKnownType = false;
+    }
+    if (isKnownType)
+    {
+      if(addPropIdToList)
+        db.ArchiveInfo.FileInfoPopIDs.Add(type);
+    }
+    else
+      SkipData(size);
+    bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||
+        db.ArchiveInfo.Version.Minor > 2);
+    if (checkRecordsSize && _inByteBack->_pos - ppp != size)
+      ThrowIncorrect();
+  }
+
+  CNum emptyFileIndex = 0;
+  CNum sizeIndex = 0;
+
+  CNum numAntiItems = 0;
+  for (i = 0; i < numEmptyStreams; i++)
+    if (antiFileVector[i])
+      numAntiItems++;
+    
+  for (i = 0; i < numFiles; i++)
+  {
+    CFileItem &file = db.Files[i];
+    bool isAnti;
+    file.HasStream = !emptyStreamVector[i];
+    if (file.HasStream)
+    {
+      file.IsDir = false;
+      isAnti = false;
+      file.Size = unpackSizes[sizeIndex];
+      file.Crc = digests[sizeIndex];
+      file.CrcDefined = digestsDefined[sizeIndex];
+      sizeIndex++;
+    }
+    else
+    {
+      file.IsDir = !emptyFileVector[emptyFileIndex];
+      isAnti = antiFileVector[emptyFileIndex];
+      emptyFileIndex++;
+      file.Size = 0;
+      file.CrcDefined = false;
+    }
+    if (numAntiItems != 0)
+      db.IsAnti.Add(isAnti);
+  }
+  return S_OK;
+}
+
+
+void CArchiveDatabaseEx::FillFolderStartPackStream()
+{
+  FolderStartPackStreamIndex.Clear();
+  FolderStartPackStreamIndex.Reserve(Folders.Size());
+  CNum startPos = 0;
+  for (int i = 0; i < Folders.Size(); i++)
+  {
+    FolderStartPackStreamIndex.Add(startPos);
+    startPos += (CNum)Folders[i].PackStreams.Size();
+  }
+}
+
+void CArchiveDatabaseEx::FillStartPos()
+{
+  PackStreamStartPositions.Clear();
+  PackStreamStartPositions.Reserve(PackSizes.Size());
+  UInt64 startPos = 0;
+  for (int i = 0; i < PackSizes.Size(); i++)
+  {
+    PackStreamStartPositions.Add(startPos);
+    startPos += PackSizes[i];
+  }
+}
+
+void CArchiveDatabaseEx::FillFolderStartFileIndex()
+{
+  FolderStartFileIndex.Clear();
+  FolderStartFileIndex.Reserve(Folders.Size());
+  FileIndexToFolderIndexMap.Clear();
+  FileIndexToFolderIndexMap.Reserve(Files.Size());
+  
+  int folderIndex = 0;
+  CNum indexInFolder = 0;
+  for (int i = 0; i < Files.Size(); i++)
+  {
+    const CFileItem &file = Files[i];
+    bool emptyStream = !file.HasStream;
+    if (emptyStream && indexInFolder == 0)
+    {
+      FileIndexToFolderIndexMap.Add(kNumNoIndex);
+      continue;
+    }
+    if (indexInFolder == 0)
+    {
+      // v3.13 incorrectly worked with empty folders
+      // v4.07: Loop for skipping empty folders
+      for (;;)
+      {
+        if (folderIndex >= Folders.Size())
+          ThrowIncorrect();
+        FolderStartFileIndex.Add(i); // check it
+        if (NumUnpackStreamsVector[folderIndex] != 0)
+          break;
+        folderIndex++;
+      }
+    }
+    FileIndexToFolderIndexMap.Add(folderIndex);
+    if (emptyStream)
+      continue;
+    indexInFolder++;
+    if (indexInFolder >= NumUnpackStreamsVector[folderIndex])
+    {
+      folderIndex++;
+      indexInFolder = 0;
+    }
+  }
+}
+
+HRESULT CInArchive::ReadDatabase2(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    CArchiveDatabaseEx &db
+    #ifndef _NO_CRYPTO
+    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+    #endif
+    )
+{
+  db.Clear();
+  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
+
+  db.ArchiveInfo.Version.Major = _header[6];
+  db.ArchiveInfo.Version.Minor = _header[7];
+
+  if (db.ArchiveInfo.Version.Major != kMajorVersion)
+    ThrowUnsupportedVersion();
+
+  UInt32 crcFromArchive = Get32(_header + 8);
+  UInt64 nextHeaderOffset = Get64(_header + 0xC);
+  UInt64 nextHeaderSize = Get64(_header + 0x14);
+  UInt32 nextHeaderCRC = Get32(_header + 0x1C);
+  UInt32 crc = CrcCalc(_header + 0xC, 20);
+
+  #ifdef FORMAT_7Z_RECOVERY
+  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)
+  {
+    UInt64 cur, cur2;
+    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));
+    const int kCheckSize = 500;
+    Byte buf[kCheckSize];
+    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));
+    int checkSize = kCheckSize;
+    if (cur2 - cur < kCheckSize)
+      checkSize = (int)(cur2 - cur);
+    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));
+    
+    RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));
+
+    int i;
+    for (i = (int)checkSize - 2; i >= 0; i--)
+      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)
+        break;
+    if (i < 0)
+      return S_FALSE;
+    nextHeaderSize = checkSize - i;
+    nextHeaderOffset = cur2 - cur + i;
+    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);
+    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));
+  }
+  else
+  #endif
+  {
+    if (crc != crcFromArchive)
+      ThrowIncorrect();
+  }
+
+  db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;
+
+  if (nextHeaderSize == 0)
+    return S_OK;
+
+  if (nextHeaderSize > (UInt64)0xFFFFFFFF)
+    return S_FALSE;
+
+  if ((Int64)nextHeaderOffset < 0)
+    return S_FALSE;
+
+  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));
+
+  CByteBuffer buffer2;
+  buffer2.SetCapacity((size_t)nextHeaderSize);
+
+  RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));
+  HeadersSize += kHeaderSize + nextHeaderSize;
+  db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;
+
+  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)
+    ThrowIncorrect();
+  
+  CStreamSwitch streamSwitch;
+  streamSwitch.Set(this, buffer2);
+  
+  CObjectVector<CByteBuffer> dataVector;
+  
+  UInt64 type = ReadID();
+  if (type != NID::kHeader)
+  {
+    if (type != NID::kEncodedHeader)
+      ThrowIncorrect();
+    HRESULT result = ReadAndDecodePackedStreams(
+        EXTERNAL_CODECS_LOC_VARS
+        db.ArchiveInfo.StartPositionAfterHeader,
+        db.ArchiveInfo.DataStartPosition2,
+        dataVector
+        #ifndef _NO_CRYPTO
+        , getTextPassword, passwordIsDefined
+        #endif
+        );
+    RINOK(result);
+    if (dataVector.Size() == 0)
+      return S_OK;
+    if (dataVector.Size() > 1)
+      ThrowIncorrect();
+    streamSwitch.Remove();
+    streamSwitch.Set(this, dataVector.Front());
+    if (ReadID() != NID::kHeader)
+      ThrowIncorrect();
+  }
+
+  db.HeadersSize = HeadersSize;
+
+  return ReadHeader(
+    EXTERNAL_CODECS_LOC_VARS
+    db
+    #ifndef _NO_CRYPTO
+    , getTextPassword, passwordIsDefined
+    #endif
+    );
+}
+
+HRESULT CInArchive::ReadDatabase(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    CArchiveDatabaseEx &db
+    #ifndef _NO_CRYPTO
+    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+    #endif
+    )
+{
+  try
+  {
+    return ReadDatabase2(
+      EXTERNAL_CODECS_LOC_VARS db
+      #ifndef _NO_CRYPTO
+      , getTextPassword, passwordIsDefined
+      #endif
+      );
+  }
+  catch(CInArchiveException &) { return S_FALSE; }
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zIn.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,245 @@
+// 7zIn.h
+
+#ifndef __7Z_IN_H
+#define __7Z_IN_H
+
+#include "../../../Common/MyCom.h"
+
+#include "../../IPassword.h"
+#include "../../IStream.h"
+
+#include "../../Common/CreateCoder.h"
+#include "../../Common/InBuffer.h"
+
+#include "7zItem.h"
+ 
+namespace NArchive {
+namespace N7z {
+  
+struct CInArchiveInfo
+{
+  CArchiveVersion Version;
+  UInt64 StartPosition;
+  UInt64 StartPositionAfterHeader;
+  UInt64 DataStartPosition;
+  UInt64 DataStartPosition2;
+  CRecordVector<UInt64> FileInfoPopIDs;
+  void Clear()
+  {
+    FileInfoPopIDs.Clear();
+  }
+};
+
+struct CArchiveDatabaseEx: public CArchiveDatabase
+{
+  CInArchiveInfo ArchiveInfo;
+  CRecordVector<UInt64> PackStreamStartPositions;
+  CRecordVector<CNum> FolderStartPackStreamIndex;
+  CRecordVector<CNum> FolderStartFileIndex;
+  CRecordVector<CNum> FileIndexToFolderIndexMap;
+
+  UInt64 HeadersSize;
+  UInt64 PhySize;
+
+  void Clear()
+  {
+    CArchiveDatabase::Clear();
+    ArchiveInfo.Clear();
+    PackStreamStartPositions.Clear();
+    FolderStartPackStreamIndex.Clear();
+    FolderStartFileIndex.Clear();
+    FileIndexToFolderIndexMap.Clear();
+
+    HeadersSize = 0;
+    PhySize = 0;
+  }
+
+  void FillFolderStartPackStream();
+  void FillStartPos();
+  void FillFolderStartFileIndex();
+
+  void Fill()
+  {
+    FillFolderStartPackStream();
+    FillStartPos();
+    FillFolderStartFileIndex();
+  }
+  
+  UInt64 GetFolderStreamPos(int folderIndex, int indexInFolder) const
+  {
+    return ArchiveInfo.DataStartPosition +
+        PackStreamStartPositions[FolderStartPackStreamIndex[folderIndex] + indexInFolder];
+  }
+  
+  UInt64 GetFolderFullPackSize(int folderIndex) const
+  {
+    CNum packStreamIndex = FolderStartPackStreamIndex[folderIndex];
+    const CFolder &folder = Folders[folderIndex];
+    UInt64 size = 0;
+    for (int i = 0; i < folder.PackStreams.Size(); i++)
+      size += PackSizes[packStreamIndex + i];
+    return size;
+  }
+  
+  UInt64 GetFolderPackStreamSize(int folderIndex, int streamIndex) const
+  {
+    return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
+  }
+
+  UInt64 GetFilePackSize(CNum fileIndex) const
+  {
+    CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];
+    if (folderIndex != kNumNoIndex)
+      if (FolderStartFileIndex[folderIndex] == fileIndex)
+        return GetFolderFullPackSize(folderIndex);
+    return 0;
+  }
+};
+
+class CInByte2
+{
+  const Byte *_buffer;
+  size_t _size;
+public:
+  size_t _pos;
+  void Init(const Byte *buffer, size_t size)
+  {
+    _buffer = buffer;
+    _size = size;
+    _pos = 0;
+  }
+  Byte ReadByte();
+  void ReadBytes(Byte *data, size_t size);
+  void SkipData(UInt64 size);
+  void SkipData();
+  UInt64 ReadNumber();
+  CNum ReadNum();
+  UInt32 ReadUInt32();
+  UInt64 ReadUInt64();
+  void ReadString(UString &s);
+};
+
+class CStreamSwitch;
+
+const UInt32 kHeaderSize = 32;
+
+class CInArchive
+{
+  friend class CStreamSwitch;
+
+  CMyComPtr<IInStream> _stream;
+
+  CObjectVector<CInByte2> _inByteVector;
+  CInByte2 *_inByteBack;
+ 
+  UInt64 _arhiveBeginStreamPosition;
+
+  Byte _header[kHeaderSize];
+
+  UInt64 HeadersSize;
+
+  void AddByteStream(const Byte *buffer, size_t size)
+  {
+    _inByteVector.Add(CInByte2());
+    _inByteBack = &_inByteVector.Back();
+    _inByteBack->Init(buffer, size);
+  }
+  
+  void DeleteByteStream()
+  {
+    _inByteVector.DeleteBack();
+    if (!_inByteVector.IsEmpty())
+      _inByteBack = &_inByteVector.Back();
+  }
+
+private:
+  HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
+  
+  void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }
+  Byte ReadByte() { return _inByteBack->ReadByte(); }
+  UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }
+  CNum ReadNum() { return _inByteBack->ReadNum(); }
+  UInt64 ReadID() { return _inByteBack->ReadNumber(); }
+  UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }
+  UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }
+  void SkipData(UInt64 size) { _inByteBack->SkipData(size); }
+  void SkipData() { _inByteBack->SkipData(); }
+  void WaitAttribute(UInt64 attribute);
+
+  void ReadArchiveProperties(CInArchiveInfo &archiveInfo);
+  void GetNextFolderItem(CFolder &itemInfo);
+  void ReadHashDigests(int numItems,
+      CBoolVector &digestsDefined, CRecordVector<UInt32> &digests);
+  
+  void ReadPackInfo(
+      UInt64 &dataOffset,
+      CRecordVector<UInt64> &packSizes,
+      CBoolVector &packCRCsDefined,
+      CRecordVector<UInt32> &packCRCs);
+  
+  void ReadUnpackInfo(
+      const CObjectVector<CByteBuffer> *dataVector,
+      CObjectVector<CFolder> &folders);
+  
+  void ReadSubStreamsInfo(
+      const CObjectVector<CFolder> &folders,
+      CRecordVector<CNum> &numUnpackStreamsInFolders,
+      CRecordVector<UInt64> &unpackSizes,
+      CBoolVector &digestsDefined,
+      CRecordVector<UInt32> &digests);
+
+  void ReadStreamsInfo(
+      const CObjectVector<CByteBuffer> *dataVector,
+      UInt64 &dataOffset,
+      CRecordVector<UInt64> &packSizes,
+      CBoolVector &packCRCsDefined,
+      CRecordVector<UInt32> &packCRCs,
+      CObjectVector<CFolder> &folders,
+      CRecordVector<CNum> &numUnpackStreamsInFolders,
+      CRecordVector<UInt64> &unpackSizes,
+      CBoolVector &digestsDefined,
+      CRecordVector<UInt32> &digests);
+
+
+  void ReadBoolVector(int numItems, CBoolVector &v);
+  void ReadBoolVector2(int numItems, CBoolVector &v);
+  void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,
+      CUInt64DefVector &v, int numFiles);
+  HRESULT ReadAndDecodePackedStreams(
+      DECL_EXTERNAL_CODECS_LOC_VARS
+      UInt64 baseOffset, UInt64 &dataOffset,
+      CObjectVector<CByteBuffer> &dataVector
+      #ifndef _NO_CRYPTO
+      , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+      #endif
+      );
+  HRESULT ReadHeader(
+      DECL_EXTERNAL_CODECS_LOC_VARS
+      CArchiveDatabaseEx &db
+      #ifndef _NO_CRYPTO
+      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+      #endif
+      );
+  HRESULT ReadDatabase2(
+      DECL_EXTERNAL_CODECS_LOC_VARS
+      CArchiveDatabaseEx &db
+      #ifndef _NO_CRYPTO
+      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+      #endif
+      );
+public:
+  HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
+  void Close();
+
+  HRESULT ReadDatabase(
+      DECL_EXTERNAL_CODECS_LOC_VARS
+      CArchiveDatabaseEx &db
+      #ifndef _NO_CRYPTO
+      ,ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
+      #endif
+      );
+};
+  
+}}
+  
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zItem.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zItem.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zItem.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zItem.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,268 @@
+// 7zItem.h
+
+#ifndef __7Z_ITEM_H
+#define __7Z_ITEM_H
+
+#include "../../../Common/Buffer.h"
+#include "../../../Common/MyString.h"
+
+#include "../../Common/MethodId.h"
+
+#include "7zHeader.h"
+
+namespace NArchive {
+namespace N7z {
+
+const UInt64 k_AES = 0x06F10701;
+
+typedef UInt32 CNum;
+const CNum kNumMax     = 0x7FFFFFFF;
+const CNum kNumNoIndex = 0xFFFFFFFF;
+
+struct CCoderInfo
+{
+  CMethodId MethodID;
+  CByteBuffer Props;
+  CNum NumInStreams;
+  CNum NumOutStreams;
+  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
+};
+
+struct CBindPair
+{
+  CNum InIndex;
+  CNum OutIndex;
+};
+
+struct CFolder
+{
+  CObjectVector<CCoderInfo> Coders;
+  CRecordVector<CBindPair> BindPairs;
+  CRecordVector<CNum> PackStreams;
+  CRecordVector<UInt64> UnpackSizes;
+  UInt32 UnpackCRC;
+  bool UnpackCRCDefined;
+
+  CFolder(): UnpackCRCDefined(false) {}
+
+  UInt64 GetUnpackSize() const // test it
+  {
+    if (UnpackSizes.IsEmpty())
+      return 0;
+    for (int i = UnpackSizes.Size() - 1; i >= 0; i--)
+      if (FindBindPairForOutStream(i) < 0)
+        return UnpackSizes[i];
+    throw 1;
+  }
+
+  CNum GetNumOutStreams() const
+  {
+    CNum result = 0;
+    for (int i = 0; i < Coders.Size(); i++)
+      result += Coders[i].NumOutStreams;
+    return result;
+  }
+
+  int FindBindPairForInStream(CNum inStreamIndex) const
+  {
+    for(int i = 0; i < BindPairs.Size(); i++)
+      if (BindPairs[i].InIndex == inStreamIndex)
+        return i;
+    return -1;
+  }
+  int FindBindPairForOutStream(CNum outStreamIndex) const
+  {
+    for(int i = 0; i < BindPairs.Size(); i++)
+      if (BindPairs[i].OutIndex == outStreamIndex)
+        return i;
+    return -1;
+  }
+  int FindPackStreamArrayIndex(CNum inStreamIndex) const
+  {
+    for(int i = 0; i < PackStreams.Size(); i++)
+      if (PackStreams[i] == inStreamIndex)
+        return i;
+    return -1;
+  }
+
+  bool IsEncrypted() const
+  {
+    for (int i = Coders.Size() - 1; i >= 0; i--)
+      if (Coders[i].MethodID == k_AES)
+        return true;
+    return false;
+  }
+
+  bool CheckStructure() const;
+};
+
+struct CUInt64DefVector
+{
+  CRecordVector<UInt64> Values;
+  CRecordVector<bool> Defined;
+  
+  void Clear()
+  {
+    Values.Clear();
+    Defined.Clear();
+  }
+  
+  void ReserveDown()
+  {
+    Values.ReserveDown();
+    Values.ReserveDown();
+  }
+
+  bool GetItem(int index, UInt64 &value) const
+  {
+    if (index < Defined.Size() && Defined[index])
+    {
+      value = Values[index];
+      return true;
+    }
+    value = 0;
+    return false;
+  }
+  
+  void SetItem(int index, bool defined, UInt64 value)
+  {
+    while (index >= Defined.Size())
+      Defined.Add(false);
+    Defined[index] = defined;
+    if (!defined)
+      return;
+    while (index >= Values.Size())
+      Values.Add(0);
+    Values[index] = value;
+  }
+
+  bool CheckSize(int size) const { return Defined.Size() == size || Defined.Size() == 0; }
+};
+
+struct CFileItem
+{
+  UInt64 Size;
+  UInt32 Attrib;
+  UInt32 Crc;
+  UString Name;
+
+  bool HasStream; // Test it !!! it means that there is
+                  // stream in some folder. It can be empty stream
+  bool IsDir;
+  bool CrcDefined;
+  bool AttribDefined;
+
+  CFileItem():
+    HasStream(true),
+    IsDir(false),
+    CrcDefined(false),
+    AttribDefined(false)
+      {}
+  void SetAttrib(UInt32 attrib)
+  {
+    AttribDefined = true;
+    Attrib = attrib;
+  }
+};
+
+struct CFileItem2
+{
+  UInt64 CTime;
+  UInt64 ATime;
+  UInt64 MTime;
+  UInt64 StartPos;
+  bool CTimeDefined;
+  bool ATimeDefined;
+  bool MTimeDefined;
+  bool StartPosDefined;
+  bool IsAnti;
+};
+
+struct CArchiveDatabase
+{
+  CRecordVector<UInt64> PackSizes;
+  CRecordVector<bool> PackCRCsDefined;
+  CRecordVector<UInt32> PackCRCs;
+  CObjectVector<CFolder> Folders;
+  CRecordVector<CNum> NumUnpackStreamsVector;
+  CObjectVector<CFileItem> Files;
+
+  CUInt64DefVector CTime;
+  CUInt64DefVector ATime;
+  CUInt64DefVector MTime;
+  CUInt64DefVector StartPos;
+  CRecordVector<bool> IsAnti;
+
+  void Clear()
+  {
+    PackSizes.Clear();
+    PackCRCsDefined.Clear();
+    PackCRCs.Clear();
+    Folders.Clear();
+    NumUnpackStreamsVector.Clear();
+    Files.Clear();
+    CTime.Clear();
+    ATime.Clear();
+    MTime.Clear();
+    StartPos.Clear();
+    IsAnti.Clear();
+  }
+
+  void ReserveDown()
+  {
+    PackSizes.ReserveDown();
+    PackCRCsDefined.ReserveDown();
+    PackCRCs.ReserveDown();
+    Folders.ReserveDown();
+    NumUnpackStreamsVector.ReserveDown();
+    Files.ReserveDown();
+    CTime.ReserveDown();
+    ATime.ReserveDown();
+    MTime.ReserveDown();
+    StartPos.ReserveDown();
+    IsAnti.ReserveDown();
+  }
+
+  bool IsEmpty() const
+  {
+    return (PackSizes.IsEmpty() &&
+      PackCRCsDefined.IsEmpty() &&
+      PackCRCs.IsEmpty() &&
+      Folders.IsEmpty() &&
+      NumUnpackStreamsVector.IsEmpty() &&
+      Files.IsEmpty());
+  }
+
+  bool CheckNumFiles() const
+  {
+    int size = Files.Size();
+    return (
+      CTime.CheckSize(size) &&
+      ATime.CheckSize(size) &&
+      MTime.CheckSize(size) &&
+      StartPos.CheckSize(size) &&
+      (size == IsAnti.Size() || IsAnti.Size() == 0));
+  }
+
+  bool IsSolid() const
+  {
+    for (int i = 0; i < NumUnpackStreamsVector.Size(); i++)
+      if (NumUnpackStreamsVector[i] > 1)
+        return true;
+    return false;
+  }
+  bool IsItemAnti(int index) const { return (index < IsAnti.Size() && IsAnti[index]); }
+  void SetItemAnti(int index, bool isAnti)
+  {
+    while (index >= IsAnti.Size())
+      IsAnti.Add(false);
+    IsAnti[index] = isAnti;
+  }
+
+  void GetFile(int index, CFileItem &file, CFileItem2 &file2) const;
+  void AddFile(const CFileItem &file, const CFileItem2 &file2);
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,866 @@
+// 7zOut.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/7zCrc.h"
+
+#include "../../../Common/AutoPtr.h"
+
+#include "../../Common/StreamObjects.h"
+
+#include "7zOut.h"
+
+static HRESULT WriteBytes(ISequentialOutStream *stream, const void *data, size_t size)
+{
+  while (size > 0)
+  {
+    UInt32 curSize = (UInt32)MyMin(size, (size_t)0xFFFFFFFF);
+    UInt32 processedSize;
+    RINOK(stream->Write(data, curSize, &processedSize));
+    if (processedSize == 0)
+      return E_FAIL;
+    data = (const void *)((const Byte *)data + processedSize);
+    size -= processedSize;
+  }
+  return S_OK;
+}
+
+namespace NArchive {
+namespace N7z {
+
+HRESULT COutArchive::WriteDirect(const void *data, UInt32 size)
+{
+  return ::WriteBytes(SeqStream, data, size);
+}
+
+HRESULT COutArchive::WriteSignature()
+{
+  Byte buf[8];
+  memcpy(buf, kSignature, kSignatureSize);
+  buf[kSignatureSize] = kMajorVersion;
+  buf[kSignatureSize + 1] = 3;
+  return WriteDirect(buf, 8);
+}
+
+#ifdef _7Z_VOL
+HRESULT COutArchive::WriteFinishSignature()
+{
+  RINOK(WriteDirect(kFinishSignature, kSignatureSize));
+  CArchiveVersion av;
+  av.Major = kMajorVersion;
+  av.Minor = 2;
+  RINOK(WriteDirectByte(av.Major));
+  return WriteDirectByte(av.Minor);
+}
+#endif
+
+static void SetUInt32(Byte *p, UInt32 d)
+{
+  for (int i = 0; i < 4; i++, d >>= 8)
+    p[i] = (Byte)d;
+}
+
+static void SetUInt64(Byte *p, UInt64 d)
+{
+  for (int i = 0; i < 8; i++, d >>= 8)
+    p[i] = (Byte)d;
+}
+
+HRESULT COutArchive::WriteStartHeader(const CStartHeader &h)
+{
+  Byte buf[24];
+  SetUInt64(buf + 4, h.NextHeaderOffset);
+  SetUInt64(buf + 12, h.NextHeaderSize);
+  SetUInt32(buf + 20, h.NextHeaderCRC);
+  SetUInt32(buf, CrcCalc(buf + 4, 20));
+  return WriteDirect(buf, 24);
+}
+
+#ifdef _7Z_VOL
+HRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)
+{
+  CCRC crc;
+  crc.UpdateUInt64(h.NextHeaderOffset);
+  crc.UpdateUInt64(h.NextHeaderSize);
+  crc.UpdateUInt32(h.NextHeaderCRC);
+  crc.UpdateUInt64(h.ArchiveStartOffset);
+  crc.UpdateUInt64(h.AdditionalStartBlockSize);
+  RINOK(WriteDirectUInt32(crc.GetDigest()));
+  RINOK(WriteDirectUInt64(h.NextHeaderOffset));
+  RINOK(WriteDirectUInt64(h.NextHeaderSize));
+  RINOK(WriteDirectUInt32(h.NextHeaderCRC));
+  RINOK(WriteDirectUInt64(h.ArchiveStartOffset));
+  return WriteDirectUInt64(h.AdditionalStartBlockSize);
+}
+#endif
+
+HRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)
+{
+  Close();
+  #ifdef _7Z_VOL
+  // endMarker = false;
+  _endMarker = endMarker;
+  #endif
+  SeqStream = stream;
+  if (!endMarker)
+  {
+    SeqStream.QueryInterface(IID_IOutStream, &Stream);
+    if (!Stream)
+    {
+      return E_NOTIMPL;
+      // endMarker = true;
+    }
+  }
+  #ifdef _7Z_VOL
+  if (endMarker)
+  {
+    /*
+    CStartHeader sh;
+    sh.NextHeaderOffset = (UInt32)(Int32)-1;
+    sh.NextHeaderSize = (UInt32)(Int32)-1;
+    sh.NextHeaderCRC = 0;
+    WriteStartHeader(sh);
+    */
+  }
+  else
+  #endif
+  {
+    if (!Stream)
+      return E_FAIL;
+    RINOK(WriteSignature());
+    RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));
+  }
+  return S_OK;
+}
+
+void COutArchive::Close()
+{
+  SeqStream.Release();
+  Stream.Release();
+}
+
+HRESULT COutArchive::SkipPrefixArchiveHeader()
+{
+  #ifdef _7Z_VOL
+  if (_endMarker)
+    return S_OK;
+  #endif
+  return Stream->Seek(24, STREAM_SEEK_CUR, NULL);
+}
+
+UInt64 COutArchive::GetPos() const
+{
+  if (_countMode)
+    return _countSize;
+  if (_writeToStream)
+    return _outByte.GetProcessedSize();
+  return _outByte2.GetPos();
+}
+
+void COutArchive::WriteBytes(const void *data, size_t size)
+{
+  if (_countMode)
+    _countSize += size;
+  else if (_writeToStream)
+  {
+    _outByte.WriteBytes(data, size);
+    _crc = CrcUpdate(_crc, data, size);
+  }
+  else
+    _outByte2.WriteBytes(data, size);
+}
+
+void COutArchive::WriteByte(Byte b)
+{
+  if (_countMode)
+    _countSize++;
+  else if (_writeToStream)
+  {
+    _outByte.WriteByte(b);
+    _crc = CRC_UPDATE_BYTE(_crc, b);
+  }
+  else
+    _outByte2.WriteByte(b);
+}
+
+void COutArchive::WriteUInt32(UInt32 value)
+{
+  for (int i = 0; i < 4; i++)
+  {
+    WriteByte((Byte)value);
+    value >>= 8;
+  }
+}
+
+void COutArchive::WriteUInt64(UInt64 value)
+{
+  for (int i = 0; i < 8; i++)
+  {
+    WriteByte((Byte)value);
+    value >>= 8;
+  }
+}
+
+void COutArchive::WriteNumber(UInt64 value)
+{
+  Byte firstByte = 0;
+  Byte mask = 0x80;
+  int i;
+  for (i = 0; i < 8; i++)
+  {
+    if (value < ((UInt64(1) << ( 7  * (i + 1)))))
+    {
+      firstByte |= Byte(value >> (8 * i));
+      break;
+    }
+    firstByte |= mask;
+    mask >>= 1;
+  }
+  WriteByte(firstByte);
+  for (;i > 0; i--)
+  {
+    WriteByte((Byte)value);
+    value >>= 8;
+  }
+}
+
+static UInt32 GetBigNumberSize(UInt64 value)
+{
+  int i;
+  for (i = 1; i < 9; i++)
+    if (value < (((UInt64)1 << (i * 7))))
+      break;
+  return i;
+}
+
+#ifdef _7Z_VOL
+UInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)
+{
+  UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;
+  if (nameLength != 0)
+  {
+    nameLength = (nameLength + 1) * 2;
+    result += nameLength + GetBigNumberSize(nameLength) + 2;
+  }
+  if (props)
+  {
+    result += 20;
+  }
+  if (result >= 128)
+    result++;
+  result += kSignatureSize + 2 + kFinishHeaderSize;
+  return result;
+}
+
+UInt64 COutArchive::GetVolPureSize(UInt64 volSize, int nameLength, bool props)
+{
+  UInt32 headersSizeBase = COutArchive::GetVolHeadersSize(1, nameLength, props);
+  int testSize;
+  if (volSize > headersSizeBase)
+    testSize = volSize - headersSizeBase;
+  else
+    testSize = 1;
+  UInt32 headersSize = COutArchive::GetVolHeadersSize(testSize, nameLength, props);
+  UInt64 pureSize = 1;
+  if (volSize > headersSize)
+    pureSize = volSize - headersSize;
+  return pureSize;
+}
+#endif
+
+void COutArchive::WriteFolder(const CFolder &folder)
+{
+  WriteNumber(folder.Coders.Size());
+  int i;
+  for (i = 0; i < folder.Coders.Size(); i++)
+  {
+    const CCoderInfo &coder = folder.Coders[i];
+    {
+      size_t propsSize = coder.Props.GetCapacity();
+      
+      UInt64 id = coder.MethodID;
+      int idSize;
+      for (idSize = 1; idSize < sizeof(id); idSize++)
+        if ((id >> (8 * idSize)) == 0)
+          break;
+      BYTE longID[15];
+      for (int t = idSize - 1; t >= 0 ; t--, id >>= 8)
+        longID[t] = (Byte)(id & 0xFF);
+      Byte b;
+      b = (Byte)(idSize & 0xF);
+      bool isComplex = !coder.IsSimpleCoder();
+      b |= (isComplex ? 0x10 : 0);
+      b |= ((propsSize != 0) ? 0x20 : 0 );
+      WriteByte(b);
+      WriteBytes(longID, idSize);
+      if (isComplex)
+      {
+        WriteNumber(coder.NumInStreams);
+        WriteNumber(coder.NumOutStreams);
+      }
+      if (propsSize == 0)
+        continue;
+      WriteNumber(propsSize);
+      WriteBytes(coder.Props, propsSize);
+    }
+  }
+  for (i = 0; i < folder.BindPairs.Size(); i++)
+  {
+    const CBindPair &bindPair = folder.BindPairs[i];
+    WriteNumber(bindPair.InIndex);
+    WriteNumber(bindPair.OutIndex);
+  }
+  if (folder.PackStreams.Size() > 1)
+    for (i = 0; i < folder.PackStreams.Size(); i++)
+    {
+      WriteNumber(folder.PackStreams[i]);
+    }
+}
+
+void COutArchive::WriteBoolVector(const CBoolVector &boolVector)
+{
+  Byte b = 0;
+  Byte mask = 0x80;
+  for (int i = 0; i < boolVector.Size(); i++)
+  {
+    if (boolVector[i])
+      b |= mask;
+    mask >>= 1;
+    if (mask == 0)
+    {
+      WriteByte(b);
+      mask = 0x80;
+      b = 0;
+    }
+  }
+  if (mask != 0x80)
+    WriteByte(b);
+}
+
+
+void COutArchive::WriteHashDigests(
+    const CRecordVector<bool> &digestsDefined,
+    const CRecordVector<UInt32> &digests)
+{
+  int numDefined = 0;
+  int i;
+  for (i = 0; i < digestsDefined.Size(); i++)
+    if (digestsDefined[i])
+      numDefined++;
+  if (numDefined == 0)
+    return;
+
+  WriteByte(NID::kCRC);
+  if (numDefined == digestsDefined.Size())
+    WriteByte(1);
+  else
+  {
+    WriteByte(0);
+    WriteBoolVector(digestsDefined);
+  }
+  for (i = 0; i < digests.Size(); i++)
+    if (digestsDefined[i])
+      WriteUInt32(digests[i]);
+}
+
+void COutArchive::WritePackInfo(
+    UInt64 dataOffset,
+    const CRecordVector<UInt64> &packSizes,
+    const CRecordVector<bool> &packCRCsDefined,
+    const CRecordVector<UInt32> &packCRCs)
+{
+  if (packSizes.IsEmpty())
+    return;
+  WriteByte(NID::kPackInfo);
+  WriteNumber(dataOffset);
+  WriteNumber(packSizes.Size());
+  WriteByte(NID::kSize);
+  for (int i = 0; i < packSizes.Size(); i++)
+    WriteNumber(packSizes[i]);
+
+  WriteHashDigests(packCRCsDefined, packCRCs);
+  
+  WriteByte(NID::kEnd);
+}
+
+void COutArchive::WriteUnpackInfo(const CObjectVector<CFolder> &folders)
+{
+  if (folders.IsEmpty())
+    return;
+
+  WriteByte(NID::kUnpackInfo);
+
+  WriteByte(NID::kFolder);
+  WriteNumber(folders.Size());
+  {
+    WriteByte(0);
+    for (int i = 0; i < folders.Size(); i++)
+      WriteFolder(folders[i]);
+  }
+  
+  WriteByte(NID::kCodersUnpackSize);
+  int i;
+  for (i = 0; i < folders.Size(); i++)
+  {
+    const CFolder &folder = folders[i];
+    for (int j = 0; j < folder.UnpackSizes.Size(); j++)
+      WriteNumber(folder.UnpackSizes[j]);
+  }
+
+  CRecordVector<bool> unpackCRCsDefined;
+  CRecordVector<UInt32> unpackCRCs;
+  for (i = 0; i < folders.Size(); i++)
+  {
+    const CFolder &folder = folders[i];
+    unpackCRCsDefined.Add(folder.UnpackCRCDefined);
+    unpackCRCs.Add(folder.UnpackCRC);
+  }
+  WriteHashDigests(unpackCRCsDefined, unpackCRCs);
+
+  WriteByte(NID::kEnd);
+}
+
+void COutArchive::WriteSubStreamsInfo(
+    const CObjectVector<CFolder> &folders,
+    const CRecordVector<CNum> &numUnpackStreamsInFolders,
+    const CRecordVector<UInt64> &unpackSizes,
+    const CRecordVector<bool> &digestsDefined,
+    const CRecordVector<UInt32> &digests)
+{
+  WriteByte(NID::kSubStreamsInfo);
+
+  int i;
+  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)
+  {
+    if (numUnpackStreamsInFolders[i] != 1)
+    {
+      WriteByte(NID::kNumUnpackStream);
+      for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)
+        WriteNumber(numUnpackStreamsInFolders[i]);
+      break;
+    }
+  }
+ 
+
+  bool needFlag = true;
+  CNum index = 0;
+  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)
+    for (CNum j = 0; j < numUnpackStreamsInFolders[i]; j++)
+    {
+      if (j + 1 != numUnpackStreamsInFolders[i])
+      {
+        if (needFlag)
+          WriteByte(NID::kSize);
+        needFlag = false;
+        WriteNumber(unpackSizes[index]);
+      }
+      index++;
+    }
+
+  CRecordVector<bool> digestsDefined2;
+  CRecordVector<UInt32> digests2;
+
+  int digestIndex = 0;
+  for (i = 0; i < folders.Size(); i++)
+  {
+    int numSubStreams = (int)numUnpackStreamsInFolders[i];
+    if (numSubStreams == 1 && folders[i].UnpackCRCDefined)
+      digestIndex++;
+    else
+      for (int j = 0; j < numSubStreams; j++, digestIndex++)
+      {
+        digestsDefined2.Add(digestsDefined[digestIndex]);
+        digests2.Add(digests[digestIndex]);
+      }
+  }
+  WriteHashDigests(digestsDefined2, digests2);
+  WriteByte(NID::kEnd);
+}
+
+void COutArchive::SkipAlign(unsigned /* pos */, unsigned /* alignSize */)
+{
+  return;
+}
+
+/*
+7-Zip 4.50 - 4.58 contain BUG, so they do not support .7z archives with Unknown field.
+
+void COutArchive::SkipAlign(unsigned pos, unsigned alignSize)
+{
+  pos += (unsigned)GetPos();
+  pos &= (alignSize - 1);
+  if (pos == 0)
+    return;
+  unsigned skip = alignSize - pos;
+  if (skip < 2)
+    skip += alignSize;
+  skip -= 2;
+  WriteByte(NID::kDummy);
+  WriteByte((Byte)skip);
+  for (unsigned i = 0; i < skip; i++)
+    WriteByte(0);
+}
+*/
+
+static inline unsigned Bv_GetSizeInBytes(const CBoolVector &v) { return ((unsigned)v.Size() + 7) / 8; }
+
+void COutArchive::WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize)
+{
+  const unsigned bvSize = (numDefined == v.Size()) ? 0 : Bv_GetSizeInBytes(v);
+  const UInt64 dataSize = (UInt64)numDefined * itemSize + bvSize + 2;
+  SkipAlign(3 + (unsigned)bvSize + (unsigned)GetBigNumberSize(dataSize), itemSize);
+
+  WriteByte(type);
+  WriteNumber(dataSize);
+  if (numDefined == v.Size())
+    WriteByte(1);
+  else
+  {
+    WriteByte(0);
+    WriteBoolVector(v);
+  }
+  WriteByte(0);
+}
+
+void COutArchive::WriteUInt64DefVector(const CUInt64DefVector &v, Byte type)
+{
+  int numDefined = 0;
+
+  int i;
+  for (i = 0; i < v.Defined.Size(); i++)
+    if (v.Defined[i])
+      numDefined++;
+
+  if (numDefined == 0)
+    return;
+
+  WriteAlignedBoolHeader(v.Defined, numDefined, type, 8);
+  
+  for (i = 0; i < v.Defined.Size(); i++)
+    if (v.Defined[i])
+      WriteUInt64(v.Values[i]);
+}
+
+HRESULT COutArchive::EncodeStream(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    CEncoder &encoder, const CByteBuffer &data,
+    CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders)
+{
+  CBufInStream *streamSpec = new CBufInStream;
+  CMyComPtr<ISequentialInStream> stream = streamSpec;
+  streamSpec->Init(data, data.GetCapacity());
+  CFolder folderItem;
+  folderItem.UnpackCRCDefined = true;
+  folderItem.UnpackCRC = CrcCalc(data, data.GetCapacity());
+  UInt64 dataSize64 = data.GetCapacity();
+  RINOK(encoder.Encode(
+      EXTERNAL_CODECS_LOC_VARS
+      stream, NULL, &dataSize64, folderItem, SeqStream, packSizes, NULL))
+  folders.Add(folderItem);
+  return S_OK;
+}
+
+void COutArchive::WriteHeader(
+    const CArchiveDatabase &db,
+    const CHeaderOptions &headerOptions,
+    UInt64 &headerOffset)
+{
+  int i;
+  
+  UInt64 packedSize = 0;
+  for (i = 0; i < db.PackSizes.Size(); i++)
+    packedSize += db.PackSizes[i];
+
+  headerOffset = packedSize;
+
+  WriteByte(NID::kHeader);
+
+  // Archive Properties
+
+  if (db.Folders.Size() > 0)
+  {
+    WriteByte(NID::kMainStreamsInfo);
+    WritePackInfo(0, db.PackSizes,
+        db.PackCRCsDefined,
+        db.PackCRCs);
+
+    WriteUnpackInfo(db.Folders);
+
+    CRecordVector<UInt64> unpackSizes;
+    CRecordVector<bool> digestsDefined;
+    CRecordVector<UInt32> digests;
+    for (i = 0; i < db.Files.Size(); i++)
+    {
+      const CFileItem &file = db.Files[i];
+      if (!file.HasStream)
+        continue;
+      unpackSizes.Add(file.Size);
+      digestsDefined.Add(file.CrcDefined);
+      digests.Add(file.Crc);
+    }
+
+    WriteSubStreamsInfo(
+        db.Folders,
+        db.NumUnpackStreamsVector,
+        unpackSizes,
+        digestsDefined,
+        digests);
+    WriteByte(NID::kEnd);
+  }
+
+  if (db.Files.IsEmpty())
+  {
+    WriteByte(NID::kEnd);
+    return;
+  }
+
+  WriteByte(NID::kFilesInfo);
+  WriteNumber(db.Files.Size());
+
+  {
+  /* ---------- Empty Streams ---------- */
+  CBoolVector emptyStreamVector;
+  emptyStreamVector.Reserve(db.Files.Size());
+  int numEmptyStreams = 0;
+  for (i = 0; i < db.Files.Size(); i++)
+    if (db.Files[i].HasStream)
+      emptyStreamVector.Add(false);
+    else
+    {
+      emptyStreamVector.Add(true);
+      numEmptyStreams++;
+    }
+  if (numEmptyStreams > 0)
+  {
+    WriteByte(NID::kEmptyStream);
+    WriteNumber(Bv_GetSizeInBytes(emptyStreamVector));
+    WriteBoolVector(emptyStreamVector);
+
+    CBoolVector emptyFileVector, antiVector;
+    emptyFileVector.Reserve(numEmptyStreams);
+    antiVector.Reserve(numEmptyStreams);
+    CNum numEmptyFiles = 0, numAntiItems = 0;
+    for (i = 0; i < db.Files.Size(); i++)
+    {
+      const CFileItem &file = db.Files[i];
+      if (!file.HasStream)
+      {
+        emptyFileVector.Add(!file.IsDir);
+        if (!file.IsDir)
+          numEmptyFiles++;
+        bool isAnti = db.IsItemAnti(i);
+        antiVector.Add(isAnti);
+        if (isAnti)
+          numAntiItems++;
+      }
+    }
+
+    if (numEmptyFiles > 0)
+    {
+      WriteByte(NID::kEmptyFile);
+      WriteNumber(Bv_GetSizeInBytes(emptyFileVector));
+      WriteBoolVector(emptyFileVector);
+    }
+
+    if (numAntiItems > 0)
+    {
+      WriteByte(NID::kAnti);
+      WriteNumber(Bv_GetSizeInBytes(antiVector));
+      WriteBoolVector(antiVector);
+    }
+  }
+  }
+
+
+  {
+    /* ---------- Names ---------- */
+    
+    int numDefined = 0;
+    size_t namesDataSize = 0;
+    for (int i = 0; i < db.Files.Size(); i++)
+    {
+      const UString &name = db.Files[i].Name;
+      if (!name.IsEmpty())
+        numDefined++;
+      namesDataSize += (name.Length() + 1) * 2;
+    }
+    
+    if (numDefined > 0)
+    {
+      namesDataSize++;
+      SkipAlign(2 + GetBigNumberSize(namesDataSize), 2);
+
+      WriteByte(NID::kName);
+      WriteNumber(namesDataSize);
+      WriteByte(0);
+      for (int i = 0; i < db.Files.Size(); i++)
+      {
+        const UString &name = db.Files[i].Name;
+        for (int t = 0; t <= name.Length(); t++)
+        {
+          wchar_t c = name[t];
+          WriteByte((Byte)c);
+          WriteByte((Byte)(c >> 8));
+        }
+      }
+    }
+  }
+
+  if (headerOptions.WriteCTime) WriteUInt64DefVector(db.CTime, NID::kCTime);
+  if (headerOptions.WriteATime) WriteUInt64DefVector(db.ATime, NID::kATime);
+  if (headerOptions.WriteMTime) WriteUInt64DefVector(db.MTime, NID::kMTime);
+  WriteUInt64DefVector(db.StartPos, NID::kStartPos);
+  
+  {
+    /* ---------- Write Attrib ---------- */
+    CBoolVector boolVector;
+    boolVector.Reserve(db.Files.Size());
+    int numDefined = 0;
+    for (i = 0; i < db.Files.Size(); i++)
+    {
+      bool defined = db.Files[i].AttribDefined;
+      boolVector.Add(defined);
+      if (defined)
+        numDefined++;
+    }
+    if (numDefined > 0)
+    {
+      WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttributes, 4);
+      for (i = 0; i < db.Files.Size(); i++)
+      {
+        const CFileItem &file = db.Files[i];
+        if (file.AttribDefined)
+          WriteUInt32(file.Attrib);
+      }
+    }
+  }
+
+  WriteByte(NID::kEnd); // for files
+  WriteByte(NID::kEnd); // for headers
+}
+
+HRESULT COutArchive::WriteDatabase(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    const CArchiveDatabase &db,
+    const CCompressionMethodMode *options,
+    const CHeaderOptions &headerOptions)
+{
+  if (!db.CheckNumFiles())
+    return E_FAIL;
+
+  UInt64 headerOffset;
+  UInt32 headerCRC;
+  UInt64 headerSize;
+  if (db.IsEmpty())
+  {
+    headerSize = 0;
+    headerOffset = 0;
+    headerCRC = CrcCalc(0, 0);
+  }
+  else
+  {
+    bool encodeHeaders = false;
+    if (options != 0)
+      if (options->IsEmpty())
+        options = 0;
+    if (options != 0)
+      if (options->PasswordIsDefined || headerOptions.CompressMainHeader)
+        encodeHeaders = true;
+
+    _outByte.SetStream(SeqStream);
+    _outByte.Init();
+    _crc = CRC_INIT_VAL;
+    _countMode = encodeHeaders;
+    _writeToStream = true;
+    _countSize = 0;
+    WriteHeader(db, headerOptions, headerOffset);
+
+    if (encodeHeaders)
+    {
+      CByteBuffer buf;
+      buf.SetCapacity(_countSize);
+      _outByte2.Init((Byte *)buf, _countSize);
+      
+      _countMode = false;
+      _writeToStream = false;
+      WriteHeader(db, headerOptions, headerOffset);
+      
+      if (_countSize != _outByte2.GetPos())
+        return E_FAIL;
+
+      CCompressionMethodMode encryptOptions;
+      encryptOptions.PasswordIsDefined = options->PasswordIsDefined;
+      encryptOptions.Password = options->Password;
+      CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions);
+      CRecordVector<UInt64> packSizes;
+      CObjectVector<CFolder> folders;
+      RINOK(EncodeStream(
+          EXTERNAL_CODECS_LOC_VARS
+          encoder, buf,
+          packSizes, folders));
+
+      _writeToStream = true;
+      
+      if (folders.Size() == 0)
+        throw 1;
+
+      WriteID(NID::kEncodedHeader);
+      WritePackInfo(headerOffset, packSizes,
+        CRecordVector<bool>(), CRecordVector<UInt32>());
+      WriteUnpackInfo(folders);
+      WriteByte(NID::kEnd);
+      for (int i = 0; i < packSizes.Size(); i++)
+        headerOffset += packSizes[i];
+    }
+    RINOK(_outByte.Flush());
+    headerCRC = CRC_GET_DIGEST(_crc);
+    headerSize = _outByte.GetProcessedSize();
+  }
+  #ifdef _7Z_VOL
+  if (_endMarker)
+  {
+    CFinishHeader h;
+    h.NextHeaderSize = headerSize;
+    h.NextHeaderCRC = headerCRC;
+    h.NextHeaderOffset =
+        UInt64(0) - (headerSize +
+        4 + kFinishHeaderSize);
+    h.ArchiveStartOffset = h.NextHeaderOffset - headerOffset;
+    h.AdditionalStartBlockSize = 0;
+    RINOK(WriteFinishHeader(h));
+    return WriteFinishSignature();
+  }
+  else
+  #endif
+  {
+    CStartHeader h;
+    h.NextHeaderSize = headerSize;
+    h.NextHeaderCRC = headerCRC;
+    h.NextHeaderOffset = headerOffset;
+    RINOK(Stream->Seek(_prefixHeaderPos, STREAM_SEEK_SET, NULL));
+    return WriteStartHeader(h);
+  }
+}
+
+void CArchiveDatabase::GetFile(int index, CFileItem &file, CFileItem2 &file2) const
+{
+  file = Files[index];
+  file2.CTimeDefined = CTime.GetItem(index, file2.CTime);
+  file2.ATimeDefined = ATime.GetItem(index, file2.ATime);
+  file2.MTimeDefined = MTime.GetItem(index, file2.MTime);
+  file2.StartPosDefined = StartPos.GetItem(index, file2.StartPos);
+  file2.IsAnti = IsItemAnti(index);
+}
+
+void CArchiveDatabase::AddFile(const CFileItem &file, const CFileItem2 &file2)
+{
+  int index = Files.Size();
+  CTime.SetItem(index, file2.CTimeDefined, file2.CTime);
+  ATime.SetItem(index, file2.ATimeDefined, file2.ATime);
+  MTime.SetItem(index, file2.MTimeDefined, file2.MTime);
+  StartPos.SetItem(index, file2.StartPosDefined, file2.StartPos);
+  SetItemAnti(index, file2.IsAnti);
+  Files.Add(file);
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zOut.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,152 @@
+// 7zOut.h
+
+#ifndef __7Z_OUT_H
+#define __7Z_OUT_H
+
+#include "7zCompressionMode.h"
+#include "7zEncode.h"
+#include "7zHeader.h"
+#include "7zItem.h"
+
+#include "../../Common/OutBuffer.h"
+
+namespace NArchive {
+namespace N7z {
+
+class CWriteBufferLoc
+{
+  Byte *_data;
+  size_t _size;
+  size_t _pos;
+public:
+  CWriteBufferLoc(): _size(0), _pos(0) {}
+  void Init(Byte *data, size_t size)
+  {
+    _data = data;
+    _size = size;
+    _pos = 0;
+  }
+  void WriteBytes(const void *data, size_t size)
+  {
+    if (size > _size - _pos)
+      throw 1;
+    memcpy(_data + _pos, data, size);
+    _pos += size;
+  }
+  void WriteByte(Byte b)
+  {
+    if (_size == _pos)
+      throw 1;
+    _data[_pos++] = b;
+  }
+  size_t GetPos() const { return _pos; }
+};
+
+struct CHeaderOptions
+{
+  bool CompressMainHeader;
+  bool WriteCTime;
+  bool WriteATime;
+  bool WriteMTime;
+
+  CHeaderOptions():
+      CompressMainHeader(true),
+      WriteCTime(false),
+      WriteATime(false),
+      WriteMTime(true)
+      {}
+};
+
+class COutArchive
+{
+  UInt64 _prefixHeaderPos;
+
+  HRESULT WriteDirect(const void *data, UInt32 size);
+  
+  UInt64 GetPos() const;
+  void WriteBytes(const void *data, size_t size);
+  void WriteBytes(const CByteBuffer &data) { WriteBytes(data, data.GetCapacity()); }
+  void WriteByte(Byte b);
+  void WriteUInt32(UInt32 value);
+  void WriteUInt64(UInt64 value);
+  void WriteNumber(UInt64 value);
+  void WriteID(UInt64 value) { WriteNumber(value); }
+
+  void WriteFolder(const CFolder &folder);
+  HRESULT WriteFileHeader(const CFileItem &itemInfo);
+  void WriteBoolVector(const CBoolVector &boolVector);
+  void WriteHashDigests(
+      const CRecordVector<bool> &digestsDefined,
+      const CRecordVector<UInt32> &hashDigests);
+
+  void WritePackInfo(
+      UInt64 dataOffset,
+      const CRecordVector<UInt64> &packSizes,
+      const CRecordVector<bool> &packCRCsDefined,
+      const CRecordVector<UInt32> &packCRCs);
+
+  void WriteUnpackInfo(const CObjectVector<CFolder> &folders);
+
+  void WriteSubStreamsInfo(
+      const CObjectVector<CFolder> &folders,
+      const CRecordVector<CNum> &numUnpackStreamsInFolders,
+      const CRecordVector<UInt64> &unpackSizes,
+      const CRecordVector<bool> &digestsDefined,
+      const CRecordVector<UInt32> &hashDigests);
+
+  void SkipAlign(unsigned pos, unsigned alignSize);
+  void WriteAlignedBoolHeader(const CBoolVector &v, int numDefined, Byte type, unsigned itemSize);
+  void WriteUInt64DefVector(const CUInt64DefVector &v, Byte type);
+
+  HRESULT EncodeStream(
+      DECL_EXTERNAL_CODECS_LOC_VARS
+      CEncoder &encoder, const CByteBuffer &data,
+      CRecordVector<UInt64> &packSizes, CObjectVector<CFolder> &folders);
+  void WriteHeader(
+      const CArchiveDatabase &db,
+      const CHeaderOptions &headerOptions,
+      UInt64 &headerOffset);
+  
+  bool _countMode;
+  bool _writeToStream;
+  size_t _countSize;
+  UInt32 _crc;
+  COutBuffer _outByte;
+  CWriteBufferLoc _outByte2;
+
+  #ifdef _7Z_VOL
+  bool _endMarker;
+  #endif
+
+  HRESULT WriteSignature();
+  #ifdef _7Z_VOL
+  HRESULT WriteFinishSignature();
+  #endif
+  HRESULT WriteStartHeader(const CStartHeader &h);
+  #ifdef _7Z_VOL
+  HRESULT WriteFinishHeader(const CFinishHeader &h);
+  #endif
+  CMyComPtr<IOutStream> Stream;
+public:
+
+  COutArchive() { _outByte.Create(1 << 16); }
+  CMyComPtr<ISequentialOutStream> SeqStream;
+  HRESULT Create(ISequentialOutStream *stream, bool endMarker);
+  void Close();
+  HRESULT SkipPrefixArchiveHeader();
+  HRESULT WriteDatabase(
+      DECL_EXTERNAL_CODECS_LOC_VARS
+      const CArchiveDatabase &db,
+      const CCompressionMethodMode *options,
+      const CHeaderOptions &headerOptions);
+
+  #ifdef _7Z_VOL
+  static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false);
+  static UInt64 GetVolPureSize(UInt64 volSize, int nameLength = 0, bool props = false);
+  #endif
+
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,164 @@
+// 7zProperties.cpp
+
+#include "StdAfx.h"
+
+#include "7zProperties.h"
+#include "7zHeader.h"
+#include "7zHandler.h"
+
+// #define _MULTI_PACK
+
+namespace NArchive {
+namespace N7z {
+
+struct CPropMap
+{
+  UInt64 FilePropID;
+  STATPROPSTG StatPROPSTG;
+};
+
+CPropMap kPropMap[] =
+{
+  { NID::kName, { NULL, kpidPath, VT_BSTR } },
+  { NID::kSize, { NULL, kpidSize, VT_UI8 } },
+  { NID::kPackInfo, { NULL, kpidPackSize, VT_UI8 } },
+  
+  #ifdef _MULTI_PACK
+  { 100, { L"Pack0", kpidPackedSize0, VT_UI8 } },
+  { 101, { L"Pack1", kpidPackedSize1, VT_UI8 } },
+  { 102, { L"Pack2", kpidPackedSize2, VT_UI8 } },
+  { 103, { L"Pack3", kpidPackedSize3, VT_UI8 } },
+  { 104, { L"Pack4", kpidPackedSize4, VT_UI8 } },
+  #endif
+
+  { NID::kCTime, { NULL, kpidCTime, VT_FILETIME } },
+  { NID::kMTime, { NULL, kpidMTime, VT_FILETIME } },
+  { NID::kATime, { NULL, kpidATime, VT_FILETIME } },
+  { NID::kWinAttributes, { NULL, kpidAttrib, VT_UI4 } },
+  { NID::kStartPos, { NULL, kpidPosition, VT_UI4 } },
+
+  { NID::kCRC, { NULL, kpidCRC, VT_UI4 } },
+  
+  { NID::kAnti, { NULL, kpidIsAnti, VT_BOOL } }
+
+  #ifndef _SFX
+  ,
+  { 97, { NULL,kpidEncrypted, VT_BOOL } },
+  { 98, { NULL,kpidMethod, VT_BSTR } },
+  { 99, { NULL,kpidBlock, VT_UI4 } }
+  #endif
+};
+
+static const int kPropMapSize = sizeof(kPropMap) / sizeof(kPropMap[0]);
+
+static int FindPropInMap(UInt64 filePropID)
+{
+  for (int i = 0; i < kPropMapSize; i++)
+    if (kPropMap[i].FilePropID == filePropID)
+      return i;
+  return -1;
+}
+
+static void CopyOneItem(CRecordVector<UInt64> &src,
+    CRecordVector<UInt64> &dest, UInt32 item)
+{
+  for (int i = 0; i < src.Size(); i++)
+    if (src[i] == item)
+    {
+      dest.Add(item);
+      src.Delete(i);
+      return;
+    }
+}
+
+static void RemoveOneItem(CRecordVector<UInt64> &src, UInt32 item)
+{
+  for (int i = 0; i < src.Size(); i++)
+    if (src[i] == item)
+    {
+      src.Delete(i);
+      return;
+    }
+}
+
+static void InsertToHead(CRecordVector<UInt64> &dest, UInt32 item)
+{
+  for (int i = 0; i < dest.Size(); i++)
+    if (dest[i] == item)
+    {
+      dest.Delete(i);
+      break;
+    }
+  dest.Insert(0, item);
+}
+
+void CHandler::FillPopIDs()
+{
+  _fileInfoPopIDs.Clear();
+
+  #ifdef _7Z_VOL
+  if(_volumes.Size() < 1)
+    return;
+  const CVolume &volume = _volumes.Front();
+  const CArchiveDatabaseEx &_db = volume.Database;
+  #endif
+
+  CRecordVector<UInt64> fileInfoPopIDs = _db.ArchiveInfo.FileInfoPopIDs;
+
+  RemoveOneItem(fileInfoPopIDs, NID::kEmptyStream);
+  RemoveOneItem(fileInfoPopIDs, NID::kEmptyFile);
+
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kName);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kAnti);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kSize);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kPackInfo);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCTime);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kMTime);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kATime);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kWinAttributes);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kCRC);
+  CopyOneItem(fileInfoPopIDs, _fileInfoPopIDs, NID::kComment);
+  _fileInfoPopIDs += fileInfoPopIDs;
+ 
+  #ifndef _SFX
+  _fileInfoPopIDs.Add(97);
+  _fileInfoPopIDs.Add(98);
+  _fileInfoPopIDs.Add(99);
+  #endif
+  #ifdef _MULTI_PACK
+  _fileInfoPopIDs.Add(100);
+  _fileInfoPopIDs.Add(101);
+  _fileInfoPopIDs.Add(102);
+  _fileInfoPopIDs.Add(103);
+  _fileInfoPopIDs.Add(104);
+  #endif
+
+  #ifndef _SFX
+  InsertToHead(_fileInfoPopIDs, NID::kMTime);
+  InsertToHead(_fileInfoPopIDs, NID::kPackInfo);
+  InsertToHead(_fileInfoPopIDs, NID::kSize);
+  InsertToHead(_fileInfoPopIDs, NID::kName);
+  #endif
+}
+
+STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties)
+{
+  *numProperties = _fileInfoPopIDs.Size();
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
+{
+  if ((int)index >= _fileInfoPopIDs.Size())
+    return E_INVALIDARG;
+  int indexInMap = FindPropInMap(_fileInfoPopIDs[index]);
+  if (indexInMap == -1)
+    return E_INVALIDARG;
+  const STATPROPSTG &srcItem = kPropMap[indexInMap].StatPROPSTG;
+  *propID = srcItem.propid;
+  *varType = srcItem.vt;
+  *name = 0;
+  return S_OK;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zProperties.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,22 @@
+// 7zProperties.h
+
+#ifndef __7Z_PROPERTIES_H
+#define __7Z_PROPERTIES_H
+
+#include "../../PropID.h"
+
+namespace NArchive {
+namespace N7z {
+
+enum
+{
+  kpidPackedSize0 = kpidUserDefined,
+  kpidPackedSize1,
+  kpidPackedSize2,
+  kpidPackedSize3,
+  kpidPackedSize4
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,18 @@
+// 7zRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/RegisterArc.h"
+
+#include "7zHandler.h"
+static IInArchive *CreateArc() { return new NArchive::N7z::CHandler; }
+#ifndef EXTRACT_ONLY
+static IOutArchive *CreateArcOut() { return new NArchive::N7z::CHandler; }
+#else
+#define CreateArcOut 0
+#endif
+
+static CArcInfo g_ArcInfo =
+  { L"7z", L"7z", 0, 7, {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}, 6, false, CreateArc, CreateArcOut };
+
+REGISTER_ARC(7z)

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,24 @@
+// 7zSpecStream.cpp
+
+#include "StdAfx.h"
+
+#include "7zSpecStream.h"
+
+STDMETHODIMP CSequentialInStreamSizeCount2::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+  UInt32 realProcessedSize;
+  HRESULT result = _stream->Read(data, size, &realProcessedSize);
+  _size += realProcessedSize;
+  if (processedSize != 0)
+    *processedSize = realProcessedSize;
+  return result;
+}
+
+STDMETHODIMP CSequentialInStreamSizeCount2::GetSubStreamSize(
+    UInt64 subStream, UInt64 *value)
+{
+  if (_getSubStreamSize == NULL)
+    return E_NOTIMPL;
+  return  _getSubStreamSize->GetSubStreamSize(subStream, value);
+}
+

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zSpecStream.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,35 @@
+// 7zSpecStream.h
+
+#ifndef __7Z_SPEC_STREAM_H
+#define __7Z_SPEC_STREAM_H
+
+#include "../../IStream.h"
+#include "../../ICoder.h"
+#include "../../../Common/MyCom.h"
+
+class CSequentialInStreamSizeCount2:
+  public ISequentialInStream,
+  public ICompressGetSubStreamSize,
+  public CMyUnknownImp
+{
+  CMyComPtr<ISequentialInStream> _stream;
+  CMyComPtr<ICompressGetSubStreamSize> _getSubStreamSize;
+  UInt64 _size;
+public:
+  void Init(ISequentialInStream *stream)
+  {
+    _stream = stream;
+    _getSubStreamSize = 0;
+    _stream.QueryInterface(IID_ICompressGetSubStreamSize, &_getSubStreamSize);
+    _size = 0;
+  }
+  UInt64 GetSize() const { return _size; }
+
+  MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
+
+  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+
+  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
+};
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,1216 @@
+// 7zUpdate.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/CpuArch.h"
+
+#include "../../Common/LimitedStreams.h"
+#include "../../Common/ProgressUtils.h"
+
+#include "../../Common/CreateCoder.h"
+
+#include "../../Compress/CopyCoder.h"
+
+#include "../Common/ItemNameUtils.h"
+#include "../Common/OutStreamWithCRC.h"
+
+#include "7zDecode.h"
+#include "7zEncode.h"
+#include "7zFolderInStream.h"
+#include "7zHandler.h"
+#include "7zOut.h"
+#include "7zUpdate.h"
+
+#ifndef WIN32
+#include "Windows/FileIO.h"
+#endif
+
+namespace NArchive {
+namespace N7z {
+
+static const UInt64 k_LZMA = 0x030101;
+static const UInt64 k_BCJ  = 0x03030103;
+static const UInt64 k_BCJ2 = 0x0303011B;
+
+static const wchar_t *kMatchFinderForBCJ2_LZMA = L"BT2";
+static const UInt32 kDictionaryForBCJ2_LZMA = 1 << 20;
+static const UInt32 kAlgorithmForBCJ2_LZMA = 1;
+static const UInt32 kNumFastBytesForBCJ2_LZMA = 64;
+
+#ifdef MY_CPU_X86_OR_AMD64
+#define USE_86_FILTER
+#endif
+
+static HRESULT WriteRange(IInStream *inStream, ISequentialOutStream *outStream,
+    UInt64 position, UInt64 size, ICompressProgressInfo *progress)
+{
+  RINOK(inStream->Seek(position, STREAM_SEEK_SET, 0));
+  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
+  CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);
+  streamSpec->SetStream(inStream);
+  streamSpec->Init(size);
+
+  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
+  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
+  RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));
+  return (copyCoderSpec->TotalSize == size ? S_OK : E_FAIL);
+}
+
+static int GetReverseSlashPos(const UString &name)
+{
+  int slashPos = name.ReverseFind(L'/');
+  #ifdef _WIN32
+  int slash1Pos = name.ReverseFind(L'\\');
+  slashPos = MyMax(slashPos, slash1Pos);
+  #endif
+  return slashPos;
+}
+
+int CUpdateItem::GetExtensionPos() const
+{
+  int slashPos = GetReverseSlashPos(Name);
+  int dotPos = Name.ReverseFind(L'.');
+  if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))
+    return Name.Length();
+  return dotPos + 1;
+}
+
+UString CUpdateItem::GetExtension() const
+{
+  return Name.Mid(GetExtensionPos());
+}
+
+#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
+
+#define RINOZ_COMP(a, b) RINOZ(MyCompare(a, b))
+
+static int CompareBuffers(const CByteBuffer &a1, const CByteBuffer &a2)
+{
+  size_t c1 = a1.GetCapacity();
+  size_t c2 = a2.GetCapacity();
+  RINOZ_COMP(c1, c2);
+  for (size_t i = 0; i < c1; i++)
+    RINOZ_COMP(a1[i], a2[i]);
+  return 0;
+}
+
+static int CompareCoders(const CCoderInfo &c1, const CCoderInfo &c2)
+{
+  RINOZ_COMP(c1.NumInStreams, c2.NumInStreams);
+  RINOZ_COMP(c1.NumOutStreams, c2.NumOutStreams);
+  RINOZ_COMP(c1.MethodID, c2.MethodID);
+  return CompareBuffers(c1.Props, c2.Props);
+}
+
+static int CompareBindPairs(const CBindPair &b1, const CBindPair &b2)
+{
+  RINOZ_COMP(b1.InIndex, b2.InIndex);
+  return MyCompare(b1.OutIndex, b2.OutIndex);
+}
+
+static int CompareFolders(const CFolder &f1, const CFolder &f2)
+{
+  int s1 = f1.Coders.Size();
+  int s2 = f2.Coders.Size();
+  RINOZ_COMP(s1, s2);
+  int i;
+  for (i = 0; i < s1; i++)
+    RINOZ(CompareCoders(f1.Coders[i], f2.Coders[i]));
+  s1 = f1.BindPairs.Size();
+  s2 = f2.BindPairs.Size();
+  RINOZ_COMP(s1, s2);
+  for (i = 0; i < s1; i++)
+    RINOZ(CompareBindPairs(f1.BindPairs[i], f2.BindPairs[i]));
+  return 0;
+}
+
+/*
+static int CompareFiles(const CFileItem &f1, const CFileItem &f2)
+{
+  return MyStringCompareNoCase(f1.Name, f2.Name);
+}
+*/
+
+struct CFolderRepack
+{
+  int FolderIndex;
+  int Group;
+  CNum NumCopyFiles;
+};
+
+static int CompareFolderRepacks(const CFolderRepack *p1, const CFolderRepack *p2, void *param)
+{
+  RINOZ_COMP(p1->Group, p2->Group);
+  int i1 = p1->FolderIndex;
+  int i2 = p2->FolderIndex;
+  const CArchiveDatabaseEx &db = *(const CArchiveDatabaseEx *)param;
+  RINOZ(CompareFolders(
+      db.Folders[i1],
+      db.Folders[i2]));
+  return MyCompare(i1, i2);
+  /*
+  RINOZ_COMP(
+      db.NumUnpackStreamsVector[i1],
+      db.NumUnpackStreamsVector[i2]);
+  if (db.NumUnpackStreamsVector[i1] == 0)
+    return 0;
+  return CompareFiles(
+      db.Files[db.FolderStartFileIndex[i1]],
+      db.Files[db.FolderStartFileIndex[i2]]);
+  */
+}
+
+////////////////////////////////////////////////////////////
+
+static int CompareEmptyItems(const int *p1, const int *p2, void *param)
+{
+  const CObjectVector<CUpdateItem> &updateItems = *(const CObjectVector<CUpdateItem> *)param;
+  const CUpdateItem &u1 = updateItems[*p1];
+  const CUpdateItem &u2 = updateItems[*p2];
+  if (u1.IsDir != u2.IsDir)
+    return (u1.IsDir) ? 1 : -1;
+  if (u1.IsDir)
+  {
+    if (u1.IsAnti != u2.IsAnti)
+      return (u1.IsAnti ? 1 : -1);
+    int n = MyStringCompareNoCase(u1.Name, u2.Name);
+    return -n;
+  }
+  if (u1.IsAnti != u2.IsAnti)
+    return (u1.IsAnti ? 1 : -1);
+  return MyStringCompareNoCase(u1.Name, u2.Name);
+}
+
+static const char *g_Exts =
+  " lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo"
+  " zip jar ear war msi"
+  " 3gp avi mov mpeg mpg mpe wmv"
+  " aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav"
+  " swf "
+  " chm hxi hxs"
+  " gif jpeg jpg jp2 png tiff  bmp ico psd psp"
+  " awg ps eps cgm dxf svg vrml wmf emf ai md"
+  " cad dwg pps key sxi"
+  " max 3ds"
+  " iso bin nrg mdf img pdi tar cpio xpi"
+  " vfd vhd vud vmc vsv"
+  " vmdk dsk nvram vmem vmsd vmsn vmss vmtm"
+  " inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def"
+  " f77 f f90 f95"
+  " asm sql manifest dep "
+  " mak clw csproj vcproj sln dsp dsw "
+  " class "
+  " bat cmd"
+  " xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml"
+  " awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs"
+  " text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf"
+  " sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf"
+  " abw afp cwk lwp wpd wps wpt wrf wri"
+  " abf afm bdf fon mgf otf pcf pfa snf ttf"
+  " dbf mdb nsf ntf wdb db fdb gdb"
+  " exe dll ocx vbx sfx sys tlb awx com obj lib out o so "
+  " pdb pch idb ncb opt";
+
+int GetExtIndex(const char *ext)
+{
+  int extIndex = 1;
+  const char *p = g_Exts;
+  for (;;)
+  {
+    char c = *p++;
+    if (c == 0)
+      return extIndex;
+    if (c == ' ')
+      continue;
+    int pos = 0;
+    for (;;)
+    {
+      char c2 = ext[pos++];
+      if (c2 == 0 && (c == 0 || c == ' '))
+        return extIndex;
+      if (c != c2)
+        break;
+      c = *p++;
+    }
+    extIndex++;
+    for (;;)
+    {
+      if (c == 0)
+        return extIndex;
+      if (c == ' ')
+        break;
+      c = *p++;
+    }
+  }
+}
+
+struct CRefItem
+{
+  const CUpdateItem *UpdateItem;
+  UInt32 Index;
+  UInt32 ExtensionPos;
+  UInt32 NamePos;
+  int ExtensionIndex;
+  CRefItem(UInt32 index, const CUpdateItem &ui, bool sortByType):
+    UpdateItem(&ui),
+    Index(index),
+    ExtensionPos(0),
+    NamePos(0),
+    ExtensionIndex(0)
+  {
+    if (sortByType)
+    {
+      int slashPos = GetReverseSlashPos(ui.Name);
+      NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0);
+      int dotPos = ui.Name.ReverseFind(L'.');
+      if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0))
+        ExtensionPos = ui.Name.Length();
+      else
+      {
+        ExtensionPos = dotPos + 1;
+        UString us = ui.Name.Mid(ExtensionPos);
+        if (!us.IsEmpty())
+        {
+          us.MakeLower();
+          int i;
+          AString s;
+          for (i = 0; i < us.Length(); i++)
+          {
+            wchar_t c = us[i];
+            if (c >= 0x80)
+              break;
+            s += (char)c;
+          }
+          if (i == us.Length())
+            ExtensionIndex = GetExtIndex(s);
+          else
+            ExtensionIndex = 0;
+        }
+      }
+    }
+  }
+};
+
+static int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *param)
+{
+  const CRefItem &a1 = *p1;
+  const CRefItem &a2 = *p2;
+  const CUpdateItem &u1 = *a1.UpdateItem;
+  const CUpdateItem &u2 = *a2.UpdateItem;
+  int n;
+  if (u1.IsDir != u2.IsDir)
+    return (u1.IsDir) ? 1 : -1;
+  if (u1.IsDir)
+  {
+    if (u1.IsAnti != u2.IsAnti)
+      return (u1.IsAnti ? 1 : -1);
+    n = MyStringCompareNoCase(u1.Name, u2.Name);
+    return -n;
+  }
+  bool sortByType = *(bool *)param;
+  if (sortByType)
+  {
+    RINOZ_COMP(a1.ExtensionIndex, a2.ExtensionIndex);
+    RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos));
+    RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos));
+    if (!u1.MTimeDefined && u2.MTimeDefined) return 1;
+    if (u1.MTimeDefined && !u2.MTimeDefined) return -1;
+    if (u1.MTimeDefined && u2.MTimeDefined) RINOZ_COMP(u1.MTime, u2.MTime);
+    RINOZ_COMP(u1.Size, u2.Size);
+  }
+  return MyStringCompareNoCase(u1.Name, u2.Name);
+}
+
+struct CSolidGroup
+{
+  CRecordVector<UInt32> Indices;
+};
+
+#ifdef _WIN32
+static wchar_t *g_ExeExts[] =
+{
+  L"dll",
+  L"exe",
+  L"ocx",
+  L"sfx",
+  L"sys"
+};
+
+static bool IsExeExt(const UString &ext)
+{
+  for (int i = 0; i < sizeof(g_ExeExts) / sizeof(g_ExeExts[0]); i++)
+    if (ext.CompareNoCase(g_ExeExts[i]) == 0)
+      return true;
+  return false;
+}
+#else
+static bool IsExeFile(const CUpdateItem &ui)
+{
+  if (ui.Attrib & FILE_ATTRIBUTE_UNIX_EXTENSION) {
+    unsigned short st_mode =  ui.Attrib >> 16;
+    if ((st_mode & 00111) && (ui.Size >= 2048))
+    {
+      // file has the execution flag and it's big enought
+      // try to find if the file is a script
+      NWindows::NFile::NIO::CInFile file;
+      if (file.Open(ui.Name))
+      {
+        char buffer[512];
+        UINT32 processedSize;
+        if (file.Read(buffer,sizeof(buffer),processedSize))
+        {
+          for(UInt32 i = 0; i < processedSize ; i++)
+          {
+            if (buffer[i] == 0) 
+	    {
+              return true; // this file is not a text (ascii, utf8, ...) !
+	    }
+          }
+       }
+     }
+   }
+  } 
+  return false;
+}
+#endif
+
+#ifdef USE_86_FILTER
+
+static inline void GetMethodFull(UInt64 methodID, UInt32 numInStreams, CMethodFull &methodResult)
+{
+  methodResult.Id = methodID;
+  methodResult.NumInStreams = numInStreams;
+  methodResult.NumOutStreams = 1;
+}
+
+static void MakeExeMethod(const CCompressionMethodMode &method,
+    bool bcj2Filter, CCompressionMethodMode &exeMethod)
+{
+  exeMethod = method;
+  if (bcj2Filter)
+  {
+    CMethodFull methodFull;
+    GetMethodFull(k_BCJ2, 4, methodFull);
+    exeMethod.Methods.Insert(0, methodFull);
+    GetMethodFull(k_LZMA, 1, methodFull);
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kAlgorithm;
+      prop.Value = kAlgorithmForBCJ2_LZMA;
+      methodFull.Props.Add(prop);
+    }
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kMatchFinder;
+      prop.Value = kMatchFinderForBCJ2_LZMA;
+      methodFull.Props.Add(prop);
+    }
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kDictionarySize;
+      prop.Value = kDictionaryForBCJ2_LZMA;
+      methodFull.Props.Add(prop);
+    }
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kNumFastBytes;
+      prop.Value = kNumFastBytesForBCJ2_LZMA;
+      methodFull.Props.Add(prop);
+    }
+    {
+      CProp prop;
+      prop.Id = NCoderPropID::kNumThreads;
+      prop.Value = (UInt32)1;
+      methodFull.Props.Add(prop);
+    }
+
+    exeMethod.Methods.Add(methodFull);
+    exeMethod.Methods.Add(methodFull);
+    CBind bind;
+
+    bind.OutCoder = 0;
+    bind.InStream = 0;
+
+    bind.InCoder = 1;
+    bind.OutStream = 0;
+    exeMethod.Binds.Add(bind);
+
+    bind.InCoder = 2;
+    bind.OutStream = 1;
+    exeMethod.Binds.Add(bind);
+
+    bind.InCoder = 3;
+    bind.OutStream = 2;
+    exeMethod.Binds.Add(bind);
+  }
+  else
+  {
+    CMethodFull methodFull;
+    GetMethodFull(k_BCJ, 1, methodFull);
+    exeMethod.Methods.Insert(0, methodFull);
+    CBind bind;
+    bind.OutCoder = 0;
+    bind.InStream = 0;
+    bind.InCoder = 1;
+    bind.OutStream = 0;
+    exeMethod.Binds.Add(bind);
+  }
+}
+
+#endif
+
+static void FromUpdateItemToFileItem(const CUpdateItem &ui,
+    CFileItem &file, CFileItem2 &file2)
+{
+  file.Name = NItemName::MakeLegalName(ui.Name);
+  if (ui.AttribDefined)
+    file.SetAttrib(ui.Attrib);
+  
+  file2.CTime = ui.CTime;  file2.CTimeDefined = ui.CTimeDefined;
+  file2.ATime = ui.ATime;  file2.ATimeDefined = ui.ATimeDefined;
+  file2.MTime = ui.MTime;  file2.MTimeDefined = ui.MTimeDefined;
+  file2.IsAnti = ui.IsAnti;
+  file2.StartPosDefined = false;
+
+  file.Size = ui.Size;
+  file.IsDir = ui.IsDir;
+  file.HasStream = ui.HasStream();
+}
+
+class CFolderOutStream2:
+  public ISequentialOutStream,
+  public CMyUnknownImp
+{
+  COutStreamWithCRC *_crcStreamSpec;
+  CMyComPtr<ISequentialOutStream> _crcStream;
+  const CArchiveDatabaseEx *_db;
+  const CBoolVector *_extractStatuses;
+  CMyComPtr<ISequentialOutStream> _outStream;
+  UInt32 _startIndex;
+  int _currentIndex;
+  bool _fileIsOpen;
+  UInt64 _rem;
+
+  void OpenFile();
+  void CloseFile();
+  HRESULT CloseFileAndSetResult();
+  HRESULT ProcessEmptyFiles();
+public:
+  MY_UNKNOWN_IMP
+  
+  CFolderOutStream2()
+  {
+    _crcStreamSpec = new COutStreamWithCRC;
+    _crcStream = _crcStreamSpec;
+  }
+
+  HRESULT Init(const CArchiveDatabaseEx *db, UInt32 startIndex,
+      const CBoolVector *extractStatuses, ISequentialOutStream *outStream);
+  void ReleaseOutStream();
+  HRESULT CheckFinishedState() const { return (_currentIndex == _extractStatuses->Size()) ? S_OK: E_FAIL; }
+
+  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+};
+
+HRESULT CFolderOutStream2::Init(const CArchiveDatabaseEx *db, UInt32 startIndex,
+    const CBoolVector *extractStatuses, ISequentialOutStream *outStream)
+{
+  _db = db;
+  _startIndex = startIndex;
+  _extractStatuses = extractStatuses;
+  _outStream = outStream;
+
+  _currentIndex = 0;
+  _fileIsOpen = false;
+  return ProcessEmptyFiles();
+}
+
+void CFolderOutStream2::ReleaseOutStream()
+{
+  _outStream.Release();
+  _crcStreamSpec->ReleaseStream();
+}
+
+void CFolderOutStream2::OpenFile()
+{
+  _crcStreamSpec->SetStream((*_extractStatuses)[_currentIndex] ? (ISequentialOutStream *)_outStream : NULL); // FIXED for gcc 2.95
+  _crcStreamSpec->Init(true);
+  _fileIsOpen = true;
+  _rem = _db->Files[_startIndex + _currentIndex].Size;
+}
+
+void CFolderOutStream2::CloseFile()
+{
+  _crcStreamSpec->ReleaseStream();
+  _fileIsOpen = false;
+  _currentIndex++;
+}
+
+HRESULT CFolderOutStream2::CloseFileAndSetResult()
+{
+  const CFileItem &file = _db->Files[_startIndex + _currentIndex];
+  CloseFile();
+  return (file.IsDir || !file.CrcDefined || file.Crc == _crcStreamSpec->GetCRC()) ? S_OK: S_FALSE;
+}
+
+HRESULT CFolderOutStream2::ProcessEmptyFiles()
+{
+  while (_currentIndex < _extractStatuses->Size() && _db->Files[_startIndex + _currentIndex].Size == 0)
+  {
+    OpenFile();
+    RINOK(CloseFileAndSetResult());
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CFolderOutStream2::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+  if (processedSize != NULL)
+    *processedSize = 0;
+  while (size != 0)
+  {
+    if (_fileIsOpen)
+    {
+      UInt32 cur = size < _rem ? size : (UInt32)_rem;
+      RINOK(_crcStream->Write(data, cur, &cur));
+      if (cur == 0)
+        break;
+      data = (const Byte *)data + cur;
+      size -= cur;
+      _rem -= cur;
+      if (processedSize != NULL)
+        *processedSize += cur;
+      if (_rem == 0)
+      {
+        RINOK(CloseFileAndSetResult());
+        RINOK(ProcessEmptyFiles());
+        continue;
+      }
+    }
+    else
+    {
+      RINOK(ProcessEmptyFiles());
+      if (_currentIndex == _extractStatuses->Size())
+      {
+        // we don't support partial extracting
+        return E_FAIL;
+      }
+      OpenFile();
+    }
+  }
+  return S_OK;
+}
+
+class CThreadDecoder: public CVirtThread
+{
+public:
+  HRESULT Result;
+  CMyComPtr<IInStream> InStream;
+
+  CFolderOutStream2 *FosSpec;
+  CMyComPtr<ISequentialOutStream> Fos;
+
+  UInt64 StartPos;
+  const UInt64 *PackSizes;
+  const CFolder *Folder;
+  #ifndef _NO_CRYPTO
+  CMyComPtr<ICryptoGetTextPassword> GetTextPassword;
+  #endif
+
+  DECL_EXTERNAL_CODECS_VARS
+  CDecoder Decoder;
+
+  #ifndef _7ZIP_ST
+  bool MtMode;
+  UInt32 NumThreads;
+  #endif
+
+  CThreadDecoder():
+    Decoder(true)
+  {
+    #ifndef _7ZIP_ST
+    MtMode = false;
+    NumThreads = 1;
+    #endif
+    FosSpec = new CFolderOutStream2;
+    Fos = FosSpec;
+    Result = E_FAIL;
+  }
+  virtual void Execute();
+};
+
+void CThreadDecoder::Execute()
+{
+  try
+  {
+    #ifndef _NO_CRYPTO
+    bool passwordIsDefined;
+    #endif
+    Result = Decoder.Decode(
+      EXTERNAL_CODECS_VARS
+      InStream,
+      StartPos,
+      PackSizes,
+      *Folder,
+      Fos,
+      NULL
+      #ifndef _NO_CRYPTO
+      , GetTextPassword, passwordIsDefined
+      #endif
+      #ifndef _7ZIP_ST
+      , MtMode, NumThreads
+      #endif
+      );
+  }
+  catch(...)
+  {
+    Result = E_FAIL;
+  }
+  if (Result == S_OK)
+    Result = FosSpec->CheckFinishedState();
+  FosSpec->ReleaseOutStream();
+}
+
+bool static Is86FilteredFolder(const CFolder &f)
+{
+  for (int i = 0; i < f.Coders.Size(); i++)
+  {
+    CMethodId m = f.Coders[i].MethodID;
+    if (m == k_BCJ || m == k_BCJ2)
+      return true;
+  }
+  return false;
+}
+
+#ifndef _NO_CRYPTO
+
+class CCryptoGetTextPassword:
+  public ICryptoGetTextPassword,
+  public CMyUnknownImp
+{
+public:
+  UString Password;
+
+  MY_UNKNOWN_IMP
+  STDMETHOD(CryptoGetTextPassword)(BSTR *password);
+};
+
+STDMETHODIMP CCryptoGetTextPassword::CryptoGetTextPassword(BSTR *password)
+{
+  return StringToBstr(Password, password);
+}
+
+#endif
+
+static const int kNumGroupsMax = 4;
+
+#ifdef USE_86_FILTER
+static bool Is86Group(int group) { return (group & 1) != 0; }
+#endif
+static bool IsEncryptedGroup(int group) { return (group & 2) != 0; }
+static int GetGroupIndex(bool encrypted, int bcjFiltered)
+  { return (encrypted ? 2 : 0) + (bcjFiltered ? 1 : 0); }
+
+HRESULT Update(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    IInStream *inStream,
+    const CArchiveDatabaseEx *db,
+    const CObjectVector<CUpdateItem> &updateItems,
+    COutArchive &archive,
+    CArchiveDatabase &newDatabase,
+    ISequentialOutStream *seqOutStream,
+    IArchiveUpdateCallback *updateCallback,
+    const CUpdateOptions &options
+    #ifndef _NO_CRYPTO
+    , ICryptoGetTextPassword *getDecoderPassword
+    #endif
+    )
+{
+  UInt64 numSolidFiles = options.NumSolidFiles;
+  if (numSolidFiles == 0)
+    numSolidFiles = 1;
+  /*
+  CMyComPtr<IOutStream> outStream;
+  RINOK(seqOutStream->QueryInterface(IID_IOutStream, (void **)&outStream));
+  if (!outStream)
+    return E_NOTIMPL;
+  */
+
+  UInt64 startBlockSize = db != 0 ? db->ArchiveInfo.StartPosition: 0;
+  if (startBlockSize > 0 && !options.RemoveSfxBlock)
+  {
+    RINOK(WriteRange(inStream, seqOutStream, 0, startBlockSize, NULL));
+  }
+
+  CRecordVector<int> fileIndexToUpdateIndexMap;
+  CRecordVector<CFolderRepack> folderRefs;
+  UInt64 complexity = 0;
+  UInt64 inSizeForReduce2 = 0;
+  bool needEncryptedRepack = false;
+  if (db != 0)
+  {
+    fileIndexToUpdateIndexMap.Reserve(db->Files.Size());
+    int i;
+    for (i = 0; i < db->Files.Size(); i++)
+      fileIndexToUpdateIndexMap.Add(-1);
+
+    for (i = 0; i < updateItems.Size(); i++)
+    {
+      int index = updateItems[i].IndexInArchive;
+      if (index != -1)
+        fileIndexToUpdateIndexMap[index] = i;
+    }
+
+    for (i = 0; i < db->Folders.Size(); i++)
+    {
+      CNum indexInFolder = 0;
+      CNum numCopyItems = 0;
+      CNum numUnpackStreams = db->NumUnpackStreamsVector[i];
+      UInt64 repackSize = 0;
+      for (CNum fi = db->FolderStartFileIndex[i]; indexInFolder < numUnpackStreams; fi++)
+      {
+        const CFileItem &file = db->Files[fi];
+        if (file.HasStream)
+        {
+          indexInFolder++;
+          int updateIndex = fileIndexToUpdateIndexMap[fi];
+          if (updateIndex >= 0 && !updateItems[updateIndex].NewData)
+          {
+            numCopyItems++;
+            repackSize += file.Size;
+          }
+        }
+      }
+
+      if (numCopyItems == 0)
+        continue;
+
+      CFolderRepack rep;
+      rep.FolderIndex = i;
+      rep.NumCopyFiles = numCopyItems;
+      const CFolder &f = db->Folders[i];
+      bool isEncrypted = f.IsEncrypted();
+      rep.Group = GetGroupIndex(isEncrypted, Is86FilteredFolder(f));
+      folderRefs.Add(rep);
+      if (numCopyItems == numUnpackStreams)
+        complexity += db->GetFolderFullPackSize(i);
+      else
+      {
+        complexity += repackSize;
+        if (repackSize > inSizeForReduce2)
+          inSizeForReduce2 = repackSize;
+        if (isEncrypted)
+          needEncryptedRepack = true;
+      }
+    }
+    folderRefs.Sort(CompareFolderRepacks, (void *)db);
+  }
+
+  UInt64 inSizeForReduce = 0;
+  int i;
+  for (i = 0; i < updateItems.Size(); i++)
+  {
+    const CUpdateItem &ui = updateItems[i];
+    if (ui.NewData)
+    {
+      complexity += ui.Size;
+      if (numSolidFiles != 1)
+        inSizeForReduce += ui.Size;
+      else if (ui.Size > inSizeForReduce)
+        inSizeForReduce = ui.Size;
+    }
+  }
+
+  if (inSizeForReduce2 > inSizeForReduce)
+    inSizeForReduce = inSizeForReduce2;
+
+  const UInt32 kMinReduceSize = (1 << 16);
+  if (inSizeForReduce < kMinReduceSize)
+    inSizeForReduce = kMinReduceSize;
+
+  RINOK(updateCallback->SetTotal(complexity));
+
+  CLocalProgress *lps = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> progress = lps;
+  lps->Init(updateCallback, true);
+
+  CThreadDecoder threadDecoder;
+  if (!folderRefs.IsEmpty())
+  {
+    #ifdef EXTERNAL_CODECS
+    threadDecoder._codecsInfo = codecsInfo;
+    threadDecoder._externalCodecs = *externalCodecs;
+    #endif
+    RINOK(threadDecoder.Create());
+  }
+
+  CObjectVector<CSolidGroup> groups;
+  for (i = 0; i < kNumGroupsMax; i++)
+    groups.Add(CSolidGroup());
+
+  {
+    // ---------- Split files to 2 groups ----------
+
+    bool useFilters = options.UseFilters;
+    const CCompressionMethodMode &method = *options.Method;
+    if (method.Methods.Size() != 1 || method.Binds.Size() != 0)
+      useFilters = false;
+    for (i = 0; i < updateItems.Size(); i++)
+    {
+      const CUpdateItem &ui = updateItems[i];
+      if (!ui.NewData || !ui.HasStream())
+        continue;
+      bool filteredGroup = false;
+      if (useFilters)
+      {
+#ifdef _WIN32
+        int dotPos = ui.Name.ReverseFind(L'.');
+        if (dotPos >= 0)
+          filteredGroup = IsExeExt(ui.Name.Mid(dotPos + 1));
+#else
+	filteredGroup = IsExeFile(ui);
+#endif
+      }
+      groups[GetGroupIndex(method.PasswordIsDefined, filteredGroup)].Indices.Add(i);
+    }
+  }
+
+  #ifndef _NO_CRYPTO
+
+  CCryptoGetTextPassword *getPasswordSpec = NULL;
+  if (needEncryptedRepack)
+  {
+    getPasswordSpec = new CCryptoGetTextPassword;
+    threadDecoder.GetTextPassword = getPasswordSpec;
+
+    if (options.Method->PasswordIsDefined)
+      getPasswordSpec->Password = options.Method->Password;
+    else
+    {
+      if (!getDecoderPassword)
+        return E_NOTIMPL;
+      CMyComBSTR password;
+      RINOK(getDecoderPassword->CryptoGetTextPassword(&password));
+      getPasswordSpec->Password = password;
+    }
+  }
+
+  #endif
+
+  // ---------- Compress ----------
+
+  RINOK(archive.Create(seqOutStream, false));
+  RINOK(archive.SkipPrefixArchiveHeader());
+
+  int folderRefIndex = 0;
+  lps->ProgressOffset = 0;
+
+  for (int groupIndex = 0; groupIndex < kNumGroupsMax; groupIndex++)
+  {
+    const CSolidGroup &group = groups[groupIndex];
+
+    CCompressionMethodMode method;
+    #ifdef USE_86_FILTER
+    if (Is86Group(groupIndex))
+      MakeExeMethod(*options.Method, options.MaxFilter, method);
+    else
+    #endif
+      method = *options.Method;
+
+    if (IsEncryptedGroup(groupIndex))
+    {
+      if (!method.PasswordIsDefined)
+      {
+        #ifndef _NO_CRYPTO
+        if (getPasswordSpec)
+          method.Password = getPasswordSpec->Password;
+        #endif
+        method.PasswordIsDefined = true;
+      }
+    }
+    else
+    {
+      method.PasswordIsDefined = false;
+      method.Password.Empty();
+    }
+
+    CEncoder encoder(method);
+
+    for (; folderRefIndex < folderRefs.Size(); folderRefIndex++)
+    {
+      const CFolderRepack &rep = folderRefs[folderRefIndex];
+      if (rep.Group != groupIndex)
+        break;
+      int folderIndex = rep.FolderIndex;
+      
+      if (rep.NumCopyFiles == db->NumUnpackStreamsVector[folderIndex])
+      {
+        UInt64 packSize = db->GetFolderFullPackSize(folderIndex);
+        RINOK(WriteRange(inStream, archive.SeqStream,
+          db->GetFolderStreamPos(folderIndex, 0), packSize, progress));
+        lps->ProgressOffset += packSize;
+        
+        const CFolder &folder = db->Folders[folderIndex];
+        CNum startIndex = db->FolderStartPackStreamIndex[folderIndex];
+        for (int j = 0; j < folder.PackStreams.Size(); j++)
+        {
+          newDatabase.PackSizes.Add(db->PackSizes[startIndex + j]);
+          // newDatabase.PackCRCsDefined.Add(db.PackCRCsDefined[startIndex + j]);
+          // newDatabase.PackCRCs.Add(db.PackCRCs[startIndex + j]);
+        }
+        newDatabase.Folders.Add(folder);
+      }
+      else
+      {
+        CStreamBinder sb;
+        RINOK(sb.CreateEvents());
+        CMyComPtr<ISequentialOutStream> sbOutStream;
+        CMyComPtr<ISequentialInStream> sbInStream;
+        sb.CreateStreams(&sbInStream, &sbOutStream);
+        CBoolVector extractStatuses;
+        
+        CNum numUnpackStreams = db->NumUnpackStreamsVector[folderIndex];
+        CNum indexInFolder = 0;
+        
+        for (CNum fi = db->FolderStartFileIndex[folderIndex]; indexInFolder < numUnpackStreams; fi++)
+        {
+          bool needExtract = false;
+          if (db->Files[fi].HasStream)
+          {
+            indexInFolder++;
+            int updateIndex = fileIndexToUpdateIndexMap[fi];
+            if (updateIndex >= 0 && !updateItems[updateIndex].NewData)
+              needExtract = true;
+          }
+          extractStatuses.Add(needExtract);
+        }
+
+        RINOK(threadDecoder.FosSpec->Init(db, db->FolderStartFileIndex[folderIndex], &extractStatuses, sbOutStream));
+        sbOutStream.Release();
+        
+        threadDecoder.InStream = inStream;
+        threadDecoder.Folder = &db->Folders[folderIndex];
+        threadDecoder.StartPos = db->GetFolderStreamPos(folderIndex, 0);
+        threadDecoder.PackSizes = &db->PackSizes[db->FolderStartPackStreamIndex[folderIndex]];
+        
+        threadDecoder.Start();
+        
+        int startPackIndex = newDatabase.PackSizes.Size();
+        CFolder newFolder;
+        RINOK(encoder.Encode(
+          EXTERNAL_CODECS_LOC_VARS
+          sbInStream, NULL, &inSizeForReduce, newFolder,
+          archive.SeqStream, newDatabase.PackSizes, progress));
+        
+        threadDecoder.WaitFinish();
+
+        RINOK(threadDecoder.Result);
+
+        for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)
+          lps->OutSize += newDatabase.PackSizes[startPackIndex];
+        lps->InSize += newFolder.GetUnpackSize();
+        
+        newDatabase.Folders.Add(newFolder);
+      }
+      
+      newDatabase.NumUnpackStreamsVector.Add(rep.NumCopyFiles);
+      
+      CNum numUnpackStreams = db->NumUnpackStreamsVector[folderIndex];
+      
+      CNum indexInFolder = 0;
+      for (CNum fi = db->FolderStartFileIndex[folderIndex]; indexInFolder < numUnpackStreams; fi++)
+      {
+        CFileItem file;
+        CFileItem2 file2;
+        db->GetFile(fi, file, file2);
+        if (file.HasStream)
+        {
+          indexInFolder++;
+          int updateIndex = fileIndexToUpdateIndexMap[fi];
+          if (updateIndex >= 0)
+          {
+            const CUpdateItem &ui = updateItems[updateIndex];
+            if (ui.NewData)
+              continue;
+            if (ui.NewProps)
+            {
+              CFileItem uf;
+              FromUpdateItemToFileItem(ui, uf, file2);
+              uf.Size = file.Size;
+              uf.Crc = file.Crc;
+              uf.CrcDefined = file.CrcDefined;
+              uf.HasStream = file.HasStream;
+              file = uf;
+            }
+            newDatabase.AddFile(file, file2);
+          }
+        }
+      }
+    }
+
+    int numFiles = group.Indices.Size();
+    if (numFiles == 0)
+      continue;
+    CRecordVector<CRefItem> refItems;
+    refItems.Reserve(numFiles);
+    bool sortByType = (numSolidFiles > 1);
+    for (i = 0; i < numFiles; i++)
+      refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType));
+    refItems.Sort(CompareUpdateItems, (void *)&sortByType);
+    
+    CRecordVector<UInt32> indices;
+    indices.Reserve(numFiles);
+
+    for (i = 0; i < numFiles; i++)
+    {
+      UInt32 index = refItems[i].Index;
+      indices.Add(index);
+      /*
+      const CUpdateItem &ui = updateItems[index];
+      CFileItem file;
+      if (ui.NewProps)
+        FromUpdateItemToFileItem(ui, file);
+      else
+        file = db.Files[ui.IndexInArchive];
+      if (file.IsAnti || file.IsDir)
+        return E_FAIL;
+      newDatabase.Files.Add(file);
+      */
+    }
+    
+    for (i = 0; i < numFiles;)
+    {
+      UInt64 totalSize = 0;
+      int numSubFiles;
+      UString prevExtension;
+      for (numSubFiles = 0; i + numSubFiles < numFiles &&
+          numSubFiles < numSolidFiles; numSubFiles++)
+      {
+        const CUpdateItem &ui = updateItems[indices[i + numSubFiles]];
+        totalSize += ui.Size;
+        if (totalSize > options.NumSolidBytes)
+          break;
+        if (options.SolidExtension)
+        {
+          UString ext = ui.GetExtension();
+          if (numSubFiles == 0)
+            prevExtension = ext;
+          else
+            if (ext.CompareNoCase(prevExtension) != 0)
+              break;
+        }
+      }
+      if (numSubFiles < 1)
+        numSubFiles = 1;
+
+      CFolderInStream *inStreamSpec = new CFolderInStream;
+      CMyComPtr<ISequentialInStream> solidInStream(inStreamSpec);
+      inStreamSpec->Init(updateCallback, &indices[i], numSubFiles);
+      
+      CFolder folderItem;
+
+      int startPackIndex = newDatabase.PackSizes.Size();
+      RINOK(encoder.Encode(
+          EXTERNAL_CODECS_LOC_VARS
+          solidInStream, NULL, &inSizeForReduce, folderItem,
+          archive.SeqStream, newDatabase.PackSizes, progress));
+
+      for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)
+        lps->OutSize += newDatabase.PackSizes[startPackIndex];
+
+      lps->InSize += folderItem.GetUnpackSize();
+      // for ()
+      // newDatabase.PackCRCsDefined.Add(false);
+      // newDatabase.PackCRCs.Add(0);
+      
+      newDatabase.Folders.Add(folderItem);
+      
+      CNum numUnpackStreams = 0;
+      for (int subIndex = 0; subIndex < numSubFiles; subIndex++)
+      {
+        const CUpdateItem &ui = updateItems[indices[i + subIndex]];
+        CFileItem file;
+        CFileItem2 file2;
+        if (ui.NewProps)
+          FromUpdateItemToFileItem(ui, file, file2);
+        else
+          db->GetFile(ui.IndexInArchive, file, file2);
+        if (file2.IsAnti || file.IsDir)
+          return E_FAIL;
+        
+        /*
+        CFileItem &file = newDatabase.Files[
+              startFileIndexInDatabase + i + subIndex];
+        */
+        if (!inStreamSpec->Processed[subIndex])
+        {
+          continue;
+          // file.Name += L".locked";
+        }
+
+        file.Crc = inStreamSpec->CRCs[subIndex];
+        file.Size = inStreamSpec->Sizes[subIndex];
+        if (file.Size != 0)
+        {
+          file.CrcDefined = true;
+          file.HasStream = true;
+          numUnpackStreams++;
+        }
+        else
+        {
+          file.CrcDefined = false;
+          file.HasStream = false;
+        }
+        newDatabase.AddFile(file, file2);
+      }
+      // numUnpackStreams = 0 is very bad case for locked files
+      // v3.13 doesn't understand it.
+      newDatabase.NumUnpackStreamsVector.Add(numUnpackStreams);
+      i += numSubFiles;
+    }
+  }
+
+  if (folderRefIndex != folderRefs.Size())
+    return E_FAIL;
+
+  /*
+  folderRefs.ClearAndFree();
+  fileIndexToUpdateIndexMap.ClearAndFree();
+  groups.ClearAndFree();
+  */
+
+  {
+    // ---------- Write Folders & Empty Files ----------
+    
+    CRecordVector<int> emptyRefs;
+    for (i = 0; i < updateItems.Size(); i++)
+    {
+      const CUpdateItem &ui = updateItems[i];
+      if (ui.NewData)
+      {
+        if (ui.HasStream())
+          continue;
+      }
+      else if (ui.IndexInArchive != -1 && db->Files[ui.IndexInArchive].HasStream)
+        continue;
+      emptyRefs.Add(i);
+    }
+    emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);
+    for (i = 0; i < emptyRefs.Size(); i++)
+    {
+      const CUpdateItem &ui = updateItems[emptyRefs[i]];
+      CFileItem file;
+      CFileItem2 file2;
+      if (ui.NewProps)
+        FromUpdateItemToFileItem(ui, file, file2);
+      else
+        db->GetFile(ui.IndexInArchive, file, file2);
+      newDatabase.AddFile(file, file2);
+    }
+  }
+    
+  newDatabase.ReserveDown();
+  return S_OK;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/7zUpdate.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,88 @@
+// 7zUpdate.h
+
+#ifndef __7Z_UPDATE_H
+#define __7Z_UPDATE_H
+
+#include "7zCompressionMode.h"
+#include "7zIn.h"
+#include "7zOut.h"
+
+#include "../IArchive.h"
+
+namespace NArchive {
+namespace N7z {
+
+struct CUpdateItem
+{
+  int IndexInArchive;
+  int IndexInClient;
+  
+  UInt64 CTime;
+  UInt64 ATime;
+  UInt64 MTime;
+
+  UInt64 Size;
+  UString Name;
+
+  UInt32 Attrib;
+  
+  bool NewData;
+  bool NewProps;
+
+  bool IsAnti;
+  bool IsDir;
+
+  bool AttribDefined;
+  bool CTimeDefined;
+  bool ATimeDefined;
+  bool MTimeDefined;
+
+  bool HasStream() const { return !IsDir && !IsAnti && Size != 0; }
+
+  CUpdateItem():
+      IsAnti(false),
+      IsDir(false),
+      AttribDefined(false),
+      CTimeDefined(false),
+      ATimeDefined(false),
+      MTimeDefined(false)
+      {}
+  void SetDirStatusFromAttrib() { IsDir = ((Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0); };
+
+  int GetExtensionPos() const;
+  UString GetExtension() const;
+};
+
+struct CUpdateOptions
+{
+  const CCompressionMethodMode *Method;
+  const CCompressionMethodMode *HeaderMethod;
+  bool UseFilters;
+  bool MaxFilter;
+
+  CHeaderOptions HeaderOptions;
+
+  UInt64 NumSolidFiles;
+  UInt64 NumSolidBytes;
+  bool SolidExtension;
+  bool RemoveSfxBlock;
+  bool VolumeMode;
+};
+
+HRESULT Update(
+    DECL_EXTERNAL_CODECS_LOC_VARS
+    IInStream *inStream,
+    const CArchiveDatabaseEx *db,
+    const CObjectVector<CUpdateItem> &updateItems,
+    COutArchive &archive,
+    CArchiveDatabase &newDatabase,
+    ISequentialOutStream *seqOutStream,
+    IArchiveUpdateCallback *updateCallback,
+    const CUpdateOptions &options
+    #ifndef _NO_CRYPTO
+    , ICryptoGetTextPassword *getDecoderPassword
+    #endif
+    );
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ApmHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ApmHandler.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ApmHandler.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ApmHandler.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,356 @@
+// ApmHandler.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/CpuArch.h"
+
+#include "Common/ComTry.h"
+#include "Common/IntToString.h"
+#include "Common/MyString.h"
+
+#include "Windows/PropVariant.h"
+
+#include "../Common/LimitedStreams.h"
+#include "../Common/ProgressUtils.h"
+#include "../Common/RegisterArc.h"
+#include "../Common/StreamUtils.h"
+
+#include "../Compress/CopyCoder.h"
+
+#define Get16(p) GetBe16(p)
+#define Get32(p) GetBe32(p)
+
+using namespace NWindows;
+
+namespace NArchive {
+namespace NApm {
+
+struct CItem
+{
+  UInt32 StartBlock;
+  UInt32 NumBlocks;
+  char Name[32];
+  char Type[32];
+  /*
+  UInt32 DataStartBlock;
+  UInt32 NumDataBlocks;
+  UInt32 Status;
+  UInt32 BootStartBlock;
+  UInt32 BootSize;
+  UInt32 BootAddr;
+  UInt32 BootEntry;
+  UInt32 BootChecksum;
+  char Processor[16];
+  */
+
+  bool Parse(const Byte *p, UInt32 &numBlocksInMap)
+  {
+    if (p[0] != 0x50 || p[1] != 0x4D || p[2] != 0 || p[3] != 0)
+      return false;
+    numBlocksInMap = Get32(p + 4);
+    StartBlock = Get32(p + 8);
+    NumBlocks = Get32(p + 0xC);
+    memcpy(Name, p + 0x10, 32);
+    memcpy(Type, p + 0x30, 32);
+    /*
+    DataStartBlock = Get32(p + 0x50);
+    NumDataBlocks = Get32(p + 0x54);
+    Status = Get32(p + 0x58);
+    BootStartBlock = Get32(p + 0x5C);
+    BootSize = Get32(p + 0x60);
+    BootAddr = Get32(p + 0x64);
+    if (Get32(p + 0x68) != 0)
+      return false;
+    BootEntry = Get32(p + 0x6C);
+    if (Get32(p + 0x70) != 0)
+      return false;
+    BootChecksum = Get32(p + 0x74);
+    memcpy(Processor, p + 0x78, 16);
+    */
+    return true;
+  }
+};
+
+class CHandler:
+  public IInArchive,
+  public IInArchiveGetStream,
+  public CMyUnknownImp
+{
+  CMyComPtr<IInStream> _stream;
+  CRecordVector<CItem> _items;
+
+  int _blockSizeLog;
+  UInt32 _numBlocks;
+
+  HRESULT ReadTables(IInStream *stream);
+  UInt64 BlocksToBytes(UInt32 i) const { return (UInt64)i << _blockSizeLog; }
+  UInt64 GetItemSize(const CItem &item) { return BlocksToBytes(item.NumBlocks); }
+public:
+  MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
+  INTERFACE_IInArchive(;)
+  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
+};
+
+static inline int GetLog(UInt32 num)
+{
+  for (int i = 0; i < 31; i++)
+    if (((UInt32)1 << i) == num)
+      return i;
+  return -1;
+}
+
+HRESULT CHandler::ReadTables(IInStream *stream)
+{
+  const UInt32 kSectorSize = 512;
+  Byte buf[kSectorSize];
+  {
+    RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
+    if (buf[0] != 0x45 || buf[1] != 0x52)
+      return S_FALSE;
+    _blockSizeLog = GetLog(Get16(buf + 2));
+    if (_blockSizeLog < 9 || _blockSizeLog > 14)
+      return S_FALSE;
+    _numBlocks = Get32(buf + 4);
+    for (int i = 8; i < 16; i++)
+      if (buf[i] != 0)
+        return S_FALSE;
+  }
+
+  unsigned numSkips = (unsigned)1 << (_blockSizeLog - 9);
+  for (unsigned j = 1; j < numSkips; j++)
+  {
+    RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
+  }
+
+  UInt32 numBlocksInMap = 0;
+  for (unsigned i = 0;;)
+  {
+    RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
+ 
+    CItem item;
+    
+    UInt32 numBlocksInMap2;
+    if (!item.Parse(buf, numBlocksInMap2))
+      return S_FALSE;
+    if (i == 0)
+    {
+      numBlocksInMap = numBlocksInMap2;
+      if (numBlocksInMap > (1 << 8))
+        return S_FALSE;
+    }
+    else if (numBlocksInMap2 != numBlocksInMap)
+      return S_FALSE;
+
+    UInt32 finish = item.StartBlock + item.NumBlocks;
+    if (finish < item.StartBlock)
+      return S_FALSE;
+    _numBlocks = MyMax(_numBlocks, finish);
+    
+    _items.Add(item);
+    for (unsigned j = 1; j < numSkips; j++)
+    {
+      RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
+    }
+    if (++i == numBlocksInMap)
+      break;
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Open(IInStream *stream,
+    const UInt64 * /* maxCheckStartPosition */,
+    IArchiveOpenCallback * /* openArchiveCallback */)
+{
+  COM_TRY_BEGIN
+  Close();
+  RINOK(ReadTables(stream));
+  _stream = stream;
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::Close()
+{
+  _items.Clear();
+  _stream.Release();
+  return S_OK;
+}
+
+STATPROPSTG kProps[] =
+{
+  { NULL, kpidPath, VT_BSTR},
+  { NULL, kpidSize, VT_UI8},
+  { NULL, kpidOffset, VT_UI8}
+};
+
+STATPROPSTG kArcProps[] =
+{
+  { NULL, kpidClusterSize, VT_UI4},
+  { NULL, kpidPhySize, VT_UI8}
+};
+
+IMP_IInArchive_Props
+IMP_IInArchive_ArcProps
+
+static AString GetString(const char *s)
+{
+  AString res;
+  for (int i = 0; i < 32 && s[i] != 0; i++)
+    res += s[i];
+  return res;
+}
+
+STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case kpidMainSubfile:
+    {
+      int mainIndex = -1;
+      for (int i = 0; i < _items.Size(); i++)
+      {
+        AString s = GetString(_items[i].Type);
+        if (s != "Apple_Free" &&
+            s != "Apple_partition_map")
+        {
+          if (mainIndex >= 0)
+          {
+            mainIndex = -1;
+            break;
+          }
+          mainIndex = i;
+        }
+      }
+      if (mainIndex >= 0)
+        prop = (UInt32)mainIndex;
+      break;
+    }
+    case kpidClusterSize: prop = (UInt32)1 << _blockSizeLog; break;
+    case kpidPhySize: prop = BlocksToBytes(_numBlocks); break;
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+{
+  *numItems = _items.Size();
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NCOM::CPropVariant prop;
+  const CItem &item = _items[index];
+  switch(propID)
+  {
+    case kpidPath:
+    {
+      AString s = GetString(item.Name);
+      if (s.IsEmpty())
+      {
+        char s2[32];
+        ConvertUInt32ToString(index, s2);
+        s = s2;
+      }
+      AString type = GetString(item.Type);
+      if (type == "Apple_HFS")
+        type = "hfs";
+      if (!type.IsEmpty())
+      {
+        s += '.';
+        s += type;
+      }
+      prop = s;
+      break;
+    }
+    case kpidSize:
+    case kpidPackSize:
+      prop = GetItemSize(item);
+      break;
+    case kpidOffset: prop = BlocksToBytes(item.StartBlock); break;
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+    Int32 testMode, IArchiveExtractCallback *extractCallback)
+{
+  COM_TRY_BEGIN
+  bool allFilesMode = (numItems == (UInt32)-1);
+  if (allFilesMode)
+    numItems = _items.Size();
+  if (numItems == 0)
+    return S_OK;
+  UInt64 totalSize = 0;
+  UInt32 i;
+  for (i = 0; i < numItems; i++)
+    totalSize += GetItemSize(_items[allFilesMode ? i : indices[i]]);
+  extractCallback->SetTotal(totalSize);
+
+  totalSize = 0;
+  
+  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
+  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
+
+  CLocalProgress *lps = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> progress = lps;
+  lps->Init(extractCallback, false);
+
+  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
+  CMyComPtr<ISequentialInStream> inStream(streamSpec);
+  streamSpec->SetStream(_stream);
+
+  for (i = 0; i < numItems; i++)
+  {
+    lps->InSize = totalSize;
+    lps->OutSize = totalSize;
+    RINOK(lps->SetCur());
+    CMyComPtr<ISequentialOutStream> outStream;
+    Int32 askMode = testMode ?
+        NExtract::NAskMode::kTest :
+        NExtract::NAskMode::kExtract;
+    Int32 index = allFilesMode ? i : indices[i];
+    const CItem &item = _items[index];
+
+    RINOK(extractCallback->GetStream(index, &outStream, askMode));
+    UInt64 size = GetItemSize(item);
+    totalSize += size;
+    if (!testMode && !outStream)
+      continue;
+    RINOK(extractCallback->PrepareOperation(askMode));
+
+    RINOK(_stream->Seek(BlocksToBytes(item.StartBlock), STREAM_SEEK_SET, NULL));
+    streamSpec->Init(size);
+    RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
+    outStream.Release();
+    RINOK(extractCallback->SetOperationResult(copyCoderSpec->TotalSize == size ?
+        NExtract::NOperationResult::kOK:
+        NExtract::NOperationResult::kDataError));
+  }
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
+{
+  COM_TRY_BEGIN
+  const CItem &item = _items[index];
+  return CreateLimitedInStream(_stream, BlocksToBytes(item.StartBlock), GetItemSize(item), stream);
+  COM_TRY_END
+}
+
+static IInArchive *CreateArc() { return new CHandler; }
+
+static CArcInfo g_ArcInfo =
+  { L"APM", L"", 0, 0xD4, { 0x50, 0x4D, 0, 0, 0, 0, 0 }, 7, false, CreateArc, 0 };
+
+REGISTER_ARC(Apm)
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArchiveExports.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArchiveExports.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArchiveExports.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArchiveExports.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,135 @@
+// ArchiveExports.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/ComTry.h"
+
+#include "../../Windows/PropVariant.h"
+
+#include "../Common/RegisterArc.h"
+
+static const unsigned int kNumArcsMax = 48;
+static unsigned int g_NumArcs = 0;
+static unsigned int g_DefaultArcIndex = 0;
+static const CArcInfo *g_Arcs[kNumArcsMax];
+void RegisterArc(const CArcInfo *arcInfo)
+{
+  if (g_NumArcs < kNumArcsMax)
+  {
+    const wchar_t *p = arcInfo->Name;
+    if (p[0] == '7' && p[1] == 'z' && p[2] == 0)
+      g_DefaultArcIndex = g_NumArcs;
+    g_Arcs[g_NumArcs++] = arcInfo;
+  }
+}
+
+DEFINE_GUID(CLSID_CArchiveHandler,
+0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);
+
+#define CLS_ARC_ID_ITEM(cls) ((cls).Data4[5])
+
+static inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)
+{
+  if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)
+    value->vt = VT_BSTR;
+  return S_OK;
+}
+
+static inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)
+{
+  return SetPropString((const char *)&guid, sizeof(GUID), value);
+}
+
+int FindFormatCalssId(const GUID *clsID)
+{
+  GUID cls = *clsID;
+  CLS_ARC_ID_ITEM(cls) = 0;
+  if (cls != CLSID_CArchiveHandler)
+    return -1;
+  Byte id = CLS_ARC_ID_ITEM(*clsID);
+  for (unsigned i = 0; i < g_NumArcs; i++)
+    if (g_Arcs[i]->ClassId == id)
+      return (int)i;
+  return -1;
+}
+
+STDAPI CreateArchiver(const GUID *clsid, const GUID *iid, void **outObject)
+{
+  COM_TRY_BEGIN
+  {
+    int needIn = (*iid == IID_IInArchive);
+    int needOut = (*iid == IID_IOutArchive);
+    if (!needIn && !needOut)
+      return E_NOINTERFACE;
+    int formatIndex = FindFormatCalssId(clsid);
+    if (formatIndex < 0)
+      return CLASS_E_CLASSNOTAVAILABLE;
+    
+    const CArcInfo &arc = *g_Arcs[formatIndex];
+    if (needIn)
+    {
+      *outObject = arc.CreateInArchive();
+      ((IInArchive *)*outObject)->AddRef();
+    }
+    else
+    {
+      if (!arc.CreateOutArchive)
+        return CLASS_E_CLASSNOTAVAILABLE;
+      *outObject = arc.CreateOutArchive();
+      ((IOutArchive *)*outObject)->AddRef();
+    }
+  }
+  COM_TRY_END
+  return S_OK;
+}
+
+STDAPI GetHandlerProperty2(UInt32 formatIndex, PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  if (formatIndex >= g_NumArcs)
+    return E_INVALIDARG;
+  const CArcInfo &arc = *g_Arcs[formatIndex];
+  NWindows::NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case NArchive::kName:
+      prop = arc.Name;
+      break;
+    case NArchive::kClassID:
+    {
+      GUID clsId = CLSID_CArchiveHandler;
+      CLS_ARC_ID_ITEM(clsId) = arc.ClassId;
+      return SetPropGUID(clsId, value);
+    }
+    case NArchive::kExtension:
+      if (arc.Ext != 0)
+        prop = arc.Ext;
+      break;
+    case NArchive::kAddExtension:
+      if (arc.AddExt != 0)
+        prop = arc.AddExt;
+      break;
+    case NArchive::kUpdate:
+      prop = (bool)(arc.CreateOutArchive != 0);
+      break;
+    case NArchive::kKeepName:
+      prop = arc.KeepName;
+      break;
+    case NArchive::kStartSignature:
+      return SetPropString((const char *)arc.Signature, arc.SignatureSize, value);
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+STDAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value)
+{
+  return GetHandlerProperty2(g_DefaultArcIndex, propID, value);
+}
+
+STDAPI GetNumberOfFormats(UINT32 *numFormats)
+{
+  *numFormats = g_NumArcs;
+  return S_OK;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArjHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArjHandler.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArjHandler.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ArjHandler.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,798 @@
+// ArjHandler.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/CpuArch.h"
+
+#include "Common/ComTry.h"
+#include "Common/StringConvert.h"
+
+#include "Windows/PropVariant.h"
+#include "Windows/Time.h"
+
+#include "../Common/LimitedStreams.h"
+#include "../Common/ProgressUtils.h"
+#include "../Common/RegisterArc.h"
+#include "../Common/StreamObjects.h"
+#include "../Common/StreamUtils.h"
+
+#include "../Compress/ArjDecoder1.h"
+#include "../Compress/ArjDecoder2.h"
+#include "../Compress/CopyCoder.h"
+
+#include "Common/ItemNameUtils.h"
+#include "Common/OutStreamWithCRC.h"
+
+using namespace NWindows;
+
+#define Get16(p) GetUi16(p)
+#define Get32(p) GetUi32(p)
+
+namespace NArchive {
+namespace NArj {
+
+const int kBlockSizeMin = 30;
+const int kBlockSizeMax = 2600;
+
+namespace NSignature
+{
+  const Byte kSig0 = 0x60;
+  const Byte kSig1 = 0xEA;
+}
+
+namespace NFileHeader
+{
+  namespace NCompressionMethod
+  {
+    enum
+    {
+      kStored = 0,
+      kCompressed1a = 1,
+      kCompressed1b = 2,
+      kCompressed1c = 3,
+      kCompressed2 = 4,
+      kNoDataNoCRC = 8,
+      kNoData = 9
+    };
+  }
+
+  namespace NFileType
+  {
+    enum
+    {
+      kBinary = 0,
+      k7BitText = 1,
+      kArchiveHeader = 2,
+      kDirectory = 3,
+      kVolumeLablel = 4,
+      kChapterLabel = 5
+    };
+  }
+  
+  namespace NFlags
+  {
+    const Byte kGarbled = 1;
+    const Byte kVolume = 4;
+    const Byte kExtFile = 8;
+    const Byte kPathSym = 0x10;
+    const Byte kBackup = 0x20;
+  }
+
+  namespace NHostOS
+  {
+    enum EEnum
+    {
+      kMSDOS = 0,  // filesystem used by MS-DOS, OS/2, Win32
+          // pkarj 2.50 (FAT / VFAT / FAT32 file systems)
+      kPRIMOS,
+      kUnix,
+      kAMIGA,
+      kMac,
+      kOS_2,
+      kAPPLE_GS,
+      kAtari_ST,
+      kNext,
+      kVAX_VMS,
+      kWIN95
+    };
+  }
+}
+
+struct CArchiveHeader
+{
+  // Byte ArchiverVersion;
+  // Byte ExtractVersion;
+  Byte HostOS;
+  // Byte Flags;
+  // Byte SecuryVersion;
+  // Byte FileType;
+  // Byte Reserved;
+  UInt32 CTime;
+  UInt32 MTime;
+  UInt32 ArchiveSize;
+  // UInt32 SecurityEnvelopeFilePosition;
+  // UInt16 FilespecPositionInFilename;
+  // UInt16 LengthOfSecurityEnvelopeSata;
+  // Byte EncryptionVersion;
+  // Byte LastChapter;
+  AString Name;
+  AString Comment;
+  
+  HRESULT Parse(const Byte *p, unsigned size);
+};
+
+static HRESULT ReadString(const Byte *p, unsigned &size, AString &res)
+{
+  AString s;
+  for (unsigned i = 0; i < size;)
+  {
+    char c = (char)p[i++];
+    if (c == 0)
+    {
+      size = i;
+      res = s;
+      return S_OK;
+    }
+    s += c;
+  }
+  return S_FALSE;
+}
+
+HRESULT CArchiveHeader::Parse(const Byte *p, unsigned size)
+{
+  if (size < kBlockSizeMin)
+    return S_FALSE;
+  Byte firstHeaderSize = p[0];
+  if (firstHeaderSize > size)
+    return S_FALSE;
+  // ArchiverVersion = p[1];
+  // ExtractVersion = p[2];
+  HostOS = p[3];
+  // Flags = p[4];
+  // SecuryVersion = p[5];
+  if (p[6] != NFileHeader::NFileType::kArchiveHeader)
+    return S_FALSE;
+  // Reserved = p[7];
+  CTime = Get32(p + 8);
+  MTime = Get32(p + 12);
+  ArchiveSize = Get32(p + 16);
+  // SecurityEnvelopeFilePosition = Get32(p + 20);
+  // UInt16 filespecPositionInFilename = Get16(p + 24);
+  // LengthOfSecurityEnvelopeSata = Get16(p + 26);
+  // EncryptionVersion = p[28];
+  // LastChapter = p[29];
+  unsigned pos = firstHeaderSize;
+  unsigned size1 = size - pos;
+  RINOK(ReadString(p + pos, size1, Name));
+  pos += size1;
+  size1 = size - pos;
+  RINOK(ReadString(p + pos, size1, Comment));
+  pos += size1;
+  return S_OK;
+}
+
+struct CItem
+{
+  AString Name;
+  AString Comment;
+
+  UInt32 MTime;
+  UInt32 PackSize;
+  UInt32 Size;
+  UInt32 FileCRC;
+  UInt32 SplitPos;
+
+  Byte Version;
+  Byte ExtractVersion;
+  Byte HostOS;
+  Byte Flags;
+  Byte Method;
+  Byte FileType;
+
+  // UInt16 FilespecPositionInFilename;
+  UInt16 FileAccessMode;
+  // Byte FirstChapter;
+  // Byte LastChapter;
+  
+  UInt64 DataPosition;
+  
+  bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kGarbled) != 0; }
+  bool IsDir() const { return (FileType == NFileHeader::NFileType::kDirectory); }
+  bool IsSplitAfter() const { return (Flags & NFileHeader::NFlags::kVolume) != 0; }
+  bool IsSplitBefore() const { return (Flags & NFileHeader::NFlags::kExtFile) != 0; }
+  UInt32 GetWinAttributes() const
+  {
+    UInt32 winAtrributes;
+    switch(HostOS)
+    {
+      case NFileHeader::NHostOS::kMSDOS:
+      case NFileHeader::NHostOS::kWIN95:
+        winAtrributes = FileAccessMode;
+        break;
+      default:
+        winAtrributes = 0;
+    }
+    if (IsDir())
+      winAtrributes |= FILE_ATTRIBUTE_DIRECTORY;
+    return winAtrributes;
+  }
+
+  HRESULT Parse(const Byte *p, unsigned size);
+};
+
+HRESULT CItem::Parse(const Byte *p, unsigned size)
+{
+  if (size < kBlockSizeMin)
+    return S_FALSE;
+
+  Byte firstHeaderSize = p[0];
+
+  Version = p[1];
+  ExtractVersion = p[2];
+  HostOS = p[3];
+  Flags = p[4];
+  Method = p[5];
+  FileType = p[6];
+  // Reserved = p[7];
+  MTime = Get32(p + 8);
+  PackSize = Get32(p + 12);
+  Size = Get32(p + 16);
+  FileCRC = Get32(p + 20);
+  // FilespecPositionInFilename = Get16(p + 24);
+  FileAccessMode = Get16(p + 26);
+  // FirstChapter = p[28];
+  // FirstChapter = p[29];
+
+  SplitPos = 0;
+  if (IsSplitBefore() && firstHeaderSize >= 34)
+    SplitPos = Get32(p + 30);
+
+  unsigned pos = firstHeaderSize;
+  unsigned size1 = size - pos;
+  RINOK(ReadString(p + pos, size1, Name));
+  pos += size1;
+  size1 = size - pos;
+  RINOK(ReadString(p + pos, size1, Comment));
+  pos += size1;
+
+  return S_OK;
+}
+
+struct CInArchiveException
+{
+  enum CCauseType
+  {
+    kUnexpectedEndOfArchive = 0,
+    kCRCError,
+    kIncorrectArchive
+  }
+  Cause;
+  CInArchiveException(CCauseType cause): Cause(cause) {};
+};
+
+class CInArchive
+{
+  UInt32 _blockSize;
+  Byte _block[kBlockSizeMax + 4];
+  
+  HRESULT ReadBlock(bool &filled);
+  HRESULT ReadSignatureAndBlock(bool &filled);
+  HRESULT SkipExtendedHeaders();
+
+  HRESULT SafeReadBytes(void *data, UInt32 size);
+    
+public:
+  CArchiveHeader Header;
+
+  IInStream *Stream;
+  IArchiveOpenCallback *Callback;
+  UInt64 NumFiles;
+  UInt64 NumBytes;
+
+  HRESULT Open(const UInt64 *searchHeaderSizeLimit);
+  HRESULT GetNextItem(bool &filled, CItem &item);
+};
+
+static inline bool TestMarkerCandidate(const Byte *p, unsigned maxSize)
+{
+  if (p[0] != NSignature::kSig0 || p[1] != NSignature::kSig1)
+    return false;
+  UInt32 blockSize = Get16(p + 2);
+  p += 4;
+  if (p[6] != NFileHeader::NFileType::kArchiveHeader ||
+      p[0] > blockSize ||
+      maxSize < 2 + 2 + blockSize + 4 ||
+      blockSize < kBlockSizeMin || blockSize > kBlockSizeMax ||
+      p[28] > 8) // EncryptionVersion
+    return false;
+  // return (Get32(p + blockSize) == CrcCalc(p, blockSize));
+  return true;
+}
+
+static HRESULT FindAndReadMarker(ISequentialInStream *stream, const UInt64 *searchHeaderSizeLimit, UInt64 &position)
+{
+  position = 0;
+
+  const int kMarkerSizeMin = 2 + 2 + kBlockSizeMin + 4;
+  const int kMarkerSizeMax = 2 + 2 + kBlockSizeMax + 4;
+
+  CByteBuffer byteBuffer;
+  const UInt32 kBufSize = 1 << 16;
+  byteBuffer.SetCapacity(kBufSize);
+  Byte *buf = byteBuffer;
+
+  size_t processedSize = kMarkerSizeMax;
+  RINOK(ReadStream(stream, buf, &processedSize));
+  if (processedSize < kMarkerSizeMin)
+    return S_FALSE;
+  if (TestMarkerCandidate(buf, (unsigned)processedSize))
+    return S_OK;
+
+  UInt32 numBytesPrev = (UInt32)processedSize - 1;
+  memmove(buf, buf + 1, numBytesPrev);
+  UInt64 curTestPos = 1;
+  for (;;)
+  {
+    if (searchHeaderSizeLimit != NULL)
+      if (curTestPos > *searchHeaderSizeLimit)
+        return S_FALSE;
+    processedSize = kBufSize - numBytesPrev;
+    RINOK(ReadStream(stream, buf + numBytesPrev, &processedSize));
+    UInt32 numBytesInBuffer = numBytesPrev + (UInt32)processedSize;
+    if (numBytesInBuffer < kMarkerSizeMin)
+      return S_FALSE;
+    UInt32 numTests = numBytesInBuffer - kMarkerSizeMin + 1;
+    UInt32 pos;
+    for (pos = 0; pos < numTests; pos++)
+    {
+      for (; buf[pos] != NSignature::kSig0 && pos < numTests; pos++);
+      if (pos == numTests)
+        break;
+      if (TestMarkerCandidate(buf + pos, numBytesInBuffer - pos))
+      {
+        position = curTestPos + pos;
+        return S_OK;
+      }
+    }
+    curTestPos += pos;
+    numBytesPrev = numBytesInBuffer - numTests;
+    memmove(buf, buf + numTests, numBytesPrev);
+  }
+}
+
+HRESULT CInArchive::SafeReadBytes(void *data, UInt32 size)
+{
+  size_t processed = size;
+  RINOK(ReadStream(Stream, data, &processed));
+  if (processed != size)
+    throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
+  return S_OK;
+}
+
+HRESULT CInArchive::ReadBlock(bool &filled)
+{
+  filled = false;
+  Byte buf[2];
+  RINOK(SafeReadBytes(buf, 2));
+  _blockSize = Get16(buf);
+  if (_blockSize == 0)
+    return S_OK;
+  if (_blockSize > kBlockSizeMax)
+    throw CInArchiveException(CInArchiveException::kIncorrectArchive);
+  RINOK(SafeReadBytes(_block, _blockSize + 4));
+  NumBytes += _blockSize + 6;
+  if (Get32(_block + _blockSize) != CrcCalc(_block, _blockSize))
+    throw CInArchiveException(CInArchiveException::kCRCError);
+  filled = true;
+  return S_OK;
+}
+
+HRESULT CInArchive::ReadSignatureAndBlock(bool &filled)
+{
+  Byte id[2];
+  RINOK(SafeReadBytes(id, 2));
+  if (id[0] != NSignature::kSig0 || id[1] != NSignature::kSig1)
+    throw CInArchiveException(CInArchiveException::kIncorrectArchive);
+  return ReadBlock(filled);
+}
+
+HRESULT CInArchive::SkipExtendedHeaders()
+{
+  for (UInt32 i = 0;; i++)
+  {
+    bool filled;
+    RINOK(ReadBlock(filled));
+    if (!filled)
+      return S_OK;
+    if (Callback && (i & 0xFF) == 0)
+      RINOK(Callback->SetCompleted(&NumFiles, &NumBytes));
+  }
+}
+
+HRESULT CInArchive::Open(const UInt64 *searchHeaderSizeLimit)
+{
+  UInt64 position = 0;
+  RINOK(FindAndReadMarker(Stream, searchHeaderSizeLimit, position));
+  RINOK(Stream->Seek(position, STREAM_SEEK_SET, NULL));
+  bool filled;
+  RINOK(ReadSignatureAndBlock(filled));
+  if (!filled)
+    return S_FALSE;
+  RINOK(Header.Parse(_block, _blockSize));
+  return SkipExtendedHeaders();
+}
+
+HRESULT CInArchive::GetNextItem(bool &filled, CItem &item)
+{
+  RINOK(ReadSignatureAndBlock(filled));
+  if (!filled)
+    return S_OK;
+  filled = false;
+  RINOK(item.Parse(_block, _blockSize));
+  /*
+  UInt32 extraData;
+  if ((header.Flags & NFileHeader::NFlags::kExtFile) != 0)
+    extraData = GetUi32(_block + pos);
+  */
+
+  RINOK(SkipExtendedHeaders());
+  filled = true;
+  return S_OK;
+}
+
+class CHandler:
+  public IInArchive,
+  public CMyUnknownImp
+{
+public:
+  MY_UNKNOWN_IMP1(IInArchive)
+
+  INTERFACE_IInArchive(;)
+
+  HRESULT Open2(IInStream *inStream, const UInt64 *maxCheckStartPosition,
+      IArchiveOpenCallback *callback);
+private:
+  CInArchive _archive;
+  CObjectVector<CItem> _items;
+  CMyComPtr<IInStream> _stream;
+};
+
+const wchar_t *kHostOS[] =
+{
+  L"MSDOS",
+  L"PRIMOS",
+  L"UNIX",
+  L"AMIGA",
+  L"MAC",
+  L"OS/2",
+  L"APPLE GS",
+  L"ATARI ST",
+  L"NEXT",
+  L"VAX VMS",
+  L"WIN95"
+};
+
+const wchar_t *kUnknownOS = L"Unknown";
+
+const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
+
+STATPROPSTG kArcProps[] =
+{
+  { NULL, kpidName, VT_BSTR},
+  { NULL, kpidCTime, VT_BSTR},
+  { NULL, kpidMTime, VT_BSTR},
+  { NULL, kpidHostOS, VT_BSTR},
+  { NULL, kpidComment, VT_BSTR}
+};
+
+STATPROPSTG kProps[] =
+{
+  { NULL, kpidPath, VT_BSTR},
+  { NULL, kpidIsDir, VT_BOOL},
+  { NULL, kpidSize, VT_UI4},
+  { NULL, kpidPosition, VT_UI8},
+  { NULL, kpidPackSize, VT_UI4},
+  { NULL, kpidMTime, VT_FILETIME},
+  { NULL, kpidAttrib, VT_UI4},
+  { NULL, kpidEncrypted, VT_BOOL},
+  { NULL, kpidCRC, VT_UI4},
+  { NULL, kpidMethod, VT_UI1},
+  { NULL, kpidHostOS, VT_BSTR},
+  { NULL, kpidComment, VT_BSTR}
+};
+
+IMP_IInArchive_Props
+IMP_IInArchive_ArcProps
+
+static void SetTime(UInt32 dosTime, NWindows::NCOM::CPropVariant &prop)
+{
+  if (dosTime == 0)
+    return;
+  FILETIME localFileTime, utc;
+  if (NTime::DosTimeToFileTime(dosTime, localFileTime))
+  {
+    if (!LocalFileTimeToFileTime(&localFileTime, &utc))
+      utc.dwHighDateTime = utc.dwLowDateTime = 0;
+  }
+  else
+    utc.dwHighDateTime = utc.dwLowDateTime = 0;
+  prop = utc;
+}
+
+static void SetHostOS(Byte hostOS, NWindows::NCOM::CPropVariant &prop)
+{
+  prop = hostOS < kNumHostOSes ? kHostOS[hostOS] : kUnknownOS;
+}
+
+static void SetUnicodeString(const AString &s, NWindows::NCOM::CPropVariant &prop)
+{
+  if (!s.IsEmpty())
+    prop = MultiByteToUnicodeString(s, CP_OEMCP);
+}
+ 
+STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NWindows::NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case kpidName:  SetUnicodeString(_archive.Header.Name, prop); break;
+    case kpidCTime:  SetTime(_archive.Header.CTime, prop); break;
+    case kpidMTime:  SetTime(_archive.Header.MTime, prop); break;
+    case kpidHostOS:  SetHostOS(_archive.Header.HostOS, prop); break;
+    case kpidComment:  SetUnicodeString(_archive.Header.Comment, prop); break;
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+{
+  *numItems = _items.Size();
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NWindows::NCOM::CPropVariant prop;
+  const CItem &item = _items[index];
+  switch(propID)
+  {
+    case kpidPath:  prop = NItemName::GetOSName(MultiByteToUnicodeString(item.Name, CP_OEMCP)); break;
+    case kpidIsDir:  prop = item.IsDir(); break;
+    case kpidSize:  prop = item.Size; break;
+    case kpidPackSize:  prop = item.PackSize; break;
+    case kpidPosition:  if (item.IsSplitBefore() || item.IsSplitAfter()) prop = (UInt64)item.SplitPos; break;
+    case kpidAttrib:  prop = item.GetWinAttributes(); break;
+    case kpidEncrypted:  prop = item.IsEncrypted(); break;
+    case kpidCRC:  prop = item.FileCRC; break;
+    case kpidMethod:  prop = item.Method; break;
+    case kpidHostOS:  SetHostOS(item.HostOS, prop); break;
+    case kpidMTime:  SetTime(item.MTime, prop); break;
+    case kpidComment:  SetUnicodeString(item.Comment, prop); break;
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+HRESULT CHandler::Open2(IInStream *inStream, const UInt64 *maxCheckStartPosition,
+      IArchiveOpenCallback *callback)
+{
+  Close();
+  
+  UInt64 endPos = 0;
+  if (callback != NULL)
+  {
+    RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));
+    RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));
+  }
+  
+  _archive.Stream = inStream;
+  _archive.Callback = callback;
+  _archive.NumFiles = _archive.NumBytes = 0;
+
+  RINOK(_archive.Open(maxCheckStartPosition));
+  if (callback != NULL)
+    RINOK(callback->SetTotal(NULL, &endPos));
+  for (;;)
+  {
+    CItem item;
+    bool filled;
+
+
+    RINOK(_archive.GetNextItem(filled, item));
+    
+    RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &item.DataPosition));
+    
+    if (!filled)
+      break;
+    _items.Add(item);
+    
+    if (inStream->Seek(item.PackSize, STREAM_SEEK_CUR, NULL) != S_OK)
+      throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
+
+    _archive.NumFiles = _items.Size();
+    _archive.NumBytes = item.DataPosition;
+    
+    if (callback != NULL && _items.Size() % 100 == 0)
+    {
+      RINOK(callback->SetCompleted(&_archive.NumFiles, &_archive.NumBytes));
+    }
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Open(IInStream *inStream,
+    const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *callback)
+{
+  COM_TRY_BEGIN
+  HRESULT res;
+  try
+  {
+    res = Open2(inStream, maxCheckStartPosition, callback);
+    if (res == S_OK)
+    {
+      _stream = inStream;
+      return S_OK;
+    }
+  }
+  catch(const CInArchiveException &) { res = S_FALSE; }
+  Close();
+  return res;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::Close()
+{
+  _items.Clear();
+  _stream.Release();
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+    Int32 testMode, IArchiveExtractCallback *extractCallback)
+{
+  COM_TRY_BEGIN
+  UInt64 totalUnpacked = 0, totalPacked = 0;
+  bool allFilesMode = (numItems == (UInt32)-1);
+  if (allFilesMode)
+    numItems = _items.Size();
+  if (numItems == 0)
+    return S_OK;
+  UInt32 i;
+  for (i = 0; i < numItems; i++)
+  {
+    const CItem &item = _items[allFilesMode ? i : indices[i]];
+    totalUnpacked += item.Size;
+    totalPacked += item.PackSize;
+  }
+  extractCallback->SetTotal(totalUnpacked);
+
+  totalUnpacked = totalPacked = 0;
+  UInt64 curUnpacked, curPacked;
+  
+  CMyComPtr<ICompressCoder> arj1Decoder;
+  CMyComPtr<ICompressCoder> arj2Decoder;
+  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
+  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
+
+  CLocalProgress *lps = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> progress = lps;
+  lps->Init(extractCallback, false);
+
+  CLimitedSequentialInStream *inStreamSpec = new CLimitedSequentialInStream;
+  CMyComPtr<ISequentialInStream> inStream(inStreamSpec);
+  inStreamSpec->SetStream(_stream);
+
+  for (i = 0; i < numItems; i++, totalUnpacked += curUnpacked, totalPacked += curPacked)
+  {
+    lps->InSize = totalPacked;
+    lps->OutSize = totalUnpacked;
+    RINOK(lps->SetCur());
+
+    curUnpacked = curPacked = 0;
+
+    CMyComPtr<ISequentialOutStream> realOutStream;
+    Int32 askMode = testMode ?
+        NExtract::NAskMode::kTest :
+        NExtract::NAskMode::kExtract;
+    Int32 index = allFilesMode ? i : indices[i];
+    const CItem &item = _items[index];
+    RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+
+    if (item.IsDir())
+    {
+      // if (!testMode)
+      {
+        RINOK(extractCallback->PrepareOperation(askMode));
+        RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+      }
+      continue;
+    }
+
+    if (!testMode && !realOutStream)
+      continue;
+
+    RINOK(extractCallback->PrepareOperation(askMode));
+    curUnpacked = item.Size;
+    curPacked = item.PackSize;
+
+    {
+      COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
+      CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
+      outStreamSpec->SetStream(realOutStream);
+      realOutStream.Release();
+      outStreamSpec->Init();
+  
+      inStreamSpec->Init(item.PackSize);
+      
+      UInt64 pos;
+      _stream->Seek(item.DataPosition, STREAM_SEEK_SET, &pos);
+
+      HRESULT result = S_OK;
+      Int32 opRes = NExtract::NOperationResult::kOK;
+
+      if (item.IsEncrypted())
+        opRes = NExtract::NOperationResult::kUnSupportedMethod;
+      else
+      {
+        switch(item.Method)
+        {
+          case NFileHeader::NCompressionMethod::kStored:
+          {
+            result = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
+            if (result == S_OK && copyCoderSpec->TotalSize != item.PackSize)
+              result = S_FALSE;
+            break;
+          }
+          case NFileHeader::NCompressionMethod::kCompressed1a:
+          case NFileHeader::NCompressionMethod::kCompressed1b:
+          case NFileHeader::NCompressionMethod::kCompressed1c:
+          {
+            if (!arj1Decoder)
+              arj1Decoder = new NCompress::NArj::NDecoder1::CCoder;
+            result = arj1Decoder->Code(inStream, outStream, NULL, &curUnpacked, progress);
+            break;
+          }
+          case NFileHeader::NCompressionMethod::kCompressed2:
+          {
+            if (!arj2Decoder)
+              arj2Decoder = new NCompress::NArj::NDecoder2::CCoder;
+            result = arj2Decoder->Code(inStream, outStream, NULL, &curUnpacked, progress);
+            break;
+          }
+          default:
+            opRes = NExtract::NOperationResult::kUnSupportedMethod;
+        }
+      }
+      if (opRes == NExtract::NOperationResult::kOK)
+      {
+        if (result == S_FALSE)
+          opRes = NExtract::NOperationResult::kDataError;
+        else
+        {
+          RINOK(result);
+          opRes = (outStreamSpec->GetCRC() == item.FileCRC) ?
+              NExtract::NOperationResult::kOK:
+              NExtract::NOperationResult::kCRCError;
+        }
+      }
+      outStream.Release();
+      RINOK(extractCallback->SetOperationResult(opRes));
+    }
+  }
+  return S_OK;
+  COM_TRY_END
+}
+
+static IInArchive *CreateArc() { return new CHandler; }
+
+static CArcInfo g_ArcInfo =
+  { L"Arj", L"arj", 0, 4, { 0x60, 0xEA }, 2, false, CreateArc, 0 };
+
+REGISTER_ARC(Arj)
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Bz2Handler.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Bz2Handler.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Bz2Handler.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Bz2Handler.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,423 @@
+// Bz2Handler.cpp
+
+#include "StdAfx.h"
+
+#include "Common/ComTry.h"
+
+#include "Windows/PropVariant.h"
+
+#ifndef _7ZIP_ST
+#include "../../Windows/System.h"
+#endif
+
+#include "../Common/CreateCoder.h"
+#include "../Common/ProgressUtils.h"
+#include "../Common/RegisterArc.h"
+#include "../Common/StreamUtils.h"
+
+#include "../Compress/BZip2Decoder.h"
+#include "../Compress/BZip2Encoder.h"
+#include "../Compress/CopyCoder.h"
+
+#include "Common/DummyOutStream.h"
+#include "Common/ParseProperties.h"
+
+using namespace NWindows;
+
+namespace NArchive {
+namespace NBz2 {
+
+static const UInt32 kNumPassesX1 = 1;
+static const UInt32 kNumPassesX7 = 2;
+static const UInt32 kNumPassesX9 = 7;
+
+static const UInt32 kDicSizeX1 = 100000;
+static const UInt32 kDicSizeX3 = 500000;
+static const UInt32 kDicSizeX5 = 900000;
+
+class CHandler:
+  public IInArchive,
+  public IArchiveOpenSeq,
+  public IOutArchive,
+  public ISetProperties,
+  public CMyUnknownImp
+{
+  CMyComPtr<IInStream> _stream;
+  CMyComPtr<ISequentialInStream> _seqStream;
+  UInt64 _packSize;
+  UInt64 _startPosition;
+  bool _packSizeDefined;
+
+  UInt32 _level;
+  UInt32 _dicSize;
+  UInt32 _numPasses;
+  #ifndef _7ZIP_ST
+  UInt32 _numThreads;
+  #endif
+
+  void InitMethodProperties()
+  {
+    _level = 5;
+    _dicSize =
+    _numPasses = 0xFFFFFFFF;
+    #ifndef _7ZIP_ST
+    _numThreads = NWindows::NSystem::GetNumberOfProcessors();;
+    #endif
+  }
+
+public:
+  MY_UNKNOWN_IMP4(IInArchive, IArchiveOpenSeq, IOutArchive, ISetProperties)
+
+  INTERFACE_IInArchive(;)
+  INTERFACE_IOutArchive(;)
+  STDMETHOD(OpenSeq)(ISequentialInStream *stream);
+  STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProps);
+
+  CHandler() { InitMethodProperties(); }
+};
+
+STATPROPSTG kProps[] =
+{
+  { NULL, kpidPackSize, VT_UI8}
+};
+
+IMP_IInArchive_Props
+IMP_IInArchive_ArcProps_NO_Table
+
+STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
+{
+  NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case kpidPhySize: if (_packSizeDefined) prop = _packSize; break;
+  }
+  prop.Detach(value);
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+{
+  *numItems = 1;
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID,  PROPVARIANT *value)
+{
+  NWindows::NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case kpidPackSize: if (_packSizeDefined) prop = _packSize; break;
+  }
+  prop.Detach(value);
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Open(IInStream *stream,
+    const UInt64 * /* maxCheckStartPosition */,
+    IArchiveOpenCallback * /* openArchiveCallback */)
+{
+  COM_TRY_BEGIN
+  try
+  {
+    Close();
+    RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_startPosition));
+    const int kSignatureSize = 3;
+    Byte buf[kSignatureSize];
+    RINOK(ReadStream_FALSE(stream, buf, kSignatureSize));
+    if (buf[0] != 'B' || buf[1] != 'Z' || buf[2] != 'h')
+      return S_FALSE;
+
+    UInt64 endPosition;
+    RINOK(stream->Seek(0, STREAM_SEEK_END, &endPosition));
+    _packSize = endPosition - _startPosition;
+    _packSizeDefined = true;
+    _stream = stream;
+    _seqStream = stream;
+  }
+  catch(...) { return S_FALSE; }
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
+{
+  Close();
+  _seqStream = stream;
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Close()
+{
+  _packSizeDefined = false;
+  _seqStream.Release();
+  _stream.Release();
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+    Int32 testMode, IArchiveExtractCallback *extractCallback)
+{
+  COM_TRY_BEGIN
+  if (numItems == 0)
+    return S_OK;
+  if (numItems != (UInt32)-1 && (numItems != 1 || indices[0] != 0))
+    return E_INVALIDARG;
+
+  if (_stream)
+    extractCallback->SetTotal(_packSize);
+  UInt64 currentTotalPacked = 0;
+  RINOK(extractCallback->SetCompleted(&currentTotalPacked));
+  CMyComPtr<ISequentialOutStream> realOutStream;
+  Int32 askMode = testMode ?
+      NExtract::NAskMode::kTest :
+      NExtract::NAskMode::kExtract;
+  RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
+  if (!testMode && !realOutStream)
+    return S_OK;
+
+  extractCallback->PrepareOperation(askMode);
+
+  NCompress::NBZip2::CDecoder *decoderSpec = new NCompress::NBZip2::CDecoder;
+  CMyComPtr<ICompressCoder> decoder = decoderSpec;
+
+  if (_stream)
+  {
+    RINOK(_stream->Seek(_startPosition, STREAM_SEEK_SET, NULL));
+  }
+
+  decoderSpec->SetInStream(_seqStream);
+
+  #ifndef _7ZIP_ST
+  RINOK(decoderSpec->SetNumberOfThreads(_numThreads));
+  #endif
+
+  CDummyOutStream *outStreamSpec = new CDummyOutStream;
+  CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
+  outStreamSpec->SetStream(realOutStream);
+  outStreamSpec->Init();
+  
+  realOutStream.Release();
+
+  CLocalProgress *lps = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> progress = lps;
+  lps->Init(extractCallback, true);
+
+  HRESULT result = S_OK;
+
+  bool firstItem = true;
+  for (;;)
+  {
+    lps->InSize = currentTotalPacked;
+    lps->OutSize = outStreamSpec->GetSize();
+
+    RINOK(lps->SetCur());
+
+    bool isBz2;
+    result = decoderSpec->CodeResume(outStream, isBz2, progress);
+
+    if (result != S_OK)
+      break;
+    if (!isBz2)
+    {
+      if (firstItem)
+        result = S_FALSE;
+      break;
+    }
+    firstItem = false;
+
+    _packSize = currentTotalPacked = decoderSpec->GetInputProcessedSize();
+    _packSizeDefined = true;
+  }
+  decoderSpec->ReleaseInStream();
+  outStream.Release();
+
+  Int32 retResult;
+  if (result == S_OK)
+    retResult = NExtract::NOperationResult::kOK;
+  else if (result == S_FALSE)
+    retResult = NExtract::NOperationResult::kDataError;
+  else
+    return result;
+  return extractCallback->SetOperationResult(retResult);
+
+  COM_TRY_END
+}
+
+static HRESULT UpdateArchive(
+    UInt64 unpackSize,
+    ISequentialOutStream *outStream,
+    int indexInClient,
+    UInt32 dictionary,
+    UInt32 numPasses,
+    #ifndef _7ZIP_ST
+    UInt32 numThreads,
+    #endif
+    IArchiveUpdateCallback *updateCallback)
+{
+  RINOK(updateCallback->SetTotal(unpackSize));
+  UInt64 complexity = 0;
+  RINOK(updateCallback->SetCompleted(&complexity));
+
+  CMyComPtr<ISequentialInStream> fileInStream;
+
+  RINOK(updateCallback->GetStream(indexInClient, &fileInStream));
+
+  CLocalProgress *localProgressSpec = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> localProgress = localProgressSpec;
+  localProgressSpec->Init(updateCallback, true);
+  
+  NCompress::NBZip2::CEncoder *encoderSpec = new NCompress::NBZip2::CEncoder;
+  CMyComPtr<ICompressCoder> encoder = encoderSpec;
+  {
+    NWindows::NCOM::CPropVariant properties[] =
+    {
+      dictionary,
+      numPasses
+      #ifndef _7ZIP_ST
+      , numThreads
+      #endif
+    };
+    PROPID propIDs[] =
+    {
+      NCoderPropID::kDictionarySize,
+      NCoderPropID::kNumPasses
+      #ifndef _7ZIP_ST
+      , NCoderPropID::kNumThreads
+      #endif
+    };
+    RINOK(encoderSpec->SetCoderProperties(propIDs, properties, sizeof(propIDs) / sizeof(propIDs[0])));
+  }
+  
+  RINOK(encoder->Code(fileInStream, outStream, NULL, NULL, localProgress));
+  
+  return updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK);
+}
+
+STDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)
+{
+  *type = NFileTimeType::kUnix;
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
+    IArchiveUpdateCallback *updateCallback)
+{
+  if (numItems != 1)
+    return E_INVALIDARG;
+
+  Int32 newData, newProps;
+  UInt32 indexInArchive;
+  if (!updateCallback)
+    return E_FAIL;
+  RINOK(updateCallback->GetUpdateItemInfo(0, &newData, &newProps, &indexInArchive));
+ 
+  if (IntToBool(newProps))
+  {
+    {
+      NCOM::CPropVariant prop;
+      RINOK(updateCallback->GetProperty(0, kpidIsDir, &prop));
+      if (prop.vt == VT_BOOL)
+      {
+        if (prop.boolVal != VARIANT_FALSE)
+          return E_INVALIDARG;
+      }
+      else if (prop.vt != VT_EMPTY)
+        return E_INVALIDARG;
+    }
+  }
+  
+  if (IntToBool(newData))
+  {
+    UInt64 size;
+    {
+      NCOM::CPropVariant prop;
+      RINOK(updateCallback->GetProperty(0, kpidSize, &prop));
+      if (prop.vt != VT_UI8)
+        return E_INVALIDARG;
+      size = prop.uhVal.QuadPart;
+    }
+  
+    UInt32 dicSize = _dicSize;
+    if (dicSize == 0xFFFFFFFF)
+      dicSize = (_level >= 5 ? kDicSizeX5 :
+                (_level >= 3 ? kDicSizeX3 :
+                               kDicSizeX1));
+
+    UInt32 numPasses = _numPasses;
+    if (numPasses == 0xFFFFFFFF)
+      numPasses = (_level >= 9 ? kNumPassesX9 :
+                  (_level >= 7 ? kNumPassesX7 :
+                                 kNumPassesX1));
+
+    return UpdateArchive(
+        size, outStream, 0, dicSize, numPasses,
+        #ifndef _7ZIP_ST
+        _numThreads,
+        #endif
+        updateCallback);
+  }
+  if (indexInArchive != 0)
+    return E_INVALIDARG;
+  if (_stream)
+    RINOK(_stream->Seek(_startPosition, STREAM_SEEK_SET, NULL));
+  return NCompress::CopyStream(_stream, outStream, NULL);
+}
+
+STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProps)
+{
+  InitMethodProperties();
+  #ifndef _7ZIP_ST
+  const UInt32 numProcessors = NSystem::GetNumberOfProcessors();
+  _numThreads = numProcessors;
+  #endif
+
+  for (int i = 0; i < numProps; i++)
+  {
+    UString name = names[i];
+    name.MakeUpper();
+    if (name.IsEmpty())
+      return E_INVALIDARG;
+    const PROPVARIANT &prop = values[i];
+    if (name[0] == L'X')
+    {
+      UInt32 level = 9;
+      RINOK(ParsePropValue(name.Mid(1), prop, level));
+      _level = level;
+    }
+    else if (name[0] == L'D')
+    {
+      UInt32 dicSize = kDicSizeX5;
+      RINOK(ParsePropDictionaryValue(name.Mid(1), prop, dicSize));
+      _dicSize = dicSize;
+    }
+    else if (name.Left(4) == L"PASS")
+    {
+      UInt32 num = kNumPassesX9;
+      RINOK(ParsePropValue(name.Mid(4), prop, num));
+      _numPasses = num;
+    }
+    else if (name.Left(2) == L"MT")
+    {
+      #ifndef _7ZIP_ST
+      RINOK(ParseMtProp(name.Mid(2), prop, numProcessors, _numThreads));
+      #endif
+    }
+    else
+      return E_INVALIDARG;
+  }
+  return S_OK;
+}
+
+static IInArchive *CreateArc() { return new CHandler; }
+#ifndef EXTRACT_ONLY
+static IOutArchive *CreateArcOut() { return new CHandler; }
+#else
+#define CreateArcOut 0
+#endif
+
+static CArcInfo g_ArcInfo =
+  { L"bzip2", L"bz2 bzip2 tbz2 tbz", L"* * .tar .tar", 2, { 'B', 'Z', 'h' }, 3, true, CreateArc, CreateArcOut };
+
+REGISTER_ARC(BZip2)
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,189 @@
+// CabBlockInStream.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/Alloc.h"
+
+#include "Common/Defs.h"
+
+#include "../../Common/StreamUtils.h"
+
+#include "CabBlockInStream.h"
+
+namespace NArchive {
+namespace NCab {
+
+static const UInt32 kBlockSize = (1 << 16);
+
+bool CCabBlockInStream::Create()
+{
+  if (!_buffer)
+    _buffer = (Byte *)::MyAlloc(kBlockSize);
+  return (_buffer != 0);
+}
+
+CCabBlockInStream::~CCabBlockInStream()
+{
+  MyFree(_buffer);
+}
+
+class CCheckSum2
+{
+  UInt32 m_Value;
+  int m_Pos;
+  Byte m_Hist[4];
+public:
+  CCheckSum2(): m_Value(0){};
+  void Init() { m_Value = 0;  m_Pos = 0; }
+  void Update(const void *data, UInt32 size);
+  void FinishDataUpdate()
+  {
+    for (int i = 0; i < m_Pos; i++)
+      m_Value ^= ((UInt32)(m_Hist[i])) << (8 * (m_Pos - i - 1));
+  }
+  void UpdateUInt32(UInt32 v) { m_Value ^= v; }
+  UInt32 GetResult() const {  return m_Value; }
+};
+
+void CCheckSum2::Update(const void *data, UInt32 size)
+{
+  UInt32 checkSum = m_Value;
+  const Byte *dataPointer = (const Byte *)data;
+
+  while (size != 0 && m_Pos != 0)
+  {
+    m_Hist[m_Pos] = *dataPointer++;
+    m_Pos = (m_Pos + 1) & 3;
+    size--;
+    if (m_Pos == 0)
+      for (int i = 0; i < 4; i++)
+        checkSum ^= ((UInt32)m_Hist[i]) << (8 * i);
+  }
+
+  int numWords = size / 4;
+  
+  while (numWords-- != 0)
+  {
+    UInt32 temp = *dataPointer++;
+    temp |= ((UInt32)(*dataPointer++)) <<  8;
+    temp |= ((UInt32)(*dataPointer++)) << 16;
+    temp |= ((UInt32)(*dataPointer++)) << 24;
+    checkSum ^= temp;
+  }
+  m_Value = checkSum;
+
+  size &= 3;
+  
+  while (size != 0)
+  {
+    m_Hist[m_Pos] = *dataPointer++;
+    m_Pos = (m_Pos + 1) & 3;
+    size--;
+  }
+}
+
+static const UInt32 kDataBlockHeaderSize = 8;
+
+class CTempCabInBuffer2
+{
+public:
+  Byte Buffer[kDataBlockHeaderSize];
+  UInt32 Pos;
+  Byte ReadByte()
+  {
+    return Buffer[Pos++];
+  }
+  UInt32 ReadUInt32()
+  {
+    UInt32 value = 0;
+    for (int i = 0; i < 4; i++)
+      value |= (((UInt32)ReadByte()) << (8 * i));
+    return value;
+  }
+  UInt16 ReadUInt16()
+  {
+    UInt16 value = 0;
+    for (int i = 0; i < 2; i++)
+      value |= (((UInt16)ReadByte()) << (8 * i));
+    return value;
+  }
+};
+
+HRESULT CCabBlockInStream::PreRead(UInt32 &packSize, UInt32 &unpackSize)
+{
+  CTempCabInBuffer2 inBuffer;
+  inBuffer.Pos = 0;
+  RINOK(ReadStream_FALSE(_stream, inBuffer.Buffer, kDataBlockHeaderSize))
+
+  UInt32 checkSum = inBuffer.ReadUInt32();
+  packSize = inBuffer.ReadUInt16();
+  unpackSize = inBuffer.ReadUInt16();
+  if (ReservedSize != 0)
+  {
+    RINOK(ReadStream_FALSE(_stream, _buffer, ReservedSize));
+  }
+  _pos = 0;
+  CCheckSum2 checkSumCalc;
+  checkSumCalc.Init();
+  UInt32 packSize2 = packSize;
+  if (MsZip && _size == 0)
+  {
+    if (packSize < 2)
+      return S_FALSE; // bad block;
+    Byte sig[2];
+    RINOK(ReadStream_FALSE(_stream, sig, 2));
+    if (sig[0] != 0x43 || sig[1] != 0x4B)
+      return S_FALSE;
+    packSize2 -= 2;
+    checkSumCalc.Update(sig, 2);
+  }
+
+  if (kBlockSize - _size < packSize2)
+    return S_FALSE;
+
+  UInt32 curSize = packSize2;
+  if (curSize != 0)
+  {
+    size_t processedSizeLoc = curSize;
+    RINOK(ReadStream(_stream, _buffer + _size, &processedSizeLoc));
+    checkSumCalc.Update(_buffer + _size, (UInt32)processedSizeLoc);
+    _size += (UInt32)processedSizeLoc;
+    if (processedSizeLoc != curSize)
+      return S_FALSE;
+  }
+  TotalPackSize = _size;
+
+  checkSumCalc.FinishDataUpdate();
+  
+  bool dataError;
+  if (checkSum == 0)
+    dataError = false;
+  else
+  {
+    checkSumCalc.UpdateUInt32(packSize | (((UInt32)unpackSize) << 16));
+    dataError = (checkSumCalc.GetResult() != checkSum);
+  }
+  DataError |= dataError;
+  return dataError ? S_FALSE : S_OK;
+}
+
+STDMETHODIMP CCabBlockInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+  if (processedSize != 0)
+    *processedSize = 0;
+  if (size == 0)
+    return S_OK;
+  if (_size != 0)
+  {
+    size = MyMin(_size, size);
+    memmove(data, _buffer + _pos, size);
+    _pos += size;
+    _size -= size;
+    if (processedSize != 0)
+      *processedSize = size;
+    return S_OK;
+  }
+  return S_OK; // no blocks data
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,44 @@
+// CabBlockInStream.cpp
+
+#ifndef __CABBLOCKINSTREAM_H
+#define __CABBLOCKINSTREAM_H
+
+#include "Common/MyCom.h"
+#include "../../IStream.h"
+
+namespace NArchive {
+namespace NCab {
+
+class CCabBlockInStream:
+  public ISequentialInStream,
+  public CMyUnknownImp
+{
+  CMyComPtr<ISequentialInStream> _stream;
+  Byte *_buffer;
+  UInt32 _pos;
+  UInt32 _size;
+
+public:
+  UInt32 TotalPackSize;
+  UInt32 ReservedSize;
+  bool DataError;
+  bool MsZip;
+
+  CCabBlockInStream(): _buffer(0), ReservedSize(0), MsZip(false), DataError(false), TotalPackSize(0) {}
+  ~CCabBlockInStream();
+  bool Create();
+  void SetStream(ISequentialInStream *stream) {  _stream = stream; }
+
+  void InitForNewFolder() { TotalPackSize = 0; }
+  void InitForNewBlock() { _size = 0; }
+
+  MY_UNKNOWN_IMP
+
+  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+
+  HRESULT PreRead(UInt32 &packSize, UInt32 &unpackSize);
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,929 @@
+// CabHandler.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/Alloc.h"
+
+#include "Common/Buffer.h"
+#include "Common/ComTry.h"
+#include "Common/Defs.h"
+#include "Common/IntToString.h"
+#include "Common/StringConvert.h"
+#include "Common/UTFConvert.h"
+
+#include "Windows/PropVariant.h"
+#include "Windows/Time.h"
+
+#include "../../Common/ProgressUtils.h"
+#include "../../Common/StreamUtils.h"
+
+#include "../../Compress/CopyCoder.h"
+#include "../../Compress/DeflateDecoder.h"
+#include "../../Compress/LzxDecoder.h"
+#include "../../Compress/QuantumDecoder.h"
+
+#include "../Common/ItemNameUtils.h"
+
+#include "CabBlockInStream.h"
+#include "CabHandler.h"
+
+using namespace NWindows;
+
+namespace NArchive {
+namespace NCab {
+
+// #define _CAB_DETAILS
+
+#ifdef _CAB_DETAILS
+enum
+{
+  kpidBlockReal = kpidUserDefined
+};
+#endif
+
+static STATPROPSTG kProps[] =
+{
+  { NULL, kpidPath, VT_BSTR},
+  { NULL, kpidSize, VT_UI8},
+  { NULL, kpidMTime, VT_FILETIME},
+  { NULL, kpidAttrib, VT_UI4},
+  { NULL, kpidMethod, VT_BSTR},
+  { NULL, kpidBlock, VT_I4}
+  #ifdef _CAB_DETAILS
+  ,
+  { L"BlockReal", kpidBlockReal, VT_UI4},
+  { NULL, kpidOffset, VT_UI4},
+  { NULL, kpidVolume, VT_UI4}
+  #endif
+};
+
+static const char *kMethods[] =
+{
+  "None",
+  "MSZip",
+  "Quantum",
+  "LZX"
+};
+
+static const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
+static const char *kUnknownMethod = "Unknown";
+
+static STATPROPSTG kArcProps[] =
+{
+  { NULL, kpidMethod, VT_BSTR},
+  // { NULL, kpidSolid, VT_BOOL},
+  { NULL, kpidNumBlocks, VT_UI4},
+  { NULL, kpidNumVolumes, VT_UI4}
+};
+
+IMP_IInArchive_Props
+IMP_IInArchive_ArcProps
+
+STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NWindows::NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case kpidMethod:
+    {
+      AString resString;
+      CRecordVector<Byte> ids;
+      int i;
+      for (int v = 0; v < m_Database.Volumes.Size(); v++)
+      {
+        const CDatabaseEx &de = m_Database.Volumes[v];
+        for (i = 0; i < de.Folders.Size(); i++)
+          ids.AddToUniqueSorted(de.Folders[i].GetCompressionMethod());
+      }
+      for (i = 0; i < ids.Size(); i++)
+      {
+        Byte id = ids[i];
+        AString method = (id < kNumMethods) ? kMethods[id] : kUnknownMethod;
+        if (!resString.IsEmpty())
+          resString += ' ';
+        resString += method;
+      }
+      prop = resString;
+      break;
+    }
+    // case kpidSolid: prop = _database.IsSolid(); break;
+    case kpidNumBlocks:
+    {
+      UInt32 numFolders = 0;
+      for (int v = 0; v < m_Database.Volumes.Size(); v++)
+        numFolders += m_Database.Volumes[v].Folders.Size();
+      prop = numFolders;
+      break;
+    }
+    case kpidNumVolumes:
+    {
+      prop = (UInt32)m_Database.Volumes.Size();
+      break;
+    }
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NWindows::NCOM::CPropVariant prop;
+  
+  const CMvItem &mvItem = m_Database.Items[index];
+  const CDatabaseEx &db = m_Database.Volumes[mvItem.VolumeIndex];
+  int itemIndex = mvItem.ItemIndex;
+  const CItem &item = db.Items[itemIndex];
+  switch(propID)
+  {
+    case kpidPath:
+    {
+      UString unicodeName;
+      if (item.IsNameUTF())
+        ConvertUTF8ToUnicode(item.Name, unicodeName);
+      else
+        unicodeName = MultiByteToUnicodeString(item.Name, CP_ACP);
+      prop = (const wchar_t *)NItemName::WinNameToOSName(unicodeName);
+      break;
+    }
+    case kpidIsDir:  prop = item.IsDir(); break;
+    case kpidSize:  prop = item.Size; break;
+    case kpidAttrib:  prop = item.GetWinAttributes(); break;
+
+    case kpidMTime:
+    {
+      FILETIME localFileTime, utcFileTime;
+      if (NTime::DosTimeToFileTime(item.Time, localFileTime))
+      {
+        if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
+          utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
+      }
+      else
+        utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
+      prop = utcFileTime;
+      break;
+    }
+
+    case kpidMethod:
+    {
+      UInt32 realFolderIndex = item.GetFolderIndex(db.Folders.Size());
+      const CFolder &folder = db.Folders[realFolderIndex];
+      int methodIndex = folder.GetCompressionMethod();
+      AString method = (methodIndex < kNumMethods) ? kMethods[methodIndex] : kUnknownMethod;
+      if (methodIndex == NHeader::NCompressionMethodMajor::kLZX ||
+        methodIndex == NHeader::NCompressionMethodMajor::kQuantum)
+      {
+        method += ':';
+        char temp[32];
+        ConvertUInt64ToString(folder.CompressionTypeMinor, temp);
+        method += temp;
+      }
+      prop = method;
+      break;
+    }
+    case kpidBlock:  prop = (Int32)m_Database.GetFolderIndex(&mvItem); break;
+    
+    #ifdef _CAB_DETAILS
+    
+    case kpidBlockReal:  prop = (UInt32)item.FolderIndex; break;
+    case kpidOffset:  prop = (UInt32)item.Offset; break;
+    case kpidVolume:  prop = (UInt32)mvItem.VolumeIndex; break;
+
+    #endif
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+/*
+class CProgressImp: public CProgressVirt
+{
+  CMyComPtr<IArchiveOpenCallback> m_OpenArchiveCallback;
+public:
+  STDMETHOD(SetTotal)(const UInt64 *numFiles);
+  STDMETHOD(SetCompleted)(const UInt64 *numFiles);
+  void Init(IArchiveOpenCallback *openArchiveCallback)
+    { m_OpenArchiveCallback = openArchiveCallback; }
+};
+
+STDMETHODIMP CProgressImp::SetTotal(const UInt64 *numFiles)
+{
+  if (m_OpenArchiveCallback)
+    return m_OpenArchiveCallback->SetCompleted(numFiles, NULL);
+  return S_OK;
+}
+
+STDMETHODIMP CProgressImp::SetCompleted(const UInt64 *numFiles)
+{
+  if (m_OpenArchiveCallback)
+    return m_OpenArchiveCallback->SetCompleted(numFiles, NULL);
+  return S_OK;
+}
+*/
+
+STDMETHODIMP CHandler::Open(IInStream *inStream,
+    const UInt64 *maxCheckStartPosition,
+    IArchiveOpenCallback *callback)
+{
+  COM_TRY_BEGIN
+  Close();
+  HRESULT res = S_FALSE;
+  CInArchive archive;
+  CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
+  callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
+  
+  CMyComPtr<IInStream> nextStream = inStream;
+  bool prevChecked = false;
+  UInt64 numItems = 0;
+  try
+  {
+    while (nextStream != 0)
+    {
+      CDatabaseEx db;
+      db.Stream = nextStream;
+      res = archive.Open(maxCheckStartPosition, db);
+      if (res == S_OK)
+      {
+        if (!m_Database.Volumes.IsEmpty())
+        {
+          const CDatabaseEx &dbPrev = m_Database.Volumes[prevChecked ? m_Database.Volumes.Size() - 1 : 0];
+          if (dbPrev.ArchiveInfo.SetID != db.ArchiveInfo.SetID ||
+              dbPrev.ArchiveInfo.CabinetNumber + (prevChecked ? 1: - 1) !=
+              db.ArchiveInfo.CabinetNumber)
+            res = S_FALSE;
+        }
+      }
+      if (res == S_OK)
+        m_Database.Volumes.Insert(prevChecked ? m_Database.Volumes.Size() : 0, db);
+      else if (res != S_FALSE)
+        return res;
+      else
+      {
+        if (m_Database.Volumes.IsEmpty())
+          return S_FALSE;
+        if (prevChecked)
+          break;
+        prevChecked = true;
+      }
+
+      numItems += db.Items.Size();
+      RINOK(callback->SetCompleted(&numItems, NULL));
+        
+      nextStream = 0;
+      for (;;)
+      {
+        const COtherArchive *otherArchive = 0;
+        if (!prevChecked)
+        {
+          const CInArchiveInfo &ai = m_Database.Volumes.Front().ArchiveInfo;
+          if (ai.IsTherePrev())
+            otherArchive = &ai.PrevArc;
+          else
+            prevChecked = true;
+        }
+        if (otherArchive == 0)
+        {
+          const CInArchiveInfo &ai = m_Database.Volumes.Back().ArchiveInfo;
+          if (ai.IsThereNext())
+            otherArchive = &ai.NextArc;
+        }
+        if (!otherArchive)
+          break;
+        const UString fullName = MultiByteToUnicodeString(otherArchive->FileName, CP_ACP);
+        if (!openVolumeCallback)
+          break;
+
+        HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);
+        if (result == S_OK)
+          break;
+        if (result != S_FALSE)
+          return result;
+        if (prevChecked)
+          break;
+        prevChecked = true;
+      }
+    }
+    if (res == S_OK)
+    {
+      m_Database.FillSortAndShrink();
+      if (!m_Database.Check())
+        res = S_FALSE;
+    }
+  }
+  catch(...)
+  {
+    res = S_FALSE;
+  }
+  if (res != S_OK)
+  {
+    Close();
+    return res;
+  }
+  COM_TRY_END
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Close()
+{
+  m_Database.Clear();
+  return S_OK;
+}
+
+class CFolderOutStream:
+  public ISequentialOutStream,
+  public CMyUnknownImp
+{
+public:
+  MY_UNKNOWN_IMP
+
+  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+private:
+  const CMvDatabaseEx *m_Database;
+  const CRecordVector<bool> *m_ExtractStatuses;
+  
+  Byte *TempBuf;
+  UInt32 TempBufSize;
+  int NumIdenticalFiles;
+  bool TempBufMode;
+  UInt32 m_BufStartFolderOffset;
+
+  int m_StartIndex;
+  int m_CurrentIndex;
+  CMyComPtr<IArchiveExtractCallback> m_ExtractCallback;
+  bool m_TestMode;
+
+  CMyComPtr<ISequentialOutStream> m_RealOutStream;
+
+  bool m_IsOk;
+  bool m_FileIsOpen;
+  UInt32 m_RemainFileSize;
+  UInt64 m_FolderSize;
+  UInt64 m_PosInFolder;
+
+  void FreeTempBuf()
+  {
+    ::MyFree(TempBuf);
+    TempBuf = NULL;
+  }
+
+  HRESULT OpenFile();
+  HRESULT CloseFileWithResOp(Int32 resOp);
+  HRESULT CloseFile();
+  HRESULT Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK);
+public:
+  HRESULT WriteEmptyFiles();
+
+  CFolderOutStream(): TempBuf(NULL) {}
+  ~CFolderOutStream() { FreeTempBuf(); }
+  void Init(
+      const CMvDatabaseEx *database,
+      const CRecordVector<bool> *extractStatuses,
+      int startIndex,
+      UInt64 folderSize,
+      IArchiveExtractCallback *extractCallback,
+      bool testMode);
+  HRESULT FlushCorrupted();
+  HRESULT Unsupported();
+
+  UInt64 GetRemain() const { return m_FolderSize - m_PosInFolder; }
+  UInt64 GetPosInFolder() const { return m_PosInFolder; }
+};
+
+void CFolderOutStream::Init(
+    const CMvDatabaseEx *database,
+    const CRecordVector<bool> *extractStatuses,
+    int startIndex,
+    UInt64 folderSize,
+    IArchiveExtractCallback *extractCallback,
+    bool testMode)
+{
+  m_Database = database;
+  m_ExtractStatuses = extractStatuses;
+  m_StartIndex = startIndex;
+  m_FolderSize = folderSize;
+
+  m_ExtractCallback = extractCallback;
+  m_TestMode = testMode;
+
+  m_CurrentIndex = 0;
+  m_PosInFolder = 0;
+  m_FileIsOpen = false;
+  m_IsOk = true;
+  TempBufMode = false;
+  NumIdenticalFiles = 0;
+}
+
+HRESULT CFolderOutStream::CloseFileWithResOp(Int32 resOp)
+{
+  m_RealOutStream.Release();
+  m_FileIsOpen = false;
+  NumIdenticalFiles--;
+  return m_ExtractCallback->SetOperationResult(resOp);
+}
+
+HRESULT CFolderOutStream::CloseFile()
+{
+  return CloseFileWithResOp(m_IsOk ?
+      NExtract::NOperationResult::kOK:
+      NExtract::NOperationResult::kDataError);
+}
+
+HRESULT CFolderOutStream::OpenFile()
+{
+  if (NumIdenticalFiles == 0)
+  {
+    const CMvItem &mvItem = m_Database->Items[m_StartIndex + m_CurrentIndex];
+    const CItem &item = m_Database->Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
+    int numExtractItems = 0;
+    int curIndex;
+    for (curIndex = m_CurrentIndex; curIndex < m_ExtractStatuses->Size(); curIndex++)
+    {
+      const CMvItem &mvItem2 = m_Database->Items[m_StartIndex + curIndex];
+      const CItem &item2 = m_Database->Volumes[mvItem2.VolumeIndex].Items[mvItem2.ItemIndex];
+      if (item.Offset != item2.Offset ||
+          item.Size != item2.Size ||
+          item.Size == 0)
+        break;
+      if (!m_TestMode && (*m_ExtractStatuses)[curIndex])
+        numExtractItems++;
+    }
+    NumIdenticalFiles = (curIndex - m_CurrentIndex);
+    if (NumIdenticalFiles == 0)
+      NumIdenticalFiles = 1;
+    TempBufMode = false;
+    if (numExtractItems > 1)
+    {
+      if (!TempBuf || item.Size > TempBufSize)
+      {
+        FreeTempBuf();
+        TempBuf = (Byte *)MyAlloc(item.Size);
+        TempBufSize = item.Size;
+        if (TempBuf == NULL)
+          return E_OUTOFMEMORY;
+      }
+      TempBufMode = true;
+      m_BufStartFolderOffset = item.Offset;
+    }
+    else if (numExtractItems == 1)
+    {
+      while (NumIdenticalFiles && !(*m_ExtractStatuses)[m_CurrentIndex])
+      {
+        CMyComPtr<ISequentialOutStream> stream;
+        RINOK(m_ExtractCallback->GetStream(m_StartIndex + m_CurrentIndex, &stream, NExtract::NAskMode::kSkip));
+        if (stream)
+          return E_FAIL;
+        RINOK(m_ExtractCallback->PrepareOperation(NExtract::NAskMode::kSkip));
+        m_CurrentIndex++;
+        m_FileIsOpen = true;
+        CloseFile();
+      }
+    }
+  }
+
+  Int32 askMode = (*m_ExtractStatuses)[m_CurrentIndex] ? (m_TestMode ?
+      NExtract::NAskMode::kTest :
+      NExtract::NAskMode::kExtract) :
+      NExtract::NAskMode::kSkip;
+  RINOK(m_ExtractCallback->GetStream(m_StartIndex + m_CurrentIndex, &m_RealOutStream, askMode));
+  if (!m_RealOutStream && !m_TestMode)
+    askMode = NExtract::NAskMode::kSkip;
+  return m_ExtractCallback->PrepareOperation(askMode);
+}
+
+HRESULT CFolderOutStream::WriteEmptyFiles()
+{
+  if (m_FileIsOpen)
+    return S_OK;
+  for (; m_CurrentIndex < m_ExtractStatuses->Size(); m_CurrentIndex++)
+  {
+    const CMvItem &mvItem = m_Database->Items[m_StartIndex + m_CurrentIndex];
+    const CItem &item = m_Database->Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
+    UInt64 fileSize = item.Size;
+    if (fileSize != 0)
+      return S_OK;
+    HRESULT result = OpenFile();
+    m_RealOutStream.Release();
+    RINOK(result);
+    RINOK(m_ExtractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+  }
+  return S_OK;
+}
+
+// This is Write function
+HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK)
+{
+  COM_TRY_BEGIN
+  UInt32 realProcessed = 0;
+  if (processedSize != NULL)
+   *processedSize = 0;
+  while (size != 0)
+  {
+    if (m_FileIsOpen)
+    {
+      UInt32 numBytesToWrite = MyMin(m_RemainFileSize, size);
+      HRESULT res = S_OK;
+      if (numBytesToWrite > 0)
+      {
+        if (!isOK)
+          m_IsOk = false;
+        if (m_RealOutStream)
+        {
+          UInt32 processedSizeLocal = 0;
+          res = m_RealOutStream->Write((const Byte *)data, numBytesToWrite, &processedSizeLocal);
+          numBytesToWrite = processedSizeLocal;
+        }
+        if (TempBufMode && TempBuf)
+          memcpy(TempBuf + (m_PosInFolder - m_BufStartFolderOffset), data, numBytesToWrite);
+      }
+      realProcessed += numBytesToWrite;
+      if (processedSize != NULL)
+        *processedSize = realProcessed;
+      data = (const void *)((const Byte *)data + numBytesToWrite);
+      size -= numBytesToWrite;
+      m_RemainFileSize -= numBytesToWrite;
+      m_PosInFolder += numBytesToWrite;
+      if (res != S_OK)
+        return res;
+      if (m_RemainFileSize == 0)
+      {
+        RINOK(CloseFile());
+
+        while (NumIdenticalFiles)
+        {
+          HRESULT result = OpenFile();
+          m_FileIsOpen = true;
+          m_CurrentIndex++;
+          if (result == S_OK && m_RealOutStream && TempBuf)
+            result = WriteStream(m_RealOutStream, TempBuf, (size_t)(m_PosInFolder - m_BufStartFolderOffset));
+          
+          if (!TempBuf && TempBufMode && m_RealOutStream)
+          {
+            RINOK(CloseFileWithResOp(NExtract::NOperationResult::kUnSupportedMethod));
+          }
+          else
+          {
+            RINOK(CloseFile());
+          }
+          RINOK(result);
+        }
+        TempBufMode = false;
+      }
+      if (realProcessed > 0)
+        break; // with this break this function works as Write-Part
+    }
+    else
+    {
+      if (m_CurrentIndex >= m_ExtractStatuses->Size())
+        return E_FAIL;
+
+      const CMvItem &mvItem = m_Database->Items[m_StartIndex + m_CurrentIndex];
+      const CItem &item = m_Database->Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
+
+      m_RemainFileSize = item.Size;
+
+      UInt32 fileOffset = item.Offset;
+      if (fileOffset < m_PosInFolder)
+        return E_FAIL;
+      if (fileOffset > m_PosInFolder)
+      {
+        UInt32 numBytesToWrite = MyMin(fileOffset - (UInt32)m_PosInFolder, size);
+        realProcessed += numBytesToWrite;
+        if (processedSize != NULL)
+          *processedSize = realProcessed;
+        data = (const void *)((const Byte *)data + numBytesToWrite);
+        size -= numBytesToWrite;
+        m_PosInFolder += numBytesToWrite;
+      }
+      if (fileOffset == m_PosInFolder)
+      {
+        RINOK(OpenFile());
+        m_FileIsOpen = true;
+        m_CurrentIndex++;
+        m_IsOk = true;
+      }
+    }
+  }
+  return WriteEmptyFiles();
+  COM_TRY_END
+}
+
+STDMETHODIMP CFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+  return Write2(data, size, processedSize, true);
+}
+
+HRESULT CFolderOutStream::FlushCorrupted()
+{
+  const UInt32 kBufferSize = (1 << 10);
+  Byte buffer[kBufferSize];
+  for (int i = 0; i < kBufferSize; i++)
+    buffer[i] = 0;
+  for (;;)
+  {
+    UInt64 remain = GetRemain();
+    if (remain == 0)
+      return S_OK;
+    UInt32 size = (UInt32)MyMin(remain, (UInt64)kBufferSize);
+    UInt32 processedSizeLocal = 0;
+    RINOK(Write2(buffer, size, &processedSizeLocal, false));
+  }
+}
+
+HRESULT CFolderOutStream::Unsupported()
+{
+  while(m_CurrentIndex < m_ExtractStatuses->Size())
+  {
+    HRESULT result = OpenFile();
+    if (result != S_FALSE && result != S_OK)
+      return result;
+    m_RealOutStream.Release();
+    RINOK(m_ExtractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
+    m_CurrentIndex++;
+  }
+  return S_OK;
+}
+
+
+STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+    Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
+{
+  COM_TRY_BEGIN
+  bool allFilesMode = (numItems == (UInt32)-1);
+  if (allFilesMode)
+    numItems = m_Database.Items.Size();
+  if(numItems == 0)
+    return S_OK;
+  bool testMode = (testModeSpec != 0);
+  UInt64 totalUnPacked = 0;
+
+  UInt32 i;
+  int lastFolder = -2;
+  UInt64 lastFolderSize = 0;
+  for(i = 0; i < numItems; i++)
+  {
+    int index = allFilesMode ? i : indices[i];
+    const CMvItem &mvItem = m_Database.Items[index];
+    const CItem &item = m_Database.Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
+    if (item.IsDir())
+      continue;
+    int folderIndex = m_Database.GetFolderIndex(&mvItem);
+    if (folderIndex != lastFolder)
+      totalUnPacked += lastFolderSize;
+    lastFolder = folderIndex;
+    lastFolderSize = item.GetEndOffset();
+  }
+  totalUnPacked += lastFolderSize;
+
+  extractCallback->SetTotal(totalUnPacked);
+
+  totalUnPacked = 0;
+
+  UInt64 totalPacked = 0;
+
+  CLocalProgress *lps = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> progress = lps;
+  lps->Init(extractCallback, false);
+
+  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
+  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
+
+  NCompress::NDeflate::NDecoder::CCOMCoder *deflateDecoderSpec = NULL;
+  CMyComPtr<ICompressCoder> deflateDecoder;
+
+  NCompress::NLzx::CDecoder *lzxDecoderSpec = NULL;
+  CMyComPtr<ICompressCoder> lzxDecoder;
+
+  NCompress::NQuantum::CDecoder *quantumDecoderSpec = NULL;
+  CMyComPtr<ICompressCoder> quantumDecoder;
+
+  CCabBlockInStream *cabBlockInStreamSpec = new CCabBlockInStream();
+  CMyComPtr<ISequentialInStream> cabBlockInStream = cabBlockInStreamSpec;
+  if (!cabBlockInStreamSpec->Create())
+    return E_OUTOFMEMORY;
+
+  CRecordVector<bool> extractStatuses;
+  for(i = 0; i < numItems;)
+  {
+    int index = allFilesMode ? i : indices[i];
+
+    const CMvItem &mvItem = m_Database.Items[index];
+    const CDatabaseEx &db = m_Database.Volumes[mvItem.VolumeIndex];
+    int itemIndex = mvItem.ItemIndex;
+    const CItem &item = db.Items[itemIndex];
+
+    i++;
+    if (item.IsDir())
+    {
+      Int32 askMode = testMode ?
+          NExtract::NAskMode::kTest :
+          NExtract::NAskMode::kExtract;
+      CMyComPtr<ISequentialOutStream> realOutStream;
+      RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+      RINOK(extractCallback->PrepareOperation(askMode));
+      realOutStream.Release();
+      RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+      continue;
+    }
+    int folderIndex = m_Database.GetFolderIndex(&mvItem);
+    if (folderIndex < 0)
+    {
+      // If we need previous archive
+      Int32 askMode= testMode ?
+          NExtract::NAskMode::kTest :
+          NExtract::NAskMode::kExtract;
+      CMyComPtr<ISequentialOutStream> realOutStream;
+      RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+      RINOK(extractCallback->PrepareOperation(askMode));
+      realOutStream.Release();
+      RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kDataError));
+      continue;
+    }
+    int startIndex2 = m_Database.FolderStartFileIndex[folderIndex];
+    int startIndex = startIndex2;
+    extractStatuses.Clear();
+    for (; startIndex < index; startIndex++)
+      extractStatuses.Add(false);
+    extractStatuses.Add(true);
+    startIndex++;
+    UInt64 curUnpack = item.GetEndOffset();
+    for(;i < numItems; i++)
+    {
+      int indexNext = allFilesMode ? i : indices[i];
+      const CMvItem &mvItem = m_Database.Items[indexNext];
+      const CItem &item = m_Database.Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
+      if (item.IsDir())
+        continue;
+      int newFolderIndex = m_Database.GetFolderIndex(&mvItem);
+
+      if (newFolderIndex != folderIndex)
+        break;
+      for (; startIndex < indexNext; startIndex++)
+        extractStatuses.Add(false);
+      extractStatuses.Add(true);
+      startIndex++;
+      curUnpack = item.GetEndOffset();
+    }
+
+    lps->OutSize = totalUnPacked;
+    lps->InSize = totalPacked;
+    RINOK(lps->SetCur());
+
+    CFolderOutStream *cabFolderOutStream = new CFolderOutStream;
+    CMyComPtr<ISequentialOutStream> outStream(cabFolderOutStream);
+
+    const CFolder &folder = db.Folders[item.GetFolderIndex(db.Folders.Size())];
+
+    cabFolderOutStream->Init(&m_Database, &extractStatuses, startIndex2,
+        curUnpack, extractCallback, testMode);
+
+    cabBlockInStreamSpec->MsZip = false;
+    switch(folder.GetCompressionMethod())
+    {
+      case NHeader::NCompressionMethodMajor::kNone:
+        break;
+      case NHeader::NCompressionMethodMajor::kMSZip:
+        if(deflateDecoderSpec == NULL)
+        {
+          deflateDecoderSpec = new NCompress::NDeflate::NDecoder::CCOMCoder;
+          deflateDecoder = deflateDecoderSpec;
+        }
+        cabBlockInStreamSpec->MsZip = true;
+        break;
+      case NHeader::NCompressionMethodMajor::kLZX:
+        if(lzxDecoderSpec == NULL)
+        {
+          lzxDecoderSpec = new NCompress::NLzx::CDecoder;
+          lzxDecoder = lzxDecoderSpec;
+        }
+        RINOK(lzxDecoderSpec->SetParams(folder.CompressionTypeMinor));
+        break;
+      case NHeader::NCompressionMethodMajor::kQuantum:
+        if(quantumDecoderSpec == NULL)
+        {
+          quantumDecoderSpec = new NCompress::NQuantum::CDecoder;
+          quantumDecoder = quantumDecoderSpec;
+        }
+        quantumDecoderSpec->SetParams(folder.CompressionTypeMinor);
+        break;
+      default:
+      {
+        RINOK(cabFolderOutStream->Unsupported());
+        totalUnPacked += curUnpack;
+        continue;
+      }
+    }
+
+    cabBlockInStreamSpec->InitForNewFolder();
+
+    HRESULT res = S_OK;
+
+    {
+      int volIndex = mvItem.VolumeIndex;
+      int locFolderIndex = item.GetFolderIndex(db.Folders.Size());
+      bool keepHistory = false;
+      bool keepInputBuffer = false;
+      for (UInt32 f = 0; cabFolderOutStream->GetRemain() != 0;)
+      {
+        if (volIndex >= m_Database.Volumes.Size())
+        {
+          res = S_FALSE;
+          break;
+        }
+
+        const CDatabaseEx &db = m_Database.Volumes[volIndex];
+        const CFolder &folder = db.Folders[locFolderIndex];
+        if (f == 0)
+        {
+          cabBlockInStreamSpec->SetStream(db.Stream);
+          cabBlockInStreamSpec->ReservedSize = db.ArchiveInfo.GetDataBlockReserveSize();
+          RINOK(db.Stream->Seek(db.StartPosition + folder.DataStart, STREAM_SEEK_SET, NULL));
+        }
+        if (f == folder.NumDataBlocks)
+        {
+          volIndex++;
+          locFolderIndex = 0;
+          f = 0;
+          continue;
+        }
+        f++;
+
+        cabBlockInStreamSpec->DataError = false;
+        
+        if (!keepInputBuffer)
+          cabBlockInStreamSpec->InitForNewBlock();
+
+        UInt32 packSize, unpackSize;
+        res = cabBlockInStreamSpec->PreRead(packSize, unpackSize);
+        if (res == S_FALSE)
+          break;
+        RINOK(res);
+        keepInputBuffer = (unpackSize == 0);
+        if (keepInputBuffer)
+          continue;
+
+        UInt64 totalUnPacked2 = totalUnPacked + cabFolderOutStream->GetPosInFolder();
+        totalPacked += packSize;
+
+        lps->OutSize = totalUnPacked2;
+        lps->InSize = totalPacked;
+        RINOK(lps->SetCur());
+
+        UInt64 unpackRemain = cabFolderOutStream->GetRemain();
+
+        const UInt32 kBlockSizeMax = (1 << 15);
+        if (unpackRemain > kBlockSizeMax)
+          unpackRemain = kBlockSizeMax;
+        if (unpackRemain > unpackSize)
+          unpackRemain  = unpackSize;
+   
+        switch(folder.GetCompressionMethod())
+        {
+          case NHeader::NCompressionMethodMajor::kNone:
+            res = copyCoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
+            break;
+          case NHeader::NCompressionMethodMajor::kMSZip:
+            deflateDecoderSpec->SetKeepHistory(keepHistory);
+            res = deflateDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
+            break;
+          case NHeader::NCompressionMethodMajor::kLZX:
+            lzxDecoderSpec->SetKeepHistory(keepHistory);
+            res = lzxDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
+            break;
+          case NHeader::NCompressionMethodMajor::kQuantum:
+            quantumDecoderSpec->SetKeepHistory(keepHistory);
+            res = quantumDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
+          break;
+        }
+        if (res != S_OK)
+        {
+          if (res != S_FALSE)
+            RINOK(res);
+          break;
+        }
+        keepHistory = true;
+      }
+      if (res == S_OK)
+      {
+        RINOK(cabFolderOutStream->WriteEmptyFiles());
+      }
+    }
+    if (res != S_OK || cabFolderOutStream->GetRemain() != 0)
+    {
+      RINOK(cabFolderOutStream->FlushCorrupted());
+    }
+    totalUnPacked += curUnpack;
+  }
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+{
+  *numItems = m_Database.Items.Size();
+  return S_OK;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHandler.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,28 @@
+// CabHandler.h
+
+#ifndef __CAB_HANDLER_H
+#define __CAB_HANDLER_H
+
+#include "Common/MyCom.h"
+#include "../IArchive.h"
+#include "CabIn.h"
+
+namespace NArchive {
+namespace NCab {
+
+class CHandler:
+  public IInArchive,
+  public CMyUnknownImp
+{
+public:
+  MY_UNKNOWN_IMP1(IInArchive)
+
+  INTERFACE_IInArchive(;)
+
+private:
+  CMvDatabaseEx m_Database;
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,15 @@
+// CabHeader.cpp
+
+#include "StdAfx.h"
+
+#include "CabHeader.h"
+
+namespace NArchive {
+namespace NCab {
+namespace NHeader {
+
+Byte kMarker[kMarkerSize] = {'M', 'S', 'C', 'F', 0, 0, 0, 0 };
+
+// struct CSignatureInitializer { CSignatureInitializer() { kMarker[0]--; }; } g_SignatureInitializer;
+
+}}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabHeader.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,44 @@
+// Archive/Cab/Header.h
+
+#ifndef __ARCHIVE_CAB_HEADER_H
+#define __ARCHIVE_CAB_HEADER_H
+
+#include "Common/Types.h"
+
+namespace NArchive {
+namespace NCab {
+namespace NHeader {
+
+const unsigned kMarkerSize = 8;
+extern Byte kMarker[kMarkerSize];
+
+namespace NArchive
+{
+  namespace NFlags
+  {
+    const int kPrevCabinet = 0x0001;
+    const int kNextCabinet = 0x0002;
+    const int kReservePresent = 0x0004;
+  }
+}
+
+namespace NCompressionMethodMajor
+{
+  const Byte kNone = 0;
+  const Byte kMSZip = 1;
+  const Byte kQuantum = 2;
+  const Byte kLZX = 3;
+}
+
+const int kFileNameIsUTFAttributeMask = 0x80;
+
+namespace NFolderIndex
+{
+  const int kContinuedFromPrev    = 0xFFFD;
+  const int kContinuedToNext      = 0xFFFE;
+  const int kContinuedPrevAndNext = 0xFFFF;
+}
+
+}}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,272 @@
+// Archive/CabIn.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/FindSignature.h"
+
+#include "CabIn.h"
+
+namespace NArchive {
+namespace NCab {
+
+Byte CInArchive::Read8()
+{
+  Byte b;
+  if (!inBuffer.ReadByte(b))
+    throw CInArchiveException(CInArchiveException::kUnsupported);
+  return b;
+}
+
+UInt16 CInArchive::Read16()
+{
+  UInt16 value = 0;
+  for (int i = 0; i < 2; i++)
+  {
+    Byte b = Read8();
+    value |= (UInt16(b) << (8 * i));
+  }
+  return value;
+}
+
+UInt32 CInArchive::Read32()
+{
+  UInt32 value = 0;
+  for (int i = 0; i < 4; i++)
+  {
+    Byte b = Read8();
+    value |= (UInt32(b) << (8 * i));
+  }
+  return value;
+}
+
+AString CInArchive::SafeReadName()
+{
+  AString name;
+  for (;;)
+  {
+    Byte b = Read8();
+    if (b == 0)
+      return name;
+    name += (char)b;
+  }
+}
+
+void CInArchive::ReadOtherArchive(COtherArchive &oa)
+{
+  oa.FileName = SafeReadName();
+  oa.DiskName = SafeReadName();
+}
+
+void CInArchive::Skip(UInt32 size)
+{
+  while (size-- != 0)
+    Read8();
+}
+
+HRESULT CInArchive::Open(const UInt64 *searchHeaderSizeLimit, CDatabaseEx &db)
+{
+  IInStream *stream = db.Stream;
+  db.Clear();
+  RINOK(stream->Seek(0, STREAM_SEEK_SET, &db.StartPosition));
+
+  RINOK(FindSignatureInStream(stream, NHeader::kMarker, NHeader::kMarkerSize,
+      searchHeaderSizeLimit, db.StartPosition));
+
+  RINOK(stream->Seek(db.StartPosition + NHeader::kMarkerSize, STREAM_SEEK_SET, NULL));
+  if (!inBuffer.Create(1 << 17))
+    return E_OUTOFMEMORY;
+  inBuffer.SetStream(stream);
+  inBuffer.Init();
+
+  CInArchiveInfo &ai = db.ArchiveInfo;
+
+  ai.Size = Read32();
+  if (Read32() != 0)
+    return S_FALSE;
+  ai.FileHeadersOffset = Read32();
+  if (Read32() != 0)
+    return S_FALSE;
+
+  ai.VersionMinor = Read8();
+  ai.VersionMajor = Read8();
+  ai.NumFolders = Read16();
+  ai.NumFiles = Read16();
+  ai.Flags = Read16();
+  if (ai.Flags > 7)
+    return S_FALSE;
+  ai.SetID = Read16();
+  ai.CabinetNumber = Read16();
+
+  if (ai.ReserveBlockPresent())
+  {
+    ai.PerCabinetAreaSize = Read16();
+    ai.PerFolderAreaSize = Read8();
+    ai.PerDataBlockAreaSize = Read8();
+
+    Skip(ai.PerCabinetAreaSize);
+  }
+
+  {
+    if (ai.IsTherePrev())
+      ReadOtherArchive(ai.PrevArc);
+    if (ai.IsThereNext())
+      ReadOtherArchive(ai.NextArc);
+  }
+  
+  int i;
+  for (i = 0; i < ai.NumFolders; i++)
+  {
+    CFolder folder;
+
+    folder.DataStart = Read32();
+    folder.NumDataBlocks = Read16();
+    folder.CompressionTypeMajor = Read8();
+    folder.CompressionTypeMinor = Read8();
+
+    Skip(ai.PerFolderAreaSize);
+    db.Folders.Add(folder);
+  }
+  
+  RINOK(stream->Seek(db.StartPosition + ai.FileHeadersOffset, STREAM_SEEK_SET, NULL));
+
+  inBuffer.SetStream(stream);
+  inBuffer.Init();
+  for (i = 0; i < ai.NumFiles; i++)
+  {
+    CItem item;
+    item.Size = Read32();
+    item.Offset = Read32();
+    item.FolderIndex = Read16();
+    UInt16 pureDate = Read16();
+    UInt16 pureTime = Read16();
+    item.Time = ((UInt32(pureDate) << 16)) | pureTime;
+    item.Attributes = Read16();
+    item.Name = SafeReadName();
+    int folderIndex = item.GetFolderIndex(db.Folders.Size());
+    if (folderIndex >= db.Folders.Size())
+      return S_FALSE;
+    db.Items.Add(item);
+  }
+  return S_OK;
+}
+
+#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
+
+static int CompareMvItems(const CMvItem *p1, const CMvItem *p2, void *param)
+{
+  const CMvDatabaseEx &mvDb = *(const CMvDatabaseEx *)param;
+  const CDatabaseEx &db1 = mvDb.Volumes[p1->VolumeIndex];
+  const CDatabaseEx &db2 = mvDb.Volumes[p2->VolumeIndex];
+  const CItem &item1 = db1.Items[p1->ItemIndex];
+  const CItem &item2 = db2.Items[p2->ItemIndex];;
+  bool isDir1 = item1.IsDir();
+  bool isDir2 = item2.IsDir();
+  if (isDir1 && !isDir2)
+    return -1;
+  if (isDir2 && !isDir1)
+    return 1;
+  int f1 = mvDb.GetFolderIndex(p1);
+  int f2 = mvDb.GetFolderIndex(p2);
+  RINOZ(MyCompare(f1, f2));
+  RINOZ(MyCompare(item1.Offset, item2.Offset));
+  RINOZ(MyCompare(item1.Size, item2.Size));
+  RINOZ(MyCompare(p1->VolumeIndex, p2->VolumeIndex));
+  return MyCompare(p1->ItemIndex, p2->ItemIndex);
+}
+
+bool CMvDatabaseEx::AreItemsEqual(int i1, int i2)
+{
+  const CMvItem *p1 = &Items[i1];
+  const CMvItem *p2 = &Items[i2];
+  const CDatabaseEx &db1 = Volumes[p1->VolumeIndex];
+  const CDatabaseEx &db2 = Volumes[p2->VolumeIndex];
+  const CItem &item1 = db1.Items[p1->ItemIndex];
+  const CItem &item2 = db2.Items[p2->ItemIndex];;
+  return GetFolderIndex(p1) == GetFolderIndex(p2) &&
+    item1.Offset == item2.Offset &&
+    item1.Size == item2.Size &&
+    item1.Name == item2.Name;
+}
+
+void CMvDatabaseEx::FillSortAndShrink()
+{
+  Items.Clear();
+  StartFolderOfVol.Clear();
+  FolderStartFileIndex.Clear();
+  int offset = 0;
+  for (int v = 0; v < Volumes.Size(); v++)
+  {
+    const CDatabaseEx &db = Volumes[v];
+    int curOffset = offset;
+    if (db.IsTherePrevFolder())
+      curOffset--;
+    StartFolderOfVol.Add(curOffset);
+    offset += db.GetNumberOfNewFolders();
+
+    CMvItem mvItem;
+    mvItem.VolumeIndex = v;
+    for (int i = 0 ; i < db.Items.Size(); i++)
+    {
+      mvItem.ItemIndex = i;
+      Items.Add(mvItem);
+    }
+  }
+
+  Items.Sort(CompareMvItems, (void *)this);
+  int j = 1;
+  int i;
+  for (i = 1; i < Items.Size(); i++)
+    if (!AreItemsEqual(i, i -1))
+      Items[j++] = Items[i];
+  Items.DeleteFrom(j);
+
+  for (i = 0; i < Items.Size(); i++)
+  {
+    int folderIndex = GetFolderIndex(&Items[i]);
+    if (folderIndex >= FolderStartFileIndex.Size())
+      FolderStartFileIndex.Add(i);
+  }
+}
+
+bool CMvDatabaseEx::Check()
+{
+  for (int v = 1; v < Volumes.Size(); v++)
+  {
+    const CDatabaseEx &db1 = Volumes[v];
+    if (db1.IsTherePrevFolder())
+    {
+      const CDatabaseEx &db0 = Volumes[v - 1];
+      if (db0.Folders.IsEmpty() || db1.Folders.IsEmpty())
+        return false;
+      const CFolder &f0 = db0.Folders.Back();
+      const CFolder &f1 = db1.Folders.Front();
+      if (f0.CompressionTypeMajor != f1.CompressionTypeMajor ||
+          f0.CompressionTypeMinor != f1.CompressionTypeMinor)
+        return false;
+    }
+  }
+  UInt32 beginPos = 0;
+  UInt64 endPos = 0;
+  int prevFolder = -2;
+  for (int i = 0; i < Items.Size(); i++)
+  {
+    const CMvItem &mvItem = Items[i];
+    int fIndex = GetFolderIndex(&mvItem);
+    if (fIndex >= FolderStartFileIndex.Size())
+      return false;
+    const CItem &item = Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
+    if (item.IsDir())
+      continue;
+    int folderIndex = GetFolderIndex(&mvItem);
+    if (folderIndex != prevFolder)
+      prevFolder = folderIndex;
+    else if (item.Offset < endPos &&
+        (item.Offset != beginPos || item.GetEndOffset() != endPos))
+      return false;
+    beginPos = item.Offset;
+    endPos = item.GetEndOffset();
+  }
+  return true;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabIn.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,161 @@
+// Archive/CabIn.h
+
+#ifndef __ARCHIVE_CAB_IN_H
+#define __ARCHIVE_CAB_IN_H
+
+#include "../../IStream.h"
+#include "../../Common/InBuffer.h"
+#include "CabHeader.h"
+#include "CabItem.h"
+
+namespace NArchive {
+namespace NCab {
+
+class CInArchiveException
+{
+public:
+  enum CCauseType
+  {
+    kUnexpectedEndOfArchive = 0,
+    kIncorrectArchive,
+    kUnsupported
+  } Cause;
+  CInArchiveException(CCauseType cause) : Cause(cause) {}
+};
+
+struct COtherArchive
+{
+  AString FileName;
+  AString DiskName;
+};
+
+struct CArchiveInfo
+{
+  Byte VersionMinor; /* cabinet file format version, minor */
+  Byte VersionMajor; /* cabinet file format version, major */
+  UInt16 NumFolders; /* number of CFFOLDER entries in this cabinet */
+  UInt16 NumFiles;   /* number of CFFILE entries in this cabinet */
+  UInt16 Flags;      /* cabinet file option indicators */
+  UInt16 SetID;      /* must be the same for all cabinets in a set */
+  UInt16 CabinetNumber; /* number of this cabinet file in a set */
+
+  bool ReserveBlockPresent() const { return (Flags & NHeader::NArchive::NFlags::kReservePresent) != 0; }
+
+  bool IsTherePrev() const { return (Flags & NHeader::NArchive::NFlags::kPrevCabinet) != 0; }
+  bool IsThereNext() const { return (Flags & NHeader::NArchive::NFlags::kNextCabinet) != 0; }
+
+  UInt16 PerCabinetAreaSize; // (optional) size of per-cabinet reserved area
+  Byte PerFolderAreaSize;    // (optional) size of per-folder reserved area
+  Byte PerDataBlockAreaSize; // (optional) size of per-datablock reserved area
+
+  Byte GetDataBlockReserveSize() const { return (Byte)(ReserveBlockPresent() ? PerDataBlockAreaSize : 0); }
+
+  COtherArchive PrevArc;
+  COtherArchive NextArc;
+
+  CArchiveInfo()
+  {
+    Clear();
+  }
+
+  void Clear()
+  {
+    PerCabinetAreaSize = 0;
+    PerFolderAreaSize = 0;
+    PerDataBlockAreaSize = 0;
+  }
+};
+
+struct CInArchiveInfo: public CArchiveInfo
+{
+  UInt32 Size; /* size of this cabinet file in bytes */
+  UInt32 FileHeadersOffset; // offset of the first CFFILE entry
+};
+
+
+struct CDatabase
+{
+  UInt64 StartPosition;
+  CInArchiveInfo ArchiveInfo;
+  CObjectVector<CFolder> Folders;
+  CObjectVector<CItem> Items;
+  
+  void Clear()
+  {
+    ArchiveInfo.Clear();
+    Folders.Clear();
+    Items.Clear();
+  }
+  bool IsTherePrevFolder() const
+  {
+    for (int i = 0; i < Items.Size(); i++)
+      if (Items[i].ContinuedFromPrev())
+        return true;
+    return false;
+  }
+  int GetNumberOfNewFolders() const
+  {
+    int res = Folders.Size();
+    if (IsTherePrevFolder())
+      res--;
+    return res;
+  }
+  UInt32 GetFileOffset(int index) const { return Items[index].Offset; }
+  UInt32 GetFileSize(int index) const { return Items[index].Size; }
+};
+
+struct CDatabaseEx: public CDatabase
+{
+  CMyComPtr<IInStream> Stream;
+};
+
+struct CMvItem
+{
+  int VolumeIndex;
+  int ItemIndex;
+};
+
+class CMvDatabaseEx
+{
+  bool AreItemsEqual(int i1, int i2);
+public:
+  CObjectVector<CDatabaseEx> Volumes;
+  CRecordVector<CMvItem> Items;
+  CRecordVector<int> StartFolderOfVol;
+  CRecordVector<int> FolderStartFileIndex;
+  
+  int GetFolderIndex(const CMvItem *mvi) const
+  {
+    const CDatabaseEx &db = Volumes[mvi->VolumeIndex];
+    return StartFolderOfVol[mvi->VolumeIndex] +
+        db.Items[mvi->ItemIndex].GetFolderIndex(db.Folders.Size());
+  }
+  void Clear()
+  {
+    Volumes.Clear();
+    Items.Clear();
+    StartFolderOfVol.Clear();
+    FolderStartFileIndex.Clear();
+  }
+  void FillSortAndShrink();
+  bool Check();
+};
+
+class CInArchive
+{
+  CInBuffer inBuffer;
+
+  Byte Read8();
+  UInt16 Read16();
+  UInt32 Read32();
+  AString SafeReadName();
+  void Skip(UInt32 size);
+  void ReadOtherArchive(COtherArchive &oa);
+
+public:
+  HRESULT Open(const UInt64 *searchHeaderSizeLimit, CDatabaseEx &db);
+};
+  
+}}
+  
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabItem.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabItem.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabItem.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabItem.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,63 @@
+// Archive/CabItem.h
+
+#ifndef __ARCHIVE_CAB_ITEM_H
+#define __ARCHIVE_CAB_ITEM_H
+
+#include "Common/Types.h"
+#include "Common/MyString.h"
+#include "CabHeader.h"
+
+namespace NArchive {
+namespace NCab {
+
+struct CFolder
+{
+  UInt32 DataStart; // offset of the first CFDATA block in this folder
+  UInt16 NumDataBlocks; // number of CFDATA blocks in this folder
+  Byte CompressionTypeMajor;
+  Byte CompressionTypeMinor;
+  Byte GetCompressionMethod() const { return (Byte)(CompressionTypeMajor & 0xF); }
+};
+
+struct CItem
+{
+  AString Name;
+  UInt32 Offset;
+  UInt32 Size;
+  UInt32 Time;
+  UInt16 FolderIndex;
+  UInt16 Flags;
+  UInt16 Attributes;
+  
+  UInt64 GetEndOffset() const { return (UInt64)Offset + Size; }
+  UInt32 GetWinAttributes() const { return (Attributes & ~NHeader::kFileNameIsUTFAttributeMask); }
+  bool IsNameUTF() const { return (Attributes & NHeader::kFileNameIsUTFAttributeMask) != 0; }
+  bool IsDir() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }
+
+  bool ContinuedFromPrev() const
+  {
+    return
+      (FolderIndex == NHeader::NFolderIndex::kContinuedFromPrev) ||
+      (FolderIndex == NHeader::NFolderIndex::kContinuedPrevAndNext);
+  }
+  
+  bool ContinuedToNext() const
+  {
+    return
+      (FolderIndex == NHeader::NFolderIndex::kContinuedToNext) ||
+      (FolderIndex == NHeader::NFolderIndex::kContinuedPrevAndNext);
+  }
+
+  int GetFolderIndex(int numFolders) const
+  {
+    if (ContinuedFromPrev())
+      return 0;
+    if (ContinuedToNext())
+      return (numFolders - 1);
+    return FolderIndex;
+  }
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/CabRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,13 @@
+// CabRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/RegisterArc.h"
+
+#include "CabHandler.h"
+static IInArchive *CreateArc() { return new NArchive::NCab::CHandler; }
+
+static CArcInfo g_ArcInfo =
+  { L"Cab", L"cab", 0, 8, { 0x4D, 0x53, 0x43, 0x46 }, 4, false, CreateArc, 0 };
+
+REGISTER_ARC(Cab)

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,721 @@
+// ChmHandler.cpp
+
+#include "StdAfx.h"
+
+#include "Common/ComTry.h"
+#include "Common/Defs.h"
+#include "Common/StringConvert.h"
+#include "Common/UTFConvert.h"
+
+#include "Windows/PropVariant.h"
+#include "Windows/Time.h"
+
+#include "../../Common/LimitedStreams.h"
+#include "../../Common/ProgressUtils.h"
+#include "../../Common/StreamUtils.h"
+
+#include "../../Compress/CopyCoder.h"
+#include "../../Compress/LzxDecoder.h"
+
+#include "../Common/ItemNameUtils.h"
+
+#include "ChmHandler.h"
+
+using namespace NWindows;
+using namespace NTime;
+
+namespace NArchive {
+namespace NChm {
+
+// #define _CHM_DETAILS
+
+#ifdef _CHM_DETAILS
+
+enum
+{
+  kpidSection = kpidUserDefined
+};
+
+#endif
+
+STATPROPSTG kProps[] =
+{
+  { NULL, kpidPath, VT_BSTR},
+  { NULL, kpidSize, VT_UI8},
+  { NULL, kpidMethod, VT_BSTR},
+  { NULL, kpidBlock, VT_UI4}
+  
+  #ifdef _CHM_DETAILS
+  ,
+  { L"Section", kpidSection, VT_UI4},
+  { NULL, kpidOffset, VT_UI4}
+  #endif
+};
+
+STATPROPSTG kArcProps[] =
+{
+  { NULL, kpidNumBlocks, VT_UI8}
+};
+
+IMP_IInArchive_Props
+
+IMP_IInArchive_ArcProps_NO
+/*
+IMP_IInArchive_ArcProps
+
+STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NWindows::NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case kpidNumBlocks:
+    {
+      UInt64 numBlocks = 0;
+      for (int i = 0; i < m_Database.Sections.Size(); i++)
+      {
+        const CSectionInfo &s = m_Database.Sections[i];
+        for (int j = 0; j < s.Methods.Size(); j++)
+        {
+          const CMethodInfo &m = s.Methods[j];
+          if (m.IsLzx())
+            numBlocks += m.LzxInfo.ResetTable.GetNumBlocks();
+        }
+      }
+      prop = numBlocks;
+      break;
+    }
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+*/
+
+STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID,  PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NWindows::NCOM::CPropVariant prop;
+  if (m_Database.NewFormat)
+  {
+    switch(propID)
+    {
+      case kpidSize:
+        prop = (UInt64)m_Database.NewFormatString.Length();
+      break;
+    }
+    prop.Detach(value);
+    return S_OK;
+  }
+  int entryIndex;
+  if (m_Database.LowLevel)
+    entryIndex = index;
+  else
+    entryIndex = m_Database.Indices[index];
+  const CItem &item = m_Database.Items[entryIndex];
+  switch(propID)
+  {
+    case kpidPath:
+    {
+      UString us;
+      if (ConvertUTF8ToUnicode(item.Name, us))
+      {
+        if (!m_Database.LowLevel)
+        {
+          if (us.Length() > 1)
+            if (us[0] == L'/')
+              us.Delete(0);
+        }
+        prop = NItemName::GetOSName2(us);
+      }
+      break;
+    }
+    case kpidIsDir:  prop = item.IsDir(); break;
+    case kpidSize:  prop = item.Size; break;
+    case kpidMethod:
+    {
+      if (!item.IsDir())
+        if (item.Section == 0)
+          prop = L"Copy";
+        else if (item.Section < m_Database.Sections.Size())
+          prop = m_Database.Sections[(int)item.Section].GetMethodName();
+      break;
+    }
+    case kpidBlock:
+      if (m_Database.LowLevel)
+        prop = item.Section;
+      else if (item.Section != 0)
+        prop = m_Database.GetFolder(index);
+      break;
+    
+    #ifdef _CHM_DETAILS
+    
+    case kpidSection:  prop = (UInt32)item.Section; break;
+    case kpidOffset:  prop = (UInt32)item.Offset; break;
+
+    #endif
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+class CProgressImp: public CProgressVirt
+{
+  CMyComPtr<IArchiveOpenCallback> _callback;
+public:
+  STDMETHOD(SetTotal)(const UInt64 *numFiles);
+  STDMETHOD(SetCompleted)(const UInt64 *numFiles);
+  CProgressImp(IArchiveOpenCallback *callback): _callback(callback) {};
+};
+
+STDMETHODIMP CProgressImp::SetTotal(const UInt64 *numFiles)
+{
+  if (_callback)
+    return _callback->SetCompleted(numFiles, NULL);
+  return S_OK;
+}
+
+STDMETHODIMP CProgressImp::SetCompleted(const UInt64 *numFiles)
+{
+  if (_callback)
+    return _callback->SetCompleted(numFiles, NULL);
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Open(IInStream *inStream,
+    const UInt64 *maxCheckStartPosition,
+    IArchiveOpenCallback * /* openArchiveCallback */)
+{
+  COM_TRY_BEGIN
+  m_Stream.Release();
+  try
+  {
+    CInArchive archive;
+    // CProgressImp progressImp(openArchiveCallback);
+    RINOK(archive.Open(inStream, maxCheckStartPosition, m_Database));
+    /*
+    if (m_Database.LowLevel)
+      return S_FALSE;
+    */
+    m_Stream = inStream;
+  }
+  catch(...)
+  {
+    return S_FALSE;
+  }
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::Close()
+{
+  m_Database.Clear();
+  m_Stream.Release();
+  return S_OK;
+}
+
+class CChmFolderOutStream:
+  public ISequentialOutStream,
+  public CMyUnknownImp
+{
+public:
+  MY_UNKNOWN_IMP
+
+  HRESULT Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK);
+  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+
+  UInt64 m_FolderSize;
+  UInt64 m_PosInFolder;
+  UInt64 m_PosInSection;
+  const CRecordVector<bool> *m_ExtractStatuses;
+  int m_StartIndex;
+  int m_CurrentIndex;
+  int m_NumFiles;
+
+private:
+  const CFilesDatabase *m_Database;
+  CMyComPtr<IArchiveExtractCallback> m_ExtractCallback;
+  bool m_TestMode;
+
+  bool m_IsOk;
+  bool m_FileIsOpen;
+  UInt64 m_RemainFileSize;
+  CMyComPtr<ISequentialOutStream> m_RealOutStream;
+
+  HRESULT OpenFile();
+  HRESULT WriteEmptyFiles();
+public:
+  void Init(
+    const CFilesDatabase *database,
+    IArchiveExtractCallback *extractCallback,
+    bool testMode);
+  HRESULT FlushCorrupted(UInt64 maxSize);
+};
+
+void CChmFolderOutStream::Init(
+    const CFilesDatabase *database,
+    IArchiveExtractCallback *extractCallback,
+    bool testMode)
+{
+  m_Database = database;
+  m_ExtractCallback = extractCallback;
+  m_TestMode = testMode;
+
+  m_CurrentIndex = 0;
+  m_FileIsOpen = false;
+}
+
+HRESULT CChmFolderOutStream::OpenFile()
+{
+  Int32 askMode = (*m_ExtractStatuses)[m_CurrentIndex] ? (m_TestMode ?
+      NExtract::NAskMode::kTest :
+      NExtract::NAskMode::kExtract) :
+      NExtract::NAskMode::kSkip;
+  m_RealOutStream.Release();
+  RINOK(m_ExtractCallback->GetStream(m_StartIndex + m_CurrentIndex, &m_RealOutStream, askMode));
+  if (!m_RealOutStream && !m_TestMode)
+    askMode = NExtract::NAskMode::kSkip;
+  return m_ExtractCallback->PrepareOperation(askMode);
+}
+
+HRESULT CChmFolderOutStream::WriteEmptyFiles()
+{
+  if (m_FileIsOpen)
+    return S_OK;
+  for (;m_CurrentIndex < m_NumFiles; m_CurrentIndex++)
+  {
+    UInt64 fileSize = m_Database->GetFileSize(m_StartIndex + m_CurrentIndex);
+    if (fileSize != 0)
+      return S_OK;
+    HRESULT result = OpenFile();
+    m_RealOutStream.Release();
+    RINOK(result);
+    RINOK(m_ExtractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+  }
+  return S_OK;
+}
+
+// This is WritePart function
+HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK)
+{
+  UInt32 realProcessed = 0;
+  if (processedSize != NULL)
+   *processedSize = 0;
+  while(size != 0)
+  {
+    if (m_FileIsOpen)
+    {
+      UInt32 numBytesToWrite = (UInt32)MyMin(m_RemainFileSize, (UInt64)(size));
+      HRESULT res = S_OK;
+      if (numBytesToWrite > 0)
+      {
+        if (!isOK)
+          m_IsOk = false;
+        if (m_RealOutStream)
+        {
+          UInt32 processedSizeLocal = 0;
+          res = m_RealOutStream->Write((const Byte *)data, numBytesToWrite, &processedSizeLocal);
+          numBytesToWrite = processedSizeLocal;
+        }
+      }
+      realProcessed += numBytesToWrite;
+      if (processedSize != NULL)
+        *processedSize = realProcessed;
+      data = (const void *)((const Byte *)data + numBytesToWrite);
+      size -= numBytesToWrite;
+      m_RemainFileSize -= numBytesToWrite;
+      m_PosInSection += numBytesToWrite;
+      m_PosInFolder += numBytesToWrite;
+      if (res != S_OK)
+        return res;
+      if (m_RemainFileSize == 0)
+      {
+        m_RealOutStream.Release();
+        RINOK(m_ExtractCallback->SetOperationResult(
+          m_IsOk ?
+            NExtract::NOperationResult::kOK:
+            NExtract::NOperationResult::kDataError));
+        m_FileIsOpen = false;
+      }
+      if (realProcessed > 0)
+        break; // with this break this function works as write part
+    }
+    else
+    {
+      if (m_CurrentIndex >= m_NumFiles)
+        return E_FAIL;
+      int fullIndex = m_StartIndex + m_CurrentIndex;
+      m_RemainFileSize = m_Database->GetFileSize(fullIndex);
+      UInt64 fileOffset = m_Database->GetFileOffset(fullIndex);
+      if (fileOffset < m_PosInSection)
+        return E_FAIL;
+      if (fileOffset > m_PosInSection)
+      {
+        UInt32 numBytesToWrite = (UInt32)MyMin(fileOffset - m_PosInSection, UInt64(size));
+        realProcessed += numBytesToWrite;
+        if (processedSize != NULL)
+          *processedSize = realProcessed;
+        data = (const void *)((const Byte *)data + numBytesToWrite);
+        size -= numBytesToWrite;
+        m_PosInSection += numBytesToWrite;
+        m_PosInFolder += numBytesToWrite;
+      }
+      if (fileOffset == m_PosInSection)
+      {
+        RINOK(OpenFile());
+        m_FileIsOpen = true;
+        m_CurrentIndex++;
+        m_IsOk = true;
+      }
+    }
+  }
+  return WriteEmptyFiles();
+}
+
+STDMETHODIMP CChmFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+  return Write2(data, size, processedSize, true);
+}
+
+HRESULT CChmFolderOutStream::FlushCorrupted(UInt64 maxSize)
+{
+  const UInt32 kBufferSize = (1 << 10);
+  Byte buffer[kBufferSize];
+  for (int i = 0; i < kBufferSize; i++)
+    buffer[i] = 0;
+  if (maxSize > m_FolderSize)
+    maxSize = m_FolderSize;
+  while (m_PosInFolder < maxSize)
+  {
+    UInt32 size = (UInt32)MyMin(maxSize - m_PosInFolder, (UInt64)kBufferSize);
+    UInt32 processedSizeLocal = 0;
+    RINOK(Write2(buffer, size, &processedSizeLocal, false));
+    if (processedSizeLocal == 0)
+      return S_OK;
+  }
+  return S_OK;
+}
+
+
+STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+    Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
+{
+  COM_TRY_BEGIN
+  bool allFilesMode = (numItems == (UInt32)-1);
+
+  if (allFilesMode)
+    numItems = m_Database.NewFormat ? 1:
+      (m_Database.LowLevel ?
+      m_Database.Items.Size():
+      m_Database.Indices.Size());
+  if (numItems == 0)
+    return S_OK;
+  bool testMode = (testModeSpec != 0);
+
+  UInt64 currentTotalSize = 0;
+
+  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
+  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
+  UInt32 i;
+
+  CLocalProgress *lps = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> progress = lps;
+  lps->Init(extractCallback, false);
+
+  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
+  CMyComPtr<ISequentialInStream> inStream(streamSpec);
+  streamSpec->SetStream(m_Stream);
+
+  if (m_Database.LowLevel)
+  {
+    UInt64 currentItemSize = 0;
+    UInt64 totalSize = 0;
+    if (m_Database.NewFormat)
+      totalSize = m_Database.NewFormatString.Length();
+    else
+      for (i = 0; i < numItems; i++)
+        totalSize += m_Database.Items[allFilesMode ? i : indices[i]].Size;
+    extractCallback->SetTotal(totalSize);
+    
+    for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
+    {
+      currentItemSize = 0;
+      lps->InSize = currentTotalSize; // Change it
+      lps->OutSize = currentTotalSize;
+
+      RINOK(lps->SetCur());
+      CMyComPtr<ISequentialOutStream> realOutStream;
+      Int32 askMode= testMode ?
+          NExtract::NAskMode::kTest :
+          NExtract::NAskMode::kExtract;
+      Int32 index = allFilesMode ? i : indices[i];
+      RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+
+      if (m_Database.NewFormat)
+      {
+        if (index != 0)
+          return E_FAIL;
+        if (!testMode && !realOutStream)
+          continue;
+        if (!testMode)
+        {
+          UInt32 size = m_Database.NewFormatString.Length();
+          RINOK(WriteStream(realOutStream, (const char *)m_Database.NewFormatString, size));
+        }
+        RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+        continue;
+      }
+      const CItem &item = m_Database.Items[index];
+      
+      currentItemSize = item.Size;
+      
+      if (!testMode && !realOutStream)
+        continue;
+      RINOK(extractCallback->PrepareOperation(askMode));
+      if (item.Section != 0)
+      {
+        RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
+        continue;
+      }
+
+      if (testMode)
+      {
+        RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+        continue;
+      }
+      
+      RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL));
+      streamSpec->Init(item.Size);
+      
+      RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
+      realOutStream.Release();
+      RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == item.Size) ?
+          NExtract::NOperationResult::kOK:
+          NExtract::NOperationResult::kDataError));
+    }
+    return S_OK;
+  }
+  
+  UInt64 lastFolderIndex = ((UInt64)0 - 1);
+  for (i = 0; i < numItems; i++)
+  {
+    UInt32 index = allFilesMode ? i : indices[i];
+    int entryIndex = m_Database.Indices[index];
+    const CItem &item = m_Database.Items[entryIndex];
+    UInt64 sectionIndex = item.Section;
+    if (item.IsDir() || item.Size == 0)
+      continue;
+    if (sectionIndex == 0)
+    {
+      currentTotalSize += item.Size;
+      continue;
+    }
+    const CSectionInfo &section = m_Database.Sections[(int)item.Section];
+    if (section.IsLzx())
+    {
+      const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo;
+      UInt64 folderIndex = m_Database.GetFolder(index);
+      if (lastFolderIndex == folderIndex)
+        folderIndex++;
+      lastFolderIndex = m_Database.GetLastFolder(index);
+      for (; folderIndex <= lastFolderIndex; folderIndex++)
+        currentTotalSize += lzxInfo.GetFolderSize();
+    }
+  }
+
+  RINOK(extractCallback->SetTotal(currentTotalSize));
+
+  NCompress::NLzx::CDecoder *lzxDecoderSpec = 0;
+  CMyComPtr<ICompressCoder> lzxDecoder;
+  CChmFolderOutStream *chmFolderOutStream = 0;
+  CMyComPtr<ISequentialOutStream> outStream;
+
+  currentTotalSize = 0;
+
+  CRecordVector<bool> extractStatuses;
+  for (i = 0; i < numItems;)
+  {
+    RINOK(extractCallback->SetCompleted(&currentTotalSize));
+    UInt32 index = allFilesMode ? i : indices[i];
+    i++;
+    int entryIndex = m_Database.Indices[index];
+    const CItem &item = m_Database.Items[entryIndex];
+    UInt64 sectionIndex = item.Section;
+    Int32 askMode= testMode ?
+        NExtract::NAskMode::kTest :
+        NExtract::NAskMode::kExtract;
+    if (item.IsDir())
+    {
+      CMyComPtr<ISequentialOutStream> realOutStream;
+      RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+      RINOK(extractCallback->PrepareOperation(askMode));
+      realOutStream.Release();
+      RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+      continue;
+    }
+
+    lps->InSize = currentTotalSize; // Change it
+    lps->OutSize = currentTotalSize;
+
+    if (item.Size == 0 || sectionIndex == 0)
+    {
+      CMyComPtr<ISequentialOutStream> realOutStream;
+      RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+      if (!testMode && !realOutStream)
+        continue;
+      RINOK(extractCallback->PrepareOperation(askMode));
+      Int32 opRes = NExtract::NOperationResult::kOK;
+      if (!testMode && item.Size != 0)
+      {
+        RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL));
+        streamSpec->Init(item.Size);
+        RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
+        if (copyCoderSpec->TotalSize != item.Size)
+          opRes = NExtract::NOperationResult::kDataError;
+      }
+      realOutStream.Release();
+      RINOK(extractCallback->SetOperationResult(opRes));
+      currentTotalSize += item.Size;
+      continue;
+    }
+  
+    const CSectionInfo &section = m_Database.Sections[(int)sectionIndex];
+
+    if (!section.IsLzx())
+    {
+      CMyComPtr<ISequentialOutStream> realOutStream;
+      RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
+      if (!testMode && !realOutStream)
+        continue;
+      RINOK(extractCallback->PrepareOperation(askMode));
+      RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
+      continue;
+    }
+
+    const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo;
+
+    if (chmFolderOutStream == 0)
+    {
+      chmFolderOutStream = new CChmFolderOutStream;
+      outStream = chmFolderOutStream;
+    }
+
+    chmFolderOutStream->Init(&m_Database, extractCallback, testMode);
+
+    if (lzxDecoderSpec == NULL)
+    {
+      lzxDecoderSpec = new NCompress::NLzx::CDecoder;
+      lzxDecoder = lzxDecoderSpec;
+    }
+
+    UInt64 folderIndex = m_Database.GetFolder(index);
+
+    UInt64 compressedPos = m_Database.ContentOffset + section.Offset;
+    UInt32 numDictBits = lzxInfo.GetNumDictBits();
+    RINOK(lzxDecoderSpec->SetParams(numDictBits));
+
+    const CItem *lastItem = &item;
+    extractStatuses.Clear();
+    extractStatuses.Add(true);
+
+    for (;; folderIndex++)
+    {
+      RINOK(extractCallback->SetCompleted(&currentTotalSize));
+
+      UInt64 startPos = lzxInfo.GetFolderPos(folderIndex);
+      UInt64 finishPos = lastItem->Offset + lastItem->Size;
+      UInt64 limitFolderIndex = lzxInfo.GetFolder(finishPos);
+
+      lastFolderIndex = m_Database.GetLastFolder(index);
+      UInt64 folderSize = lzxInfo.GetFolderSize();
+      UInt64 unPackSize = folderSize;
+      if (extractStatuses.IsEmpty())
+        chmFolderOutStream->m_StartIndex = index + 1;
+      else
+        chmFolderOutStream->m_StartIndex = index;
+      if (limitFolderIndex == folderIndex)
+      {
+        for (; i < numItems; i++)
+        {
+          UInt32 nextIndex = allFilesMode ? i : indices[i];
+          int entryIndex = m_Database.Indices[nextIndex];
+          const CItem &nextItem = m_Database.Items[entryIndex];
+          if (nextItem.Section != sectionIndex)
+            break;
+          UInt64 nextFolderIndex = m_Database.GetFolder(nextIndex);
+          if (nextFolderIndex != folderIndex)
+            break;
+          for (index++; index < nextIndex; index++)
+            extractStatuses.Add(false);
+          extractStatuses.Add(true);
+          index = nextIndex;
+          lastItem = &nextItem;
+          if (nextItem.Size != 0)
+            finishPos = nextItem.Offset + nextItem.Size;
+          lastFolderIndex = m_Database.GetLastFolder(index);
+        }
+      }
+      unPackSize = MyMin(finishPos - startPos, unPackSize);
+
+      chmFolderOutStream->m_FolderSize = folderSize;
+      chmFolderOutStream->m_PosInFolder = 0;
+      chmFolderOutStream->m_PosInSection = startPos;
+      chmFolderOutStream->m_ExtractStatuses = &extractStatuses;
+      chmFolderOutStream->m_NumFiles = extractStatuses.Size();
+      chmFolderOutStream->m_CurrentIndex = 0;
+      try
+      {
+        UInt64 startBlock = lzxInfo.GetBlockIndexFromFolderIndex(folderIndex);
+        const CResetTable &rt = lzxInfo.ResetTable;
+        UInt32 numBlocks = (UInt32)rt.GetNumBlocks(unPackSize);
+        for (UInt32 b = 0; b < numBlocks; b++)
+        {
+          UInt64 completedSize = currentTotalSize + chmFolderOutStream->m_PosInSection - startPos;
+          RINOK(extractCallback->SetCompleted(&completedSize));
+          UInt64 bCur = startBlock + b;
+          if (bCur >= rt.ResetOffsets.Size())
+            return E_FAIL;
+          UInt64 offset = rt.ResetOffsets[(int)bCur];
+          UInt64 compressedSize;
+          rt.GetCompressedSizeOfBlock(bCur, compressedSize);
+          UInt64 rem = finishPos - chmFolderOutStream->m_PosInSection;
+          if (rem > rt.BlockSize)
+            rem = rt.BlockSize;
+          RINOK(m_Stream->Seek(compressedPos + offset, STREAM_SEEK_SET, NULL));
+          streamSpec->SetStream(m_Stream);
+          streamSpec->Init(compressedSize);
+          lzxDecoderSpec->SetKeepHistory(b > 0);
+          HRESULT res = lzxDecoder->Code(inStream, outStream, NULL, &rem, NULL);
+          if (res != S_OK)
+          {
+            if (res != S_FALSE)
+              return res;
+            throw 1;
+          }
+        }
+      }
+      catch(...)
+      {
+        RINOK(chmFolderOutStream->FlushCorrupted(unPackSize));
+      }
+      currentTotalSize += folderSize;
+      if (folderIndex == lastFolderIndex)
+        break;
+      extractStatuses.Clear();
+    }
+  }
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+{
+    *numItems = m_Database.NewFormat ? 1:
+      (m_Database.LowLevel ?
+      m_Database.Items.Size():
+      m_Database.Indices.Size());
+  return S_OK;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHandler.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,29 @@
+// ChmHandler.h
+
+#ifndef __ARCHIVE_CHM_HANDLER_H
+#define __ARCHIVE_CHM_HANDLER_H
+
+#include "Common/MyCom.h"
+#include "../IArchive.h"
+#include "ChmIn.h"
+
+namespace NArchive {
+namespace NChm {
+
+class CHandler:
+  public IInArchive,
+  public CMyUnknownImp
+{
+public:
+  MY_UNKNOWN_IMP1(IInArchive)
+
+  INTERFACE_IInArchive(;)
+
+private:
+  CFilesDatabase m_Database;
+  CMyComPtr<IInStream> m_Stream;
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,24 @@
+// Archive/Chm/Header.h
+
+#include "StdAfx.h"
+
+#include "ChmHeader.h"
+
+namespace NArchive{
+namespace NChm{
+namespace NHeader{
+
+UInt32 kItsfSignature = 0x46535449 + 1;
+UInt32 kItolSignature = 0x4C4F5449 + 1;
+static class CSignatureInitializer
+{
+public:
+  CSignatureInitializer()
+  {
+    kItsfSignature--;
+    kItolSignature--;
+  }
+}g_SignatureInitializer;
+
+
+}}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmHeader.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,28 @@
+// Archive/Chm/Header.h
+
+#ifndef __ARCHIVE_CHM_HEADER_H
+#define __ARCHIVE_CHM_HEADER_H
+
+#include "Common/Types.h"
+
+namespace NArchive {
+namespace NChm {
+namespace NHeader{
+
+const UInt32 kItspSignature = 0x50535449;
+const UInt32 kPmglSignature = 0x4C474D50;
+const UInt32 kLzxcSignature = 0x43585A4C;
+
+const UInt32 kIfcmSignature = 0x4D434649;
+const UInt32 kAollSignature = 0x4C4C4F41;
+const UInt32 kCaolSignature = 0x4C4F4143;
+
+extern UInt32 kItsfSignature;
+
+extern UInt32 kItolSignature;
+const UInt32 kItlsSignature = 0x534C5449;
+UInt64 inline GetHxsSignature() { return ((UInt64)kItlsSignature << 32) | kItolSignature; }
+  
+}}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,937 @@
+// Archive/ChmIn.cpp
+
+#include "StdAfx.h"
+
+#include "Common/IntToString.h"
+#include "Common/UTFConvert.h"
+
+#include "../../Common/LimitedStreams.h"
+
+#include "ChmIn.h"
+
+namespace NArchive {
+namespace NChm {
+
+// define CHM_LOW, if you want to see low level items
+// #define CHM_LOW
+
+static const GUID kChmLzxGuid   = { 0x7FC28940, 0x9D31, 0x11D0, { 0x9B, 0x27, 0x00, 0xA0, 0xC9, 0x1E, 0x9C, 0x7C } };
+static const GUID kHelp2LzxGuid = { 0x0A9007C6, 0x4076, 0x11D3, { 0x87, 0x89, 0x00, 0x00, 0xF8, 0x10, 0x57, 0x54 } };
+static const GUID kDesGuid =      { 0x67F6E4A2, 0x60BF, 0x11D3, { 0x85, 0x40, 0x00, 0xC0, 0x4F, 0x58, 0xC3, 0xCF } };
+
+static bool AreGuidsEqual(REFGUID g1, REFGUID g2)
+{
+  if (g1.Data1 != g2.Data1 ||
+      g1.Data2 != g2.Data2 ||
+      g1.Data3 != g2.Data3)
+    return false;
+  for (int i = 0; i < 8; i++)
+    if (g1.Data4[i] != g2.Data4[i])
+      return false;
+  return true;
+}
+
+static char GetHex(Byte value)
+{
+  return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));
+}
+
+static void PrintByte(Byte b, AString &s)
+{
+  s += GetHex(b >> 4);
+  s += GetHex(b & 0xF);
+}
+
+static void PrintUInt16(UInt16 v, AString &s)
+{
+  PrintByte((Byte)(v >> 8), s);
+  PrintByte((Byte)v, s);
+}
+
+static void PrintUInt32(UInt32 v, AString &s)
+{
+  PrintUInt16((UInt16)(v >> 16), s);
+  PrintUInt16((UInt16)v, s);
+}
+
+AString CMethodInfo::GetGuidString() const
+{
+  AString s;
+  s += '{';
+  PrintUInt32(Guid.Data1, s);
+  s += '-';
+  PrintUInt16(Guid.Data2, s);
+  s += '-';
+  PrintUInt16(Guid.Data3, s);
+  s += '-';
+  PrintByte(Guid.Data4[0], s);
+  PrintByte(Guid.Data4[1], s);
+  s += '-';
+  for (int i = 2; i < 8; i++)
+    PrintByte(Guid.Data4[i], s);
+  s += '}';
+  return s;
+}
+
+bool CMethodInfo::IsLzx() const
+{
+  if (AreGuidsEqual(Guid, kChmLzxGuid))
+    return true;
+  return AreGuidsEqual(Guid, kHelp2LzxGuid);
+}
+
+bool CMethodInfo::IsDes() const
+{
+  return AreGuidsEqual(Guid, kDesGuid);
+}
+
+UString CMethodInfo::GetName() const
+{
+  UString s;
+  if (IsLzx())
+  {
+    s = L"LZX:";
+    wchar_t temp[16];
+    ConvertUInt32ToString(LzxInfo.GetNumDictBits(), temp);
+    s += temp;
+  }
+  else
+  {
+    AString s2;
+    if (IsDes())
+      s2 = "DES";
+    else
+    {
+      s2 = GetGuidString();
+      if (ControlData.GetCapacity() > 0)
+      {
+        s2 += ':';
+        for (size_t i = 0; i < ControlData.GetCapacity(); i++)
+          PrintByte(ControlData[i], s2);
+      }
+    }
+    ConvertUTF8ToUnicode(s2, s);
+  }
+  return s;
+}
+
+bool CSectionInfo::IsLzx() const
+{
+  if (Methods.Size() != 1)
+    return false;
+  return Methods[0].IsLzx();
+}
+
+UString CSectionInfo::GetMethodName() const
+{
+  UString s;
+  if (!IsLzx())
+  {
+    UString temp;
+    if (ConvertUTF8ToUnicode(Name, temp))
+      s += temp;
+    s += L": ";
+  }
+  for (int i = 0; i < Methods.Size(); i++)
+  {
+    if (i != 0)
+      s += L' ';
+    s += Methods[i].GetName();
+  }
+  return s;
+}
+
+Byte CInArchive::ReadByte()
+{
+  Byte b;
+  if (!_inBuffer.ReadByte(b))
+    throw 1;
+  return b;
+}
+
+void CInArchive::Skip(size_t size)
+{
+  while (size-- != 0)
+    ReadByte();
+}
+
+void CInArchive::ReadBytes(Byte *data, UInt32 size)
+{
+  for (UInt32 i = 0; i < size; i++)
+    data[i] = ReadByte();
+}
+
+UInt16 CInArchive::ReadUInt16()
+{
+  UInt16 value = 0;
+  for (int i = 0; i < 2; i++)
+    value |= ((UInt16)(ReadByte()) << (8 * i));
+  return value;
+}
+
+UInt32 CInArchive::ReadUInt32()
+{
+  UInt32 value = 0;
+  for (int i = 0; i < 4; i++)
+    value |= ((UInt32)(ReadByte()) << (8 * i));
+  return value;
+}
+
+UInt64 CInArchive::ReadUInt64()
+{
+  UInt64 value = 0;
+  for (int i = 0; i < 8; i++)
+    value |= ((UInt64)(ReadByte()) << (8 * i));
+  return value;
+}
+
+UInt64 CInArchive::ReadEncInt()
+{
+  UInt64 val = 0;;
+  for (int i = 0; i < 10; i++)
+  {
+    Byte b = ReadByte();
+    val |= (b & 0x7F);
+    if (b < 0x80)
+      return val;
+    val <<= 7;
+  }
+  throw 1;
+}
+
+void CInArchive::ReadGUID(GUID &g)
+{
+  g.Data1 = ReadUInt32();
+  g.Data2 = ReadUInt16();
+  g.Data3 = ReadUInt16();
+  ReadBytes(g.Data4, 8);
+}
+
+void CInArchive::ReadString(int size, AString &s)
+{
+  s.Empty();
+  while(size-- != 0)
+  {
+    char c = (char)ReadByte();
+    if (c == 0)
+    {
+      Skip(size);
+      return;
+    }
+    s += c;
+  }
+}
+
+void CInArchive::ReadUString(int size, UString &s)
+{
+  s.Empty();
+  while(size-- != 0)
+  {
+    wchar_t c = ReadUInt16();
+    if (c == 0)
+    {
+      Skip(2 * size);
+      return;
+    }
+    s += c;
+  }
+}
+
+HRESULT CInArchive::ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size)
+{
+  RINOK(inStream->Seek(pos, STREAM_SEEK_SET, NULL));
+  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
+  CMyComPtr<ISequentialInStream> limitedStream(streamSpec);
+  streamSpec->SetStream(inStream);
+  streamSpec->Init(size);
+  _inBuffer.SetStream(limitedStream);
+  _inBuffer.Init();
+  return S_OK;
+}
+
+HRESULT CInArchive::ReadDirEntry(CDatabase &database)
+{
+  CItem item;
+  UInt64 nameLength = ReadEncInt();
+  if (nameLength == 0 || nameLength >= 0x10000000)
+    return S_FALSE;
+  ReadString((int)nameLength, item.Name);
+  item.Section = ReadEncInt();
+  item.Offset = ReadEncInt();
+  item.Size = ReadEncInt();
+  database.Items.Add(item);
+  return S_OK;
+}
+
+HRESULT CInArchive::OpenChm(IInStream *inStream, CDatabase &database)
+{
+  UInt32 headerSize = ReadUInt32();
+  if (headerSize != 0x60)
+    return S_FALSE;
+  UInt32 unknown1 = ReadUInt32();
+  if (unknown1 != 0 && unknown1 != 1) // it's 0 in one .sll file
+    return S_FALSE;
+  /* UInt32 timeStamp = */ ReadUInt32();
+      // Considered as a big-endian DWORD, it appears to contain seconds (MSB) and
+      // fractional seconds (second byte).
+      // The third and fourth bytes may contain even more fractional bits.
+      // The 4 least significant bits in the last byte are constant.
+  /* UInt32 lang = */ ReadUInt32();
+  GUID g;
+  ReadGUID(g); // {7C01FD10-7BAA-11D0-9E0C-00A0-C922-E6EC}
+  ReadGUID(g); // {7C01FD11-7BAA-11D0-9E0C-00A0-C922-E6EC}
+  const int kNumSections = 2;
+  UInt64 sectionOffsets[kNumSections];
+  UInt64 sectionSizes[kNumSections];
+  int i;
+  for (i = 0; i < kNumSections; i++)
+  {
+    sectionOffsets[i] = ReadUInt64();
+    sectionSizes[i] = ReadUInt64();
+  }
+  // if (chmVersion == 3)
+    database.ContentOffset = ReadUInt64();
+  /*
+  else
+    database.ContentOffset = _startPosition + 0x58
+  */
+
+  /*
+  // Section 0
+  ReadChunk(inStream, sectionOffsets[0], sectionSizes[0]);
+  if (sectionSizes[0] != 0x18)
+    return S_FALSE;
+  ReadUInt32(); // unknown:  01FE
+  ReadUInt32(); // unknown:  0
+  UInt64 fileSize = ReadUInt64();
+  ReadUInt32(); // unknown:  0
+  ReadUInt32(); // unknown:  0
+  */
+
+  // Section 1: The Directory Listing
+  ReadChunk(inStream, sectionOffsets[1], sectionSizes[1]);
+  if (ReadUInt32() != NHeader::kItspSignature)
+    return S_FALSE;
+  if (ReadUInt32() != 1) // version
+    return S_FALSE;
+  /* UInt32 dirHeaderSize = */ ReadUInt32();
+  ReadUInt32(); // 0x0A (unknown)
+  UInt32 dirChunkSize = ReadUInt32(); // $1000
+  if (dirChunkSize < 32)
+    return S_FALSE;
+  /* UInt32 density = */ ReadUInt32(); //  "Density" of quickref section, usually 2.
+  /* UInt32 depth = */ ReadUInt32(); //  Depth of the index tree: 1 there is no index,
+                               // 2 if there is one level of PMGI chunks.
+
+  /* UInt32 chunkNumber = */ ReadUInt32(); //  Chunk number of root index chunk, -1 if there is none
+                                     // (though at least one file has 0 despite there being no
+                                     // index chunk, probably a bug.)
+  /* UInt32 firstPmglChunkNumber = */ ReadUInt32(); // Chunk number of first PMGL (listing) chunk
+  /* UInt32 lastPmglChunkNumber = */ ReadUInt32();  // Chunk number of last PMGL (listing) chunk
+  ReadUInt32(); // -1 (unknown)
+  UInt32 numDirChunks = ReadUInt32(); // Number of directory chunks (total)
+  /* UInt32 windowsLangId = */ ReadUInt32();
+  ReadGUID(g);  // {5D02926A-212E-11D0-9DF9-00A0C922E6EC}
+  ReadUInt32(); // 0x54 (This is the length again)
+  ReadUInt32(); // -1 (unknown)
+  ReadUInt32(); // -1 (unknown)
+  ReadUInt32(); // -1 (unknown)
+
+  for (UInt32 ci = 0; ci < numDirChunks; ci++)
+  {
+    UInt64 chunkPos = _inBuffer.GetProcessedSize();
+    if (ReadUInt32() == NHeader::kPmglSignature)
+    {
+      // The quickref area is written backwards from the end of the chunk.
+      // One quickref entry exists for every n entries in the file, where n
+      // is calculated as 1 + (1 << quickref density). So for density = 2, n = 5.
+
+      UInt32 quickrefLength = ReadUInt32(); // Length of free space and/or quickref area at end of directory chunk
+      if (quickrefLength > dirChunkSize || quickrefLength < 2)
+        return S_FALSE;
+      ReadUInt32(); // Always 0
+      ReadUInt32(); // Chunk number of previous listing chunk when reading
+                    // directory in sequence (-1 if this is the first listing chunk)
+      ReadUInt32(); // Chunk number of next  listing chunk when reading
+                    // directory in sequence (-1 if this is the last listing chunk)
+      int numItems = 0;
+      for (;;)
+      {
+        UInt64 offset = _inBuffer.GetProcessedSize() - chunkPos;
+        UInt32 offsetLimit = dirChunkSize - quickrefLength;
+        if (offset > offsetLimit)
+          return S_FALSE;
+        if (offset == offsetLimit)
+          break;
+        RINOK(ReadDirEntry(database));
+        numItems++;
+      }
+      Skip(quickrefLength - 2);
+      if (ReadUInt16() != numItems)
+        return S_FALSE;
+    }
+    else
+      Skip(dirChunkSize - 4);
+  }
+  return S_OK;
+}
+
+HRESULT CInArchive::OpenHelp2(IInStream *inStream, CDatabase &database)
+{
+  if (ReadUInt32() != 1) // version
+    return S_FALSE;
+  if (ReadUInt32() != 0x28) // Location of header section table
+    return S_FALSE;
+  UInt32 numHeaderSections = ReadUInt32();
+  const int kNumHeaderSectionsMax = 5;
+  if (numHeaderSections != kNumHeaderSectionsMax)
+    return S_FALSE;
+  ReadUInt32(); // Length of post-header table
+  GUID g;
+  ReadGUID(g);  // {0A9007C1-4076-11D3-8789-0000F8105754}
+
+  // header section table
+  UInt64 sectionOffsets[kNumHeaderSectionsMax];
+  UInt64 sectionSizes[kNumHeaderSectionsMax];
+  UInt32 i;
+  for (i = 0; i < numHeaderSections; i++)
+  {
+    sectionOffsets[i] = ReadUInt64();
+    sectionSizes[i] = ReadUInt64();
+  }
+  
+  // Post-Header
+  ReadUInt32(); // 2
+  ReadUInt32(); // 0x98: offset to CAOL from beginning of post-header)
+  // ----- Directory information
+  ReadUInt64(); // Chunk number of top-level AOLI chunk in directory, or -1
+  ReadUInt64(); // Chunk number of first AOLL chunk in directory
+  ReadUInt64(); // Chunk number of last AOLL chunk in directory
+  ReadUInt64(); // 0 (unknown)
+  ReadUInt32(); // $2000 (Directory chunk size of directory)
+  ReadUInt32(); // Quickref density for main directory, usually 2
+  ReadUInt32(); // 0 (unknown)
+  ReadUInt32(); // Depth of main directory index tree
+                // 1 there is no index, 2 if there is one level of AOLI chunks.
+  ReadUInt64(); // 0 (unknown)
+  UInt64 numDirEntries = ReadUInt64(); // Number of directory entries
+  // ----- Directory Index Information
+  ReadUInt64(); // -1 (unknown, probably chunk number of top-level AOLI in directory index)
+  ReadUInt64(); // Chunk number of first AOLL chunk in directory index
+  ReadUInt64(); // Chunk number of last AOLL chunk in directory index
+  ReadUInt64(); // 0 (unknown)
+  ReadUInt32(); // $200 (Directory chunk size of directory index)
+  ReadUInt32(); // Quickref density for directory index, usually 2
+  ReadUInt32(); // 0 (unknown)
+  ReadUInt32(); // Depth of directory index index tree.
+  ReadUInt64(); // Possibly flags -- sometimes 1, sometimes 0.
+  ReadUInt64(); // Number of directory index entries (same as number of AOLL
+               // chunks in main directory)
+  
+  // (The obvious guess for the following two fields, which recur in a number
+  // of places, is they are maximum sizes for the directory and directory index.
+  // However, I have seen no direct evidence that this is the case.)
+
+  ReadUInt32(); // $100000 (Same as field following chunk size in directory)
+  ReadUInt32(); // $20000 (Same as field following chunk size in directory index)
+
+  ReadUInt64(); // 0 (unknown)
+  if (ReadUInt32() != NHeader::kCaolSignature)
+    return S_FALSE;
+  if (ReadUInt32() != 2) // (Most likely a version number)
+    return S_FALSE;
+  UInt32 caolLength = ReadUInt32(); // $50 (Length of the CAOL section, which includes the ITSF section)
+  if (caolLength >= 0x2C)
+  {
+    /* UInt32 c7 = */ ReadUInt16(); // Unknown.  Remains the same when identical files are built.
+              // Does not appear to be a checksum.  Many files have
+              // 'HH' (HTML Help?) here, indicating this may be a compiler ID
+              //  field.  But at least one ITOL/ITLS compiler does not set this
+              // field to a constant value.
+    ReadUInt16(); // 0 (Unknown.  Possibly part of 00A4 field)
+    ReadUInt32(); // Unknown.  Two values have been seen -- $43ED, and 0.
+    ReadUInt32(); // $2000 (Directory chunk size of directory)
+    ReadUInt32(); // $200 (Directory chunk size of directory index)
+    ReadUInt32(); // $100000 (Same as field following chunk size in directory)
+    ReadUInt32(); // $20000 (Same as field following chunk size in directory index)
+    ReadUInt32(); // 0 (unknown)
+    ReadUInt32(); // 0 (Unknown)
+    if (caolLength == 0x2C)
+    {
+      database.ContentOffset = 0;
+      database.NewFormat = true;
+    }
+    else if (caolLength == 0x50)
+    {
+      ReadUInt32(); // 0 (Unknown)
+      if (ReadUInt32() != NHeader::kItsfSignature)
+        return S_FALSE;
+      if (ReadUInt32() != 4) // $4 (Version number -- CHM uses 3)
+        return S_FALSE;
+      if (ReadUInt32() != 0x20) // $20 (length of ITSF)
+        return S_FALSE;
+      UInt32 unknown = ReadUInt32();
+      if (unknown != 0 && unknown != 1) // = 0 for some HxW files, 1 in other cases;
+        return S_FALSE;
+      database.ContentOffset = _startPosition + ReadUInt64();
+      /* UInt32 timeStamp = */ ReadUInt32();
+          // A timestamp of some sort.
+          // Considered as a big-endian DWORD, it appears to contain
+          // seconds (MSB) and fractional seconds (second byte).
+          // The third and fourth bytes may contain even more fractional
+          // bits.  The 4 least significant bits in the last byte are constant.
+      /* UInt32 lang = */ ReadUInt32(); // BE?
+    }
+    else
+      return S_FALSE;
+  }
+
+  /*
+  // Section 0
+  ReadChunk(inStream, _startPosition + sectionOffsets[0], sectionSizes[0]);
+  if (sectionSizes[0] != 0x18)
+    return S_FALSE;
+  ReadUInt32(); // unknown:  01FE
+  ReadUInt32(); // unknown:  0
+  UInt64 fileSize = ReadUInt64();
+  ReadUInt32(); // unknown:  0
+  ReadUInt32(); // unknown:  0
+  */
+
+  // Section 1: The Directory Listing
+  ReadChunk(inStream, _startPosition + sectionOffsets[1], sectionSizes[1]);
+  if (ReadUInt32() != NHeader::kIfcmSignature)
+    return S_FALSE;
+  if (ReadUInt32() != 1) // (probably a version number)
+    return S_FALSE;
+  UInt32 dirChunkSize = ReadUInt32(); // $2000
+  if (dirChunkSize < 64)
+    return S_FALSE;
+  ReadUInt32(); // $100000  (unknown)
+  ReadUInt32(); // -1 (unknown)
+  ReadUInt32(); // -1 (unknown)
+  UInt32 numDirChunks = ReadUInt32();
+  ReadUInt32(); // 0 (unknown, probably high word of above)
+
+  for (UInt32 ci = 0; ci < numDirChunks; ci++)
+  {
+    UInt64 chunkPos = _inBuffer.GetProcessedSize();
+    if (ReadUInt32() == NHeader::kAollSignature)
+    {
+      UInt32 quickrefLength = ReadUInt32(); // Length of quickref area at end of directory chunk
+      if (quickrefLength > dirChunkSize || quickrefLength < 2)
+        return S_FALSE;
+      ReadUInt64(); // Directory chunk number
+            // This must match physical position in file, that is
+            // the chunk size times the chunk number must be the
+            // offset from the end of the directory header.
+      ReadUInt64(); // Chunk number of previous listing chunk when reading
+                    // directory in sequence (-1 if first listing chunk)
+      ReadUInt64(); // Chunk number of next listing chunk when reading
+                    // directory in sequence (-1 if last listing chunk)
+      ReadUInt64(); // Number of first listing entry in this chunk
+      ReadUInt32(); // 1 (unknown -- other values have also been seen here)
+      ReadUInt32(); // 0 (unknown)
+      
+      int numItems = 0;
+      for (;;)
+      {
+        UInt64 offset = _inBuffer.GetProcessedSize() - chunkPos;
+        UInt32 offsetLimit = dirChunkSize - quickrefLength;
+        if (offset > offsetLimit)
+          return S_FALSE;
+        if (offset == offsetLimit)
+          break;
+        if (database.NewFormat)
+        {
+          UInt16 nameLength = ReadUInt16();
+          if (nameLength == 0)
+            return S_FALSE;
+          UString name;
+          ReadUString((int)nameLength, name);
+          AString s;
+          ConvertUnicodeToUTF8(name, s);
+          Byte b = ReadByte();
+          s += ' ';
+          PrintByte(b, s);
+          s += ' ';
+          UInt64 len = ReadEncInt();
+          // then number of items ?
+          // then length ?
+          // then some data (binary encoding?)
+          while (len-- != 0)
+          {
+            b = ReadByte();
+            PrintByte(b, s);
+          }
+          database.NewFormatString += s;
+          database.NewFormatString += "\r\n";
+        }
+        else
+        {
+          RINOK(ReadDirEntry(database));
+        }
+        numItems++;
+      }
+      Skip(quickrefLength - 2);
+      if (ReadUInt16() != numItems)
+        return S_FALSE;
+      if (numItems > numDirEntries)
+        return S_FALSE;
+      numDirEntries -= numItems;
+    }
+    else
+      Skip(dirChunkSize - 4);
+  }
+  return numDirEntries == 0 ? S_OK : S_FALSE;
+}
+
+HRESULT CInArchive::DecompressStream(IInStream *inStream, const CDatabase &database, const AString &name)
+{
+  int index = database.FindItem(name);
+  if (index < 0)
+    return S_FALSE;
+  const CItem &item = database.Items[index];
+  _chunkSize = item.Size;
+  return ReadChunk(inStream, database.ContentOffset + item.Offset, item.Size);
+}
+
+
+#define DATA_SPACE "::DataSpace/"
+static const char *kNameList = DATA_SPACE "NameList";
+static const char *kStorage = DATA_SPACE "Storage/";
+static const char *kContent = "Content";
+static const char *kControlData = "ControlData";
+static const char *kSpanInfo = "SpanInfo";
+static const char *kTransform = "Transform/";
+static const char *kResetTable = "/InstanceData/ResetTable";
+static const char *kTransformList = "List";
+
+static AString GetSectionPrefix(const AString &name)
+{
+  return AString(kStorage) + name + AString("/");
+}
+
+#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
+
+static int CompareFiles(const int *p1, const int *p2, void *param)
+{
+  const CObjectVector<CItem> &items = *(const CObjectVector<CItem> *)param;
+  const CItem &item1 = items[*p1];
+  const CItem &item2 = items[*p2];
+  bool isDir1 = item1.IsDir();
+  bool isDir2 = item2.IsDir();
+  if (isDir1 && !isDir2)
+    return -1;
+  if (isDir2)
+  {
+    if (isDir1)
+      return MyCompare(*p1, *p2);
+    return 1;
+  }
+  RINOZ(MyCompare(item1.Section, item2.Section));
+  RINOZ(MyCompare(item1.Offset, item2.Offset));
+  RINOZ(MyCompare(item1.Size, item2.Size));
+  return MyCompare(*p1, *p2);
+}
+
+void CFilesDatabase::SetIndices()
+{
+  for (int i = 0; i < Items.Size(); i++)
+  {
+    const CItem &item = Items[i];
+    if (item.IsUserItem() && item.Name.Length() != 1)
+      Indices.Add(i);
+  }
+}
+
+void CFilesDatabase::Sort()
+{
+  Indices.Sort(CompareFiles, (void *)&Items);
+}
+
+bool CFilesDatabase::Check()
+{
+  UInt64 maxPos = 0;
+  UInt64 prevSection = 0;
+  for(int i = 0; i < Indices.Size(); i++)
+  {
+    const CItem &item = Items[Indices[i]];
+    if (item.Section == 0 || item.IsDir())
+      continue;
+    if (item.Section != prevSection)
+    {
+      prevSection = item.Section;
+      maxPos = 0;
+      continue;
+    }
+    if (item.Offset < maxPos)
+      return false;
+    maxPos = item.Offset + item.Size;
+    if (maxPos < item.Offset)
+      return false;
+  }
+  return true;
+}
+
+HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
+{
+  {
+    // The NameList file
+    RINOK(DecompressStream(inStream, database, kNameList));
+    /* UInt16 length = */ ReadUInt16();
+    UInt16 numSections = ReadUInt16();
+    for (int i = 0; i < numSections; i++)
+    {
+      CSectionInfo section;
+      UInt16 nameLength  = ReadUInt16();
+      UString name;
+      ReadUString(nameLength, name);
+      if (ReadUInt16() != 0)
+        return S_FALSE;
+      if (!ConvertUnicodeToUTF8(name, section.Name))
+        return S_FALSE;
+      database.Sections.Add(section);
+    }
+  }
+
+  int i;
+  for (i = 1; i < database.Sections.Size(); i++)
+  {
+    CSectionInfo &section = database.Sections[i];
+    AString sectionPrefix = GetSectionPrefix(section.Name);
+    {
+      // Content
+      int index = database.FindItem(sectionPrefix + kContent);
+      if (index < 0)
+        return S_FALSE;
+      const CItem &item = database.Items[index];
+      section.Offset = item.Offset;
+      section.CompressedSize = item.Size;
+    }
+    AString transformPrefix = sectionPrefix + kTransform;
+    if (database.Help2Format)
+    {
+      // Transform List
+      RINOK(DecompressStream(inStream, database, transformPrefix + kTransformList));
+      if ((_chunkSize & 0xF) != 0)
+        return S_FALSE;
+      int numGuids = (int)(_chunkSize / 0x10);
+      if (numGuids < 1)
+        return S_FALSE;
+      for (int i = 0; i < numGuids; i++)
+      {
+        CMethodInfo method;
+        ReadGUID(method.Guid);
+        section.Methods.Add(method);
+      }
+    }
+    else
+    {
+      CMethodInfo method;
+      method.Guid = kChmLzxGuid;
+      section.Methods.Add(method);
+    }
+
+    {
+      // Control Data
+      RINOK(DecompressStream(inStream, database, sectionPrefix + kControlData));
+      for (int mi = 0; mi < section.Methods.Size(); mi++)
+      {
+        CMethodInfo &method = section.Methods[mi];
+        UInt32 numDWORDS = ReadUInt32();
+        if (method.IsLzx())
+        {
+          if (numDWORDS < 5)
+            return S_FALSE;
+          if (ReadUInt32() != NHeader::kLzxcSignature)
+            return S_FALSE;
+          CLzxInfo &li = method.LzxInfo;
+          li.Version = ReadUInt32();
+          if (li.Version != 2 && li.Version != 3)
+            return S_FALSE;
+          li.ResetInterval = ReadUInt32();
+          li.WindowSize = ReadUInt32();
+          li.CacheSize = ReadUInt32();
+          if (
+              li.ResetInterval != 1 &&
+              li.ResetInterval != 2 &&
+              li.ResetInterval != 4 &&
+              li.ResetInterval != 8 &&
+              li.ResetInterval != 16 &&
+              li.ResetInterval != 32 &&
+              li.ResetInterval != 64)
+            return S_FALSE;
+          if (
+              li.WindowSize != 1 &&
+              li.WindowSize != 2 &&
+              li.WindowSize != 4 &&
+              li.WindowSize != 8 &&
+              li.WindowSize != 16 &&
+              li.WindowSize != 32 &&
+              li.WindowSize != 64)
+            return S_FALSE;
+          numDWORDS -= 5;
+          while (numDWORDS-- != 0)
+            ReadUInt32();
+        }
+        else
+        {
+          UInt32 numBytes = numDWORDS * 4;
+          method.ControlData.SetCapacity(numBytes);
+          ReadBytes(method.ControlData, numBytes);
+        }
+      }
+    }
+
+    {
+      // SpanInfo
+      RINOK(DecompressStream(inStream, database, sectionPrefix + kSpanInfo));
+      section.UncompressedSize = ReadUInt64();
+    }
+
+    // read ResetTable for LZX
+    for (int mi = 0; mi < section.Methods.Size(); mi++)
+    {
+      CMethodInfo &method = section.Methods[mi];
+      if (method.IsLzx())
+      {
+        // ResetTable;
+        RINOK(DecompressStream(inStream, database, transformPrefix +
+            method.GetGuidString() + kResetTable));
+        CResetTable &rt = method.LzxInfo.ResetTable;
+        if (_chunkSize < 4)
+        {
+          if (_chunkSize != 0)
+            return S_FALSE;
+          // ResetTable is empty in .chw files
+          if (section.UncompressedSize != 0)
+            return S_FALSE;
+          rt.UncompressedSize = 0;
+          rt.CompressedSize = 0;
+          rt.BlockSize = 0;
+        }
+        else
+        {
+          UInt32 ver = ReadUInt32(); // 2  unknown (possibly a version number)
+          if (ver != 2 && ver != 3)
+            return S_FALSE;
+          UInt32 numEntries = ReadUInt32();
+          if (ReadUInt32() != 8) // Size of table entry (bytes)
+            return S_FALSE;
+          if (ReadUInt32() != 0x28) // Length of table header
+            return S_FALSE;
+          rt.UncompressedSize = ReadUInt64();
+          rt.CompressedSize = ReadUInt64();
+          rt.BlockSize = ReadUInt64(); //  0x8000 block size for locations below
+          if (rt.BlockSize != 0x8000)
+            return S_FALSE;
+          rt.ResetOffsets.Reserve(numEntries);
+          for (UInt32 i = 0; i < numEntries; i++)
+            rt.ResetOffsets.Add(ReadUInt64());
+        }
+      }
+    }
+  }
+
+  database.SetIndices();
+  database.Sort();
+  return database.Check() ? S_OK : S_FALSE;
+}
+
+HRESULT CInArchive::Open2(IInStream *inStream,
+    const UInt64 *searchHeaderSizeLimit,
+    CFilesDatabase &database)
+{
+  database.Clear();
+
+  RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &_startPosition));
+
+  database.Help2Format = false;
+  const UInt32 chmVersion = 3;
+  {
+    if (!_inBuffer.Create(1 << 14))
+      return E_OUTOFMEMORY;
+    _inBuffer.SetStream(inStream);
+    _inBuffer.Init();
+    UInt64 value = 0;
+    const int kSignatureSize = 8;
+    UInt64 hxsSignature = NHeader::GetHxsSignature();
+    UInt64 chmSignature = ((UInt64)chmVersion << 32)| NHeader::kItsfSignature;
+    UInt64 limit = 1 << 18;
+    if (searchHeaderSizeLimit)
+      if (limit > *searchHeaderSizeLimit)
+        limit = *searchHeaderSizeLimit;
+
+    for (;;)
+    {
+      Byte b;
+      if (!_inBuffer.ReadByte(b))
+        return S_FALSE;
+      value >>= 8;
+      value |= ((UInt64)b) << ((kSignatureSize - 1) * 8);
+      if (_inBuffer.GetProcessedSize() >= kSignatureSize)
+      {
+        if (value == chmSignature)
+          break;
+        if (value == hxsSignature)
+        {
+          database.Help2Format = true;
+          break;
+        }
+        if (_inBuffer.GetProcessedSize() > limit)
+          return S_FALSE;
+      }
+    }
+    _startPosition += _inBuffer.GetProcessedSize() - kSignatureSize;
+  }
+
+  if (database.Help2Format)
+  {
+    RINOK(OpenHelp2(inStream, database));
+    if (database.NewFormat)
+      return S_OK;
+  }
+  else
+  {
+    RINOK(OpenChm(inStream, database));
+  }
+
+  #ifndef CHM_LOW
+  try
+  {
+    HRESULT res = OpenHighLevel(inStream, database);
+    if (res == S_FALSE)
+    {
+      database.HighLevelClear();
+      return S_OK;
+    }
+    RINOK(res);
+    database.LowLevel = false;
+  }
+  catch(...)
+  {
+    return S_OK;
+  }
+  #endif
+  return S_OK;
+}
+
+HRESULT CInArchive::Open(IInStream *inStream,
+    const UInt64 *searchHeaderSizeLimit,
+    CFilesDatabase &database)
+{
+  try
+  {
+    HRESULT res = Open2(inStream, searchHeaderSizeLimit, database);
+    _inBuffer.ReleaseStream();
+    return res;
+  }
+  catch(...)
+  {
+    _inBuffer.ReleaseStream();
+    throw;
+  }
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmIn.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,244 @@
+// Archive/ChmIn.h
+
+#ifndef __ARCHIVE_CHM_IN_H
+#define __ARCHIVE_CHM_IN_H
+
+#include "Common/Buffer.h"
+#include "Common/MyString.h"
+
+#include "../../IStream.h"
+#include "../../Common/InBuffer.h"
+
+#include "ChmHeader.h"
+
+namespace NArchive {
+namespace NChm {
+
+struct CItem
+{
+  UInt64 Section;
+  UInt64 Offset;
+  UInt64 Size;
+  AString Name;
+
+  bool IsFormatRelatedItem() const
+  {
+    if (Name.Length() < 2)
+      return false;
+    return Name[0] == ':' && Name[1] == ':';
+  }
+  
+  bool IsUserItem() const
+  {
+    if (Name.Length() < 2)
+      return false;
+    return Name[0] == '/';
+  }
+  
+  bool IsDir() const
+  {
+    if (Name.Length() == 0)
+      return false;
+    return (Name[Name.Length() - 1] == '/');
+  }
+};
+
+struct CDatabase
+{
+  UInt64 ContentOffset;
+  CObjectVector<CItem> Items;
+  AString NewFormatString;
+  bool Help2Format;
+  bool NewFormat;
+
+  int FindItem(const AString &name) const
+  {
+    for (int i = 0; i < Items.Size(); i++)
+      if (Items[i].Name == name)
+        return i;
+    return -1;
+  }
+
+  void Clear()
+  {
+    NewFormat = false;
+    NewFormatString.Empty();
+    Help2Format = false;
+    Items.Clear();
+  }
+};
+
+struct CResetTable
+{
+  UInt64 UncompressedSize;
+  UInt64 CompressedSize;
+  UInt64 BlockSize;
+  CRecordVector<UInt64> ResetOffsets;
+  bool GetCompressedSizeOfBlocks(UInt64 blockIndex, UInt32 numBlocks, UInt64 &size) const
+  {
+    if (blockIndex >= ResetOffsets.Size())
+      return false;
+    UInt64 startPos = ResetOffsets[(int)blockIndex];
+    if (blockIndex + numBlocks >= ResetOffsets.Size())
+      size = CompressedSize - startPos;
+    else
+      size = ResetOffsets[(int)(blockIndex + numBlocks)] - startPos;
+    return true;
+  }
+  bool GetCompressedSizeOfBlock(UInt64 blockIndex, UInt64 &size) const
+  {
+    return GetCompressedSizeOfBlocks(blockIndex, 1, size);
+  }
+  UInt64 GetNumBlocks(UInt64 size) const
+  {
+    return (size + BlockSize - 1) / BlockSize;
+  }
+};
+
+struct CLzxInfo
+{
+  UInt32 Version;
+  UInt32 ResetInterval;
+  UInt32 WindowSize;
+  UInt32 CacheSize;
+  CResetTable ResetTable;
+
+  UInt32 GetNumDictBits() const
+  {
+    if (Version == 2 || Version == 3)
+    {
+      for (int i = 0; i <= 31; i++)
+        if (((UInt32)1 << i) >= WindowSize)
+          return 15 + i;
+    }
+    return 0;
+  }
+
+  UInt64 GetFolderSize() const { return ResetTable.BlockSize * ResetInterval; };
+  UInt64 GetFolder(UInt64 offset) const { return offset / GetFolderSize(); };
+  UInt64 GetFolderPos(UInt64 folderIndex) const { return folderIndex * GetFolderSize(); };
+  UInt64 GetBlockIndexFromFolderIndex(UInt64 folderIndex) const { return folderIndex * ResetInterval; };
+  bool GetOffsetOfFolder(UInt64 folderIndex, UInt64 &offset) const
+  {
+    UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex);
+    if (blockIndex >= ResetTable.ResetOffsets.Size())
+      return false;
+    offset = ResetTable.ResetOffsets[(int)blockIndex];
+    return true;
+  }
+  bool GetCompressedSizeOfFolder(UInt64 folderIndex, UInt64 &size) const
+  {
+    UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex);
+    return ResetTable.GetCompressedSizeOfBlocks(blockIndex, ResetInterval, size);
+  }
+};
+
+struct CMethodInfo
+{
+  GUID Guid;
+  CByteBuffer ControlData;
+  CLzxInfo LzxInfo;
+  bool IsLzx() const;
+  bool IsDes() const;
+  AString GetGuidString() const;
+  UString GetName() const;
+};
+
+struct CSectionInfo
+{
+  UInt64 Offset;
+  UInt64 CompressedSize;
+  UInt64 UncompressedSize;
+
+  AString Name;
+  CObjectVector<CMethodInfo> Methods;
+
+  bool IsLzx() const;
+  UString GetMethodName() const;
+};
+
+class CFilesDatabase: public CDatabase
+{
+public:
+  bool LowLevel;
+  CRecordVector<int> Indices;
+  CObjectVector<CSectionInfo> Sections;
+
+  UInt64 GetFileSize(int fileIndex) const { return Items[Indices[fileIndex]].Size; }
+  UInt64 GetFileOffset(int fileIndex) const { return Items[Indices[fileIndex]].Offset; }
+
+  UInt64 GetFolder(int fileIndex) const
+  {
+    const CItem &item = Items[Indices[fileIndex]];
+    const CSectionInfo &section = Sections[(int)item.Section];
+    if (section.IsLzx())
+      return section.Methods[0].LzxInfo.GetFolder(item.Offset);
+    return 0;
+  }
+
+  UInt64 GetLastFolder(int fileIndex) const
+  {
+    const CItem &item = Items[Indices[fileIndex]];
+    const CSectionInfo &section = Sections[(int)item.Section];
+    if (section.IsLzx())
+      return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1);
+    return 0;
+  }
+
+  void HighLevelClear()
+  {
+    LowLevel = true;
+    Indices.Clear();
+    Sections.Clear();
+  }
+
+  void Clear()
+  {
+    CDatabase::Clear();
+    HighLevelClear();
+  }
+  void SetIndices();
+  void Sort();
+  bool Check();
+};
+
+class CProgressVirt
+{
+public:
+  STDMETHOD(SetTotal)(const UInt64 *numFiles) PURE;
+  STDMETHOD(SetCompleted)(const UInt64 *numFiles) PURE;
+};
+
+class CInArchive
+{
+  UInt64 _startPosition;
+  ::CInBuffer _inBuffer;
+  UInt64 _chunkSize;
+
+  Byte ReadByte();
+  void ReadBytes(Byte *data, UInt32 size);
+  void Skip(size_t size);
+  UInt16 ReadUInt16();
+  UInt32 ReadUInt32();
+  UInt64 ReadUInt64();
+  UInt64 ReadEncInt();
+  void ReadString(int size, AString &s);
+  void ReadUString(int size, UString &s);
+  void ReadGUID(GUID &g);
+
+  HRESULT ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size);
+
+  HRESULT ReadDirEntry(CDatabase &database);
+  HRESULT DecompressStream(IInStream *inStream, const CDatabase &database, const AString &name);
+
+public:
+  HRESULT OpenChm(IInStream *inStream, CDatabase &database);
+  HRESULT OpenHelp2(IInStream *inStream, CDatabase &database);
+  HRESULT OpenHighLevel(IInStream *inStream, CFilesDatabase &database);
+  HRESULT Open2(IInStream *inStream, const UInt64 *searchHeaderSizeLimit, CFilesDatabase &database);
+  HRESULT Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit, CFilesDatabase &database);
+};
+  
+}}
+  
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,13 @@
+// ChmRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/RegisterArc.h"
+
+#include "ChmHandler.h"
+static IInArchive *CreateArc() { return new NArchive::NChm::CHandler; }
+
+static CArcInfo g_ArcInfo =
+  { L"Chm", L"chm chi chq chw hxs hxi hxr hxq hxw lit", 0, 0xE9, { 'I', 'T', 'S', 'F' }, 4, false, CreateArc, 0 };
+
+REGISTER_ARC(Chm)

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,239 @@
+// ComHandler.cpp
+
+#include "StdAfx.h"
+
+#include "Common/ComTry.h"
+
+#include "Windows/PropVariant.h"
+
+#include "../../Common/LimitedStreams.h"
+#include "../../Common/ProgressUtils.h"
+#include "../../Common/StreamUtils.h"
+
+#include "../../Compress/CopyCoder.h"
+
+#include "ComHandler.h"
+
+namespace NArchive {
+namespace NCom {
+
+STATPROPSTG kProps[] =
+{
+  { NULL, kpidPath, VT_BSTR},
+  { NULL, kpidIsDir, VT_BOOL},
+  { NULL, kpidSize, VT_UI8},
+  { NULL, kpidPackSize, VT_UI8},
+  { NULL, kpidCTime, VT_FILETIME},
+  { NULL, kpidMTime, VT_FILETIME}
+};
+
+STATPROPSTG kArcProps[] =
+{
+  { NULL, kpidClusterSize, VT_UI4},
+  { NULL, kpidSectorSize, VT_UI4}
+};
+
+IMP_IInArchive_Props
+IMP_IInArchive_ArcProps
+
+STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NWindows::NCOM::CPropVariant prop;
+  switch(propID)
+  {
+    case kpidClusterSize: prop = (UInt32)1 << _db.SectorSizeBits; break;
+    case kpidSectorSize: prop = (UInt32)1 << _db.MiniSectorSizeBits; break;
+    case kpidMainSubfile: if (_db.MainSubfile >= 0) prop = (UInt32)_db.MainSubfile; break;
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+{
+  COM_TRY_BEGIN
+  NWindows::NCOM::CPropVariant prop;
+  const CRef &ref = _db.Refs[index];
+  const CItem &item = _db.Items[ref.Did];
+    
+  switch(propID)
+  {
+    case kpidPath:  prop = _db.GetItemPath(index); break;
+    case kpidIsDir:  prop = item.IsDir(); break;
+    case kpidCTime:  prop = item.CTime; break;
+    case kpidMTime:  prop = item.MTime; break;
+    case kpidPackSize:  if (!item.IsDir()) prop = _db.GetItemPackSize(item.Size); break;
+    case kpidSize:  if (!item.IsDir()) prop = item.Size; break;
+  }
+  prop.Detach(value);
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::Open(IInStream *inStream,
+    const UInt64 * /* maxCheckStartPosition */,
+    IArchiveOpenCallback * /* openArchiveCallback */)
+{
+  COM_TRY_BEGIN
+  Close();
+  try
+  {
+    if (_db.Open(inStream) != S_OK)
+      return S_FALSE;
+    _stream = inStream;
+  }
+  catch(...) { return S_FALSE; }
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::Close()
+{
+  _db.Clear();
+  _stream.Release();
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
+    Int32 testMode, IArchiveExtractCallback *extractCallback)
+{
+  COM_TRY_BEGIN
+  bool allFilesMode = (numItems == (UInt32)-1);
+  if (allFilesMode)
+    numItems = _db.Refs.Size();
+  if (numItems == 0)
+    return S_OK;
+  UInt32 i;
+  UInt64 totalSize = 0;
+  for(i = 0; i < numItems; i++)
+  {
+    const CItem &item = _db.Items[_db.Refs[allFilesMode ? i : indices[i]].Did];
+    if (!item.IsDir())
+      totalSize += item.Size;
+  }
+  RINOK(extractCallback->SetTotal(totalSize));
+
+  UInt64 totalPackSize;
+  totalSize = totalPackSize = 0;
+  
+  NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
+  CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
+
+  CLocalProgress *lps = new CLocalProgress;
+  CMyComPtr<ICompressProgressInfo> progress = lps;
+  lps->Init(extractCallback, false);
+
+  for (i = 0; i < numItems; i++)
+  {
+    lps->InSize = totalPackSize;
+    lps->OutSize = totalSize;
+    RINOK(lps->SetCur());
+    Int32 index = allFilesMode ? i : indices[i];
+    const CItem &item = _db.Items[_db.Refs[index].Did];
+
+    CMyComPtr<ISequentialOutStream> outStream;
+    Int32 askMode = testMode ?
+        NExtract::NAskMode::kTest :
+        NExtract::NAskMode::kExtract;
+    RINOK(extractCallback->GetStream(index, &outStream, askMode));
+
+    if (item.IsDir())
+    {
+      RINOK(extractCallback->PrepareOperation(askMode));
+      RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+      continue;
+    }
+
+    totalPackSize += _db.GetItemPackSize(item.Size);
+    totalSize += item.Size;
+    
+    if (!testMode && !outStream)
+      continue;
+    RINOK(extractCallback->PrepareOperation(askMode));
+    Int32 res = NExtract::NOperationResult::kDataError;
+    CMyComPtr<ISequentialInStream> inStream;
+    HRESULT hres = GetStream(index, &inStream);
+    if (hres == S_FALSE)
+      res = NExtract::NOperationResult::kDataError;
+    else if (hres == E_NOTIMPL)
+      res = NExtract::NOperationResult::kUnSupportedMethod;
+    else
+    {
+      RINOK(hres);
+      if (inStream)
+      {
+        RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
+        if (copyCoderSpec->TotalSize == item.Size)
+          res = NExtract::NOperationResult::kOK;
+      }
+    }
+    outStream.Release();
+    RINOK(extractCallback->SetOperationResult(res));
+  }
+  return S_OK;
+  COM_TRY_END
+}
+
+STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
+{
+  *numItems = _db.Refs.Size();
+  return S_OK;
+}
+
+STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
+{
+  COM_TRY_BEGIN
+  *stream = 0;
+  const CItem &item = _db.Items[_db.Refs[index].Did];
+  CClusterInStream *streamSpec = new CClusterInStream;
+  CMyComPtr<ISequentialInStream> streamTemp = streamSpec;
+  streamSpec->Stream = _stream;
+  streamSpec->StartOffset = 0;
+
+  bool isLargeStream = _db.IsLargeStream(item.Size);
+  int bsLog = isLargeStream ? _db.SectorSizeBits : _db.MiniSectorSizeBits;
+  streamSpec->BlockSizeLog = bsLog;
+  streamSpec->Size = item.Size;
+
+  UInt32 clusterSize = (UInt32)1 << bsLog;
+  UInt64 numClusters64 = (item.Size + clusterSize - 1) >> bsLog;
+  if (numClusters64 >= ((UInt32)1 << 31))
+    return E_NOTIMPL;
+  streamSpec->Vector.Reserve((int)numClusters64);
+  UInt32 sid = item.Sid;
+  UInt64 size = item.Size;
+
+  if (size != 0)
+  {
+    for (;; size -= clusterSize)
+    {
+      if (isLargeStream)
+      {
+        if (sid >= _db.FatSize)
+          return S_FALSE;
+        streamSpec->Vector.Add(sid + 1);
+        sid = _db.Fat[sid];
+      }
+      else
+      {
+        UInt64 val;
+        if (sid >= _db.MatSize || !_db.GetMiniCluster(sid, val) || val >= (UInt64)1 << 32)
+          return S_FALSE;
+        streamSpec->Vector.Add((UInt32)val);
+        sid = _db.Mat[sid];
+      }
+      if (size <= clusterSize)
+        break;
+    }
+  }
+  if (sid != NFatID::kEndOfChain)
+    return S_FALSE;
+  RINOK(streamSpec->InitAndSeek());
+  *stream = streamTemp.Detach();
+  return S_OK;
+  COM_TRY_END
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComHandler.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,28 @@
+// ComHandler.h
+
+#ifndef __ARCHIVE_COM_HANDLER_H
+#define __ARCHIVE_COM_HANDLER_H
+
+#include "Common/MyCom.h"
+#include "../IArchive.h"
+#include "ComIn.h"
+
+namespace NArchive {
+namespace NCom {
+
+class CHandler:
+  public IInArchive,
+  public IInArchiveGetStream,
+  public CMyUnknownImp
+{
+  CMyComPtr<IInStream> _stream;
+  CDatabase _db;
+public:
+  MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
+  INTERFACE_IInArchive(;)
+  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
+};
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,389 @@
+// Archive/ComIn.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/Alloc.h"
+#include "../../../../C/CpuArch.h"
+
+#include "Common/IntToString.h"
+#include "Common/MyCom.h"
+
+#include "../../Common/StreamUtils.h"
+
+#include "ComIn.h"
+
+#define Get16(p) GetUi16(p)
+#define Get32(p) GetUi32(p)
+
+namespace NArchive{
+namespace NCom{
+
+static const UInt32 kSignatureSize = 8;
+static const Byte kSignature[kSignatureSize] = { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 };
+
+void CUInt32Buf::Free()
+{
+  MyFree(_buf);
+  _buf = 0;
+}
+
+bool CUInt32Buf::Allocate(UInt32 numItems)
+{
+  Free();
+  if (numItems == 0)
+    return true;
+  size_t newSize = (size_t)numItems * sizeof(UInt32);
+  if (newSize / sizeof(UInt32) != numItems)
+    return false;
+  _buf = (UInt32 *)MyAlloc(newSize);
+  return (_buf != 0);
+}
+
+static HRESULT ReadSector(IInStream *inStream, Byte *buf, int sectorSizeBits, UInt32 sid)
+{
+  RINOK(inStream->Seek((((UInt64)sid + 1) << sectorSizeBits), STREAM_SEEK_SET, NULL));
+  return ReadStream_FALSE(inStream, buf, (UInt32)1 << sectorSizeBits);
+}
+
+static HRESULT ReadIDs(IInStream *inStream, Byte *buf, int sectorSizeBits, UInt32 sid, UInt32 *dest)
+{
+  RINOK(ReadSector(inStream, buf, sectorSizeBits, sid));
+  UInt32 sectorSize = (UInt32)1 << sectorSizeBits;
+  for (UInt32 t = 0; t < sectorSize; t += 4)
+    *dest++ = Get32(buf + t);
+  return S_OK;
+}
+
+static void GetFileTimeFromMem(const Byte *p, FILETIME *ft)
+{
+  ft->dwLowDateTime = Get32(p);
+  ft->dwHighDateTime = Get32(p + 4);
+}
+
+void CItem::Parse(const Byte *p, bool mode64bit)
+{
+  memcpy(Name, p, kNameSizeMax);
+  // NameSize = Get16(p + 64);
+  Type = p[66];
+  LeftDid = Get32(p + 68);
+  RightDid = Get32(p + 72);
+  SonDid = Get32(p + 76);
+  // Flags = Get32(p + 96);
+  GetFileTimeFromMem(p + 100, &CTime);
+  GetFileTimeFromMem(p + 108, &MTime);
+  Sid = Get32(p + 116);
+  Size = Get32(p + 120);
+  if (mode64bit)
+    Size |= ((UInt64)Get32(p + 124) << 32);
+}
+
+void CDatabase::Clear()
+{
+  Fat.Free();
+  MiniSids.Free();
+  Mat.Free();
+  Items.Clear();
+  Refs.Clear();
+}
+
+static const UInt32 kNoDid = 0xFFFFFFFF;
+
+HRESULT CDatabase::AddNode(int parent, UInt32 did)
+{
+  if (did == kNoDid)
+    return S_OK;
+  if (did >= (UInt32)Items.Size())
+    return S_FALSE;
+  const CItem &item = Items[did];
+  if (item.IsEmpty())
+    return S_FALSE;
+  CRef ref;
+  ref.Parent = parent;
+  ref.Did = did;
+  int index = Refs.Add(ref);
+  if (Refs.Size() > Items.Size())
+    return S_FALSE;
+  RINOK(AddNode(parent, item.LeftDid));
+  RINOK(AddNode(parent, item.RightDid));
+  if (item.IsDir())
+  {
+    RINOK(AddNode(index, item.SonDid));
+  }
+  return S_OK;
+}
+
+static const char kCharOpenBracket  = '[';
+static const char kCharCloseBracket = ']';
+
+static UString CompoundNameToFileName(const UString &s)
+{
+  UString res;
+  for (int i = 0; i < s.Length(); i++)
+  {
+    wchar_t c = s[i];
+    if (c < 0x20)
+    {
+      res += kCharOpenBracket;
+      wchar_t buf[32];
+      ConvertUInt32ToString(c, buf);
+      res += buf;
+      res += kCharCloseBracket;
+    }
+    else
+      res += c;
+  }
+  return res;
+}
+
+static char g_MsiChars[] =
+"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._";
+
+static const wchar_t *kMsi_ID = L""; // L"{msi}";
+
+static const int kMsiNumBits = 6;
+static const UInt32 kMsiNumChars = 1 << kMsiNumBits;
+static const UInt32 kMsiCharMask = kMsiNumChars - 1;
+static const UInt32 kMsiStartUnicodeChar = 0x3800;
+static const UInt32 kMsiUnicodeRange = kMsiNumChars * (kMsiNumChars + 1);
+
+bool CompoundMsiNameToFileName(const UString &name, UString &resultName)
+{
+  resultName.Empty();
+  for (int i = 0; i < name.Length(); i++)
+  {
+    wchar_t c =  name[i];
+    if (c < kMsiStartUnicodeChar || c > kMsiStartUnicodeChar + kMsiUnicodeRange)
+      return false;
+    if (i == 0)
+      resultName += kMsi_ID;
+    c -= kMsiStartUnicodeChar;
+    
+    UInt32 c0 = c & kMsiCharMask;
+    UInt32 c1 = c >> kMsiNumBits;
+
+    if (c1 <= kMsiNumChars)
+    {
+      resultName += (wchar_t)g_MsiChars[c0];
+      if (c1 == kMsiNumChars)
+        break;
+      resultName += (wchar_t)g_MsiChars[c1];
+    }
+    else
+      resultName += L'!';
+  }
+  return true;
+}
+
+static UString ConvertName(const Byte *p, bool &isMsi)
+{
+  isMsi = false;
+  UString s;
+  for (int i = 0; i < kNameSizeMax; i += 2)
+  {
+    wchar_t c = (p[i] | (wchar_t)p[i + 1] << 8);
+    if (c == 0)
+      break;
+    s += c;
+  }
+  UString msiName;
+  if (CompoundMsiNameToFileName(s, msiName))
+  {
+    isMsi = true;
+    return msiName;
+  }
+  return CompoundNameToFileName(s);
+}
+
+static UString ConvertName(const Byte *p)
+{
+  bool isMsi;
+  return ConvertName(p, isMsi);
+}
+
+UString CDatabase::GetItemPath(UInt32 index) const
+{
+  UString s;
+  while (index != kNoDid)
+  {
+    const CRef &ref = Refs[index];
+    const CItem &item = Items[ref.Did];
+    if (!s.IsEmpty())
+      s = (UString)WCHAR_PATH_SEPARATOR + s;
+    s = ConvertName(item.Name) + s;
+    index = ref.Parent;
+  }
+  return s;
+}
+
+HRESULT CDatabase::Open(IInStream *inStream)
+{
+  MainSubfile = -1;
+  static const UInt32 kHeaderSize = 512;
+  Byte p[kHeaderSize];
+  RINOK(ReadStream_FALSE(inStream, p, kHeaderSize));
+  if (memcmp(p, kSignature, kSignatureSize) != 0)
+    return S_FALSE;
+  if (Get16(p + 0x1A) > 4) // majorVer
+    return S_FALSE;
+  if (Get16(p + 0x1C) != 0xFFFE)
+    return S_FALSE;
+  int sectorSizeBits = Get16(p + 0x1E);
+  bool mode64bit = (sectorSizeBits >= 12);
+  int miniSectorSizeBits = Get16(p + 0x20);
+  SectorSizeBits = sectorSizeBits;
+  MiniSectorSizeBits = miniSectorSizeBits;
+
+  if (sectorSizeBits > 28 || miniSectorSizeBits > 28 ||
+      sectorSizeBits < 7 || miniSectorSizeBits < 2 || miniSectorSizeBits > sectorSizeBits)
+    return S_FALSE;
+  UInt32 numSectorsForFAT = Get32(p + 0x2C);
+  LongStreamMinSize = Get32(p + 0x38);
+  
+  UInt32 sectSize = (UInt32)1 << (int)sectorSizeBits;
+
+  CByteBuffer sect;
+  sect.SetCapacity(sectSize);
+
+  int ssb2 = (int)(sectorSizeBits - 2);
+  UInt32 numSidsInSec = (UInt32)1 << ssb2;
+  UInt32 numFatItems = numSectorsForFAT << ssb2;
+  if ((numFatItems >> ssb2) != numSectorsForFAT)
+    return S_FALSE;
+  FatSize = numFatItems;
+
+  {
+    CUInt32Buf bat;
+    UInt32 numSectorsForBat = Get32(p + 0x48);
+    const UInt32 kNumHeaderBatItems = 109;
+    UInt32 numBatItems = kNumHeaderBatItems + (numSectorsForBat << ssb2);
+    if (numBatItems < kNumHeaderBatItems || ((numBatItems - kNumHeaderBatItems) >> ssb2) != numSectorsForBat)
+      return S_FALSE;
+    if (!bat.Allocate(numBatItems))
+      return S_FALSE;
+    UInt32 i;
+    for (i = 0; i < kNumHeaderBatItems; i++)
+      bat[i] = Get32(p + 0x4c + i * 4);
+    UInt32 sid = Get32(p + 0x44);
+    for (UInt32 s = 0; s < numSectorsForBat; s++)
+    {
+      RINOK(ReadIDs(inStream, sect, sectorSizeBits, sid, bat + i));
+      i += numSidsInSec - 1;
+      sid = bat[i];
+    }
+    numBatItems = i;
+    
+    if (!Fat.Allocate(numFatItems))
+      return S_FALSE;
+    UInt32 j = 0;
+      
+    for (i = 0; i < numFatItems; j++, i += numSidsInSec)
+    {
+      if (j >= numBatItems)
+        return S_FALSE;
+      RINOK(ReadIDs(inStream, sect, sectorSizeBits, bat[j], Fat + i));
+    }
+  }
+
+  UInt32 numMatItems;
+  {
+    UInt32 numSectorsForMat = Get32(p + 0x40);
+    numMatItems = (UInt32)numSectorsForMat << ssb2;
+    if ((numMatItems >> ssb2) != numSectorsForMat)
+      return S_FALSE;
+    if (!Mat.Allocate(numMatItems))
+      return S_FALSE;
+    UInt32 i;
+    UInt32 sid = Get32(p + 0x3C);
+    for (i = 0; i < numMatItems; i += numSidsInSec)
+    {
+      RINOK(ReadIDs(inStream, sect, sectorSizeBits, sid, Mat + i));
+      if (sid >= numFatItems)
+        return S_FALSE;
+      sid = Fat[sid];
+    }
+    if (sid != NFatID::kEndOfChain)
+      return S_FALSE;
+  }
+
+  {
+    UInt32 sid = Get32(p + 0x30);
+    for (;;)
+    {
+      if (sid >= numFatItems)
+        return S_FALSE;
+      RINOK(ReadSector(inStream, sect, sectorSizeBits, sid));
+      for (UInt32 i = 0; i < sectSize; i += 128)
+      {
+        CItem item;
+        item.Parse(sect + i, mode64bit);
+        Items.Add(item);
+      }
+      sid = Fat[sid];
+      if (sid == NFatID::kEndOfChain)
+        break;
+    }
+  }
+
+  CItem root = Items[0];
+
+  {
+    UInt32 numSectorsInMiniStream;
+    {
+      UInt64 numSatSects64 = (root.Size + sectSize - 1) >> sectorSizeBits;
+      if (numSatSects64 > NFatID::kMaxValue)
+        return S_FALSE;
+      numSectorsInMiniStream = (UInt32)numSatSects64;
+    }
+    NumSectorsInMiniStream = numSectorsInMiniStream;
+    if (!MiniSids.Allocate(numSectorsInMiniStream))
+      return S_FALSE;
+    {
+      UInt64 matSize64 = (root.Size + ((UInt64)1 << miniSectorSizeBits) - 1) >> miniSectorSizeBits;
+      if (matSize64 > NFatID::kMaxValue)
+        return S_FALSE;
+      MatSize = (UInt32)matSize64;
+      if (numMatItems < MatSize)
+        return S_FALSE;
+    }
+
+    UInt32 sid = root.Sid;
+    for (UInt32 i = 0; ; i++)
+    {
+      if (sid == NFatID::kEndOfChain)
+      {
+        if (i != numSectorsInMiniStream)
+          return S_FALSE;
+        break;
+      }
+      if (i >= numSectorsInMiniStream)
+        return S_FALSE;
+      MiniSids[i] = sid;
+      if (sid >= numFatItems)
+        return S_FALSE;
+      sid = Fat[sid];
+    }
+  }
+
+  RINOK(AddNode(-1, root.SonDid));
+  
+  unsigned numCabs = 0;
+  for (int i = 0; i < Refs.Size(); i++)
+  {
+    const CItem &item = Items[Refs[i].Did];
+    if (item.IsDir() || numCabs > 1)
+      continue;
+    bool isMsiName;
+    UString msiName = ConvertName(item.Name, isMsiName);
+    if (isMsiName && msiName.Right(4).CompareNoCase(L".cab") == 0)
+    {
+      numCabs++;
+      MainSubfile = i;
+    }
+  }
+  if (numCabs > 1)
+    MainSubfile = -1;
+
+  return S_OK;
+}
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComIn.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,119 @@
+// Archive/ComIn.h
+
+#ifndef __ARCHIVE_COM_IN_H
+#define __ARCHIVE_COM_IN_H
+
+#include "Common/MyString.h"
+#include "Common/Buffer.h"
+
+namespace NArchive {
+namespace NCom {
+
+struct CUInt32Buf
+{
+  UInt32 *_buf;
+public:
+  CUInt32Buf(): _buf(0) {}
+  ~CUInt32Buf() { Free(); }
+  void Free();
+  bool Allocate(UInt32 numItems);
+  operator UInt32 *() const { return _buf; };
+};
+
+namespace NFatID
+{
+  const UInt32 kFree       = 0xFFFFFFFF;
+  const UInt32 kEndOfChain = 0xFFFFFFFE;
+  const UInt32 kFatSector  = 0xFFFFFFFD;
+  const UInt32 kMatSector  = 0xFFFFFFFC;
+  const UInt32 kMaxValue   = 0xFFFFFFFA;
+}
+
+namespace NItemType
+{
+  const Byte kEmpty = 0;
+  const Byte kStorage = 1;
+  const Byte kStream = 2;
+  const Byte kLockBytes = 3;
+  const Byte kProperty = 4;
+  const Byte kRootStorage = 5;
+}
+
+const UInt32 kNameSizeMax = 64;
+
+struct CItem
+{
+  Byte Name[kNameSizeMax];
+  // UInt16 NameSize;
+  // UInt32 Flags;
+  FILETIME CTime;
+  FILETIME MTime;
+  UInt64 Size;
+  UInt32 LeftDid;
+  UInt32 RightDid;
+  UInt32 SonDid;
+  UInt32 Sid;
+  Byte Type;
+
+  bool IsEmpty() const { return Type == NItemType::kEmpty; }
+  bool IsDir() const { return Type == NItemType::kStorage || Type == NItemType::kRootStorage; }
+
+  void Parse(const Byte *p, bool mode64bit);
+};
+
+struct CRef
+{
+  int Parent;
+  UInt32 Did;
+};
+
+class CDatabase
+{
+  UInt32 NumSectorsInMiniStream;
+  CUInt32Buf MiniSids;
+
+  HRESULT AddNode(int parent, UInt32 did);
+public:
+
+  CUInt32Buf Fat;
+  UInt32 FatSize;
+  
+  CUInt32Buf Mat;
+  UInt32 MatSize;
+
+  CObjectVector<CItem> Items;
+  CRecordVector<CRef> Refs;
+
+  UInt32 LongStreamMinSize;
+  int SectorSizeBits;
+  int MiniSectorSizeBits;
+
+  Int32 MainSubfile;
+
+  void Clear();
+  bool IsLargeStream(UInt64 size) const { return size >= LongStreamMinSize; }
+  UString GetItemPath(UInt32 index) const;
+
+  UInt64 GetItemPackSize(UInt64 size) const
+  {
+    UInt64 mask = ((UInt64)1 << (IsLargeStream(size) ? SectorSizeBits : MiniSectorSizeBits)) - 1;
+    return (size + mask) & ~mask;
+  }
+
+  bool GetMiniCluster(UInt32 sid, UInt64 &res) const
+  {
+    int subBits = SectorSizeBits - MiniSectorSizeBits;
+    UInt32 fid = sid >> subBits;
+    if (fid >= NumSectorsInMiniStream)
+      return false;
+    res = (((UInt64)MiniSids[fid] + 1) << subBits) + (sid & ((1 << subBits) - 1));
+    return true;
+  }
+
+  HRESULT Open(IInStream *inStream);
+};
+
+
+}}
+  
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ComRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,13 @@
+// ComRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/RegisterArc.h"
+
+#include "ComHandler.h"
+static IInArchive *CreateArc() { return new NArchive::NCom::CHandler; }
+
+static CArcInfo g_ArcInfo =
+  { L"Compound", L"msi msp doc xls ppt", 0, 0xE5, { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 }, 8, false, CreateArc, 0 };
+
+REGISTER_ARC(Com)

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,121 @@
+// CoderMixer2.cpp
+
+#include "StdAfx.h"
+
+#include "CoderMixer2.h"
+
+namespace NCoderMixer {
+
+CBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo):
+  _srcBindInfo(srcBindInfo)
+{
+  srcBindInfo.GetNumStreams(NumSrcInStreams, _numSrcOutStreams);
+
+  UInt32  j;
+  for (j = 0; j < NumSrcInStreams; j++)
+  {
+    _srcInToDestOutMap.Add(0);
+    DestOutToSrcInMap.Add(0);
+  }
+  for (j = 0; j < _numSrcOutStreams; j++)
+  {
+    _srcOutToDestInMap.Add(0);
+    _destInToSrcOutMap.Add(0);
+  }
+
+  UInt32 destInOffset = 0;
+  UInt32 destOutOffset = 0;
+  UInt32 srcInOffset = NumSrcInStreams;
+  UInt32 srcOutOffset = _numSrcOutStreams;
+
+  for (int i = srcBindInfo.Coders.Size() - 1; i >= 0; i--)
+  {
+    const CCoderStreamsInfo &srcCoderInfo = srcBindInfo.Coders[i];
+
+    srcInOffset -= srcCoderInfo.NumInStreams;
+    srcOutOffset -= srcCoderInfo.NumOutStreams;
+    
+    UInt32 j;
+    for (j = 0; j < srcCoderInfo.NumInStreams; j++, destOutOffset++)
+    {
+      UInt32 index = srcInOffset + j;
+      _srcInToDestOutMap[index] = destOutOffset;
+      DestOutToSrcInMap[destOutOffset] = index;
+    }
+    for (j = 0; j < srcCoderInfo.NumOutStreams; j++, destInOffset++)
+    {
+      UInt32 index = srcOutOffset + j;
+      _srcOutToDestInMap[index] = destInOffset;
+      _destInToSrcOutMap[destInOffset] = index;
+    }
+  }
+}
+
+void CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo)
+{
+  destBindInfo.Coders.Clear();
+  destBindInfo.BindPairs.Clear();
+  destBindInfo.InStreams.Clear();
+  destBindInfo.OutStreams.Clear();
+
+  int i;
+  for (i = _srcBindInfo.Coders.Size() - 1; i >= 0; i--)
+  {
+    const CCoderStreamsInfo &srcCoderInfo = _srcBindInfo.Coders[i];
+    CCoderStreamsInfo destCoderInfo;
+    destCoderInfo.NumInStreams = srcCoderInfo.NumOutStreams;
+    destCoderInfo.NumOutStreams = srcCoderInfo.NumInStreams;
+    destBindInfo.Coders.Add(destCoderInfo);
+  }
+  for (i = _srcBindInfo.BindPairs.Size() - 1; i >= 0; i--)
+  {
+    const CBindPair &srcBindPair = _srcBindInfo.BindPairs[i];
+    CBindPair destBindPair;
+    destBindPair.InIndex = _srcOutToDestInMap[srcBindPair.OutIndex];
+    destBindPair.OutIndex = _srcInToDestOutMap[srcBindPair.InIndex];
+    destBindInfo.BindPairs.Add(destBindPair);
+  }
+  for (i = 0; i < _srcBindInfo.InStreams.Size(); i++)
+    destBindInfo.OutStreams.Add(_srcInToDestOutMap[_srcBindInfo.InStreams[i]]);
+  for (i = 0; i < _srcBindInfo.OutStreams.Size(); i++)
+    destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]);
+}
+
+CCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams):
+    NumInStreams(numInStreams),
+    NumOutStreams(numOutStreams)
+{
+  InSizes.Reserve(NumInStreams);
+  InSizePointers.Reserve(NumInStreams);
+  OutSizes.Reserve(NumOutStreams);
+  OutSizePointers.Reserve(NumOutStreams);
+}
+
+static void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,
+    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)
+{
+  sizes.Clear();
+  sizePointers.Clear();
+  for(UInt32 i = 0; i < numItems; i++)
+  {
+    if (srcSizes == 0 || srcSizes[i] == NULL)
+    {
+      sizes.Add(0);
+      sizePointers.Add(NULL);
+    }
+    else
+    {
+      sizes.Add(*srcSizes[i]);
+      sizePointers.Add(&sizes.Back());
+    }
+  }
+}
+
+void CCoderInfo2::SetCoderInfo(const UInt64 **inSizes,
+      const UInt64 **outSizes)
+{
+  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);
+  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);
+}
+
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,174 @@
+// CoderMixer2.h
+
+#ifndef __CODER_MIXER2_H
+#define __CODER_MIXER2_H
+
+#include "../../../Common/MyVector.h"
+#include "../../../Common/Types.h"
+#include "../../../Common/MyCom.h"
+#include "../../ICoder.h"
+
+namespace NCoderMixer {
+
+struct CBindPair
+{
+  UInt32 InIndex;
+  UInt32 OutIndex;
+};
+
+struct CCoderStreamsInfo
+{
+  UInt32 NumInStreams;
+  UInt32 NumOutStreams;
+};
+
+struct CBindInfo
+{
+  CRecordVector<CCoderStreamsInfo> Coders;
+  CRecordVector<CBindPair> BindPairs;
+  CRecordVector<UInt32> InStreams;
+  CRecordVector<UInt32> OutStreams;
+
+  void Clear()
+  {
+    Coders.Clear();
+    BindPairs.Clear();
+    InStreams.Clear();
+    OutStreams.Clear();
+  }
+
+  /*
+  UInt32 GetCoderStartOutStream(UInt32 coderIndex) const
+  {
+    UInt32 numOutStreams = 0;
+    for (UInt32 i = 0; i < coderIndex; i++)
+      numOutStreams += Coders[i].NumOutStreams;
+    return numOutStreams;
+  }
+  */
+
+
+  void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const
+  {
+    numInStreams = 0;
+    numOutStreams = 0;
+    for (int i = 0; i < Coders.Size(); i++)
+    {
+      const CCoderStreamsInfo &coderStreamsInfo = Coders[i];
+      numInStreams += coderStreamsInfo.NumInStreams;
+      numOutStreams += coderStreamsInfo.NumOutStreams;
+    }
+  }
+
+  int FindBinderForInStream(UInt32 inStream) const
+  {
+    for (int i = 0; i < BindPairs.Size(); i++)
+      if (BindPairs[i].InIndex == inStream)
+        return i;
+    return -1;
+  }
+  int FindBinderForOutStream(UInt32 outStream) const
+  {
+    for (int i = 0; i < BindPairs.Size(); i++)
+      if (BindPairs[i].OutIndex == outStream)
+        return i;
+    return -1;
+  }
+
+  UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const
+  {
+    UInt32 streamIndex = 0;
+    for (UInt32 i = 0; i < coderIndex; i++)
+      streamIndex += Coders[i].NumInStreams;
+    return streamIndex;
+  }
+
+  UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const
+  {
+    UInt32 streamIndex = 0;
+    for (UInt32 i = 0; i < coderIndex; i++)
+      streamIndex += Coders[i].NumOutStreams;
+    return streamIndex;
+  }
+
+
+  void FindInStream(UInt32 streamIndex, UInt32 &coderIndex,
+      UInt32 &coderStreamIndex) const
+  {
+    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
+    {
+      UInt32 curSize = Coders[coderIndex].NumInStreams;
+      if (streamIndex < curSize)
+      {
+        coderStreamIndex = streamIndex;
+        return;
+      }
+      streamIndex -= curSize;
+    }
+    throw 1;
+  }
+  void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex,
+      UInt32 &coderStreamIndex) const
+  {
+    for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
+    {
+      UInt32 curSize = Coders[coderIndex].NumOutStreams;
+      if (streamIndex < curSize)
+      {
+        coderStreamIndex = streamIndex;
+        return;
+      }
+      streamIndex -= curSize;
+    }
+    throw 1;
+  }
+};
+
+class CBindReverseConverter
+{
+  UInt32 _numSrcOutStreams;
+  NCoderMixer::CBindInfo _srcBindInfo;
+  CRecordVector<UInt32> _srcInToDestOutMap;
+  CRecordVector<UInt32> _srcOutToDestInMap;
+  CRecordVector<UInt32> _destInToSrcOutMap;
+public:
+  UInt32 NumSrcInStreams;
+  CRecordVector<UInt32> DestOutToSrcInMap;
+
+  CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);
+  void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);
+};
+
+struct CCoderInfo2
+{
+  CMyComPtr<ICompressCoder> Coder;
+  CMyComPtr<ICompressCoder2> Coder2;
+  UInt32 NumInStreams;
+  UInt32 NumOutStreams;
+
+  CRecordVector<UInt64> InSizes;
+  CRecordVector<UInt64> OutSizes;
+  CRecordVector<const UInt64 *> InSizePointers;
+  CRecordVector<const UInt64 *> OutSizePointers;
+
+  CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);
+  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
+
+  HRESULT QueryInterface(REFGUID iid, void** pp) const
+  {
+    IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;
+    return p->QueryInterface(iid, pp);
+  }
+};
+
+class CCoderMixer2
+{
+public:
+  virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;
+  virtual void ReInit() = 0;
+  virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;
+};
+
+}
+#endif
+

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,240 @@
+// CoderMixer2MT.cpp
+
+#include "StdAfx.h"
+
+#include "CoderMixer2MT.h"
+
+namespace NCoderMixer {
+
+CCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams):
+    CCoderInfo2(numInStreams, numOutStreams)
+{
+  InStreams.Reserve(NumInStreams);
+  InStreamPointers.Reserve(NumInStreams);
+  OutStreams.Reserve(NumOutStreams);
+  OutStreamPointers.Reserve(NumOutStreams);
+}
+
+void CCoder2::Execute() { Code(NULL); }
+
+void CCoder2::Code(ICompressProgressInfo *progress)
+{
+  InStreamPointers.Clear();
+  OutStreamPointers.Clear();
+  UInt32 i;
+  for (i = 0; i < NumInStreams; i++)
+  {
+    if (InSizePointers[i] != NULL)
+      InSizePointers[i] = &InSizes[i];
+    InStreamPointers.Add((ISequentialInStream *)InStreams[i]);
+  }
+  for (i = 0; i < NumOutStreams; i++)
+  {
+    if (OutSizePointers[i] != NULL)
+      OutSizePointers[i] = &OutSizes[i];
+    OutStreamPointers.Add((ISequentialOutStream *)OutStreams[i]);
+  }
+  if (Coder)
+    Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0],
+        InSizePointers[0], OutSizePointers[0], progress);
+  else
+    Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams,
+      &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress);
+  {
+    int i;
+    for (i = 0; i < InStreams.Size(); i++)
+      InStreams[i].Release();
+    for (i = 0; i < OutStreams.Size(); i++)
+      OutStreams[i].Release();
+  }
+}
+
+static void SetSizes(const UInt64 **srcSizes, CRecordVector<UInt64> &sizes,
+    CRecordVector<const UInt64 *> &sizePointers, UInt32 numItems)
+{
+  sizes.Clear();
+  sizePointers.Clear();
+  for (UInt32 i = 0; i < numItems; i++)
+  {
+    if (srcSizes == 0 || srcSizes[i] == NULL)
+    {
+      sizes.Add(0);
+      sizePointers.Add(NULL);
+    }
+    else
+    {
+      sizes.Add(*srcSizes[i]);
+      sizePointers.Add(&sizes.Back());
+    }
+  }
+}
+
+
+void CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes)
+{
+  SetSizes(inSizes, InSizes, InSizePointers, NumInStreams);
+  SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams);
+}
+
+//////////////////////////////////////
+// CCoderMixer2MT
+
+HRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo)
+{
+  _bindInfo = bindInfo;
+  _streamBinders.Clear();
+  for (int i = 0; i < _bindInfo.BindPairs.Size(); i++)
+  {
+    _streamBinders.Add(CStreamBinder());
+    RINOK(_streamBinders.Back().CreateEvents());
+  }
+  return S_OK;
+}
+
+void CCoderMixer2MT::AddCoderCommon()
+{
+  const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()];
+  CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams);
+  _coders.Add(threadCoderInfo);
+}
+
+void CCoderMixer2MT::AddCoder(ICompressCoder *coder)
+{
+  AddCoderCommon();
+  _coders.Back().Coder = coder;
+}
+
+void CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder)
+{
+  AddCoderCommon();
+  _coders.Back().Coder2 = coder;
+}
+
+
+void CCoderMixer2MT::ReInit()
+{
+  for (int i = 0; i < _streamBinders.Size(); i++)
+    _streamBinders[i].ReInit();
+}
+
+
+HRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams)
+{
+  /*
+  if (_coders.Size() != _bindInfo.Coders.Size())
+    throw 0;
+  */
+  int i;
+  for (i = 0; i < _coders.Size(); i++)
+  {
+    CCoder2 &coderInfo = _coders[i];
+    const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i];
+    coderInfo.InStreams.Clear();
+    UInt32 j;
+    for (j = 0; j < coderStreamsInfo.NumInStreams; j++)
+      coderInfo.InStreams.Add(NULL);
+    coderInfo.OutStreams.Clear();
+    for (j = 0; j < coderStreamsInfo.NumOutStreams; j++)
+      coderInfo.OutStreams.Add(NULL);
+  }
+
+  for (i = 0; i < _bindInfo.BindPairs.Size(); i++)
+  {
+    const CBindPair &bindPair = _bindInfo.BindPairs[i];
+    UInt32 inCoderIndex, inCoderStreamIndex;
+    UInt32 outCoderIndex, outCoderStreamIndex;
+    _bindInfo.FindInStream(bindPair.InIndex, inCoderIndex, inCoderStreamIndex);
+    _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex);
+
+    _streamBinders[i].CreateStreams(
+        &_coders[inCoderIndex].InStreams[inCoderStreamIndex],
+        &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]);
+
+    CMyComPtr<ICompressSetBufSize> inSetSize, outSetSize;
+    _coders[inCoderIndex].QueryInterface(IID_ICompressSetBufSize, (void **)&inSetSize);
+    _coders[outCoderIndex].QueryInterface(IID_ICompressSetBufSize, (void **)&outSetSize);
+    if (inSetSize && outSetSize)
+    {
+      const UInt32 kBufSize = 1 << 19;
+      inSetSize->SetInBufSize(inCoderStreamIndex, kBufSize);
+      outSetSize->SetOutBufSize(outCoderStreamIndex, kBufSize);
+    }
+  }
+
+  for (i = 0; i < _bindInfo.InStreams.Size(); i++)
+  {
+    UInt32 inCoderIndex, inCoderStreamIndex;
+    _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex);
+    _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i];
+  }
+  
+  for (i = 0; i < _bindInfo.OutStreams.Size(); i++)
+  {
+    UInt32 outCoderIndex, outCoderStreamIndex;
+    _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex);
+    _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i];
+  }
+  return S_OK;
+}
+
+HRESULT CCoderMixer2MT::ReturnIfError(HRESULT code)
+{
+  for (int i = 0; i < _coders.Size(); i++)
+    if (_coders[i].Result == code)
+      return code;
+  return S_OK;
+}
+
+STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams,
+      const UInt64 ** /* inSizes */,
+      UInt32 numInStreams,
+      ISequentialOutStream **outStreams,
+      const UInt64 ** /* outSizes */,
+      UInt32 numOutStreams,
+      ICompressProgressInfo *progress)
+{
+  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||
+      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())
+    return E_INVALIDARG;
+
+  Init(inStreams, outStreams);
+
+  int i;
+  for (i = 0; i < _coders.Size(); i++)
+    if (i != _progressCoderIndex)
+    {
+      RINOK(_coders[i].Create());
+    }
+
+  for (i = 0; i < _coders.Size(); i++)
+    if (i != _progressCoderIndex)
+      _coders[i].Start();
+
+  _coders[_progressCoderIndex].Code(progress);
+
+  for (i = 0; i < _coders.Size(); i++)
+    if (i != _progressCoderIndex)
+      _coders[i].WaitFinish();
+
+  RINOK(ReturnIfError(E_ABORT));
+  RINOK(ReturnIfError(E_OUTOFMEMORY));
+
+  for (i = 0; i < _coders.Size(); i++)
+  {
+    HRESULT result = _coders[i].Result;
+    if (result != S_OK && result != E_FAIL && result != S_FALSE)
+      return result;
+  }
+
+  RINOK(ReturnIfError(S_FALSE));
+
+  for (i = 0; i < _coders.Size(); i++)
+  {
+    HRESULT result = _coders[i].Result;
+    if (result != S_OK)
+      return result;
+  }
+  return S_OK;
+}
+
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,80 @@
+// CoderMixer2MT.h
+
+#ifndef __CODER_MIXER2_MT_H
+#define __CODER_MIXER2_MT_H
+
+#include "CoderMixer2.h"
+#include "../../../Common/MyCom.h"
+#include "../../Common/StreamBinder.h"
+#include "../../Common/VirtThread.h"
+
+namespace NCoderMixer {
+
+struct CCoder2: public CCoderInfo2, public CVirtThread
+{
+  HRESULT Result;
+  CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;
+  CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;
+  CRecordVector<ISequentialInStream*> InStreamPointers;
+  CRecordVector<ISequentialOutStream*> OutStreamPointers;
+
+  CCoder2(UInt32 numInStreams, UInt32 numOutStreams);
+  void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
+  virtual void Execute();
+  void Code(ICompressProgressInfo *progress);
+};
+
+
+/*
+  SetBindInfo()
+  for each coder
+    AddCoder[2]()
+  SetProgressIndex(UInt32 coderIndex);
+ 
+  for each file
+  {
+    ReInit()
+    for each coder
+      SetCoderInfo
+    Code
+  }
+*/
+
+class CCoderMixer2MT:
+  public ICompressCoder2,
+  public CCoderMixer2,
+  public CMyUnknownImp
+{
+  CBindInfo _bindInfo;
+  CObjectVector<CStreamBinder> _streamBinders;
+  int _progressCoderIndex;
+
+  void AddCoderCommon();
+  HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams);
+  HRESULT ReturnIfError(HRESULT code);
+public:
+  CObjectVector<CCoder2> _coders;
+  MY_UNKNOWN_IMP
+
+  STDMETHOD(Code)(ISequentialInStream **inStreams,
+      const UInt64 **inSizes,
+      UInt32 numInStreams,
+      ISequentialOutStream **outStreams,
+      const UInt64 **outSizes,
+      UInt32 numOutStreams,
+      ICompressProgressInfo *progress);
+
+  HRESULT SetBindInfo(const CBindInfo &bindInfo);
+  void AddCoder(ICompressCoder *coder);
+  void AddCoder2(ICompressCoder2 *coder);
+  void SetProgressCoderIndex(int coderIndex) {  _progressCoderIndex = coderIndex; }
+
+  void ReInit();
+  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)
+    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }
+  UInt64 GetWriteProcessedSize(UInt32 binderIndex) const
+    {  return _streamBinders[binderIndex].ProcessedSize; }
+};
+
+}
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,239 @@
+// CoderMixer2ST.cpp
+
+#include "StdAfx.h"
+
+#include "CoderMixer2ST.h"
+
+namespace NCoderMixer2 {
+
+CCoderMixer2ST::CCoderMixer2ST() {}
+
+CCoderMixer2ST::~CCoderMixer2ST(){ }
+
+HRESULT CCoderMixer2ST::SetBindInfo(const CBindInfo &bindInfo)
+{
+  _bindInfo = bindInfo;
+  return S_OK;
+}
+
+void CCoderMixer2ST::AddCoderCommon(bool isMain)
+{
+  const CCoderStreamsInfo &csi = _bindInfo.Coders[_coders.Size()];
+  _coders.Add(CSTCoderInfo(csi.NumInStreams, csi.NumOutStreams, isMain));
+}
+
+void CCoderMixer2ST::AddCoder(ICompressCoder *coder, bool isMain)
+{
+  AddCoderCommon(isMain);
+  _coders.Back().Coder = coder;
+}
+
+void CCoderMixer2ST::AddCoder2(ICompressCoder2 *coder, bool isMain)
+{
+  AddCoderCommon(isMain);
+  _coders.Back().Coder2 = coder;
+}
+
+void CCoderMixer2ST::ReInit() { }
+
+HRESULT CCoderMixer2ST::GetInStream(
+    ISequentialInStream **inStreams, const UInt64 **inSizes,
+    UInt32 streamIndex, ISequentialInStream **inStreamRes)
+{
+  CMyComPtr<ISequentialInStream> seqInStream;
+  int i;
+  for(i = 0; i < _bindInfo.InStreams.Size(); i++)
+    if (_bindInfo.InStreams[i] == streamIndex)
+    {
+      seqInStream = inStreams[i];
+      *inStreamRes = seqInStream.Detach();
+      return  S_OK;
+    }
+  int binderIndex = _bindInfo.FindBinderForInStream(streamIndex);
+  if (binderIndex < 0)
+    return E_INVALIDARG;
+
+  UInt32 coderIndex, coderStreamIndex;
+  _bindInfo.FindOutStream(_bindInfo.BindPairs[binderIndex].OutIndex,
+      coderIndex, coderStreamIndex);
+
+  CCoderInfo &coder = _coders[coderIndex];
+  if (!coder.Coder)
+    return E_NOTIMPL;
+  coder.Coder.QueryInterface(IID_ISequentialInStream, &seqInStream);
+  if (!seqInStream)
+    return E_NOTIMPL;
+
+  UInt32 startIndex = _bindInfo.GetCoderInStreamIndex(coderIndex);
+
+  CMyComPtr<ICompressSetInStream> setInStream;
+  if (!coder.Coder)
+    return E_NOTIMPL;
+  coder.Coder.QueryInterface(IID_ICompressSetInStream, &setInStream);
+  if (!setInStream)
+    return E_NOTIMPL;
+
+  if (coder.NumInStreams > 1)
+    return E_NOTIMPL;
+  for (i = 0; i < (int)coder.NumInStreams; i++)
+  {
+    CMyComPtr<ISequentialInStream> seqInStream2;
+    RINOK(GetInStream(inStreams, inSizes, startIndex + i, &seqInStream2));
+    RINOK(setInStream->SetInStream(seqInStream2));
+  }
+  *inStreamRes = seqInStream.Detach();
+  return S_OK;
+}
+
+HRESULT CCoderMixer2ST::GetOutStream(
+    ISequentialOutStream **outStreams, const UInt64 **outSizes,
+    UInt32 streamIndex, ISequentialOutStream **outStreamRes)
+{
+  CMyComPtr<ISequentialOutStream> seqOutStream;
+  int i;
+  for(i = 0; i < _bindInfo.OutStreams.Size(); i++)
+    if (_bindInfo.OutStreams[i] == streamIndex)
+    {
+      seqOutStream = outStreams[i];
+      *outStreamRes = seqOutStream.Detach();
+      return  S_OK;
+    }
+  int binderIndex = _bindInfo.FindBinderForOutStream(streamIndex);
+  if (binderIndex < 0)
+    return E_INVALIDARG;
+
+  UInt32 coderIndex, coderStreamIndex;
+  _bindInfo.FindInStream(_bindInfo.BindPairs[binderIndex].InIndex,
+      coderIndex, coderStreamIndex);
+
+  CCoderInfo &coder = _coders[coderIndex];
+  if (!coder.Coder)
+    return E_NOTIMPL;
+  coder.Coder.QueryInterface(IID_ISequentialOutStream, &seqOutStream);
+  if (!seqOutStream)
+    return E_NOTIMPL;
+
+  UInt32 startIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);
+
+  CMyComPtr<ICompressSetOutStream> setOutStream;
+  if (!coder.Coder)
+    return E_NOTIMPL;
+  coder.Coder.QueryInterface(IID_ICompressSetOutStream, &setOutStream);
+  if (!setOutStream)
+    return E_NOTIMPL;
+
+  if (coder.NumOutStreams > 1)
+    return E_NOTIMPL;
+  for (i = 0; i < (int)coder.NumOutStreams; i++)
+  {
+    CMyComPtr<ISequentialOutStream> seqOutStream2;
+    RINOK(GetOutStream(outStreams, outSizes, startIndex + i, &seqOutStream2));
+    RINOK(setOutStream->SetOutStream(seqOutStream2));
+  }
+  *outStreamRes = seqOutStream.Detach();
+  return S_OK;
+}
+    
+
+STDMETHODIMP CCoderMixer2ST::Code(ISequentialInStream **inStreams,
+      const UInt64 **inSizes,
+      UInt32 numInStreams,
+      ISequentialOutStream **outStreams,
+      const UInt64 **outSizes,
+      UInt32 numOutStreams,
+      ICompressProgressInfo *progress)
+{
+  if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||
+      numOutStreams != (UInt32)_bindInfo.OutStreams.Size())
+    return E_INVALIDARG;
+
+  // Find main coder
+  int _mainCoderIndex = -1;
+  int i;
+  for (i = 0; i < _coders.Size(); i++)
+    if (_coders[i].IsMain)
+    {
+      _mainCoderIndex = i;
+      break;
+    }
+  if (_mainCoderIndex < 0)
+  for (i = 0; i < _coders.Size(); i++)
+    if (_coders[i].NumInStreams > 1)
+    {
+      if (_mainCoderIndex >= 0)
+        return E_NOTIMPL;
+      _mainCoderIndex = i;
+    }
+  if (_mainCoderIndex < 0)
+    _mainCoderIndex = 0;
+ 
+  // _mainCoderIndex = 0;
+  // _mainCoderIndex = _coders.Size() - 1;
+  CCoderInfo &mainCoder = _coders[_mainCoderIndex];
+
+  CObjectVector< CMyComPtr<ISequentialInStream> > seqInStreams;
+  CObjectVector< CMyComPtr<ISequentialOutStream> > seqOutStreams;
+  UInt32 startInIndex = _bindInfo.GetCoderInStreamIndex(_mainCoderIndex);
+  UInt32 startOutIndex = _bindInfo.GetCoderOutStreamIndex(_mainCoderIndex);
+  for (i = 0; i < (int)mainCoder.NumInStreams; i++)
+  {
+    CMyComPtr<ISequentialInStream> seqInStream;
+    RINOK(GetInStream(inStreams, inSizes, startInIndex + i, &seqInStream));
+    seqInStreams.Add(seqInStream);
+  }
+  for (i = 0; i < (int)mainCoder.NumOutStreams; i++)
+  {
+    CMyComPtr<ISequentialOutStream> seqOutStream;
+    RINOK(GetOutStream(outStreams, outSizes, startOutIndex + i, &seqOutStream));
+    seqOutStreams.Add(seqOutStream);
+  }
+  CRecordVector< ISequentialInStream * > seqInStreamsSpec;
+  CRecordVector< ISequentialOutStream * > seqOutStreamsSpec;
+  for (i = 0; i < (int)mainCoder.NumInStreams; i++)
+    seqInStreamsSpec.Add(seqInStreams[i]);
+  for (i = 0; i < (int)mainCoder.NumOutStreams; i++)
+    seqOutStreamsSpec.Add(seqOutStreams[i]);
+
+  for (i = 0; i < _coders.Size(); i++)
+  {
+    if (i == _mainCoderIndex)
+      continue;
+    CCoderInfo &coder = _coders[i];
+    CMyComPtr<ICompressSetOutStreamSize> setOutStreamSize;
+    coder.Coder.QueryInterface(IID_ICompressSetOutStreamSize, &setOutStreamSize);
+    if (setOutStreamSize)
+    {
+      RINOK(setOutStreamSize->SetOutStreamSize(coder.OutSizePointers[0]));
+    }
+  }
+  if (mainCoder.Coder)
+  {
+    RINOK(mainCoder.Coder->Code(
+        seqInStreamsSpec[0], seqOutStreamsSpec[0],
+        mainCoder.InSizePointers[0], mainCoder.OutSizePointers[0],
+        progress));
+  }
+  else
+  {
+    RINOK(mainCoder.Coder2->Code(
+        &seqInStreamsSpec.Front(),
+        &mainCoder.InSizePointers.Front(), mainCoder.NumInStreams,
+        &seqOutStreamsSpec.Front(),
+        &mainCoder.OutSizePointers.Front(), mainCoder.NumOutStreams,
+        progress));
+  }
+  CMyComPtr<IOutStreamFlush> flush;
+  seqOutStreams.Front().QueryInterface(IID_IOutStreamFlush, &flush);
+  if (flush)
+    return flush->Flush();
+  return S_OK;
+}
+
+/*
+UInt64 CCoderMixer2ST::GetWriteProcessedSize(UInt32 binderIndex) const
+{
+  return _streamBinders[binderIndex].ProcessedSize;
+}
+*/
+
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,88 @@
+// CoderMixer2ST.h
+
+#ifndef __CODER_MIXER2_ST_H
+#define __CODER_MIXER2_ST_H
+
+#include "CoderMixer2.h"
+#include "../../../Common/MyCom.h"
+#include "../../ICoder.h"
+
+namespace NCoderMixer2 {
+
+//  SetBindInfo()
+//  for each coder
+//  {
+//    AddCoder[2]()
+//  }
+//
+//  for each file
+//  {
+//    ReInit()
+//    for each coder
+//    {
+//      SetCoderInfo
+//    }
+//    SetProgressIndex(UInt32 coderIndex);
+//    Code
+//  }
+
+struct CSTCoderInfo: public CCoderInfo
+{
+  bool IsMain;
+  CSTCoderInfo(UInt32 numInStreams, UInt32 numOutStreams, bool isMain):
+    CCoderInfo(numInStreams, numOutStreams),IsMain(isMain) {}
+};
+
+class CCoderMixer2ST:
+  public ICompressCoder2,
+  public CCoderMixer2,
+  public CMyUnknownImp
+{
+  MY_UNKNOWN_IMP
+
+  HRESULT GetInStream(
+    ISequentialInStream **inStreams, const UInt64 **inSizes,
+    UInt32 streamIndex, ISequentialInStream **inStreamRes);
+  HRESULT GetOutStream(
+    ISequentialOutStream **outStreams, const UInt64 **outSizes,
+    UInt32 streamIndex, ISequentialOutStream **outStreamRes);
+public:
+  STDMETHOD(Code)(ISequentialInStream **inStreams,
+      const UInt64 **inSizes,
+      UInt32 numInStreams,
+      ISequentialOutStream **outStreams,
+      const UInt64 **outSizes,
+      UInt32 numOutStreams,
+      ICompressProgressInfo *progress);
+
+  CCoderMixer2ST();
+  ~CCoderMixer2ST();
+  void AddCoderCommon(bool isMain);
+  void AddCoder(ICompressCoder *coder, bool isMain);
+  void AddCoder2(ICompressCoder2 *coder, bool isMain);
+
+  void ReInit();
+  void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)
+  {
+    {  _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }
+  }
+
+  void SetProgressCoderIndex(UInt32 /*coderIndex*/)
+  {
+    // _progressCoderIndex = coderIndex;
+  }
+
+  // UInt64 GetWriteProcessedSize(UInt32 binderIndex) const;
+
+private:
+  CBindInfo _bindInfo;
+  CObjectVector<CSTCoderInfo> _coders;
+  int _mainCoderIndex;
+public:
+  HRESULT SetBindInfo(const CBindInfo &bindInfo);
+
+};
+
+}
+#endif
+

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,15 @@
+// CrossThreadProgress.cpp
+
+#include "StdAfx.h"
+
+#include "CrossThreadProgress.h"
+
+STDMETHODIMP CCrossThreadProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
+{
+  InSize = inSize;
+  OutSize = outSize;
+  ProgressEvent.Set();
+  WaitEvent.Lock();
+  return Result;
+}
+

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,37 @@
+// CrossThreadProgress.h
+
+#ifndef __CROSSTHREADPROGRESS_H
+#define __CROSSTHREADPROGRESS_H
+
+#include "../../ICoder.h"
+#include "../../../Windows/Synchronization.h"
+#include "../../../Common/MyCom.h"
+
+class CCrossThreadProgress:
+  public ICompressProgressInfo,
+  public CMyUnknownImp
+{
+public:
+  const UInt64 *InSize;
+  const UInt64 *OutSize;
+  HRESULT Result;
+  NWindows::NSynchronization::CAutoResetEvent ProgressEvent;
+  NWindows::NSynchronization::CAutoResetEvent WaitEvent;
+
+  HRes Create()
+  {
+    RINOK(ProgressEvent.CreateIfNotCreated());
+    return WaitEvent.CreateIfNotCreated();
+  }
+  void Init()
+  {
+    ProgressEvent.Reset();
+    WaitEvent.Reset();
+  }
+
+  MY_UNKNOWN_IMP
+
+  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
+};
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,22 @@
+// DummyOutStream.cpp
+
+#include "StdAfx.h"
+
+#include "DummyOutStream.h"
+
+STDMETHODIMP CDummyOutStream::Write(const void *data,  UInt32 size, UInt32 *processedSize)
+{
+  UInt32 realProcessedSize;
+  HRESULT result;
+  if(!_stream)
+  {
+    realProcessedSize = size;
+    result = S_OK;
+  }
+  else
+    result = _stream->Write(data, size, &realProcessedSize);
+  _size += realProcessedSize;
+  if(processedSize != NULL)
+    *processedSize = realProcessedSize;
+  return result;
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/DummyOutStream.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,24 @@
+// DummyOutStream.h
+
+#ifndef __DUMMYOUTSTREAM_H
+#define __DUMMYOUTSTREAM_H
+
+#include "../../IStream.h"
+#include "Common/MyCom.h"
+
+class CDummyOutStream:
+  public ISequentialOutStream,
+  public CMyUnknownImp
+{
+  CMyComPtr<ISequentialOutStream> _stream;
+  UInt64 _size;
+public:
+  void SetStream(ISequentialOutStream *outStream) { _stream = outStream; }
+  void ReleaseStream() { _stream.Release(); }
+  void Init() { _size = 0; }
+  MY_UNKNOWN_IMP
+  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+  UInt64 GetSize() const { return _size; }
+};
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,62 @@
+// FindSignature.cpp
+
+#include "StdAfx.h"
+
+#include "Common/Buffer.h"
+
+#include "FindSignature.h"
+
+#include "../../Common/StreamUtils.h"
+
+HRESULT FindSignatureInStream(ISequentialInStream *stream,
+    const Byte *signature, unsigned signatureSize,
+    const UInt64 *limit, UInt64 &resPos)
+{
+  resPos = 0;
+  CByteBuffer byteBuffer2;
+  byteBuffer2.SetCapacity(signatureSize);
+  RINOK(ReadStream_FALSE(stream, byteBuffer2, signatureSize));
+
+  if (memcmp(byteBuffer2, signature, signatureSize) == 0)
+    return S_OK;
+
+  const UInt32 kBufferSize = (1 << 16);
+  CByteBuffer byteBuffer;
+  byteBuffer.SetCapacity(kBufferSize);
+  Byte *buffer = byteBuffer;
+  UInt32 numPrevBytes = signatureSize - 1;
+  memcpy(buffer, (const Byte *)byteBuffer2 + 1, numPrevBytes);
+  resPos = 1;
+  for (;;)
+  {
+    if (limit != NULL)
+      if (resPos > *limit)
+        return S_FALSE;
+    do
+    {
+      UInt32 numReadBytes = kBufferSize - numPrevBytes;
+      UInt32 processedSize;
+      RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
+      numPrevBytes += processedSize;
+      if (processedSize == 0)
+        return S_FALSE;
+    }
+    while (numPrevBytes < signatureSize);
+    UInt32 numTests = numPrevBytes - signatureSize + 1;
+    for (UInt32 pos = 0; pos < numTests; pos++)
+    {
+      Byte b = signature[0];
+      for (; buffer[pos] != b && pos < numTests; pos++);
+      if (pos == numTests)
+        break;
+      if (memcmp(buffer + pos, signature, signatureSize) == 0)
+      {
+        resPos += pos;
+        return S_OK;
+      }
+    }
+    resPos += numTests;
+    numPrevBytes -= numTests;
+    memmove(buffer, buffer + numTests, numPrevBytes);
+  }
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/FindSignature.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,12 @@
+// FindSignature.h
+
+#ifndef __FINDSIGNATURE_H
+#define __FINDSIGNATURE_H
+
+#include "../../IStream.h"
+
+HRESULT FindSignatureInStream(ISequentialInStream *stream,
+    const Byte *signature, unsigned signatureSize,
+    const UInt64 *limit, UInt64 &resPos);
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,623 @@
+// HandlerOut.cpp
+
+#include "StdAfx.h"
+
+#include "../../../Common/StringToInt.h"
+
+#include "../../../Windows/PropVariant.h"
+
+#ifndef _7ZIP_ST
+#include "../../../Windows/System.h"
+#endif
+
+#include "../../ICoder.h"
+
+#include "../Common/ParseProperties.h"
+
+#include "HandlerOut.h"
+
+using namespace NWindows;
+
+namespace NArchive {
+
+static const wchar_t *kCopyMethod = L"Copy";
+static const wchar_t *kLZMAMethodName = L"LZMA";
+static const wchar_t *kLZMA2MethodName = L"LZMA2";
+static const wchar_t *kBZip2MethodName = L"BZip2";
+static const wchar_t *kPpmdMethodName = L"PPMd";
+static const wchar_t *kDeflateMethodName = L"Deflate";
+static const wchar_t *kDeflate64MethodName = L"Deflate64";
+
+static const wchar_t *kLzmaMatchFinderX1 = L"HC4";
+static const wchar_t *kLzmaMatchFinderX5 = L"BT4";
+
+static const UInt32 kLzmaAlgoX1 = 0;
+static const UInt32 kLzmaAlgoX5 = 1;
+
+static const UInt32 kLzmaDicSizeX1 = 1 << 16;
+static const UInt32 kLzmaDicSizeX3 = 1 << 20;
+static const UInt32 kLzmaDicSizeX5 = 1 << 24;
+static const UInt32 kLzmaDicSizeX7 = 1 << 25;
+static const UInt32 kLzmaDicSizeX9 = 1 << 26;
+
+static const UInt32 kLzmaFastBytesX1 = 32;
+static const UInt32 kLzmaFastBytesX7 = 64;
+
+static const UInt32 kPpmdMemSizeX1 = (1 << 22);
+static const UInt32 kPpmdMemSizeX5 = (1 << 24);
+static const UInt32 kPpmdMemSizeX7 = (1 << 26);
+static const UInt32 kPpmdMemSizeX9 = (192 << 20);
+
+static const UInt32 kPpmdOrderX1 = 4;
+static const UInt32 kPpmdOrderX5 = 6;
+static const UInt32 kPpmdOrderX7 = 16;
+static const UInt32 kPpmdOrderX9 = 32;
+
+static const UInt32 kDeflateAlgoX1 = 0;
+static const UInt32 kDeflateAlgoX5 = 1;
+
+static const UInt32 kDeflateFastBytesX1 = 32;
+static const UInt32 kDeflateFastBytesX7 = 64;
+static const UInt32 kDeflateFastBytesX9 = 128;
+
+static const UInt32 kDeflatePassesX1 = 1;
+static const UInt32 kDeflatePassesX7 = 3;
+static const UInt32 kDeflatePassesX9 = 10;
+
+static const UInt32 kBZip2NumPassesX1 = 1;
+static const UInt32 kBZip2NumPassesX7 = 2;
+static const UInt32 kBZip2NumPassesX9 = 7;
+
+static const UInt32 kBZip2DicSizeX1 = 100000;
+static const UInt32 kBZip2DicSizeX3 = 500000;
+static const UInt32 kBZip2DicSizeX5 = 900000;
+
+static const wchar_t *kDefaultMethodName = kLZMAMethodName;
+
+static const wchar_t *kLzmaMatchFinderForHeaders = L"BT2";
+static const UInt32 kDictionaryForHeaders = 1 << 20;
+static const UInt32 kNumFastBytesForHeaders = 273;
+static const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5;
+
+static bool AreEqual(const UString &methodName, const wchar_t *s)
+  { return (methodName.CompareNoCase(s) == 0); }
+
+bool COneMethodInfo::IsLzma() const
+{
+  return
+    AreEqual(MethodName, kLZMAMethodName) ||
+    AreEqual(MethodName, kLZMA2MethodName);
+}
+
+static inline bool IsBZip2Method(const UString &methodName)
+  { return AreEqual(methodName, kBZip2MethodName); }
+
+static inline bool IsPpmdMethod(const UString &methodName)
+  { return AreEqual(methodName, kPpmdMethodName); }
+
+static inline bool IsDeflateMethod(const UString &methodName)
+{
+  return
+    AreEqual(methodName, kDeflateMethodName) ||
+    AreEqual(methodName, kDeflate64MethodName);
+}
+
+struct CNameToPropID
+{
+  PROPID PropID;
+  VARTYPE VarType;
+  const wchar_t *Name;
+};
+
+static CNameToPropID g_NameToPropID[] =
+{
+  { NCoderPropID::kBlockSize, VT_UI4, L"C" },
+  { NCoderPropID::kDictionarySize, VT_UI4, L"D" },
+  { NCoderPropID::kUsedMemorySize, VT_UI4, L"MEM" },
+
+  { NCoderPropID::kOrder, VT_UI4, L"O" },
+  { NCoderPropID::kPosStateBits, VT_UI4, L"PB" },
+  { NCoderPropID::kLitContextBits, VT_UI4, L"LC" },
+  { NCoderPropID::kLitPosBits, VT_UI4, L"LP" },
+  { NCoderPropID::kEndMarker, VT_BOOL, L"eos" },
+
+  { NCoderPropID::kNumPasses, VT_UI4, L"Pass" },
+  { NCoderPropID::kNumFastBytes, VT_UI4, L"fb" },
+  { NCoderPropID::kMatchFinderCycles, VT_UI4, L"mc" },
+  { NCoderPropID::kAlgorithm, VT_UI4, L"a" },
+  { NCoderPropID::kMatchFinder, VT_BSTR, L"mf" },
+  { NCoderPropID::kNumThreads, VT_UI4, L"mt" },
+  { NCoderPropID::kDefaultProp, VT_UI4, L"" }
+};
+
+static bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp)
+{
+  if (varType == srcProp.vt)
+  {
+    destProp = srcProp;
+    return true;
+  }
+  if (varType == VT_UI1)
+  {
+    if (srcProp.vt == VT_UI4)
+    {
+      UInt32 value = srcProp.ulVal;
+      if (value > 0xFF)
+        return false;
+      destProp = (Byte)value;
+      return true;
+    }
+  }
+  else if (varType == VT_BOOL)
+  {
+    bool res;
+    if (SetBoolProperty(res, srcProp) != S_OK)
+      return false;
+    destProp = res;
+    return true;
+  }
+  return false;
+}
+    
+static int FindPropIdExact(const UString &name)
+{
+  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)
+    if (name.CompareNoCase(g_NameToPropID[i].Name) == 0)
+      return i;
+  return -1;
+}
+
+static int FindPropIdStart(const UString &name)
+{
+  for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++)
+  {
+    UString t = g_NameToPropID[i].Name;
+    if (t.CompareNoCase(name.Left(t.Length())) == 0)
+      return i;
+  }
+  return -1;
+}
+
+static void SetMethodProp(COneMethodInfo &m, PROPID propID, const NCOM::CPropVariant &value)
+{
+  for (int j = 0; j < m.Props.Size(); j++)
+    if (m.Props[j].Id == propID)
+      return;
+  CProp prop;
+  prop.Id = propID;
+  prop.Value = value;
+  m.Props.Add(prop);
+}
+
+void COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo
+    #ifndef _7ZIP_ST
+    , UInt32 numThreads
+    #endif
+    )
+{
+  UInt32 level = _level;
+  if (oneMethodInfo.MethodName.IsEmpty())
+    oneMethodInfo.MethodName = kDefaultMethodName;
+  
+  if (oneMethodInfo.IsLzma())
+  {
+    UInt32 dicSize =
+      (level >= 9 ? kLzmaDicSizeX9 :
+      (level >= 7 ? kLzmaDicSizeX7 :
+      (level >= 5 ? kLzmaDicSizeX5 :
+      (level >= 3 ? kLzmaDicSizeX3 :
+                    kLzmaDicSizeX1))));
+    
+    UInt32 algo =
+      (level >= 5 ? kLzmaAlgoX5 :
+                    kLzmaAlgoX1);
+    
+    UInt32 fastBytes =
+      (level >= 7 ? kLzmaFastBytesX7 :
+                    kLzmaFastBytesX1);
+    
+    const wchar_t *matchFinder =
+      (level >= 5 ? kLzmaMatchFinderX5 :
+                    kLzmaMatchFinderX1);
+    
+    SetMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);
+    SetMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);
+    SetMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);
+    SetMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder);
+    #ifndef _7ZIP_ST
+    SetMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);
+    #endif
+  }
+  else if (IsDeflateMethod(oneMethodInfo.MethodName))
+  {
+    UInt32 fastBytes =
+      (level >= 9 ? kDeflateFastBytesX9 :
+      (level >= 7 ? kDeflateFastBytesX7 :
+                    kDeflateFastBytesX1));
+    
+    UInt32 numPasses =
+      (level >= 9 ? kDeflatePassesX9 :
+      (level >= 7 ? kDeflatePassesX7 :
+                    kDeflatePassesX1));
+    
+    UInt32 algo =
+      (level >= 5 ? kDeflateAlgoX5 :
+                    kDeflateAlgoX1);
+    
+    SetMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo);
+    SetMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes);
+    SetMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);
+  }
+  else if (IsBZip2Method(oneMethodInfo.MethodName))
+  {
+    UInt32 numPasses =
+      (level >= 9 ? kBZip2NumPassesX9 :
+      (level >= 7 ? kBZip2NumPassesX7 :
+                    kBZip2NumPassesX1));
+    
+    UInt32 dicSize =
+      (level >= 5 ? kBZip2DicSizeX5 :
+      (level >= 3 ? kBZip2DicSizeX3 :
+                    kBZip2DicSizeX1));
+    
+    SetMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses);
+    SetMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize);
+    #ifndef _7ZIP_ST
+    SetMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads);
+    #endif
+  }
+  else if (IsPpmdMethod(oneMethodInfo.MethodName))
+  {
+    UInt32 useMemSize =
+      (level >= 9 ? kPpmdMemSizeX9 :
+      (level >= 7 ? kPpmdMemSizeX7 :
+      (level >= 5 ? kPpmdMemSizeX5 :
+                    kPpmdMemSizeX1)));
+    
+    UInt32 order =
+      (level >= 9 ? kPpmdOrderX9 :
+      (level >= 7 ? kPpmdOrderX7 :
+      (level >= 5 ? kPpmdOrderX5 :
+                    kPpmdOrderX1)));
+    
+    SetMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize);
+    SetMethodProp(oneMethodInfo, NCoderPropID::kOrder, order);
+  }
+}
+
+static void SplitParams(const UString &srcString, UStringVector &subStrings)
+{
+  subStrings.Clear();
+  UString name;
+  int len = srcString.Length();
+  if (len == 0)
+    return;
+  for (int i = 0; i < len; i++)
+  {
+    wchar_t c = srcString[i];
+    if (c == L':')
+    {
+      subStrings.Add(name);
+      name.Empty();
+    }
+    else
+      name += c;
+  }
+  subStrings.Add(name);
+}
+
+static void SplitParam(const UString &param, UString &name, UString &value)
+{
+  int eqPos = param.Find(L'=');
+  if (eqPos >= 0)
+  {
+    name = param.Left(eqPos);
+    value = param.Mid(eqPos + 1);
+    return;
+  }
+  for(int i = 0; i < param.Length(); i++)
+  {
+    wchar_t c = param[i];
+    if (c >= L'0' && c <= L'9')
+    {
+      name = param.Left(i);
+      value = param.Mid(i);
+      return;
+    }
+  }
+  name = param;
+}
+
+HRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value)
+{
+  CProp prop;
+  int index = FindPropIdExact(name);
+  if (index < 0)
+    return E_INVALIDARG;
+  const CNameToPropID &nameToPropID = g_NameToPropID[index];
+  prop.Id = nameToPropID.PropID;
+
+  if (prop.Id == NCoderPropID::kBlockSize ||
+      prop.Id == NCoderPropID::kDictionarySize ||
+      prop.Id == NCoderPropID::kUsedMemorySize)
+  {
+    UInt32 dicSize;
+    RINOK(ParsePropDictionaryValue(value, dicSize));
+    prop.Value = dicSize;
+  }
+  else
+  {
+    NCOM::CPropVariant propValue;
+    
+    if (nameToPropID.VarType == VT_BSTR)
+      propValue = value;
+    else if (nameToPropID.VarType == VT_BOOL)
+    {
+      bool res;
+      if (!StringToBool(value, res))
+        return E_INVALIDARG;
+      propValue = res;
+    }
+    else
+    {
+      UInt32 number;
+      if (ParseStringToUInt32(value, number) == value.Length())
+        propValue = number;
+      else
+        propValue = value;
+    }
+    
+    if (!ConvertProperty(propValue, nameToPropID.VarType, prop.Value))
+      return E_INVALIDARG;
+  }
+  oneMethodInfo.Props.Add(prop);
+  return S_OK;
+}
+
+HRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString)
+{
+  UStringVector params;
+  SplitParams(srcString, params);
+  if (params.Size() > 0)
+    oneMethodInfo.MethodName = params[0];
+  for (int i = 1; i < params.Size(); i++)
+  {
+    const UString &param = params[i];
+    UString name, value;
+    SplitParam(param, name, value);
+    RINOK(SetParam(oneMethodInfo, name, value));
+  }
+  return S_OK;
+}
+
+HRESULT COutHandler::SetSolidSettings(const UString &s)
+{
+  UString s2 = s;
+  s2.MakeUpper();
+  for (int i = 0; i < s2.Length();)
+  {
+    const wchar_t *start = ((const wchar_t *)s2) + i;
+    const wchar_t *end;
+    UInt64 v = ConvertStringToUInt64(start, &end);
+    if (start == end)
+    {
+      if (s2[i++] != 'E')
+        return E_INVALIDARG;
+      _solidExtension = true;
+      continue;
+    }
+    i += (int)(end - start);
+    if (i == s2.Length())
+      return E_INVALIDARG;
+    wchar_t c = s2[i++];
+    switch(c)
+    {
+      case 'F':
+        if (v < 1)
+          v = 1;
+        _numSolidFiles = v;
+        break;
+      case 'B':
+        _numSolidBytes = v;
+        _numSolidBytesDefined = true;
+        break;
+      case 'K':
+        _numSolidBytes = (v << 10);
+        _numSolidBytesDefined = true;
+        break;
+      case 'M':
+        _numSolidBytes = (v << 20);
+        _numSolidBytesDefined = true;
+        break;
+      case 'G':
+        _numSolidBytes = (v << 30);
+        _numSolidBytesDefined = true;
+        break;
+      default:
+        return E_INVALIDARG;
+    }
+  }
+  return S_OK;
+}
+
+HRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value)
+{
+  bool isSolid;
+  switch(value.vt)
+  {
+    case VT_EMPTY:
+      isSolid = true;
+      break;
+    case VT_BOOL:
+      isSolid = (value.boolVal != VARIANT_FALSE);
+      break;
+    case VT_BSTR:
+      if (StringToBool(value.bstrVal, isSolid))
+        break;
+      return SetSolidSettings(value.bstrVal);
+    default:
+      return E_INVALIDARG;
+  }
+  if (isSolid)
+    InitSolid();
+  else
+    _numSolidFiles = 1;
+  return S_OK;
+}
+
+void COutHandler::Init()
+{
+  _removeSfxBlock = false;
+  _compressHeaders = true;
+  _encryptHeadersSpecified = false;
+  _encryptHeaders = false;
+  
+  WriteCTime = false;
+  WriteATime = false;
+  WriteMTime = true;
+  
+  #ifndef _7ZIP_ST
+  _numThreads = NSystem::GetNumberOfProcessors();
+  #endif
+  
+  _level = 5;
+  _autoFilter = true;
+  _volumeMode = false;
+  _crcSize = 4;
+  InitSolid();
+}
+
+void COutHandler::BeforeSetProperty()
+{
+  Init();
+  #ifndef _7ZIP_ST
+  numProcessors = NSystem::GetNumberOfProcessors();
+  #endif
+
+  mainDicSize = 0xFFFFFFFF;
+  mainDicMethodIndex = 0xFFFFFFFF;
+  minNumber = 0;
+  _crcSize = 4;
+}
+
+HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)
+{
+  UString name = nameSpec;
+  name.MakeUpper();
+  if (name.IsEmpty())
+    return E_INVALIDARG;
+  
+  if (name[0] == 'X')
+  {
+    name.Delete(0);
+    _level = 9;
+    return ParsePropValue(name, value, _level);
+  }
+  
+  if (name[0] == L'S')
+  {
+    name.Delete(0);
+    if (name.IsEmpty())
+      return SetSolidSettings(value);
+    if (value.vt != VT_EMPTY)
+      return E_INVALIDARG;
+    return SetSolidSettings(name);
+  }
+  
+  if (name == L"CRC")
+  {
+    _crcSize = 4;
+    name.Delete(0, 3);
+    return ParsePropValue(name, value, _crcSize);
+  }
+  
+  UInt32 number;
+  int index = ParseStringToUInt32(name, number);
+  UString realName = name.Mid(index);
+  if (index == 0)
+  {
+    if(name.Left(2).CompareNoCase(L"MT") == 0)
+    {
+      #ifndef _7ZIP_ST
+      RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads));
+      #endif
+      return S_OK;
+    }
+    if (name.CompareNoCase(L"RSFX") == 0)  return SetBoolProperty(_removeSfxBlock, value);
+    if (name.CompareNoCase(L"F") == 0) return SetBoolProperty(_autoFilter, value);
+    if (name.CompareNoCase(L"HC") == 0) return SetBoolProperty(_compressHeaders, value);
+    if (name.CompareNoCase(L"HCF") == 0)
+    {
+      bool compressHeadersFull = true;
+      RINOK(SetBoolProperty(compressHeadersFull, value));
+      if (!compressHeadersFull)
+        return E_INVALIDARG;
+      return S_OK;
+    }
+    if (name.CompareNoCase(L"HE") == 0)
+    {
+      RINOK(SetBoolProperty(_encryptHeaders, value));
+      _encryptHeadersSpecified = true;
+      return S_OK;
+    }
+    if (name.CompareNoCase(L"TC") == 0) return SetBoolProperty(WriteCTime, value);
+    if (name.CompareNoCase(L"TA") == 0) return SetBoolProperty(WriteATime, value);
+    if (name.CompareNoCase(L"TM") == 0) return SetBoolProperty(WriteMTime, value);
+    if (name.CompareNoCase(L"V") == 0) return SetBoolProperty(_volumeMode, value);
+    number = 0;
+  }
+  if (number > 10000)
+    return E_FAIL;
+  if (number < minNumber)
+    return E_INVALIDARG;
+  number -= minNumber;
+  for(int j = _methods.Size(); j <= (int)number; j++)
+  {
+    COneMethodInfo oneMethodInfo;
+    _methods.Add(oneMethodInfo);
+  }
+  
+  COneMethodInfo &oneMethodInfo = _methods[number];
+  
+  if (realName.Length() == 0)
+  {
+    if (value.vt != VT_BSTR)
+      return E_INVALIDARG;
+    
+    RINOK(SetParams(oneMethodInfo, value.bstrVal));
+  }
+  else
+  {
+    int index = FindPropIdStart(realName);
+    if (index < 0)
+      return E_INVALIDARG;
+    const CNameToPropID &nameToPropID = g_NameToPropID[index];
+    CProp prop;
+    prop.Id = nameToPropID.PropID;
+
+    if (prop.Id == NCoderPropID::kBlockSize ||
+        prop.Id == NCoderPropID::kDictionarySize ||
+        prop.Id == NCoderPropID::kUsedMemorySize)
+    {
+      UInt32 dicSize;
+      RINOK(ParsePropDictionaryValue(realName.Mid(MyStringLen(nameToPropID.Name)), value, dicSize));
+      prop.Value = dicSize;
+      if (number <= mainDicMethodIndex)
+        mainDicSize = dicSize;
+    }
+    else
+    {
+      int index = FindPropIdExact(realName);
+      if (index < 0)
+        return E_INVALIDARG;
+      const CNameToPropID &nameToPropID = g_NameToPropID[index];
+      prop.Id = nameToPropID.PropID;
+      if (!ConvertProperty(value, nameToPropID.VarType, prop.Value))
+        return E_INVALIDARG;
+    }
+    oneMethodInfo.Props.Add(prop);
+  }
+  return S_OK;
+}
+
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/HandlerOut.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,87 @@
+// HandlerOut.h
+
+#ifndef __HANDLER_OUT_H
+#define __HANDLER_OUT_H
+
+#include "../../../Common/MyString.h"
+#include "../../Common/MethodProps.h"
+
+namespace NArchive {
+
+struct COneMethodInfo
+{
+  CObjectVector<CProp> Props;
+  UString MethodName;
+
+  bool IsLzma() const;
+};
+
+class COutHandler
+{
+public:
+  HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);
+  
+  HRESULT SetSolidSettings(const UString &s);
+  HRESULT SetSolidSettings(const PROPVARIANT &value);
+
+  #ifndef _7ZIP_ST
+  UInt32 _numThreads;
+  #endif
+
+  UInt32 _crcSize;
+
+  CObjectVector<COneMethodInfo> _methods;
+  bool _removeSfxBlock;
+  
+  UInt64 _numSolidFiles;
+  UInt64 _numSolidBytes;
+  bool _numSolidBytesDefined;
+  bool _solidExtension;
+
+  bool _compressHeaders;
+  bool _encryptHeadersSpecified;
+  bool _encryptHeaders;
+
+  bool WriteCTime;
+  bool WriteATime;
+  bool WriteMTime;
+
+  bool _autoFilter;
+  UInt32 _level;
+
+  bool _volumeMode;
+
+  HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value);
+  HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString);
+
+  void SetCompressionMethod2(COneMethodInfo &oneMethodInfo
+      #ifndef _7ZIP_ST
+      , UInt32 numThreads
+      #endif
+      );
+
+  void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }
+  void InitSolidSize()  { _numSolidBytes = (UInt64)(Int64)(-1); }
+  void InitSolid()
+  {
+    InitSolidFiles();
+    InitSolidSize();
+    _solidExtension = false;
+    _numSolidBytesDefined = false;
+  }
+
+  void Init();
+
+  COutHandler() { Init(); }
+
+  void BeforeSetProperty();
+
+  UInt32 minNumber;
+  UInt32 numProcessors;
+  UInt32 mainDicSize;
+  UInt32 mainDicMethodIndex;
+};
+
+}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,42 @@
+// InStreamWithCRC.cpp
+
+#include "StdAfx.h"
+
+#include "InStreamWithCRC.h"
+
+STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+  UInt32 realProcessedSize;
+  HRESULT result = _stream->Read(data, size, &realProcessedSize);
+  _size += realProcessedSize;
+  if (size > 0 && realProcessedSize == 0)
+    _wasFinished = true;
+  _crc = CrcUpdate(_crc, data, realProcessedSize);
+  if(processedSize != NULL)
+    *processedSize = realProcessedSize;
+  return result;
+}
+
+STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+  UInt32 realProcessedSize;
+  HRESULT result = _stream->Read(data, size, &realProcessedSize);
+  /*
+  if (size > 0 && realProcessedSize == 0)
+    _wasFinished = true;
+  */
+  _size += realProcessedSize;
+  _crc = CrcUpdate(_crc, data, realProcessedSize);
+  if(processedSize != NULL)
+    *processedSize = realProcessedSize;
+  return result;
+}
+
+STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
+{
+  if (seekOrigin != STREAM_SEEK_SET || offset != 0)
+    return E_FAIL;
+  _size = 0;
+  _crc = CRC_INIT_VAL;
+  return _stream->Seek(offset, seekOrigin, newPosition);
+}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/InStreamWithCRC.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,67 @@
+// InStreamWithCRC.h
+
+#ifndef __IN_STREAM_WITH_CRC_H
+#define __IN_STREAM_WITH_CRC_H
+
+#include "../../../../C/7zCrc.h"
+
+#include "../../../Common/MyCom.h"
+
+#include "../../IStream.h"
+
+class CSequentialInStreamWithCRC:
+  public ISequentialInStream,
+  public CMyUnknownImp
+{
+public:
+  MY_UNKNOWN_IMP
+
+  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+private:
+  CMyComPtr<ISequentialInStream> _stream;
+  UInt64 _size;
+  UInt32 _crc;
+  bool _wasFinished;
+public:
+  void SetStream(ISequentialInStream *stream) { _stream = stream;  }
+  void Init()
+  {
+    _size = 0;
+    _wasFinished = false;
+    _crc = CRC_INIT_VAL;
+  }
+  void ReleaseStream() { _stream.Release(); }
+  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
+  UInt64 GetSize() const { return _size; }
+  bool WasFinished() const { return _wasFinished; }
+};
+
+class CInStreamWithCRC:
+  public IInStream,
+  public CMyUnknownImp
+{
+public:
+  MY_UNKNOWN_IMP1(IInStream)
+
+  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
+private:
+  CMyComPtr<IInStream> _stream;
+  UInt64 _size;
+  UInt32 _crc;
+  // bool _wasFinished;
+public:
+  void SetStream(IInStream *stream) { _stream = stream;  }
+  void Init()
+  {
+    _size = 0;
+    // _wasFinished = false;
+    _crc = CRC_INIT_VAL;
+  }
+  void ReleaseStream() { _stream.Release(); }
+  UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
+  UInt64 GetSize() const { return _size; }
+  // bool WasFinished() const { return _wasFinished; }
+};
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,61 @@
+// Archive/Common/ItemNameUtils.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/Types.h"
+
+#include "ItemNameUtils.h"
+
+namespace NArchive {
+namespace NItemName {
+
+static const wchar_t kOSDirDelimiter = WCHAR_PATH_SEPARATOR;
+static const wchar_t kDirDelimiter = L'/';
+
+UString MakeLegalName(const UString &name)
+{
+  UString zipName = name;
+  zipName.Replace(kOSDirDelimiter, kDirDelimiter);
+  return zipName;
+}
+
+UString GetOSName(const UString &name)
+{
+  UString newName = name;
+  newName.Replace(kDirDelimiter, kOSDirDelimiter);
+  return newName;
+}
+
+UString GetOSName2(const UString &name)
+{
+  if (name.IsEmpty())
+    return UString();
+  UString newName = GetOSName(name);
+  if (newName[newName.Length() - 1] == kOSDirDelimiter)
+    newName.Delete(newName.Length() - 1);
+  return newName;
+}
+
+bool HasTailSlash(const AString &name, UINT codePage)
+{
+  if (name.IsEmpty())
+    return false;
+  LPCSTR prev =
+  #if defined(_WIN32) && !defined(UNDER_CE)
+    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);
+  #else
+    (LPCSTR)(name) + (name.Length() - 1);
+  #endif
+  return (*prev == '/');
+}
+
+#ifndef _WIN32
+UString WinNameToOSName(const UString &name)
+{
+  UString newName = name;
+  newName.Replace(L'\\', kOSDirDelimiter);
+  return newName;
+}
+#endif
+
+}}

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/ItemNameUtils.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,24 @@
+// Archive/Common/ItemNameUtils.h
+
+#ifndef __ARCHIVE_ITEMNAMEUTILS_H
+#define __ARCHIVE_ITEMNAMEUTILS_H
+
+#include "../../../Common/MyString.h"
+
+namespace NArchive {
+namespace NItemName {
+
+  UString MakeLegalName(const UString &name);
+  UString GetOSName(const UString &name);
+  UString GetOSName2(const UString &name);
+  bool HasTailSlash(const AString &name, UINT codePage);
+
+  #ifdef _WIN32
+  inline UString WinNameToOSName(const UString &name)  { return name; }
+  #else
+  UString WinNameToOSName(const UString &name);
+  #endif
+
+}}
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,190 @@
+// MultiStream.cpp
+
+#include "StdAfx.h"
+
+#include "MultiStream.h"
+
+STDMETHODIMP CMultiStream::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+  if (processedSize)
+    *processedSize = 0;
+  if (size == 0)
+    return S_OK;
+  if (_pos >= _totalLength)
+    return (_pos == _totalLength) ? S_OK : E_FAIL;
+
+  {
+    int left = 0, mid = _streamIndex, right = Streams.Size();
+    for (;;)
+    {
+      CSubStreamInfo &m = Streams[mid];
+      if (_pos < m.GlobalOffset)
+        right = mid;
+      else if (_pos >= m.GlobalOffset + m.Size)
+        left = mid + 1;
+      else
+      {
+        _streamIndex = mid;
+        break;
+      }
+      mid = (left + right) / 2;
+    }
+    _streamIndex = mid;
+  }
+  
+  CSubStreamInfo &s = Streams[_streamIndex];
+  UInt64 localPos = _pos - s.GlobalOffset;
+  if (localPos != s.LocalPos)
+  {
+    RINOK(s.Stream->Seek(localPos, STREAM_SEEK_SET, &s.LocalPos));
+  }
+  UInt64 rem = s.Size - localPos;
+  if (size > rem)
+    size = (UInt32)rem;
+  HRESULT result = s.Stream->Read(data, size, &size);
+  _pos += size;
+  s.LocalPos += size;
+  if (processedSize)
+    *processedSize = size;
+  return result;
+}
+  
+STDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
+{
+  switch(seekOrigin)
+  {
+    case STREAM_SEEK_SET: _pos = offset; break;
+    case STREAM_SEEK_CUR: _pos = _pos + offset; break;
+    case STREAM_SEEK_END: _pos = _totalLength + offset; break;
+    default: return STG_E_INVALIDFUNCTION;
+  }
+  if (newPosition != 0)
+    *newPosition = _pos;
+  return S_OK;
+}
+
+
+/*
+class COutVolumeStream:
+  public ISequentialOutStream,
+  public CMyUnknownImp
+{
+  int _volIndex;
+  UInt64 _volSize;
+  UInt64 _curPos;
+  CMyComPtr<ISequentialOutStream> _volumeStream;
+  COutArchive _archive;
+  CCRC _crc;
+
+public:
+  MY_UNKNOWN_IMP
+
+  CFileItem _file;
+  CUpdateOptions _options;
+  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
+  void Init(IArchiveUpdateCallback2 *volumeCallback,
+      const UString &name)
+  {
+    _file.Name = name;
+    _file.IsStartPosDefined = true;
+    _file.StartPos = 0;
+    
+    VolumeCallback = volumeCallback;
+    _volIndex = 0;
+    _volSize = 0;
+  }
+  
+  HRESULT Flush();
+  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+};
+
+HRESULT COutVolumeStream::Flush()
+{
+  if (_volumeStream)
+  {
+    _file.UnPackSize = _curPos;
+    _file.FileCRC = _crc.GetDigest();
+    RINOK(WriteVolumeHeader(_archive, _file, _options));
+    _archive.Close();
+    _volumeStream.Release();
+    _file.StartPos += _file.UnPackSize;
+  }
+  return S_OK;
+}
+*/
+
+/*
+STDMETHODIMP COutMultiStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+  if(processedSize != NULL)
+    *processedSize = 0;
+  while(size > 0)
+  {
+    if (_streamIndex >= Streams.Size())
+    {
+      CSubStreamInfo subStream;
+      RINOK(VolumeCallback->GetVolumeSize(Streams.Size(), &subStream.Size));
+      RINOK(VolumeCallback->GetVolumeStream(Streams.Size(), &subStream.Stream));
+      subStream.Pos = 0;
+      Streams.Add(subStream);
+      continue;
+    }
+    CSubStreamInfo &subStream = Streams[_streamIndex];
+    if (_offsetPos >= subStream.Size)
+    {
+      _offsetPos -= subStream.Size;
+      _streamIndex++;
+      continue;
+    }
+    if (_offsetPos != subStream.Pos)
+    {
+      CMyComPtr<IOutStream> outStream;
+      RINOK(subStream.Stream.QueryInterface(IID_IOutStream, &outStream));
+      RINOK(outStream->Seek(_offsetPos, STREAM_SEEK_SET, NULL));
+      subStream.Pos = _offsetPos;
+    }
+
+    UInt32 curSize = (UInt32)MyMin((UInt64)size, subStream.Size - subStream.Pos);
+    UInt32 realProcessed;
+    RINOK(subStream.Stream->Write(data, curSize, &realProcessed));
+    data = (void *)((Byte *)data + realProcessed);
+    size -= realProcessed;
+    subStream.Pos += realProcessed;
+    _offsetPos += realProcessed;
+    _absPos += realProcessed;
+    if (_absPos > _length)
+      _length = _absPos;
+    if(processedSize != NULL)
+      *processedSize += realProcessed;
+    if (subStream.Pos == subStream.Size)
+    {
+      _streamIndex++;
+      _offsetPos = 0;
+    }
+    if (realProcessed != curSize && realProcessed == 0)
+      return E_FAIL;
+  }
+  return S_OK;
+}
+
+STDMETHODIMP COutMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
+{
+  if(seekOrigin >= 3)
+    return STG_E_INVALIDFUNCTION;
+  switch(seekOrigin)
+  {
+    case STREAM_SEEK_SET:
+      _absPos = offset;
+      break;
+    case STREAM_SEEK_CUR:
+      _absPos += offset;
+      break;
+    case STREAM_SEEK_END:
+      _absPos = _length + offset;
+      break;
+  }
+  _offsetPos = _absPos;
+  _streamIndex = 0;
+  return S_OK;
+}
+*/

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/MultiStream.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,84 @@
+// MultiStream.h
+
+#ifndef __MULTI_STREAM_H
+#define __MULTI_STREAM_H
+
+#include "../../../Common/MyCom.h"
+#include "../../../Common/MyVector.h"
+
+#include "../../IStream.h"
+
+class CMultiStream:
+  public IInStream,
+  public CMyUnknownImp
+{
+  UInt64 _pos;
+  UInt64 _totalLength;
+  int _streamIndex;
+public:
+  struct CSubStreamInfo
+  {
+    CMyComPtr<IInStream> Stream;
+    UInt64 Size;
+    UInt64 GlobalOffset;
+    UInt64 LocalPos;
+  };
+  CObjectVector<CSubStreamInfo> Streams;
+  
+  HRESULT Init()
+  {
+    UInt64 total = 0;
+    for (int i = 0; i < Streams.Size(); i++)
+    {
+      CSubStreamInfo &s = Streams[i];
+      s.GlobalOffset = total;
+      total += Streams[i].Size;
+      RINOK(s.Stream->Seek(0, STREAM_SEEK_CUR, &s.LocalPos));
+    }
+    _totalLength = total;
+    _pos = 0;
+    _streamIndex = 0;
+    return S_OK;
+  }
+
+  MY_UNKNOWN_IMP1(IInStream)
+
+  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
+};
+
+/*
+class COutMultiStream:
+  public IOutStream,
+  public CMyUnknownImp
+{
+  int _streamIndex; // required stream
+  UInt64 _offsetPos; // offset from start of _streamIndex index
+  UInt64 _absPos;
+  UInt64 _length;
+
+  struct CSubStreamInfo
+  {
+    CMyComPtr<ISequentialOutStream> Stream;
+    UInt64 Size;
+    UInt64 Pos;
+ };
+  CObjectVector<CSubStreamInfo> Streams;
+public:
+  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
+  void Init()
+  {
+    _streamIndex = 0;
+    _offsetPos = 0;
+    _absPos = 0;
+    _length = 0;
+  }
+
+  MY_UNKNOWN_IMP1(IOutStream)
+
+  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
+};
+*/
+
+#endif

Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,18 @@
+// OutStreamWithCRC.cpp
+
+#include "StdAfx.h"
+
+#include "OutStreamWithCRC.h"
+
+STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+  HRESULT result = S_OK;
+  if (_stream)
+    result = _stream->Write(data, size, &size);
+  if (_calculate)
+    _crc = CrcUpdate(_crc, data, size);
+  _size += size;
+  if (processedSize != NULL)
+    *processedSize = size;
+  return result;
+}





More information about the llvm-commits mailing list