1 /* 2 * Copyright (c) 2016, 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 package compiler.intrinsics.bmi; 25 26 /* 27 * Verify that the C2 implementations of lzcnt return correct 28 * values. 29 * This class is extended to provide Integer and Long implementation 30 * tests. 31 * @see VerifyLzcntI.java and VerifyLzcntL.java 32 */ 33 abstract class VerifyLzcntBase<T extends Number> 34 { 35 protected static final int WARMUP_LOOPCOUNT = 10000000; 36 protected static final int TEST_LOOPCOUNT = 100000000; 37 38 protected long warmupLoopCount = WARMUP_LOOPCOUNT; 39 protected long testLoopCount = TEST_LOOPCOUNT; 40 41 protected int count = 0; 42 protected int expCount = 0; 43 44 protected static int expMax; 45 46 protected T testValue; 47 48 /** 49 * Create a new instance of VerifyLzcnt 50 **/ 51 protected VerifyLzcntBase() 52 { 53 } 54 55 public void setTestLoopCount(long loopCount) 56 { 57 if (loopCount > 0) { 58 this.testLoopCount = loopCount; 59 } 60 } 61 62 protected void testFail() 63 { 64 System.err.println("FAIL: test-value: " + valueToHexString() + 65 " expected: " + expCount + "; got: " + count); 66 } 67 68 protected abstract int getCount(); 69 protected abstract void initValue(); 70 protected abstract void nextValue(); 71 protected abstract String valueToHexString(); 72 73 public void runTest() 74 { 75 System.out.println("Test: " + toString()); 76 77 warmup(); 78 run(); 79 } 80 81 protected void warmup() 82 { 83 System.out.println("Warmup: " + warmupLoopCount + " iterations"); 84 85 initValue(); 86 87 for (int i=0; i<warmupLoopCount; i++) { 88 count = getCount(); 89 90 nextValue(); 91 } 92 } 93 94 protected void run() 95 { 96 System.out.println("Run: " + testLoopCount + " iterations"); 97 98 initValue(); 99 expCount = expMax; 100 101 for (int i = 0; i < testLoopCount; i++) { 102 count = getCount(); 103 104 if (count != expCount) { 105 testFail(); 106 System.exit(97); 107 } 108 109 nextValue(); 110 111 if (--expCount == -1) { 112 expCount = expMax; 113 } 114 } 115 } 116 117 public String toString() 118 { 119 return getClass().getName(); 120 } 121 }