package org.graalvm.compiler.core.aarch64.test;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.aarch64.AArch64BitFieldOp;
import org.junit.Test;
import java.util.function.Predicate;
public class AArch64BitFieldTest extends AArch64MatchRuleTest {
private static final Predicate<LIRInstruction> predicate = op -> (op instanceof AArch64BitFieldOp);
private void testAndCheckLIR(String method, String negativeMethod, Object input) {
testAndCheckLIR(method, input);
test(negativeMethod, input);
checkLIR(negativeMethod, predicate, 0);
}
private void testAndCheckLIR(String method, Object input) {
test(method, input);
checkLIR(method, predicate, 1);
}
public static int (int input) {
return (input >>> 6) & 0xffff;
}
public static int (int input) {
int result = 0;
result += ((input >>> 10) & 0xfff0);
result += ((input >>> 2) & 0x7fffffff);
result += ((input >>> 16) & 0x1ffff);
return result;
}
@Test
public void () {
testAndCheckLIR("extractInt", "invalidExtractInt", 0x12345678);
}
public static long (long input) {
return (input >>> 25) & 0xffffffffL;
}
public static long (long input) {
long result = 0L;
result += ((input >>> 10) & 0x230L);
result += ((input >>> 2) & 0x7fffffffffffffffL);
result += ((input >>> 62) & 0x7L);
return result;
}
@Test
public void () {
testAndCheckLIR("extractLong", "invalidExtractLong", 0xfedcba9876543210L);
}
public static int insertInt(int input) {
return (input & 0xfff) << 10;
}
public static int invalidInsertInt(int input) {
int result = 0;
result += ((input & 0xe) << 25);
result += ((input & 0x7fffffff) << 1);
result += ((input & 0x1ffff) << 16);
return result;
}
@Test
public void testInsertInt() {
testAndCheckLIR("insertInt", "invalidInsertInt", 0xcafebabe);
}
public static long insertLong(long input) {
return (input & 0x3fffffffffffL) << 7;
}
public static long invalidInsertLong(long input) {
long result = 0L;
result += ((input & 0x1a) << 39);
result += ((input & 0x7fffffffffffffffL) << 1);
result += ((input & 0x3fffffff) << 52);
return result;
}
@Test
public void testInsertLong() {
testAndCheckLIR("insertLong", "invalidInsertLong", 0xdeadbeefdeadbeefL);
}
public static long unsignedInsertExtend(int input) {
return ((long) (input & 0xffff)) << 8;
}
@Test
public void testUnsignedInsertExtend() {
testAndCheckLIR("unsignedInsertExtend", 0x234);
}
public static long unsignedExtendInsert(int input) {
return (input & 0xfff) << 5;
}
@Test
public void testUnsignedExtendInsert() {
testAndCheckLIR("unsignedExtendInsert", 0x4334);
}
public static long (int input) {
return (input >>> 6) & 0xffffff;
}
@Test
public void () {
testAndCheckLIR("unsignedExtendExtract", 0x325ab);
}
public long signedB2LInsert(long input) {
byte b = (byte) input;
return ((long) b) << 2;
}
@Test
public void testSignedB2LInsert() {
testAndCheckLIR("signedB2LInsert", 0xab3213efL);
}
public long signedS2LInsert(long input) {
short s = (short) input;
return ((long) s) << -5;
}
@Test
public void testSignedS2LInsert() {
testAndCheckLIR("signedS2LInsert", 0x328032bL);
}
public static long signedI2LInsert(int input) {
return ((long) input) << 1;
}
@Test
public void testSignedI2LInsert() {
testAndCheckLIR("signedI2LInsert", 31);
}
public int signedB2IInsert(int input) {
byte b = (byte) input;
return b << 31;
}
@Test
public void testSignedB2IInsert() {
testAndCheckLIR("signedB2IInsert", 0x23);
}
public int signedS2IInsert(int input) {
short s = (short) input;
return s << 2;
}
@Test
public void testSignedS2IInsert() {
testAndCheckLIR("signedS2IInsert", 0x92);
}
public static int (int input) {
return (input << 8) >> 15;
}
@Test
public void () {
testAndCheckLIR("signedExtractInt", 0x123);
}
public static long (long input) {
return (input << 8) >> 15;
}
@Test
public void () {
testAndCheckLIR("signedExtractLong", 0x125L);
}
public static int signedInsertInt(int input) {
return (input << 15) >> 8;
}
@Test
public void testSignedInsertInt() {
testAndCheckLIR("signedInsertInt", 0x1253);
}
public static long signedInsertLong(long input) {
return (input << 15) >> 8;
}
@Test
public void testSignedInsertLong() {
testAndCheckLIR("signedInsertLong", 0xabcddbc325L);
}
public static int (int input) {
return (input << 8) >>> 31;
}
@Test
public void () {
testAndCheckLIR("unsignedExtractInt", 0x125);
}
public static long (long input) {
return (input << 8) >>> 12;
}
@Test
public void () {
testAndCheckLIR("unsignedExtractLong", 0x32222e125L);
}
public static int unsignedInsertInt(int input) {
return (input << 15) >>> 8;
}
@Test
public void testUnsignedInsertInt() {
testAndCheckLIR("unsignedInsertInt", 125);
}
public static long unsignedInsertLong(long input) {
return (input << 63) >>> 1;
}
@Test
public void testUnsignedInsertLong() {
testAndCheckLIR("unsignedInsertLong", 0x2339fb125L);
}
}