1 /* 2 * Copyright (c) 2014, 2018, 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 24 25 package org.graalvm.compiler.replacements.test; 26 27 import org.junit.Test; 28 29 import org.graalvm.compiler.core.common.calc.UnsignedMath; 30 import org.graalvm.compiler.core.test.GraalCompilerTest; 31 32 /** 33 * Tests the substitutions for the {@link UnsignedMath} class. 34 */ 35 public class UnsignedMathTest extends GraalCompilerTest { 36 aboveThanInt(int a, int b)37 public static boolean aboveThanInt(int a, int b) { 38 return UnsignedMath.aboveThan(a, b); 39 } 40 aboveOrEqualInt(int a, int b)41 public static boolean aboveOrEqualInt(int a, int b) { 42 return UnsignedMath.aboveOrEqual(a, b); 43 } 44 belowThanInt(int a, int b)45 public static boolean belowThanInt(int a, int b) { 46 return UnsignedMath.belowThan(a, b); 47 } 48 belowOrEqualInt(int a, int b)49 public static boolean belowOrEqualInt(int a, int b) { 50 return UnsignedMath.belowOrEqual(a, b); 51 } 52 divideInt(int a, int b)53 public static int divideInt(int a, int b) { 54 return Integer.divideUnsigned(a, b); 55 } 56 remainderInt(int a, int b)57 public static int remainderInt(int a, int b) { 58 return Integer.remainderUnsigned(a, b); 59 } 60 aboveThanLong(long a, long b)61 public static boolean aboveThanLong(long a, long b) { 62 return UnsignedMath.aboveThan(a, b); 63 } 64 aboveOrEqualLong(long a, long b)65 public static boolean aboveOrEqualLong(long a, long b) { 66 return UnsignedMath.aboveOrEqual(a, b); 67 } 68 belowThanLong(long a, long b)69 public static boolean belowThanLong(long a, long b) { 70 return UnsignedMath.belowThan(a, b); 71 } 72 belowOrEqualLong(long a, long b)73 public static boolean belowOrEqualLong(long a, long b) { 74 return UnsignedMath.belowOrEqual(a, b); 75 } 76 divideLong(long a, long b)77 public static long divideLong(long a, long b) { 78 return Long.divideUnsigned(a, b); 79 } 80 remainderLong(long a, long b)81 public static long remainderLong(long a, long b) { 82 return Long.remainderUnsigned(a, b); 83 } 84 testInt(int a, int b)85 private void testInt(int a, int b) { 86 test("aboveThanInt", a, b); 87 test("aboveOrEqualInt", a, b); 88 test("belowThanInt", a, b); 89 test("belowOrEqualInt", a, b); 90 test("divideInt", a, b); 91 test("remainderInt", a, b); 92 } 93 testLong(long a, long b)94 private void testLong(long a, long b) { 95 test("aboveThanLong", a, b); 96 test("aboveOrEqualLong", a, b); 97 test("belowThanLong", a, b); 98 test("belowOrEqualLong", a, b); 99 test("divideLong", a, b); 100 test("remainderLong", a, b); 101 } 102 103 @Test testInt()104 public void testInt() { 105 testInt(5, 7); 106 testInt(-3, -7); 107 testInt(-3, 7); 108 testInt(42, -5); 109 } 110 111 @Test testLong()112 public void testLong() { 113 testLong(5, 7); 114 testLong(-3, -7); 115 testLong(-3, 7); 116 testLong(42, -5); 117 } 118 } 119