Debian Codegraph @

src/org/tukaani/xz/simple/ARMThumb.java

raw symbols SCIP
1 // SPDX-License-Identifier: 0BSD
2 // SPDX-FileCopyrightText: The XZ for Java authors and contributors
3 // SPDX-FileContributor: Lasse Collin <[email protected]>
4 // SPDX-FileContributor: Igor Pavlov <https://7-zip.org/>
5
6 package org.tukaani.xz.simple;
7
8 // BCJ filter for little endian ARM-Thumb instructions
9 public final class ARMThumb implements SimpleFilter {
10 private final boolean isEncoder;
11 private int pos;
12
13 public ARMThumb(boolean isEncoder, int startPos) {
14 this.isEncoder = isEncoder;
15 pos = startPos + 4;
16 }
17
18 @Override
19 public int code(byte[] buf, int off, int len) {
20 int end = off + len - 4;
21 int i;
22
23 for (i = off; i <= end; i += 2) {
24 if ((buf[i + 1] & 0xF8) == 0xF0 && (buf[i + 3] & 0xF8) == 0xF8) {
25 int src = ((buf[i + 1] & 0x07) << 19)
26 | ((buf[i] & 0xFF) << 11)
27 | ((buf[i + 3] & 0x07) << 8)
28 | (buf[i + 2] & 0xFF);
29 src <<= 1;
30
31 int dest;
32 if (isEncoder)
33 dest = src + (pos + i - off);
34 else
35 dest = src - (pos + i - off);
36
37 dest >>>= 1;
38 buf[i + 1] = (byte)(0xF0 | ((dest >>> 19) & 0x07));
39 buf[i] = (byte)(dest >>> 11);
40 buf[i + 3] = (byte)(0xF8 | ((dest >>> 8) & 0x07));
41 buf[i + 2] = (byte)dest;
42 i += 2;
43 }
44 }
45
46 i -= off;
47 pos += i;
48 return i;
49 }
50 }