1// BranchMisc.cpp 2 3#include "StdAfx.h" 4 5#include "../../../C/CpuArch.h" 6 7#include "../Common/StreamUtils.h" 8 9#include "BranchMisc.h" 10 11namespace NCompress { 12namespace NBranch { 13 14Z7_COM7F_IMF(CCoder::Init()) 15{ 16 _pc = 0; 17 return S_OK; 18} 19 20 21Z7_COM7F_IMF2(UInt32, CCoder::Filter(Byte *data, UInt32 size)) 22{ 23 const UInt32 processed = (UInt32)(size_t)(BraFunc(data, size, _pc) - data); 24 _pc += processed; 25 return processed; 26} 27 28 29namespace NArm64 { 30 31#ifndef Z7_EXTRACT_ONLY 32 33Z7_COM7F_IMF(CEncoder::Init()) 34{ 35 _pc = _pc_Init; 36 return S_OK; 37} 38 39Z7_COM7F_IMF2(UInt32, CEncoder::Filter(Byte *data, UInt32 size)) 40{ 41 const UInt32 processed = (UInt32)(size_t)(Z7_BRANCH_CONV_ENC(ARM64)(data, size, _pc) - data); 42 _pc += processed; 43 return processed; 44} 45 46Z7_COM7F_IMF(CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)) 47{ 48 UInt32 pc = 0; 49 for (UInt32 i = 0; i < numProps; i++) 50 { 51 const PROPID propID = propIDs[i]; 52 if (propID == NCoderPropID::kDefaultProp || 53 propID == NCoderPropID::kBranchOffset) 54 { 55 const PROPVARIANT &prop = props[i]; 56 if (prop.vt != VT_UI4) 57 return E_INVALIDARG; 58 pc = prop.ulVal; 59 if ((pc & 3) != 0) 60 return E_INVALIDARG; 61 } 62 } 63 _pc_Init = pc; 64 return S_OK; 65} 66 67 68Z7_COM7F_IMF(CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)) 69{ 70 if (_pc_Init == 0) 71 return S_OK; 72 Byte buf[4]; 73 SetUi32(buf, _pc_Init) 74 return WriteStream(outStream, buf, 4); 75} 76 77#endif 78 79 80Z7_COM7F_IMF(CDecoder::Init()) 81{ 82 _pc = _pc_Init; 83 return S_OK; 84} 85 86Z7_COM7F_IMF2(UInt32, CDecoder::Filter(Byte *data, UInt32 size)) 87{ 88 const UInt32 processed = (UInt32)(size_t)(Z7_BRANCH_CONV_DEC(ARM64)(data, size, _pc) - data); 89 _pc += processed; 90 return processed; 91} 92 93Z7_COM7F_IMF(CDecoder::SetDecoderProperties2(const Byte *props, UInt32 size)) 94{ 95 UInt32 val = 0; 96 if (size != 0) 97 { 98 if (size != 4) 99 return E_NOTIMPL; 100 val = GetUi32(props); 101 if ((val & 3) != 0) 102 return E_NOTIMPL; 103 } 104 _pc_Init = val; 105 return S_OK; 106} 107 108} 109 110}} 111