RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / scripts / squashfs / lzma / C / 7zip / Compress / Branch / BranchIA64.c
blob8571aac180681eae6d4c019e3157683895eb9130
1 // BranchIA64.c
3 #include "BranchIA64.h"
5 const Byte kBranchTable[32] =
6 {
7 0, 0, 0, 0, 0, 0, 0, 0,
8 0, 0, 0, 0, 0, 0, 0, 0,
9 4, 4, 6, 6, 0, 0, 7, 7,
10 4, 4, 0, 0, 4, 4, 0, 0
13 UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
15 UInt32 i;
16 for (i = 0; i + 16 <= size; i += 16)
18 UInt32 instrTemplate = data[i] & 0x1F;
19 UInt32 mask = kBranchTable[instrTemplate];
20 UInt32 bitPos = 5;
21 for (int slot = 0; slot < 3; slot++, bitPos += 41)
23 if (((mask >> slot) & 1) == 0)
24 continue;
25 UInt32 bytePos = (bitPos >> 3);
26 UInt32 bitRes = bitPos & 0x7;
27 // UInt64 instruction = *(UInt64 *)(data + i + bytePos);
28 UInt64 instruction = 0;
29 int j;
30 for (j = 0; j < 6; j++)
31 instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);
33 UInt64 instNorm = instruction >> bitRes;
34 if (((instNorm >> 37) & 0xF) == 0x5
35 && ((instNorm >> 9) & 0x7) == 0
36 // && (instNorm & 0x3F)== 0
39 UInt32 src = UInt32((instNorm >> 13) & 0xFFFFF);
40 src |= ((instNorm >> 36) & 1) << 20;
42 src <<= 4;
44 UInt32 dest;
45 if (encoding)
46 dest = nowPos + i + src;
47 else
48 dest = src - (nowPos + i);
50 dest >>= 4;
52 instNorm &= ~(UInt64(0x8FFFFF) << 13);
53 instNorm |= (UInt64(dest & 0xFFFFF) << 13);
54 instNorm |= (UInt64(dest & 0x100000) << (36 - 20));
56 instruction &= (1 << bitRes) - 1;
57 instruction |= (instNorm << bitRes);
58 // *(UInt64 *)(data + i + bytePos) = instruction;
59 for (j = 0; j < 6; j++)
60 data[i + j + bytePos] = Byte(instruction >> (8 * j));
64 return i;