Roll src/third_party/skia c6f3e2c:efb7e42
[chromium-blink-merge.git] / third_party / lzma_sdk / Bra.c
blob2e47b1413c1fa3e425dbb390c05f7b61d1b2f72a
1 /* Bra.c -- Converters for RISC code
2 2010-04-16 : Igor Pavlov : Public domain */
4 #include "Bra.h"
6 SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
8 SizeT i;
9 if (size < 4)
10 return 0;
11 size -= 4;
12 ip += 8;
13 for (i = 0; i <= size; i += 4)
15 if (data[i + 3] == 0xEB)
17 UInt32 dest;
18 UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
19 src <<= 2;
20 if (encoding)
21 dest = ip + (UInt32)i + src;
22 else
23 dest = src - (ip + (UInt32)i);
24 dest >>= 2;
25 data[i + 2] = (Byte)(dest >> 16);
26 data[i + 1] = (Byte)(dest >> 8);
27 data[i + 0] = (Byte)dest;
30 return i;
33 SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
35 SizeT i;
36 if (size < 4)
37 return 0;
38 size -= 4;
39 ip += 4;
40 for (i = 0; i <= size; i += 2)
42 if ((data[i + 1] & 0xF8) == 0xF0 &&
43 (data[i + 3] & 0xF8) == 0xF8)
45 UInt32 dest;
46 UInt32 src =
47 (((UInt32)data[i + 1] & 0x7) << 19) |
48 ((UInt32)data[i + 0] << 11) |
49 (((UInt32)data[i + 3] & 0x7) << 8) |
50 (data[i + 2]);
52 src <<= 1;
53 if (encoding)
54 dest = ip + (UInt32)i + src;
55 else
56 dest = src - (ip + (UInt32)i);
57 dest >>= 1;
59 data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
60 data[i + 0] = (Byte)(dest >> 11);
61 data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
62 data[i + 2] = (Byte)dest;
63 i += 2;
66 return i;
69 SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
71 SizeT i;
72 if (size < 4)
73 return 0;
74 size -= 4;
75 for (i = 0; i <= size; i += 4)
77 if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
79 UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
80 ((UInt32)data[i + 1] << 16) |
81 ((UInt32)data[i + 2] << 8) |
82 ((UInt32)data[i + 3] & (~3));
84 UInt32 dest;
85 if (encoding)
86 dest = ip + (UInt32)i + src;
87 else
88 dest = src - (ip + (UInt32)i);
89 data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3));
90 data[i + 1] = (Byte)(dest >> 16);
91 data[i + 2] = (Byte)(dest >> 8);
92 data[i + 3] &= 0x3;
93 data[i + 3] |= dest;
96 return i;
99 SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
101 UInt32 i;
102 if (size < 4)
103 return 0;
104 size -= 4;
105 for (i = 0; i <= size; i += 4)
107 if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) ||
108 (data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0))
110 UInt32 src =
111 ((UInt32)data[i + 0] << 24) |
112 ((UInt32)data[i + 1] << 16) |
113 ((UInt32)data[i + 2] << 8) |
114 ((UInt32)data[i + 3]);
115 UInt32 dest;
117 src <<= 2;
118 if (encoding)
119 dest = ip + i + src;
120 else
121 dest = src - (ip + i);
122 dest >>= 2;
124 dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
126 data[i + 0] = (Byte)(dest >> 24);
127 data[i + 1] = (Byte)(dest >> 16);
128 data[i + 2] = (Byte)(dest >> 8);
129 data[i + 3] = (Byte)dest;
132 return i;