Upload 2.0.2
[physicsfs] / lzma / C / Compress / Branch / BranchIA64.c
1 /* BranchIA64.c */
2
3 #include "BranchIA64.h"
4
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 
11 };
12
13 UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding)
14 {
15   UInt32 i;
16   for (i = 0; i + 16 <= size; i += 16)
17   {
18     UInt32 instrTemplate = data[i] & 0x1F;
19     UInt32 mask = kBranchTable[instrTemplate];
20     UInt32 bitPos = 5;
21     int slot;
22     for (slot = 0; slot < 3; slot++, bitPos += 41)
23     {
24       UInt32 bytePos, bitRes;
25       UInt64 instruction, instNorm;
26       int j;
27       if (((mask >> slot) & 1) == 0)
28         continue;
29       bytePos = (bitPos >> 3);
30       bitRes = bitPos & 0x7;
31       instruction = 0;
32       for (j = 0; j < 6; j++)
33         instruction += (UInt64)(data[i + j + bytePos]) << (8 * j);
34
35       instNorm = instruction >> bitRes;
36       if (((instNorm >> 37) & 0xF) == 0x5 
37         &&  ((instNorm >> 9) & 0x7) == 0 
38         /* &&  (instNorm & 0x3F)== 0 */
39         )
40       {
41         UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
42         UInt32 dest;
43         src |= ((UInt32)(instNorm >> 36) & 1) << 20;
44         
45         src <<= 4;
46         
47         if (encoding)
48           dest = nowPos + i + src;
49         else
50           dest = src - (nowPos + i);
51         
52         dest >>= 4;
53         
54         instNorm &= ~((UInt64)(0x8FFFFF) << 13);
55         instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
56         instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
57         
58         instruction &= (1 << bitRes) - 1;
59         instruction |= (instNorm << bitRes);
60         for (j = 0; j < 6; j++)
61           data[i + j + bytePos] = (Byte)(instruction >> (8 * j));
62       }
63     }
64   }
65   return i;
66 }