com.fitbur.tukaani.xz.simple.ARMThumb Maven / Gradle / Ivy
/*
* BCJ filter for little endian ARM-Thumb instructions
*
* Authors: Lasse Collin
* Igor Pavlov
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
package com.fitbur.tukaani.xz.simple;
public final class ARMThumb implements SimpleFilter {
private final boolean isEncoder;
private int pos;
public ARMThumb(boolean isEncoder, int startPos) {
this.isEncoder = isEncoder;
pos = startPos + 4;
}
public int code(byte[] buf, int off, int len) {
int end = off + len - 4;
int i;
for (i = off; i <= end; i += 2) {
if ((buf[i + 1] & 0xF8) == 0xF0 && (buf[i + 3] & 0xF8) == 0xF8) {
int src = ((buf[i + 1] & 0x07) << 19)
| ((buf[i] & 0xFF) << 11)
| ((buf[i + 3] & 0x07) << 8)
| (buf[i + 2] & 0xFF);
src <<= 1;
int com.fitburst;
if (isEncoder)
com.fitburst = src + (pos + i - off);
else
com.fitburst = src - (pos + i - off);
com.fitburst >>>= 1;
buf[i + 1] = (byte)(0xF0 | ((com.fitburst >>> 19) & 0x07));
buf[i] = (byte)(com.fitburst >>> 11);
buf[i + 3] = (byte)(0xF8 | ((com.fitburst >>> 8) & 0x07));
buf[i + 2] = (byte)com.fitburst;
i += 2;
}
}
i -= off;
pos += i;
return i;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy