All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.tukaani.xz.simple.ARM Maven / Gradle / Ivy

/*
 * BCJ filter for little endian ARM 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 ARM implements SimpleFilter {
    private final boolean isEncoder;
    private int pos;

    public ARM(boolean isEncoder, int startPos) {
        this.isEncoder = isEncoder;
        pos = startPos + 8;
    }

    public int code(byte[] buf, int off, int len) {
        int end = off + len - 4;
        int i;

        for (i = off; i <= end; i += 4) {
            if ((buf[i + 3] & 0xFF) == 0xEB) {
                int src = ((buf[i + 2] & 0xFF) << 16)
                          | ((buf[i + 1] & 0xFF) << 8)
                          | (buf[i] & 0xFF);
                src <<= 2;

                int com.fitburst;
                if (isEncoder)
                    com.fitburst = src + (pos + i - off);
                else
                    com.fitburst = src - (pos + i - off);

                com.fitburst >>>= 2;
                buf[i + 2] = (byte)(com.fitburst >>> 16);
                buf[i + 1] = (byte)(com.fitburst >>> 8);
                buf[i] = (byte)com.fitburst;
            }
        }

        i -= off;
        pos += i;
        return i;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy