1 /* 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package com.oracle.graal.lir.hsail; 24 25 import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; 26 import com.oracle.graal.api.meta.*; 27 import com.oracle.graal.asm.hsail.*; 28 import com.oracle.graal.graph.*; 29 import com.oracle.graal.lir.asm.*; 30 import com.oracle.graal.nodes.calc.*; 31 import com.oracle.graal.lir.*; 32 33 /** 34 * Implementation of compare operations. 35 */ 36 public enum HSAILCompare { 37 ICMP, LCMP, ACMP, FCMP, DCMP; 38 39 public static class CompareOp extends HSAILLIRInstruction { 40 41 @Opcode private final HSAILCompare opcode; 42 @Use({REG, STACK, CONST}) protected Value x; 43 @Use({REG, STACK, CONST}) protected Value y; 44 @Def({REG}) protected Value z; 45 private final Condition condition; 46 public boolean unordered = false; 47 48 public CompareOp(HSAILCompare opcode, Condition condition, Value x, Value y, Value z) { 49 this.opcode = opcode; 50 this.condition = condition; 51 this.x = x; 52 this.y = y; 53 this.z = z; 54 } 55 56 @Override 57 public void emitCode(TargetMethodAssembler tasm, HSAILAssembler masm) { 58 emit(tasm, masm, condition, x, y, z, unordered); 59 } 60 61 @Override 62 protected void verify() { 63 super.verify(); 64 assert (x.getKind() == y.getKind() && ((name().startsWith("I") && x.getKind() == Kind.Int) || (name().startsWith("L") && x.getKind() == Kind.Long) || 65 (name().startsWith("A") && x.getKind() == Kind.Object) || (name().startsWith("F") && x.getKind() == Kind.Float) || (name().startsWith("D") && x.getKind() == Kind.Double))); 66 } 67 } 68 69 @SuppressWarnings("unused") 70 public static void emit(TargetMethodAssembler tasm, HSAILAssembler masm, Condition condition, Value x, Value y, Value z, boolean unorderedIsTrue) { 71 emitCompare(masm, condition, x, y, unorderedIsTrue); 72 } 73 74 private static String conditionToString(Condition condition) { 75 switch (condition) { 76 case EQ: 77 return "eq"; 78 case NE: 79 return "ne"; 80 case LT: 81 case BT: 82 return "lt"; 83 case LE: 84 case BE: 85 return "le"; 86 case GT: 87 case AT: 88 return "gt"; 89 case GE: 90 case AE: 91 return "ge"; 92 default: 93 throw GraalInternalError.shouldNotReachHere(); 94 } 95 } 96 97 private static boolean isUnsignedCompare(Condition condition) { 98 switch (condition) { 99 case BT: 100 case BE: 101 case AT: 102 case AE: 103 return true; 104 default: 105 return false; 106 } 107 } 108 109 private static void emitCompare(HSAILAssembler masm, Condition condition, Value src0, Value src1, boolean unordered) { 110 masm.emitCompare(src0, src1, conditionToString(condition), unordered, isUnsignedCompare(condition)); 111 } 112 113 }