3 #include "BranchIA64.h"
5 const Byte kBranchTable
[32] =
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
)
16 for (i
= 0; i
+ 16 <= size
; i
+= 16)
18 UInt32 instrTemplate
= data
[i
] & 0x1F;
19 UInt32 mask
= kBranchTable
[instrTemplate
];
21 for (int slot
= 0; slot
< 3; slot
++, bitPos
+= 41)
23 if (((mask
>> slot
) & 1) == 0)
25 UInt32 bytePos
= (bitPos
>> 3);
26 UInt32 bitRes
= bitPos
& 0x7;
27 // UInt64 instruction = *(UInt64 *)(data + i + bytePos);
28 UInt64 instruction
= 0;
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;
46 dest
= nowPos
+ i
+ src
;
48 dest
= src
- (nowPos
+ i
);
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
));