Mercurial > hg > truffle
annotate test/compiler/6603011/Test.java @ 1322:21141e23627a
6923488: 4/4 need minor tweaks to HotSpot build for Cygwin
Summary: Clean up get_msc_ver, build.bat and build.make in general and for Cygwin.
Reviewed-by: ohair
author | dcubed |
---|---|
date | Tue, 16 Mar 2010 17:47:03 -0600 |
parents | bbef4344adb2 |
children | c18cbe5936b8 |
rev | line source |
---|---|
567
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
1 /* |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
2 * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
4 * |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
8 * |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
13 * accompanied this code). |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
14 * |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
18 * |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
21 * have any questions. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
22 */ |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
23 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
24 /** |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
25 * @test |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
26 * @bug 6603011 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
27 * @summary long/int division by constant |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
28 * |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
29 * @run main/othervm -Xcomp -Xbatch -XX:-Inline Test |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
30 */ |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
31 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
32 // |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
33 // -XX:-Inline is essential to this test so that verification functions |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
34 // divi, modi, divl and modl generate "plain" divides. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
35 // -Xcomp -Xbatch are also useful to ensure the full range of |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
36 // dividend and divisor combinations are tested |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
37 // |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
38 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
39 import java.net.*; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
40 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
41 class s { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
42 static int divi(int dividend, int divisor) { return dividend / divisor; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
43 static int modi(int dividend, int divisor) { return dividend % divisor; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
44 static long divl(long dividend, long divisor) { return dividend / divisor; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
45 static long modl(long dividend, long divisor) { return dividend % divisor; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
46 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
47 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
48 public class Test implements Runnable { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
49 // Report verbose messages on failure; turn off to suppress |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
50 // too much output with gross numbers of failures. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
51 static final boolean VERBOSE = true; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
52 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
53 // Initailize DIVISOR so that it is final in this class. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
54 static final int DIVISOR; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
55 static { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
56 int value = 0; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
57 try { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
58 value = Integer.decode(System.getProperty("divisor")); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
59 } catch (Throwable e) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
60 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
61 DIVISOR = value; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
62 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
63 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
64 // The methods of interest. We want the JIT to compile these |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
65 // and convert the divide into a multiply. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
66 public int divbyI (int dividend) { return dividend / DIVISOR; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
67 public int modbyI (int dividend) { return dividend % DIVISOR; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
68 public long divbyL (long dividend) { return dividend / DIVISOR; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
69 public long modbyL (long dividend) { return dividend % DIVISOR; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
70 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
71 public int divisor() { return DIVISOR; } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
72 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
73 public boolean checkI (int dividend) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
74 int quo = divbyI(dividend); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
75 int rem = modbyI(dividend); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
76 int quo0 = s.divi(dividend, divisor()); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
77 int rem0 = s.modi(dividend, divisor()); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
78 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
79 if (quo != quo0 || rem != rem0) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
80 if (VERBOSE) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
81 System.out.println("Computed: " + dividend + " / " + divisor() + " = " + |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
82 quo + ", " + dividend + " % " + divisor() + " = " + rem ); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
83 System.out.println("expected: " + dividend + " / " + divisor() + " = " + |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
84 quo0 + ", " + dividend + " % " + divisor() + " = " + rem0); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
85 // Report sign of rem failure |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
86 if (rem != 0 && (rem ^ dividend) < 0) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
87 System.out.println(" rem & dividend have different signs"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
88 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
89 // Report range of rem failure |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
90 if (java.lang.Math.abs(rem) >= java.lang.Math.abs(divisor())) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
91 System.out.println(" remainder out of range"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
92 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
93 // Report quo/rem identity relationship failure |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
94 if ((quo * divisor()) + rem != dividend) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
95 System.out.println(" quotien/remainder invariant broken"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
96 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
97 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
98 return false; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
99 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
100 return true; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
101 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
102 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
103 public boolean checkL (long dividend) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
104 long quo = divbyL(dividend); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
105 long rem = modbyL(dividend); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
106 long quo0 = s.divl(dividend, divisor()); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
107 long rem0 = s.modl(dividend, divisor()); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
108 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
109 if (quo != quo0 || rem != rem0) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
110 if (VERBOSE) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
111 System.out.println(" " + dividend + " / " + divisor() + " = " + |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
112 quo + ", " + dividend + " % " + divisor() + " = " + rem); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
113 // Report sign of rem failure |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
114 if (rem != 0 && (rem ^ dividend) < 0) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
115 System.out.println(" rem & dividend have different signs"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
116 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
117 // Report range of rem failure |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
118 if (java.lang.Math.abs(rem) >= java.lang.Math.abs(divisor())) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
119 System.out.println(" remainder out of range"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
120 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
121 // Report quo/rem identity relationship failure |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
122 if ((quo * divisor()) + rem != dividend) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
123 System.out.println(" (" + quo + " * " + divisor() + ") + " + rem + " != " |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
124 + dividend); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
125 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
126 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
127 return false; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
128 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
129 return true; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
130 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
131 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
132 public void run() { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
133 // Don't try to divide by zero |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
134 if (divisor() == 0) return; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
135 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
136 // Range of dividends to check. Try dividends from start to end |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
137 // inclusive, as well as variations on those values as shifted |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
138 // left. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
139 int start = -1024; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
140 int end = 1024; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
141 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
142 // Test int division using a variety of dividends. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
143 int wrong = 0; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
144 int total = 0; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
145 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
146 outerloop: |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
147 for (int i = start; i <= end; i++) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
148 for (int s = 0; s < 32; s += 4) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
149 total++; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
150 int dividend = i << s; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
151 if (!checkI(dividend)) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
152 wrong++; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
153 // Stop on the first failure |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
154 // break outerloop; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
155 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
156 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
157 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
158 if (wrong > 0) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
159 System.out.println("divisor " + divisor() + ": " + |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
160 wrong + "/" + total + " wrong int divisions"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
161 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
162 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
163 // Test long division using a variety of dividends. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
164 wrong = 0; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
165 total = 0; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
166 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
167 outerloop: |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
168 for (int i = start; i <= end; i++) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
169 for (int s = 0; s < 64; s += 4) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
170 total++; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
171 long dividend = i << s; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
172 if (!checkL(dividend)) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
173 wrong++; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
174 // Stop on the first failure |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
175 // break outerloop; |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
176 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
177 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
178 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
179 if (wrong > 0) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
180 System.out.println("divisor " + divisor() + ": " + |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
181 wrong + "/" + total + " wrong long divisions"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
182 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
183 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
184 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
185 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
186 // Reload this class with the "divisor" property set to the input parameter. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
187 // This allows the JIT to see q.DIVISOR as a final constant, and change |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
188 // any divisions or mod operations into multiplies. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
189 public static void test_divisor(int divisor, |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
190 URLClassLoader apploader) throws Exception { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
191 System.setProperty("divisor", "" + divisor); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
192 ClassLoader loader = new URLClassLoader(apploader.getURLs(), |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
193 apploader.getParent()); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
194 Class c = loader.loadClass("Test"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
195 Runnable r = (Runnable)c.newInstance(); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
196 r.run(); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
197 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
198 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
199 public static void main(String[] args) throws Exception { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
200 Class cl = Class.forName("Test"); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
201 URLClassLoader apploader = (URLClassLoader)cl.getClassLoader(); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
202 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
203 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
204 // Test every divisor between -100 and 100. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
205 for (int i = -100; i <= 100; i++) { |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
206 test_divisor(i, apploader); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
207 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
208 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
209 // Try a few divisors outside the typical range. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
210 // The values below have been observed in rt.jar. |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
211 test_divisor(101, apploader); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
212 test_divisor(400, apploader); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
213 test_divisor(1000, apploader); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
214 test_divisor(3600, apploader); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
215 test_divisor(9973, apploader); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
216 test_divisor(86400, apploader); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
217 test_divisor(1000000, apploader); |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
218 } |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
219 |
bbef4344adb2
6800154: Add comments to long_by_long_mulhi() for better understandability
twisti
parents:
diff
changeset
|
220 } |