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 blsi pattern matching and result. 32 */ 33 public class BmiBlsi extends BmiCompilerTest { 34 // from Intel manual VEX.NDD.LZ.0F38.W0 F3 /3, example c4e260f2c2 35 private final byte[] instrMask = new byte[]{ 36 (byte) 0xFF, 37 (byte) 0x1F, 38 (byte) 0x00, 39 (byte) 0xFF, 40 (byte) 0b0011_1000}; 41 private final byte[] instrPattern = new byte[]{ 42 (byte) 0xC4, // prefix for 3-byte VEX instruction 43 (byte) 0x02, // 00010 implied 0F 38 leading opcode bytes 44 (byte) 0x00, 45 (byte) 0xF3, 46 (byte) 0b0001_1000}; // bits 543 == 011 (3) 47 48 public int blsii(int n1) { 49 return (n1 & (-n1)); 50 } 51 52 public long blsil(long n1) { 53 return (n1 & (-n1)); 54 } 55 56 // Pattern matching check for blsii 57 @Test 58 public void test1() { 59 Assert.assertTrue(verifyPositive("blsii", instrMask, instrPattern)); 60 } 61 62 // Pattern matching check for blsil 63 @Test 64 public void test2() { 65 Assert.assertTrue(verifyPositive("blsil", instrMask, instrPattern)); 66 } 67 68 // Result correctness check 69 @Test 70 public void test3() { 71 int n1 = 42; 72 test("blsii", n1); 73 } 74 75 @Test 76 public void test4() { 77 long n1 = 420000000; 78 test("blsil", n1); 79 } 80 }