[feat] Add emitIntegerTestMove operation in PTX
/*
- * Copyright (c) 2020, APT Group, Department of Computer Science,
+ * Copyright (c) 2020, 2022, APT Group, Department of Computer Science,
* School of Engineering, The University of Manchester. All rights reserved.
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -39,7 +39,6 @@ import org.graalvm.compiler.lir.ConstantValue;
import org.graalvm.compiler.lir.LIRFrameState;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.LabelRef;
-import org.graalvm.compiler.lir.StandardOp;
import org.graalvm.compiler.lir.SwitchStrategy;
import org.graalvm.compiler.lir.Variable;
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
@@ -307,10 +306,38 @@ public class PTXLIRGenerator extends LIRGenerator {
return null;
}
+ /**
+ * It generates an IntegerTestMove operation, which moves a value to a parameter
+ * based on a bitwise and operation between two values.
+ *
+ * @param leftVal
+ * the left value of a condition
+ * @param right
+ * the right value of a condition
+ * @param trueValue
+ * the true value to move in the result
+ * @param falseValue
+ * the false value to move in the result
+ * @return Variable: reference to the variable that contains the result
+ */
@Override
public Variable emitIntegerTestMove(Value leftVal, Value right, Value trueValue, Value falseValue) {
- unimplemented();
- return null;
+ Logger.traceBuildLIR(Logger.BACKEND.PTX, "emitIntegerTestMove");
+ assert leftVal.getPlatformKind() == right.getPlatformKind() && ((PTXKind) leftVal.getPlatformKind()).isInteger();
+
+ assert trueValue.getPlatformKind() == falseValue.getPlatformKind();
+
+ LIRKind kind = LIRKind.combine(trueValue, falseValue);
+ final Variable andResult = newVariable(LIRKind.combine(leftVal, right));
+ final ConstantValue constant = new ConstantValue(andResult.getValueKind(), JavaConstant.forInt(0));
+ final Variable predicate = newVariable(LIRKind.value(PTXKind.PRED));
+ final Variable result = newVariable(kind);
+
+ append(new PTXLIRStmt.AssignStmt(andResult, new PTXBinary.Expr(PTXBinaryOp.BITWISE_AND, kind, leftVal, right)));
+ append(new PTXLIRStmt.AssignStmt(predicate, new PTXBinary.Expr(PTXBinaryOp.SETP_EQ, kind, andResult, constant)));
+ append(new PTXLIRStmt.AssignStmt(result, new PTXTernary.Expr(PTXAssembler.PTXTernaryOp.SELP, kind, trueValue, falseValue, predicate)));
+
+ return result;
}
@Override
