1 /*
   2  * Copyright (c) 2013, 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.compiler.ptx.test;
  24 
  25 import java.lang.reflect.Method;
  26 
  27 import org.junit.Test;
  28 
  29 
  30 /* PTX ISA 3.1 - 8.7.5 Logic and Shift Instructions */
  31 public class LogicPTXTest extends PTXTestBase {
  32 
  33     @Test
  34     public void testAnd() {
  35         compile("testAnd2I");
  36         compile("testAnd2L");
  37     }
  38     
  39     public static int testAnd2I(int a, int b) {
  40         return a & b;
  41     }
  42 
  43     public static long testAnd2L(long a, long b) {
  44         return a & b;
  45     }
  46 
  47     @Test
  48     public void testOr() {
  49         compile("testOr2I");
  50         compile("testOr2L");
  51     }
  52     
  53     public static int testOr2I(int a, int b) {
  54         return a | b;
  55     }
  56 
  57     public static long testOr2L(long a, long b) {
  58         return a | b;
  59     }
  60 
  61     @Test
  62     public void testXor() {
  63         compile("testXor2I");
  64         compile("testXor2L");
  65     }
  66     
  67     public static int testXor2I(int a, int b) {
  68         return a ^ b;
  69     }
  70 
  71     public static long testXor2L(long a, long b) {
  72         return a ^ b;
  73     }
  74 
  75     @Test
  76     public void testNot() {
  77         compile("testNot1I");
  78         compile("testNot1L");
  79     }
  80     
  81     public static int testNot1I(int a) {
  82         return ~a;
  83     }
  84 
  85     public static long testNot1L(long a) {
  86         return ~a;
  87     }
  88 
  89     @Test
  90     public void testShiftLeft() {
  91         compile("testShiftLeft2I");
  92         compile("testShiftLeft2L");
  93     }
  94     
  95     public static int testShiftLeft2I(int a, int b) {
  96         return a << b;
  97     }
  98 
  99     public static long testShiftLeft2L(long a, int b) {
 100         return a << b;
 101     }
 102 
 103     @Test
 104     public void testShiftRight() {
 105         compile("testShiftRight2I");
 106         compile("testShiftRight2L");
 107         compile("testUnsignedShiftRight2I");
 108         compile("testUnsignedShiftRight2L");
 109     }
 110     
 111     public static int testShiftRight2I(int a, int b) {
 112         return a >> b;
 113     }
 114 
 115     public static long testShiftRight2L(long a, int b) {
 116         return a >> b;
 117     }
 118 
 119     public static int testUnsignedShiftRight2I(int a, int b) {
 120         return a >>> b;
 121     }
 122 
 123     public static long testUnsignedShiftRight2L(long a, long b) {
 124         return a >>> b;
 125     }
 126 
 127     public static void main(String[] args) {
 128         LogicPTXTest test = new LogicPTXTest();
 129         for (Method m : LogicPTXTest.class.getMethods()) {
 130             String name = m.getName();
 131             if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
 132                 System.out.println(name + ": \n" + new String(test.compile(name).getTargetCode()));             
 133             }
 134         }
 135     }
 136 }