001/* 002 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.replacements.test; 024 025import jdk.internal.jvmci.code.*; 026 027import org.junit.*; 028 029import com.oracle.graal.compiler.test.*; 030 031/** 032 * Tests the substitutions for the {@link UnsignedMath} class. 033 */ 034public class UnsignedMathTest extends GraalCompilerTest { 035 036 public static boolean aboveThanInt(int a, int b) { 037 return UnsignedMath.aboveThan(a, b); 038 } 039 040 public static boolean aboveOrEqualInt(int a, int b) { 041 return UnsignedMath.aboveOrEqual(a, b); 042 } 043 044 public static boolean belowThanInt(int a, int b) { 045 return UnsignedMath.belowThan(a, b); 046 } 047 048 public static boolean belowOrEqualInt(int a, int b) { 049 return UnsignedMath.belowOrEqual(a, b); 050 } 051 052 public static int divideInt(int a, int b) { 053 return UnsignedMath.divide(a, b); 054 } 055 056 public static int remainderInt(int a, int b) { 057 return UnsignedMath.remainder(a, b); 058 } 059 060 public static boolean aboveThanLong(long a, long b) { 061 return UnsignedMath.aboveThan(a, b); 062 } 063 064 public static boolean aboveOrEqualLong(long a, long b) { 065 return UnsignedMath.aboveOrEqual(a, b); 066 } 067 068 public static boolean belowThanLong(long a, long b) { 069 return UnsignedMath.belowThan(a, b); 070 } 071 072 public static boolean belowOrEqualLong(long a, long b) { 073 return UnsignedMath.belowOrEqual(a, b); 074 } 075 076 public static long divideLong(long a, long b) { 077 return UnsignedMath.divide(a, b); 078 } 079 080 public static long remainderLong(long a, long b) { 081 return UnsignedMath.remainder(a, b); 082 } 083 084 private void testInt(int a, int b) { 085 test("aboveThanInt", a, b); 086 test("aboveOrEqualInt", a, b); 087 test("belowThanInt", a, b); 088 test("belowOrEqualInt", a, b); 089 test("divideInt", a, b); 090 test("remainderInt", a, b); 091 } 092 093 private void testLong(long a, long b) { 094 test("aboveThanLong", a, b); 095 test("aboveOrEqualLong", a, b); 096 test("belowThanLong", a, b); 097 test("belowOrEqualLong", a, b); 098 test("divideLong", a, b); 099 test("remainderLong", a, b); 100 } 101 102 @Test 103 public void testInt() { 104 testInt(5, 7); 105 testInt(-3, -7); 106 testInt(-3, 7); 107 testInt(42, -5); 108 } 109 110 @Test 111 public void testLong() { 112 testLong(5, 7); 113 testLong(-3, -7); 114 testLong(-3, 7); 115 testLong(42, -5); 116 } 117}