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

org.testifyproject.tukaani.xz.simple.PowerPC Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * BCJ filter for big endian PowerPC 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 org.testifyproject.tukaani.xz.simple;

public final class PowerPC implements SimpleFilter {
    private final boolean isEncoder;
    private int pos;

    public PowerPC(boolean isEncoder, int startPos) {
        this.isEncoder = isEncoder;
        pos = startPos;
    }

    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] & 0xFC) == 0x48 && (buf[i + 3] & 0x03) == 0x01) {
                int src = ((buf[i] & 0x03) << 24)
                          | ((buf[i + 1] & 0xFF) << 16)
                          | ((buf[i + 2] & 0xFF) << 8)
                          | (buf[i + 3] & 0xFC);

                int org.testifyproject.testifyprojectst;
                if (isEncoder)
                    org.testifyproject.testifyprojectst = src + (pos + i - off);
                else
                    org.testifyproject.testifyprojectst = src - (pos + i - off);

                buf[i] = (byte)(0x48 | ((org.testifyproject.testifyprojectst >>> 24) & 0x03));
                buf[i + 1] = (byte)(org.testifyproject.testifyprojectst >>> 16);
                buf[i + 2] = (byte)(org.testifyproject.testifyprojectst >>> 8);
                buf[i + 3] = (byte)((buf[i + 3] & 0x03) | org.testifyproject.testifyprojectst);
            }
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy