1 /* 2 * Copyright (c) 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.hotspot.amd64.test; 26 27 import org.junit.Test; 28 import org.junit.Assert; 29 30 /** 31 * Tests Bit Manipulation Instruction andn pattern matching and result. 32 */ 33 public class BmiAndn extends BmiCompilerTest { 34 // from Intel manual VEX.NDS.LZ.0F38.W0 F2 /r, example c4e260f2c2 35 private final byte[] instrMask = new byte[]{ 36 (byte) 0xFF, 37 (byte) 0x1F, 38 (byte) 0x00, 39 (byte) 0xFF}; 40 private final byte[] instrPattern = new byte[]{ 41 (byte) 0xC4, // prefix for 3-byte VEX instruction 42 (byte) 0x02, // 00010 implied 0F 38 leading opcode bytes 43 (byte) 0x00, 44 (byte) 0xF2}; 45 46 public int andni(int n1, int n2) { 47 return (n1 & (~n2)); 48 } 49 50 public long andnl(long n1, long n2) { 51 return (n1 & (~n2)); 52 } 53 54 // Pattern matching check for andni 55 @Test 56 public void test1() { 57 Assert.assertTrue(verifyPositive("andni", instrMask, instrPattern)); 58 } 59 60 // Pattern matching check for andnl 61 @Test 62 public void test2() { 63 Assert.assertTrue(verifyPositive("andnl", instrMask, instrPattern)); 64 } 65 66 // Result correctness check 67 @Test 68 public void test3() { 69 int n1 = 42; 70 int n2 = 100; 71 test("andni", n1, n2); 72 } 73 74 @Test 75 public void test4() { 76 long n1 = 420000000; 77 long n2 = 1000000000; 78 test("andnl", n1, n2); 79 } 80 }