Fri, 18 Oct 2013 10:41:56 +0200
8026844: Various Math functions needs intrinsification
Reviewed-by: kvn, twisti
1.1 --- a/src/cpu/sparc/vm/sparc.ad Wed Oct 23 16:25:48 2013 -0700 1.2 +++ b/src/cpu/sparc/vm/sparc.ad Fri Oct 18 10:41:56 2013 +0200 1.3 @@ -2022,6 +2022,10 @@ 1.4 return G1_REGI_mask(); 1.5 } 1.6 1.7 +const RegMask Matcher::mathExactL_result_proj_mask() { 1.8 + return G1_REGL_mask(); 1.9 +} 1.10 + 1.11 const RegMask Matcher::mathExactI_flags_proj_mask() { 1.12 return INT_FLAGS_mask(); 1.13 }
2.1 --- a/src/cpu/x86/vm/assembler_x86.cpp Wed Oct 23 16:25:48 2013 -0700 2.2 +++ b/src/cpu/x86/vm/assembler_x86.cpp Fri Oct 18 10:41:56 2013 +0200 2.3 @@ -1405,6 +1405,15 @@ 2.4 } 2.5 } 2.6 2.7 +void Assembler::imull(Register dst, Address src) { 2.8 + InstructionMark im(this); 2.9 + prefix(src, dst); 2.10 + emit_int8(0x0F); 2.11 + emit_int8((unsigned char) 0xAF); 2.12 + emit_operand(dst, src); 2.13 +} 2.14 + 2.15 + 2.16 void Assembler::incl(Address dst) { 2.17 // Don't use it directly. Use MacroAssembler::increment() instead. 2.18 InstructionMark im(this); 2.19 @@ -5024,6 +5033,14 @@ 2.20 } 2.21 } 2.22 2.23 +void Assembler::imulq(Register dst, Address src) { 2.24 + InstructionMark im(this); 2.25 + prefixq(src, dst); 2.26 + emit_int8(0x0F); 2.27 + emit_int8((unsigned char) 0xAF); 2.28 + emit_operand(dst, src); 2.29 +} 2.30 + 2.31 void Assembler::incl(Register dst) { 2.32 // Don't use it directly. Use MacroAssembler::incrementl() instead. 2.33 // Use two-byte form (one-byte from is a REX prefix in 64-bit mode)
3.1 --- a/src/cpu/x86/vm/assembler_x86.hpp Wed Oct 23 16:25:48 2013 -0700 3.2 +++ b/src/cpu/x86/vm/assembler_x86.hpp Fri Oct 18 10:41:56 2013 +0200 3.3 @@ -1162,9 +1162,13 @@ 3.4 3.5 void imull(Register dst, Register src); 3.6 void imull(Register dst, Register src, int value); 3.7 + void imull(Register dst, Address src); 3.8 3.9 void imulq(Register dst, Register src); 3.10 void imulq(Register dst, Register src, int value); 3.11 +#ifdef _LP64 3.12 + void imulq(Register dst, Address src); 3.13 +#endif 3.14 3.15 3.16 // jcc is the generic conditional branch generator to run-
4.1 --- a/src/cpu/x86/vm/x86_32.ad Wed Oct 23 16:25:48 2013 -0700 4.2 +++ b/src/cpu/x86/vm/x86_32.ad Fri Oct 18 10:41:56 2013 +0200 4.3 @@ -1538,6 +1538,11 @@ 4.4 return EAX_REG_mask(); 4.5 } 4.6 4.7 +const RegMask Matcher::mathExactL_result_proj_mask() { 4.8 + ShouldNotReachHere(); 4.9 + return RegMask(); 4.10 +} 4.11 + 4.12 const RegMask Matcher::mathExactI_flags_proj_mask() { 4.13 return INT_FLAGS_mask(); 4.14 } 4.15 @@ -7519,7 +7524,7 @@ 4.16 //----------Arithmetic Instructions-------------------------------------------- 4.17 //----------Addition Instructions---------------------------------------------- 4.18 4.19 -instruct addExactI_rReg(eAXRegI dst, rRegI src, eFlagsReg cr) 4.20 +instruct addExactI_eReg(eAXRegI dst, rRegI src, eFlagsReg cr) 4.21 %{ 4.22 match(AddExactI dst src); 4.23 effect(DEF cr); 4.24 @@ -7531,7 +7536,7 @@ 4.25 ins_pipe(ialu_reg_reg); 4.26 %} 4.27 4.28 -instruct addExactI_rReg_imm(eAXRegI dst, immI src, eFlagsReg cr) 4.29 +instruct addExactI_eReg_imm(eAXRegI dst, immI src, eFlagsReg cr) 4.30 %{ 4.31 match(AddExactI dst src); 4.32 effect(DEF cr); 4.33 @@ -7543,6 +7548,20 @@ 4.34 ins_pipe(ialu_reg_reg); 4.35 %} 4.36 4.37 +instruct addExactI_eReg_mem(eAXRegI dst, memory src, eFlagsReg cr) 4.38 +%{ 4.39 + match(AddExactI dst (LoadI src)); 4.40 + effect(DEF cr); 4.41 + 4.42 + ins_cost(125); 4.43 + format %{ "ADD $dst,$src\t# addExact int" %} 4.44 + ins_encode %{ 4.45 + __ addl($dst$$Register, $src$$Address); 4.46 + %} 4.47 + ins_pipe( ialu_reg_mem ); 4.48 +%} 4.49 + 4.50 + 4.51 // Integer Addition Instructions 4.52 instruct addI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{ 4.53 match(Set dst (AddI dst src)); 4.54 @@ -7851,6 +7870,44 @@ 4.55 %} 4.56 4.57 //----------Subtraction Instructions------------------------------------------- 4.58 + 4.59 +instruct subExactI_eReg(eAXRegI dst, rRegI src, eFlagsReg cr) 4.60 +%{ 4.61 + match(SubExactI dst src); 4.62 + effect(DEF cr); 4.63 + 4.64 + format %{ "SUB $dst, $src\t# subExact int" %} 4.65 + ins_encode %{ 4.66 + __ subl($dst$$Register, $src$$Register); 4.67 + %} 4.68 + ins_pipe(ialu_reg_reg); 4.69 +%} 4.70 + 4.71 +instruct subExactI_eReg_imm(eAXRegI dst, immI src, eFlagsReg cr) 4.72 +%{ 4.73 + match(SubExactI dst src); 4.74 + effect(DEF cr); 4.75 + 4.76 + format %{ "SUB $dst, $src\t# subExact int" %} 4.77 + ins_encode %{ 4.78 + __ subl($dst$$Register, $src$$constant); 4.79 + %} 4.80 + ins_pipe(ialu_reg_reg); 4.81 +%} 4.82 + 4.83 +instruct subExactI_eReg_mem(eAXRegI dst, memory src, eFlagsReg cr) 4.84 +%{ 4.85 + match(SubExactI dst (LoadI src)); 4.86 + effect(DEF cr); 4.87 + 4.88 + ins_cost(125); 4.89 + format %{ "SUB $dst,$src\t# subExact int" %} 4.90 + ins_encode %{ 4.91 + __ subl($dst$$Register, $src$$Address); 4.92 + %} 4.93 + ins_pipe( ialu_reg_mem ); 4.94 +%} 4.95 + 4.96 // Integer Subtraction Instructions 4.97 instruct subI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{ 4.98 match(Set dst (SubI dst src)); 4.99 @@ -7919,6 +7976,16 @@ 4.100 ins_pipe( ialu_reg ); 4.101 %} 4.102 4.103 +instruct negExactI_eReg(eAXRegI dst, eFlagsReg cr) %{ 4.104 + match(NegExactI dst); 4.105 + effect(DEF cr); 4.106 + 4.107 + format %{ "NEG $dst\t# negExact int"%} 4.108 + ins_encode %{ 4.109 + __ negl($dst$$Register); 4.110 + %} 4.111 + ins_pipe(ialu_reg); 4.112 +%} 4.113 4.114 //----------Multiplication/Division Instructions------------------------------- 4.115 // Integer Multiplication Instructions 4.116 @@ -8131,6 +8198,46 @@ 4.117 ins_pipe( pipe_slow ); 4.118 %} 4.119 4.120 +instruct mulExactI_eReg(eAXRegI dst, rRegI src, eFlagsReg cr) 4.121 +%{ 4.122 + match(MulExactI dst src); 4.123 + effect(DEF cr); 4.124 + 4.125 + ins_cost(300); 4.126 + format %{ "IMUL $dst, $src\t# mulExact int" %} 4.127 + ins_encode %{ 4.128 + __ imull($dst$$Register, $src$$Register); 4.129 + %} 4.130 + ins_pipe(ialu_reg_reg_alu0); 4.131 +%} 4.132 + 4.133 +instruct mulExactI_eReg_imm(eAXRegI dst, rRegI src, immI imm, eFlagsReg cr) 4.134 +%{ 4.135 + match(MulExactI src imm); 4.136 + effect(DEF cr); 4.137 + 4.138 + ins_cost(300); 4.139 + format %{ "IMUL $dst, $src, $imm\t# mulExact int" %} 4.140 + ins_encode %{ 4.141 + __ imull($dst$$Register, $src$$Register, $imm$$constant); 4.142 + %} 4.143 + ins_pipe(ialu_reg_reg_alu0); 4.144 +%} 4.145 + 4.146 +instruct mulExactI_eReg_mem(eAXRegI dst, memory src, eFlagsReg cr) 4.147 +%{ 4.148 + match(MulExactI dst (LoadI src)); 4.149 + effect(DEF cr); 4.150 + 4.151 + ins_cost(350); 4.152 + format %{ "IMUL $dst, $src\t# mulExact int" %} 4.153 + ins_encode %{ 4.154 + __ imull($dst$$Register, $src$$Address); 4.155 + %} 4.156 + ins_pipe(ialu_reg_mem_alu0); 4.157 +%} 4.158 + 4.159 + 4.160 // Integer DIV with Register 4.161 instruct divI_eReg(eAXRegI rax, eDXRegI rdx, eCXRegI div, eFlagsReg cr) %{ 4.162 match(Set rax (DivI rax div));
5.1 --- a/src/cpu/x86/vm/x86_64.ad Wed Oct 23 16:25:48 2013 -0700 5.2 +++ b/src/cpu/x86/vm/x86_64.ad Fri Oct 18 10:41:56 2013 +0200 5.3 @@ -1653,6 +1653,10 @@ 5.4 return INT_RAX_REG_mask(); 5.5 } 5.6 5.7 +const RegMask Matcher::mathExactL_result_proj_mask() { 5.8 + return LONG_RAX_REG_mask(); 5.9 +} 5.10 + 5.11 const RegMask Matcher::mathExactI_flags_proj_mask() { 5.12 return INT_FLAGS_mask(); 5.13 } 5.14 @@ -6962,6 +6966,58 @@ 5.15 ins_pipe(ialu_reg_reg); 5.16 %} 5.17 5.18 +instruct addExactI_rReg_mem(rax_RegI dst, memory src, rFlagsReg cr) 5.19 +%{ 5.20 + match(AddExactI dst (LoadI src)); 5.21 + effect(DEF cr); 5.22 + 5.23 + ins_cost(125); // XXX 5.24 + format %{ "addl $dst, $src\t# addExact int" %} 5.25 + ins_encode %{ 5.26 + __ addl($dst$$Register, $src$$Address); 5.27 + %} 5.28 + 5.29 + ins_pipe(ialu_reg_mem); 5.30 +%} 5.31 + 5.32 +instruct addExactL_rReg(rax_RegL dst, rRegL src, rFlagsReg cr) 5.33 +%{ 5.34 + match(AddExactL dst src); 5.35 + effect(DEF cr); 5.36 + 5.37 + format %{ "addq $dst, $src\t# addExact long" %} 5.38 + ins_encode %{ 5.39 + __ addq($dst$$Register, $src$$Register); 5.40 + %} 5.41 + ins_pipe(ialu_reg_reg); 5.42 +%} 5.43 + 5.44 +instruct addExactL_rReg_imm(rax_RegL dst, immL32 src, rFlagsReg cr) 5.45 +%{ 5.46 + match(AddExactL dst src); 5.47 + effect(DEF cr); 5.48 + 5.49 + format %{ "addq $dst, $src\t# addExact long" %} 5.50 + ins_encode %{ 5.51 + __ addq($dst$$Register, $src$$constant); 5.52 + %} 5.53 + ins_pipe(ialu_reg_reg); 5.54 +%} 5.55 + 5.56 +instruct addExactL_rReg_mem(rax_RegL dst, memory src, rFlagsReg cr) 5.57 +%{ 5.58 + match(AddExactL dst (LoadL src)); 5.59 + effect(DEF cr); 5.60 + 5.61 + ins_cost(125); // XXX 5.62 + format %{ "addq $dst, $src\t# addExact long" %} 5.63 + ins_encode %{ 5.64 + __ addq($dst$$Register, $src$$Address); 5.65 + %} 5.66 + 5.67 + ins_pipe(ialu_reg_mem); 5.68 +%} 5.69 + 5.70 instruct addI_rReg(rRegI dst, rRegI src, rFlagsReg cr) 5.71 %{ 5.72 match(Set dst (AddI dst src)); 5.73 @@ -7574,6 +7630,80 @@ 5.74 ins_pipe(ialu_mem_imm); 5.75 %} 5.76 5.77 +instruct subExactI_rReg(rax_RegI dst, rRegI src, rFlagsReg cr) 5.78 +%{ 5.79 + match(SubExactI dst src); 5.80 + effect(DEF cr); 5.81 + 5.82 + format %{ "subl $dst, $src\t# subExact int" %} 5.83 + ins_encode %{ 5.84 + __ subl($dst$$Register, $src$$Register); 5.85 + %} 5.86 + ins_pipe(ialu_reg_reg); 5.87 +%} 5.88 + 5.89 +instruct subExactI_rReg_imm(rax_RegI dst, immI src, rFlagsReg cr) 5.90 +%{ 5.91 + match(SubExactI dst src); 5.92 + effect(DEF cr); 5.93 + 5.94 + format %{ "subl $dst, $src\t# subExact int" %} 5.95 + ins_encode %{ 5.96 + __ subl($dst$$Register, $src$$constant); 5.97 + %} 5.98 + ins_pipe(ialu_reg_reg); 5.99 +%} 5.100 + 5.101 +instruct subExactI_rReg_mem(rax_RegI dst, memory src, rFlagsReg cr) 5.102 +%{ 5.103 + match(SubExactI dst (LoadI src)); 5.104 + effect(DEF cr); 5.105 + 5.106 + ins_cost(125); 5.107 + format %{ "subl $dst, $src\t# subExact int" %} 5.108 + ins_encode %{ 5.109 + __ subl($dst$$Register, $src$$Address); 5.110 + %} 5.111 + ins_pipe(ialu_reg_mem); 5.112 +%} 5.113 + 5.114 +instruct subExactL_rReg(rax_RegL dst, rRegL src, rFlagsReg cr) 5.115 +%{ 5.116 + match(SubExactL dst src); 5.117 + effect(DEF cr); 5.118 + 5.119 + format %{ "subq $dst, $src\t# subExact long" %} 5.120 + ins_encode %{ 5.121 + __ subq($dst$$Register, $src$$Register); 5.122 + %} 5.123 + ins_pipe(ialu_reg_reg); 5.124 +%} 5.125 + 5.126 +instruct subExactL_rReg_imm(rax_RegL dst, immL32 src, rFlagsReg cr) 5.127 +%{ 5.128 + match(SubExactL dst (LoadL src)); 5.129 + effect(DEF cr); 5.130 + 5.131 + format %{ "subq $dst, $src\t# subExact long" %} 5.132 + ins_encode %{ 5.133 + __ subq($dst$$Register, $src$$constant); 5.134 + %} 5.135 + ins_pipe(ialu_reg_reg); 5.136 +%} 5.137 + 5.138 +instruct subExactL_rReg_mem(rax_RegI dst, memory src, rFlagsReg cr) 5.139 +%{ 5.140 + match(SubExactI dst src); 5.141 + effect(DEF cr); 5.142 + 5.143 + ins_cost(125); 5.144 + format %{ "subq $dst, $src\t# subExact long" %} 5.145 + ins_encode %{ 5.146 + __ subq($dst$$Register, $src$$Address); 5.147 + %} 5.148 + ins_pipe(ialu_reg_mem); 5.149 +%} 5.150 + 5.151 instruct subL_rReg(rRegL dst, rRegL src, rFlagsReg cr) 5.152 %{ 5.153 match(Set dst (SubL dst src)); 5.154 @@ -7690,6 +7820,30 @@ 5.155 ins_pipe(ialu_reg); 5.156 %} 5.157 5.158 +instruct negExactI_rReg(rax_RegI dst, rFlagsReg cr) 5.159 +%{ 5.160 + match(NegExactI dst); 5.161 + effect(KILL cr); 5.162 + 5.163 + format %{ "negl $dst\t# negExact int" %} 5.164 + ins_encode %{ 5.165 + __ negl($dst$$Register); 5.166 + %} 5.167 + ins_pipe(ialu_reg); 5.168 +%} 5.169 + 5.170 +instruct negExactL_rReg(rax_RegL dst, rFlagsReg cr) 5.171 +%{ 5.172 + match(NegExactL dst); 5.173 + effect(KILL cr); 5.174 + 5.175 + format %{ "negq $dst\t# negExact long" %} 5.176 + ins_encode %{ 5.177 + __ negq($dst$$Register); 5.178 + %} 5.179 + ins_pipe(ialu_reg); 5.180 +%} 5.181 + 5.182 5.183 //----------Multiplication/Division Instructions------------------------------- 5.184 // Integer Multiplication Instructions 5.185 @@ -7807,6 +7961,86 @@ 5.186 ins_pipe(ialu_reg_reg_alu0); 5.187 %} 5.188 5.189 + 5.190 +instruct mulExactI_rReg(rax_RegI dst, rRegI src, rFlagsReg cr) 5.191 +%{ 5.192 + match(MulExactI dst src); 5.193 + effect(DEF cr); 5.194 + 5.195 + ins_cost(300); 5.196 + format %{ "imull $dst, $src\t# mulExact int" %} 5.197 + ins_encode %{ 5.198 + __ imull($dst$$Register, $src$$Register); 5.199 + %} 5.200 + ins_pipe(ialu_reg_reg_alu0); 5.201 +%} 5.202 + 5.203 + 5.204 +instruct mulExactI_rReg_imm(rax_RegI dst, rRegI src, immI imm, rFlagsReg cr) 5.205 +%{ 5.206 + match(MulExactI src imm); 5.207 + effect(DEF cr); 5.208 + 5.209 + ins_cost(300); 5.210 + format %{ "imull $dst, $src, $imm\t# mulExact int" %} 5.211 + ins_encode %{ 5.212 + __ imull($dst$$Register, $src$$Register, $imm$$constant); 5.213 + %} 5.214 + ins_pipe(ialu_reg_reg_alu0); 5.215 +%} 5.216 + 5.217 +instruct mulExactI_rReg_mem(rax_RegI dst, memory src, rFlagsReg cr) 5.218 +%{ 5.219 + match(MulExactI dst (LoadI src)); 5.220 + effect(DEF cr); 5.221 + 5.222 + ins_cost(350); 5.223 + format %{ "imull $dst, $src\t# mulExact int" %} 5.224 + ins_encode %{ 5.225 + __ imull($dst$$Register, $src$$Address); 5.226 + %} 5.227 + ins_pipe(ialu_reg_mem_alu0); 5.228 +%} 5.229 + 5.230 +instruct mulExactL_rReg(rax_RegL dst, rRegL src, rFlagsReg cr) 5.231 +%{ 5.232 + match(MulExactL dst src); 5.233 + effect(DEF cr); 5.234 + 5.235 + ins_cost(300); 5.236 + format %{ "imulq $dst, $src\t# mulExact long" %} 5.237 + ins_encode %{ 5.238 + __ imulq($dst$$Register, $src$$Register); 5.239 + %} 5.240 + ins_pipe(ialu_reg_reg_alu0); 5.241 +%} 5.242 + 5.243 +instruct mulExactL_rReg_imm(rax_RegL dst, rRegL src, immL32 imm, rFlagsReg cr) 5.244 +%{ 5.245 + match(MulExactL src imm); 5.246 + effect(DEF cr); 5.247 + 5.248 + ins_cost(300); 5.249 + format %{ "imulq $dst, $src, $imm\t# mulExact long" %} 5.250 + ins_encode %{ 5.251 + __ imulq($dst$$Register, $src$$Register, $imm$$constant); 5.252 + %} 5.253 + ins_pipe(ialu_reg_reg_alu0); 5.254 +%} 5.255 + 5.256 +instruct mulExactL_rReg_mem(rax_RegL dst, memory src, rFlagsReg cr) 5.257 +%{ 5.258 + match(MulExactL dst (LoadL src)); 5.259 + effect(DEF cr); 5.260 + 5.261 + ins_cost(350); 5.262 + format %{ "imulq $dst, $src\t# mulExact long" %} 5.263 + ins_encode %{ 5.264 + __ imulq($dst$$Register, $src$$Address); 5.265 + %} 5.266 + ins_pipe(ialu_reg_mem_alu0); 5.267 +%} 5.268 + 5.269 instruct divI_rReg(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div, 5.270 rFlagsReg cr) 5.271 %{
6.1 --- a/src/share/vm/adlc/archDesc.cpp Wed Oct 23 16:25:48 2013 -0700 6.2 +++ b/src/share/vm/adlc/archDesc.cpp Fri Oct 18 10:41:56 2013 +0200 6.3 @@ -1193,6 +1193,13 @@ 6.4 || strcmp(idealName,"FastLock") == 0 6.5 || strcmp(idealName,"FastUnlock") == 0 6.6 || strcmp(idealName,"AddExactI") == 0 6.7 + || strcmp(idealName,"AddExactL") == 0 6.8 + || strcmp(idealName,"SubExactI") == 0 6.9 + || strcmp(idealName,"SubExactL") == 0 6.10 + || strcmp(idealName,"MulExactI") == 0 6.11 + || strcmp(idealName,"MulExactL") == 0 6.12 + || strcmp(idealName,"NegExactI") == 0 6.13 + || strcmp(idealName,"NegExactL") == 0 6.14 || strcmp(idealName,"FlagsProj") == 0 6.15 || strcmp(idealName,"Bool") == 0 6.16 || strcmp(idealName,"Binary") == 0 ) {
7.1 --- a/src/share/vm/classfile/vmSymbols.hpp Wed Oct 23 16:25:48 2013 -0700 7.2 +++ b/src/share/vm/classfile/vmSymbols.hpp Fri Oct 18 10:41:56 2013 +0200 7.3 @@ -624,6 +624,7 @@ 7.4 do_class(java_lang_StrictMath, "java/lang/StrictMath") \ 7.5 do_signature(double2_double_signature, "(DD)D") \ 7.6 do_signature(int2_int_signature, "(II)I") \ 7.7 + do_signature(long2_long_signature, "(JJ)J") \ 7.8 \ 7.9 /* here are the math names, all together: */ \ 7.10 do_name(abs_name,"abs") do_name(sin_name,"sin") do_name(cos_name,"cos") \ 7.11 @@ -632,8 +633,11 @@ 7.12 do_name(exp_name,"exp") do_name(min_name,"min") do_name(max_name,"max") \ 7.13 \ 7.14 do_name(addExact_name,"addExact") \ 7.15 + do_name(decrementExact_name,"decrementExact") \ 7.16 + do_name(incrementExact_name,"incrementExact") \ 7.17 + do_name(multiplyExact_name,"multiplyExact") \ 7.18 + do_name(negateExact_name,"negateExact") \ 7.19 do_name(subtractExact_name,"subtractExact") \ 7.20 - do_name(multiplyExact_name,"multiplyExact") \ 7.21 \ 7.22 do_intrinsic(_dabs, java_lang_Math, abs_name, double_double_signature, F_S) \ 7.23 do_intrinsic(_dsin, java_lang_Math, sin_name, double_double_signature, F_S) \ 7.24 @@ -647,7 +651,18 @@ 7.25 do_intrinsic(_dexp, java_lang_Math, exp_name, double_double_signature, F_S) \ 7.26 do_intrinsic(_min, java_lang_Math, min_name, int2_int_signature, F_S) \ 7.27 do_intrinsic(_max, java_lang_Math, max_name, int2_int_signature, F_S) \ 7.28 - do_intrinsic(_addExact, java_lang_Math, addExact_name, int2_int_signature, F_S) \ 7.29 + do_intrinsic(_addExactI, java_lang_Math, addExact_name, int2_int_signature, F_S) \ 7.30 + do_intrinsic(_addExactL, java_lang_Math, addExact_name, long2_long_signature, F_S) \ 7.31 + do_intrinsic(_decrementExactI, java_lang_Math, decrementExact_name, int_int_signature, F_S) \ 7.32 + do_intrinsic(_decrementExactL, java_lang_Math, decrementExact_name, long2_long_signature, F_S) \ 7.33 + do_intrinsic(_incrementExactI, java_lang_Math, incrementExact_name, int_int_signature, F_S) \ 7.34 + do_intrinsic(_incrementExactL, java_lang_Math, incrementExact_name, long2_long_signature, F_S) \ 7.35 + do_intrinsic(_multiplyExactI, java_lang_Math, multiplyExact_name, int2_int_signature, F_S) \ 7.36 + do_intrinsic(_multiplyExactL, java_lang_Math, multiplyExact_name, long2_long_signature, F_S) \ 7.37 + do_intrinsic(_negateExactI, java_lang_Math, negateExact_name, int_int_signature, F_S) \ 7.38 + do_intrinsic(_negateExactL, java_lang_Math, negateExact_name, long_long_signature, F_S) \ 7.39 + do_intrinsic(_subtractExactI, java_lang_Math, subtractExact_name, int2_int_signature, F_S) \ 7.40 + do_intrinsic(_subtractExactL, java_lang_Math, subtractExact_name, long2_long_signature, F_S) \ 7.41 \ 7.42 do_intrinsic(_floatToRawIntBits, java_lang_Float, floatToRawIntBits_name, float_int_signature, F_S) \ 7.43 do_name( floatToRawIntBits_name, "floatToRawIntBits") \
8.1 --- a/src/share/vm/opto/classes.hpp Wed Oct 23 16:25:48 2013 -0700 8.2 +++ b/src/share/vm/opto/classes.hpp Fri Oct 18 10:41:56 2013 +0200 8.3 @@ -30,6 +30,7 @@ 8.4 macro(AbsI) 8.5 macro(AddD) 8.6 macro(AddExactI) 8.7 +macro(AddExactL) 8.8 macro(AddF) 8.9 macro(AddI) 8.10 macro(AddL) 8.11 @@ -170,6 +171,8 @@ 8.12 macro(Mach) 8.13 macro(MachProj) 8.14 macro(MathExact) 8.15 +macro(MathExactI) 8.16 +macro(MathExactL) 8.17 macro(MaxI) 8.18 macro(MemBarAcquire) 8.19 macro(MemBarAcquireLock) 8.20 @@ -189,12 +192,16 @@ 8.21 macro(MoveL2D) 8.22 macro(MoveD2L) 8.23 macro(MulD) 8.24 +macro(MulExactI) 8.25 +macro(MulExactL) 8.26 macro(MulF) 8.27 macro(MulHiL) 8.28 macro(MulI) 8.29 macro(MulL) 8.30 macro(Multi) 8.31 macro(NegD) 8.32 +macro(NegExactI) 8.33 +macro(NegExactL) 8.34 macro(NegF) 8.35 macro(NeverBranch) 8.36 macro(Opaque1) 8.37 @@ -244,6 +251,8 @@ 8.38 macro(StrEquals) 8.39 macro(StrIndexOf) 8.40 macro(SubD) 8.41 +macro(SubExactI) 8.42 +macro(SubExactL) 8.43 macro(SubF) 8.44 macro(SubI) 8.45 macro(SubL)
9.1 --- a/src/share/vm/opto/library_call.cpp Wed Oct 23 16:25:48 2013 -0700 9.2 +++ b/src/share/vm/opto/library_call.cpp Fri Oct 18 10:41:56 2013 +0200 9.3 @@ -203,8 +203,15 @@ 9.4 bool inline_math_native(vmIntrinsics::ID id); 9.5 bool inline_trig(vmIntrinsics::ID id); 9.6 bool inline_math(vmIntrinsics::ID id); 9.7 - bool inline_math_mathExact(Node* math); 9.8 - bool inline_math_addExact(); 9.9 + void inline_math_mathExact(Node* math); 9.10 + bool inline_math_addExactI(bool is_increment); 9.11 + bool inline_math_addExactL(bool is_increment); 9.12 + bool inline_math_multiplyExactI(); 9.13 + bool inline_math_multiplyExactL(); 9.14 + bool inline_math_negateExactI(); 9.15 + bool inline_math_negateExactL(); 9.16 + bool inline_math_subtractExactI(bool is_decrement); 9.17 + bool inline_math_subtractExactL(bool is_decrement); 9.18 bool inline_exp(); 9.19 bool inline_pow(); 9.20 void finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName); 9.21 @@ -507,13 +514,33 @@ 9.22 if (!UseCRC32Intrinsics) return NULL; 9.23 break; 9.24 9.25 - case vmIntrinsics::_addExact: 9.26 - if (!Matcher::match_rule_supported(Op_AddExactI)) { 9.27 - return NULL; 9.28 - } 9.29 - if (!UseMathExactIntrinsics) { 9.30 - return NULL; 9.31 - } 9.32 + case vmIntrinsics::_incrementExactI: 9.33 + case vmIntrinsics::_addExactI: 9.34 + if (!Matcher::match_rule_supported(Op_AddExactI) || !UseMathExactIntrinsics) return NULL; 9.35 + break; 9.36 + case vmIntrinsics::_incrementExactL: 9.37 + case vmIntrinsics::_addExactL: 9.38 + if (!Matcher::match_rule_supported(Op_AddExactL) || !UseMathExactIntrinsics) return NULL; 9.39 + break; 9.40 + case vmIntrinsics::_decrementExactI: 9.41 + case vmIntrinsics::_subtractExactI: 9.42 + if (!Matcher::match_rule_supported(Op_SubExactI) || !UseMathExactIntrinsics) return NULL; 9.43 + break; 9.44 + case vmIntrinsics::_decrementExactL: 9.45 + case vmIntrinsics::_subtractExactL: 9.46 + if (!Matcher::match_rule_supported(Op_SubExactL) || !UseMathExactIntrinsics) return NULL; 9.47 + break; 9.48 + case vmIntrinsics::_negateExactI: 9.49 + if (!Matcher::match_rule_supported(Op_NegExactI) || !UseMathExactIntrinsics) return NULL; 9.50 + break; 9.51 + case vmIntrinsics::_negateExactL: 9.52 + if (!Matcher::match_rule_supported(Op_NegExactL) || !UseMathExactIntrinsics) return NULL; 9.53 + break; 9.54 + case vmIntrinsics::_multiplyExactI: 9.55 + if (!Matcher::match_rule_supported(Op_MulExactI) || !UseMathExactIntrinsics) return NULL; 9.56 + break; 9.57 + case vmIntrinsics::_multiplyExactL: 9.58 + if (!Matcher::match_rule_supported(Op_MulExactL) || !UseMathExactIntrinsics) return NULL; 9.59 break; 9.60 9.61 default: 9.62 @@ -686,7 +713,18 @@ 9.63 case vmIntrinsics::_min: 9.64 case vmIntrinsics::_max: return inline_min_max(intrinsic_id()); 9.65 9.66 - case vmIntrinsics::_addExact: return inline_math_addExact(); 9.67 + case vmIntrinsics::_addExactI: return inline_math_addExactI(false /* add */); 9.68 + case vmIntrinsics::_addExactL: return inline_math_addExactL(false /* add */); 9.69 + case vmIntrinsics::_decrementExactI: return inline_math_subtractExactI(true /* decrement */); 9.70 + case vmIntrinsics::_decrementExactL: return inline_math_subtractExactL(true /* decrement */); 9.71 + case vmIntrinsics::_incrementExactI: return inline_math_addExactI(true /* increment */); 9.72 + case vmIntrinsics::_incrementExactL: return inline_math_addExactL(true /* increment */); 9.73 + case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI(); 9.74 + case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL(); 9.75 + case vmIntrinsics::_negateExactI: return inline_math_negateExactI(); 9.76 + case vmIntrinsics::_negateExactL: return inline_math_negateExactL(); 9.77 + case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */); 9.78 + case vmIntrinsics::_subtractExactL: return inline_math_subtractExactL(false /* subtract */); 9.79 9.80 case vmIntrinsics::_arraycopy: return inline_arraycopy(); 9.81 9.82 @@ -1931,7 +1969,14 @@ 9.83 return true; 9.84 } 9.85 9.86 -bool LibraryCallKit::inline_math_mathExact(Node* math) { 9.87 +void LibraryCallKit::inline_math_mathExact(Node* math) { 9.88 + // If we didn't get the expected opcode it means we have optimized 9.89 + // the node to something else and don't need the exception edge. 9.90 + if (!math->is_MathExact()) { 9.91 + set_result(math); 9.92 + return; 9.93 + } 9.94 + 9.95 Node* result = _gvn.transform( new(C) ProjNode(math, MathExactNode::result_proj_node)); 9.96 Node* flags = _gvn.transform( new(C) FlagsProjNode(math, MathExactNode::flags_proj_node)); 9.97 9.98 @@ -1954,19 +1999,106 @@ 9.99 9.100 set_control(fast_path); 9.101 set_result(result); 9.102 +} 9.103 + 9.104 +bool LibraryCallKit::inline_math_addExactI(bool is_increment) { 9.105 + Node* arg1 = argument(0); 9.106 + Node* arg2 = NULL; 9.107 + 9.108 + if (is_increment) { 9.109 + arg2 = intcon(1); 9.110 + } else { 9.111 + arg2 = argument(1); 9.112 + } 9.113 + 9.114 + Node* add = _gvn.transform( new(C) AddExactINode(NULL, arg1, arg2) ); 9.115 + inline_math_mathExact(add); 9.116 return true; 9.117 } 9.118 9.119 -bool LibraryCallKit::inline_math_addExact() { 9.120 +bool LibraryCallKit::inline_math_addExactL(bool is_increment) { 9.121 + Node* arg1 = argument(0); // type long 9.122 + // argument(1) == TOP 9.123 + Node* arg2 = NULL; 9.124 + 9.125 + if (is_increment) { 9.126 + arg2 = longcon(1); 9.127 + } else { 9.128 + arg2 = argument(2); // type long 9.129 + // argument(3) == TOP 9.130 + } 9.131 + 9.132 + Node* add = _gvn.transform(new(C) AddExactLNode(NULL, arg1, arg2)); 9.133 + inline_math_mathExact(add); 9.134 + return true; 9.135 +} 9.136 + 9.137 +bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) { 9.138 + Node* arg1 = argument(0); 9.139 + Node* arg2 = NULL; 9.140 + 9.141 + if (is_decrement) { 9.142 + arg2 = intcon(1); 9.143 + } else { 9.144 + arg2 = argument(1); 9.145 + } 9.146 + 9.147 + Node* sub = _gvn.transform(new(C) SubExactINode(NULL, arg1, arg2)); 9.148 + inline_math_mathExact(sub); 9.149 + return true; 9.150 +} 9.151 + 9.152 +bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) { 9.153 + Node* arg1 = argument(0); // type long 9.154 + // argument(1) == TOP 9.155 + Node* arg2 = NULL; 9.156 + 9.157 + if (is_decrement) { 9.158 + arg2 = longcon(1); 9.159 + } else { 9.160 + Node* arg2 = argument(2); // type long 9.161 + // argument(3) == TOP 9.162 + } 9.163 + 9.164 + Node* sub = _gvn.transform(new(C) SubExactLNode(NULL, arg1, arg2)); 9.165 + inline_math_mathExact(sub); 9.166 + return true; 9.167 +} 9.168 + 9.169 +bool LibraryCallKit::inline_math_negateExactI() { 9.170 + Node* arg1 = argument(0); 9.171 + 9.172 + Node* neg = _gvn.transform(new(C) NegExactINode(NULL, arg1)); 9.173 + inline_math_mathExact(neg); 9.174 + return true; 9.175 +} 9.176 + 9.177 +bool LibraryCallKit::inline_math_negateExactL() { 9.178 + Node* arg1 = argument(0); 9.179 + // argument(1) == TOP 9.180 + 9.181 + Node* neg = _gvn.transform(new(C) NegExactLNode(NULL, arg1)); 9.182 + inline_math_mathExact(neg); 9.183 + return true; 9.184 +} 9.185 + 9.186 +bool LibraryCallKit::inline_math_multiplyExactI() { 9.187 Node* arg1 = argument(0); 9.188 Node* arg2 = argument(1); 9.189 9.190 - Node* add = _gvn.transform( new(C) AddExactINode(NULL, arg1, arg2) ); 9.191 - if (add->Opcode() == Op_AddExactI) { 9.192 - return inline_math_mathExact(add); 9.193 - } else { 9.194 - set_result(add); 9.195 - } 9.196 + Node* mul = _gvn.transform(new(C) MulExactINode(NULL, arg1, arg2)); 9.197 + inline_math_mathExact(mul); 9.198 + return true; 9.199 +} 9.200 + 9.201 +bool LibraryCallKit::inline_math_multiplyExactL() { 9.202 + Node* arg1 = argument(0); 9.203 + // argument(1) == TOP 9.204 + Node* arg2 = argument(2); 9.205 + // argument(3) == TOP 9.206 + 9.207 + Node* mul = _gvn.transform(new(C) MulExactLNode(NULL, arg1, arg2)); 9.208 + inline_math_mathExact(mul); 9.209 return true; 9.210 } 9.211
10.1 --- a/src/share/vm/opto/matcher.hpp Wed Oct 23 16:25:48 2013 -0700 10.2 +++ b/src/share/vm/opto/matcher.hpp Fri Oct 18 10:41:56 2013 +0200 10.3 @@ -338,6 +338,7 @@ 10.4 static RegMask modL_proj_mask(); 10.5 10.6 static const RegMask mathExactI_result_proj_mask(); 10.7 + static const RegMask mathExactL_result_proj_mask(); 10.8 static const RegMask mathExactI_flags_proj_mask(); 10.9 10.10 // Use hardware DIV instruction when it is faster than
11.1 --- a/src/share/vm/opto/mathexactnode.cpp Wed Oct 23 16:25:48 2013 -0700 11.2 +++ b/src/share/vm/opto/mathexactnode.cpp Fri Oct 18 10:41:56 2013 +0200 11.3 @@ -31,10 +31,17 @@ 11.4 #include "opto/mathexactnode.hpp" 11.5 #include "opto/subnode.hpp" 11.6 11.7 -MathExactNode::MathExactNode(Node* ctrl, Node* n1, Node* n2) : MultiNode(3) { 11.8 +MathExactNode::MathExactNode(Node* ctrl, Node* in1) : MultiNode(2) { 11.9 + init_class_id(Class_MathExact); 11.10 init_req(0, ctrl); 11.11 - init_req(1, n1); 11.12 - init_req(2, n2); 11.13 + init_req(1, in1); 11.14 +} 11.15 + 11.16 +MathExactNode::MathExactNode(Node* ctrl, Node* in1, Node* in2) : MultiNode(3) { 11.17 + init_class_id(Class_MathExact); 11.18 + init_req(0, ctrl); 11.19 + init_req(1, in1); 11.20 + init_req(2, in2); 11.21 } 11.22 11.23 BoolNode* MathExactNode::bool_node() const { 11.24 @@ -64,23 +71,10 @@ 11.25 return ifnode->proj_out(1); 11.26 } 11.27 11.28 -Node* AddExactINode::match(const ProjNode* proj, const Matcher* m) { 11.29 - uint ideal_reg = proj->ideal_reg(); 11.30 - RegMask rm; 11.31 - if (proj->_con == result_proj_node) { 11.32 - rm = m->mathExactI_result_proj_mask(); 11.33 - } else { 11.34 - assert(proj->_con == flags_proj_node, "must be result or flags"); 11.35 - assert(ideal_reg == Op_RegFlags, "sanity"); 11.36 - rm = m->mathExactI_flags_proj_mask(); 11.37 - } 11.38 - return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg); 11.39 -} 11.40 - 11.41 // If the MathExactNode won't overflow we have to replace the 11.42 // FlagsProjNode and ProjNode that is generated by the MathExactNode 11.43 -Node* MathExactNode::no_overflow(PhaseGVN *phase, Node* new_result) { 11.44 - PhaseIterGVN *igvn = phase->is_IterGVN(); 11.45 +Node* MathExactNode::no_overflow(PhaseGVN* phase, Node* new_result) { 11.46 + PhaseIterGVN* igvn = phase->is_IterGVN(); 11.47 if (igvn) { 11.48 ProjNode* result = result_node(); 11.49 ProjNode* flags = flags_node(); 11.50 @@ -110,9 +104,35 @@ 11.51 return new_result; 11.52 } 11.53 11.54 -Node *AddExactINode::Ideal(PhaseGVN *phase, bool can_reshape) { 11.55 - Node *arg1 = in(1); 11.56 - Node *arg2 = in(2); 11.57 +Node* MathExactINode::match(const ProjNode* proj, const Matcher* m) { 11.58 + uint ideal_reg = proj->ideal_reg(); 11.59 + RegMask rm; 11.60 + if (proj->_con == result_proj_node) { 11.61 + rm = m->mathExactI_result_proj_mask(); 11.62 + } else { 11.63 + assert(proj->_con == flags_proj_node, "must be result or flags"); 11.64 + assert(ideal_reg == Op_RegFlags, "sanity"); 11.65 + rm = m->mathExactI_flags_proj_mask(); 11.66 + } 11.67 + return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg); 11.68 +} 11.69 + 11.70 +Node* MathExactLNode::match(const ProjNode* proj, const Matcher* m) { 11.71 + uint ideal_reg = proj->ideal_reg(); 11.72 + RegMask rm; 11.73 + if (proj->_con == result_proj_node) { 11.74 + rm = m->mathExactL_result_proj_mask(); 11.75 + } else { 11.76 + assert(proj->_con == flags_proj_node, "must be result or flags"); 11.77 + assert(ideal_reg == Op_RegFlags, "sanity"); 11.78 + rm = m->mathExactI_flags_proj_mask(); 11.79 + } 11.80 + return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg); 11.81 +} 11.82 + 11.83 +Node* AddExactINode::Ideal(PhaseGVN* phase, bool can_reshape) { 11.84 + Node* arg1 = in(1); 11.85 + Node* arg2 = in(2); 11.86 11.87 const Type* type1 = phase->type(arg1); 11.88 const Type* type2 = phase->type(arg2); 11.89 @@ -130,12 +150,7 @@ 11.90 return NULL; 11.91 } 11.92 11.93 - if (type1 == TypeInt::ZERO) { // (Add 0 x) == x 11.94 - Node* add_result = new (phase->C) AddINode(arg1, arg2); 11.95 - return no_overflow(phase, add_result); 11.96 - } 11.97 - 11.98 - if (type2 == TypeInt::ZERO) { // (Add x 0) == x 11.99 + if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) { // (Add 0 x) == x 11.100 Node* add_result = new (phase->C) AddINode(arg1, arg2); 11.101 return no_overflow(phase, add_result); 11.102 } 11.103 @@ -169,3 +184,247 @@ 11.104 return NULL; 11.105 } 11.106 11.107 +Node* AddExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 11.108 + Node* arg1 = in(1); 11.109 + Node* arg2 = in(2); 11.110 + 11.111 + const Type* type1 = phase->type(arg1); 11.112 + const Type* type2 = phase->type(arg2); 11.113 + 11.114 + if (type1 != Type::TOP && type1->singleton() && 11.115 + type2 != Type::TOP && type2->singleton()) { 11.116 + jlong val1 = arg1->get_long(); 11.117 + jlong val2 = arg2->get_long(); 11.118 + jlong result = val1 + val2; 11.119 + // Hacker's Delight 2-12 Overflow if both arguments have the opposite sign of the result 11.120 + if ( (((val1 ^ result) & (val2 ^ result)) >= 0)) { 11.121 + Node* con_result = ConLNode::make(phase->C, result); 11.122 + return no_overflow(phase, con_result); 11.123 + } 11.124 + return NULL; 11.125 + } 11.126 + 11.127 + if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) { // (Add 0 x) == x 11.128 + Node* add_result = new (phase->C) AddLNode(arg1, arg2); 11.129 + return no_overflow(phase, add_result); 11.130 + } 11.131 + 11.132 + if (type2->singleton()) { 11.133 + return NULL; // no change - keep constant on the right 11.134 + } 11.135 + 11.136 + if (type1->singleton()) { 11.137 + // Make it x + Constant - move constant to the right 11.138 + swap_edges(1, 2); 11.139 + return this; 11.140 + } 11.141 + 11.142 + if (arg2->is_Load()) { 11.143 + return NULL; // no change - keep load on the right 11.144 + } 11.145 + 11.146 + if (arg1->is_Load()) { 11.147 + // Make it x + Load - move load to the right 11.148 + swap_edges(1, 2); 11.149 + return this; 11.150 + } 11.151 + 11.152 + if (arg1->_idx > arg2->_idx) { 11.153 + // Sort the edges 11.154 + swap_edges(1, 2); 11.155 + return this; 11.156 + } 11.157 + 11.158 + return NULL; 11.159 +} 11.160 + 11.161 +Node* SubExactINode::Ideal(PhaseGVN* phase, bool can_reshape) { 11.162 + Node* arg1 = in(1); 11.163 + Node* arg2 = in(2); 11.164 + 11.165 + const Type* type1 = phase->type(arg1); 11.166 + const Type* type2 = phase->type(arg2); 11.167 + 11.168 + if (type1 != Type::TOP && type1->singleton() && 11.169 + type2 != Type::TOP && type2->singleton()) { 11.170 + jint val1 = arg1->get_int(); 11.171 + jint val2 = arg2->get_int(); 11.172 + jint result = val1 - val2; 11.173 + 11.174 + // Hacker's Delight 2-12 Overflow iff the arguments have different signs and 11.175 + // the sign of the result is different than the sign of arg1 11.176 + if (((val1 ^ val2) & (val1 ^ result)) >= 0) { 11.177 + Node* con_result = ConINode::make(phase->C, result); 11.178 + return no_overflow(phase, con_result); 11.179 + } 11.180 + return NULL; 11.181 + } 11.182 + 11.183 + if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) { 11.184 + // Sub with zero is the same as add with zero 11.185 + Node* add_result = new (phase->C) AddINode(arg1, arg2); 11.186 + return no_overflow(phase, add_result); 11.187 + } 11.188 + 11.189 + return NULL; 11.190 +} 11.191 + 11.192 +Node* SubExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 11.193 + Node* arg1 = in(1); 11.194 + Node* arg2 = in(2); 11.195 + 11.196 + const Type* type1 = phase->type(arg1); 11.197 + const Type* type2 = phase->type(arg2); 11.198 + 11.199 + if (type1 != Type::TOP && type1->singleton() && 11.200 + type2 != Type::TOP && type2->singleton()) { 11.201 + jlong val1 = arg1->get_long(); 11.202 + jlong val2 = arg2->get_long(); 11.203 + jlong result = val1 - val2; 11.204 + 11.205 + // Hacker's Delight 2-12 Overflow iff the arguments have different signs and 11.206 + // the sign of the result is different than the sign of arg1 11.207 + if (((val1 ^ val2) & (val1 ^ result)) >= 0) { 11.208 + Node* con_result = ConLNode::make(phase->C, result); 11.209 + return no_overflow(phase, con_result); 11.210 + } 11.211 + return NULL; 11.212 + } 11.213 + 11.214 + if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) { 11.215 + // Sub with zero is the same as add with zero 11.216 + Node* add_result = new (phase->C) AddLNode(arg1, arg2); 11.217 + return no_overflow(phase, add_result); 11.218 + } 11.219 + 11.220 + return NULL; 11.221 +} 11.222 + 11.223 +Node* NegExactINode::Ideal(PhaseGVN* phase, bool can_reshape) { 11.224 + Node *arg = in(1); 11.225 + 11.226 + const Type* type = phase->type(arg); 11.227 + if (type != Type::TOP && type->singleton()) { 11.228 + jint value = arg->get_int(); 11.229 + if (value != min_jint) { 11.230 + Node* neg_result = ConINode::make(phase->C, -value); 11.231 + return no_overflow(phase, neg_result); 11.232 + } 11.233 + } 11.234 + return NULL; 11.235 +} 11.236 + 11.237 +Node* NegExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 11.238 + Node *arg = in(1); 11.239 + 11.240 + const Type* type = phase->type(arg); 11.241 + if (type != Type::TOP && type->singleton()) { 11.242 + jlong value = arg->get_long(); 11.243 + if (value != min_jlong) { 11.244 + Node* neg_result = ConLNode::make(phase->C, -value); 11.245 + return no_overflow(phase, neg_result); 11.246 + } 11.247 + } 11.248 + return NULL; 11.249 +} 11.250 + 11.251 +Node* MulExactINode::Ideal(PhaseGVN* phase, bool can_reshape) { 11.252 + Node* arg1 = in(1); 11.253 + Node* arg2 = in(2); 11.254 + 11.255 + const Type* type1 = phase->type(arg1); 11.256 + const Type* type2 = phase->type(arg2); 11.257 + 11.258 + if (type1 != Type::TOP && type1->singleton() && 11.259 + type2 != Type::TOP && type2->singleton()) { 11.260 + jint val1 = arg1->get_int(); 11.261 + jint val2 = arg2->get_int(); 11.262 + jlong result = (jlong) val1 * (jlong) val2; 11.263 + if ((jint) result == result) { 11.264 + // no overflow 11.265 + Node* mul_result = ConINode::make(phase->C, result); 11.266 + return no_overflow(phase, mul_result); 11.267 + } 11.268 + } 11.269 + 11.270 + if (type1 == TypeInt::ZERO || type2 == TypeInt::ZERO) { 11.271 + return no_overflow(phase, ConINode::make(phase->C, 0)); 11.272 + } 11.273 + 11.274 + if (type1 == TypeInt::ONE) { 11.275 + Node* mul_result = new (phase->C) AddINode(arg2, phase->intcon(0)); 11.276 + return no_overflow(phase, mul_result); 11.277 + } 11.278 + if (type2 == TypeInt::ONE) { 11.279 + Node* mul_result = new (phase->C) AddINode(arg1, phase->intcon(0)); 11.280 + return no_overflow(phase, mul_result); 11.281 + } 11.282 + 11.283 + if (type1 == TypeInt::MINUS_1) { 11.284 + return new (phase->C) NegExactINode(NULL, arg2); 11.285 + } 11.286 + 11.287 + if (type2 == TypeInt::MINUS_1) { 11.288 + return new (phase->C) NegExactINode(NULL, arg1); 11.289 + } 11.290 + 11.291 + return NULL; 11.292 +} 11.293 + 11.294 +Node* MulExactLNode::Ideal(PhaseGVN* phase, bool can_reshape) { 11.295 + Node* arg1 = in(1); 11.296 + Node* arg2 = in(2); 11.297 + 11.298 + const Type* type1 = phase->type(arg1); 11.299 + const Type* type2 = phase->type(arg2); 11.300 + 11.301 + if (type1 != Type::TOP && type1->singleton() && 11.302 + type2 != Type::TOP && type2->singleton()) { 11.303 + jlong val1 = arg1->get_long(); 11.304 + jlong val2 = arg2->get_long(); 11.305 + 11.306 + jlong result = val1 * val2; 11.307 + jlong ax = (val1 < 0 ? -val1 : val1); 11.308 + jlong ay = (val2 < 0 ? -val2 : val2); 11.309 + 11.310 + bool overflow = false; 11.311 + if ((ax | ay) & CONST64(0xFFFFFFFF00000000)) { 11.312 + // potential overflow if any bit in upper 32 bits are set 11.313 + if ((val1 == min_jlong && val2 == -1) || (val2 == min_jlong && val1 == -1)) { 11.314 + // -1 * Long.MIN_VALUE will overflow 11.315 + overflow = true; 11.316 + } else if (val2 != 0 && (result / val2 != val1)) { 11.317 + overflow = true; 11.318 + } 11.319 + } 11.320 + 11.321 + if (!overflow) { 11.322 + Node* mul_result = ConLNode::make(phase->C, result); 11.323 + return no_overflow(phase, mul_result); 11.324 + } 11.325 + } 11.326 + 11.327 + if (type1 == TypeLong::ZERO || type2 == TypeLong::ZERO) { 11.328 + return no_overflow(phase, ConLNode::make(phase->C, 0)); 11.329 + } 11.330 + 11.331 + if (type1 == TypeLong::ONE) { 11.332 + Node* mul_result = new (phase->C) AddLNode(arg2, phase->longcon(0)); 11.333 + return no_overflow(phase, mul_result); 11.334 + } 11.335 + if (type2 == TypeLong::ONE) { 11.336 + Node* mul_result = new (phase->C) AddLNode(arg1, phase->longcon(0)); 11.337 + return no_overflow(phase, mul_result); 11.338 + } 11.339 + 11.340 + if (type1 == TypeLong::MINUS_1) { 11.341 + return new (phase->C) NegExactLNode(NULL, arg2); 11.342 + } 11.343 + 11.344 + if (type2 == TypeLong::MINUS_1) { 11.345 + return new (phase->C) NegExactLNode(NULL, arg1); 11.346 + } 11.347 + 11.348 + return NULL; 11.349 +} 11.350 +
12.1 --- a/src/share/vm/opto/mathexactnode.hpp Wed Oct 23 16:25:48 2013 -0700 12.2 +++ b/src/share/vm/opto/mathexactnode.hpp Fri Oct 18 10:41:56 2013 +0200 12.3 @@ -39,6 +39,7 @@ 12.4 12.5 class MathExactNode : public MultiNode { 12.6 public: 12.7 + MathExactNode(Node* ctrl, Node* in1); 12.8 MathExactNode(Node* ctrl, Node* in1, Node* in2); 12.9 enum { 12.10 result_proj_node = 0, 12.11 @@ -62,15 +63,80 @@ 12.12 Node* no_overflow(PhaseGVN *phase, Node* new_result); 12.13 }; 12.14 12.15 -class AddExactINode : public MathExactNode { 12.16 +class MathExactINode : public MathExactNode { 12.17 + public: 12.18 + MathExactINode(Node* ctrl, Node* in1) : MathExactNode(ctrl, in1) {} 12.19 + MathExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {} 12.20 + virtual int Opcode() const; 12.21 + virtual Node* match(const ProjNode* proj, const Matcher* m); 12.22 + virtual const Type* bottom_type() const { return TypeTuple::INT_CC_PAIR; } 12.23 +}; 12.24 + 12.25 +class MathExactLNode : public MathExactNode { 12.26 public: 12.27 - AddExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {} 12.28 + MathExactLNode(Node* ctrl, Node* in1) : MathExactNode(ctrl, in1) {} 12.29 + MathExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {} 12.30 virtual int Opcode() const; 12.31 - virtual const Type* bottom_type() const { return TypeTuple::INT_CC_PAIR; } 12.32 virtual Node* match(const ProjNode* proj, const Matcher* m); 12.33 + virtual const Type* bottom_type() const { return TypeTuple::LONG_CC_PAIR; } 12.34 +}; 12.35 + 12.36 +class AddExactINode : public MathExactINode { 12.37 +public: 12.38 + AddExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {} 12.39 + virtual int Opcode() const; 12.40 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 12.41 }; 12.42 12.43 +class AddExactLNode : public MathExactLNode { 12.44 +public: 12.45 + AddExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {} 12.46 + virtual int Opcode() const; 12.47 + virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 12.48 +}; 12.49 + 12.50 +class SubExactINode : public MathExactINode { 12.51 +public: 12.52 + SubExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {} 12.53 + virtual int Opcode() const; 12.54 + virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 12.55 +}; 12.56 + 12.57 +class SubExactLNode : public MathExactLNode { 12.58 +public: 12.59 + SubExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {} 12.60 + virtual int Opcode() const; 12.61 + virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 12.62 +}; 12.63 + 12.64 +class NegExactINode : public MathExactINode { 12.65 +public: 12.66 + NegExactINode(Node* ctrl, Node* in1) : MathExactINode(ctrl, in1) {} 12.67 + virtual int Opcode() const; 12.68 + virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 12.69 +}; 12.70 + 12.71 +class NegExactLNode : public MathExactLNode { 12.72 +public: 12.73 + NegExactLNode(Node* ctrl, Node* in1) : MathExactLNode(ctrl, in1) {} 12.74 + virtual int Opcode() const; 12.75 + virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 12.76 +}; 12.77 + 12.78 +class MulExactINode : public MathExactINode { 12.79 +public: 12.80 + MulExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {} 12.81 + virtual int Opcode() const; 12.82 + virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 12.83 +}; 12.84 + 12.85 +class MulExactLNode : public MathExactLNode { 12.86 +public: 12.87 + MulExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {} 12.88 + virtual int Opcode() const; 12.89 + virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 12.90 +}; 12.91 + 12.92 class FlagsProjNode : public ProjNode { 12.93 public: 12.94 FlagsProjNode(Node* src, uint con) : ProjNode(src, con) {
13.1 --- a/src/share/vm/opto/node.hpp Wed Oct 23 16:25:48 2013 -0700 13.2 +++ b/src/share/vm/opto/node.hpp Fri Oct 18 10:41:56 2013 +0200 13.3 @@ -100,6 +100,7 @@ 13.4 class MachSpillCopyNode; 13.5 class MachTempNode; 13.6 class Matcher; 13.7 +class MathExactNode; 13.8 class MemBarNode; 13.9 class MemBarStoreStoreNode; 13.10 class MemNode; 13.11 @@ -568,6 +569,7 @@ 13.12 DEFINE_CLASS_ID(MemBar, Multi, 3) 13.13 DEFINE_CLASS_ID(Initialize, MemBar, 0) 13.14 DEFINE_CLASS_ID(MemBarStoreStore, MemBar, 1) 13.15 + DEFINE_CLASS_ID(MathExact, Multi, 4) 13.16 13.17 DEFINE_CLASS_ID(Mach, Node, 1) 13.18 DEFINE_CLASS_ID(MachReturn, Mach, 0) 13.19 @@ -757,6 +759,7 @@ 13.20 DEFINE_CLASS_QUERY(MachSafePoint) 13.21 DEFINE_CLASS_QUERY(MachSpillCopy) 13.22 DEFINE_CLASS_QUERY(MachTemp) 13.23 + DEFINE_CLASS_QUERY(MathExact) 13.24 DEFINE_CLASS_QUERY(Mem) 13.25 DEFINE_CLASS_QUERY(MemBar) 13.26 DEFINE_CLASS_QUERY(MemBarStoreStore)
14.1 --- a/src/share/vm/opto/type.cpp Wed Oct 23 16:25:48 2013 -0700 14.2 +++ b/src/share/vm/opto/type.cpp Fri Oct 18 10:41:56 2013 +0200 14.3 @@ -435,6 +435,11 @@ 14.4 intccpair[1] = TypeInt::CC; 14.5 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair); 14.6 14.7 + const Type **longccpair = TypeTuple::fields(2); 14.8 + longccpair[0] = TypeLong::LONG; 14.9 + longccpair[1] = TypeInt::CC; 14.10 + TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair); 14.11 + 14.12 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM; 14.13 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM; 14.14 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL; 14.15 @@ -1675,6 +1680,7 @@ 14.16 const TypeTuple *TypeTuple::INT_PAIR; 14.17 const TypeTuple *TypeTuple::LONG_PAIR; 14.18 const TypeTuple *TypeTuple::INT_CC_PAIR; 14.19 +const TypeTuple *TypeTuple::LONG_CC_PAIR; 14.20 14.21 14.22 //------------------------------make-------------------------------------------
15.1 --- a/src/share/vm/opto/type.hpp Wed Oct 23 16:25:48 2013 -0700 15.2 +++ b/src/share/vm/opto/type.hpp Fri Oct 18 10:41:56 2013 +0200 15.3 @@ -593,6 +593,7 @@ 15.4 static const TypeTuple *INT_PAIR; 15.5 static const TypeTuple *LONG_PAIR; 15.6 static const TypeTuple *INT_CC_PAIR; 15.7 + static const TypeTuple *LONG_CC_PAIR; 15.8 #ifndef PRODUCT 15.9 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping 15.10 #endif
16.1 --- a/src/share/vm/runtime/vmStructs.cpp Wed Oct 23 16:25:48 2013 -0700 16.2 +++ b/src/share/vm/runtime/vmStructs.cpp Fri Oct 18 10:41:56 2013 +0200 16.3 @@ -1938,7 +1938,13 @@ 16.4 declare_c2_type(CmpDNode, CmpNode) \ 16.5 declare_c2_type(CmpD3Node, CmpDNode) \ 16.6 declare_c2_type(MathExactNode, MultiNode) \ 16.7 - declare_c2_type(AddExactINode, MathExactNode) \ 16.8 + declare_c2_type(MathExactINode, MathExactNode) \ 16.9 + declare_c2_type(AddExactINode, MathExactINode) \ 16.10 + declare_c2_type(AddExactLNode, MathExactLNode) \ 16.11 + declare_c2_type(SubExactINode, MathExactINode) \ 16.12 + declare_c2_type(SubExactLNode, MathExactLNode) \ 16.13 + declare_c2_type(NegExactINode, MathExactINode) \ 16.14 + declare_c2_type(MulExactINode, MathExactINode) \ 16.15 declare_c2_type(FlagsProjNode, ProjNode) \ 16.16 declare_c2_type(BoolNode, Node) \ 16.17 declare_c2_type(AbsNode, Node) \
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/compiler/intrinsics/mathexact/AddExactICondTest.java Fri Oct 18 10:41:56 2013 +0200 17.3 @@ -0,0 +1,57 @@ 17.4 +/* 17.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +/* 17.28 + * @test 17.29 + * @bug 8024924 17.30 + * @summary Test non constant addExact 17.31 + * @compile AddExactICondTest.java 17.32 + * @run main AddExactICondTest 17.33 + * 17.34 + */ 17.35 + 17.36 +public class AddExactICondTest { 17.37 + public static int result = 0; 17.38 + 17.39 + public static void main(String[] args) { 17.40 + for (int i = 0; i < 50000; ++i) { 17.41 + runTest(); 17.42 + } 17.43 + } 17.44 + 17.45 + public static void runTest() { 17.46 + int i = 7; 17.47 + while (java.lang.Math.addExact(i, result) < 89361) { 17.48 + if ((java.lang.Math.addExact(i, i) & 1) == 1) { 17.49 + i += 3; 17.50 + } else if ((i & 5) == 4) { 17.51 + i += 7; 17.52 + } else if ((i & 0xf) == 6) { 17.53 + i += 2; 17.54 + } else { 17.55 + i += 1; 17.56 + } 17.57 + result += 2; 17.58 + } 17.59 + } 17.60 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/compiler/intrinsics/mathexact/AddExactIConstantTest.java Fri Oct 18 10:41:56 2013 +0200 18.3 @@ -0,0 +1,37 @@ 18.4 +/* 18.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 + * 18.8 + * This code is free software; you can redistribute it and/or modify it 18.9 + * under the terms of the GNU General Public License version 2 only, as 18.10 + * published by the Free Software Foundation. 18.11 + * 18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.15 + * version 2 for more details (a copy is included in the LICENSE file that 18.16 + * accompanied this code). 18.17 + * 18.18 + * You should have received a copy of the GNU General Public License version 18.19 + * 2 along with this work; if not, write to the Free Software Foundation, 18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.21 + * 18.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 18.23 + * or visit www.oracle.com if you need additional information or have any 18.24 + * questions. 18.25 + */ 18.26 + 18.27 +/* 18.28 + * @test 18.29 + * @bug 8024924 18.30 + * @summary Test constant addExact 18.31 + * @compile AddExactIConstantTest.java Verify.java 18.32 + * @run main AddExactIConstantTest 18.33 + * 18.34 + */ 18.35 + 18.36 +public class AddExactIConstantTest { 18.37 + public static void main(String[] args) { 18.38 + Verify.ConstantTest.verify(new Verify.AddExactI()); 18.39 + } 18.40 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/compiler/intrinsics/mathexact/AddExactILoadTest.java Fri Oct 18 10:41:56 2013 +0200 19.3 @@ -0,0 +1,38 @@ 19.4 +/* 19.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +/* 19.28 + * @test 19.29 + * @bug 8024924 19.30 + * @summary Test non constant addExact 19.31 + * @compile AddExactILoadTest.java Verify.java 19.32 + * @run main AddExactILoadTest 19.33 + * 19.34 + */ 19.35 + 19.36 +public class AddExactILoadTest { 19.37 + public static void main(String[] args) { 19.38 + Verify.LoadTest.init(); 19.39 + Verify.LoadTest.verify(new Verify.AddExactI()); 19.40 + } 19.41 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/compiler/intrinsics/mathexact/AddExactILoopDependentTest.java Fri Oct 18 10:41:56 2013 +0200 20.3 @@ -0,0 +1,37 @@ 20.4 +/* 20.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.23 + * or visit www.oracle.com if you need additional information or have any 20.24 + * questions. 20.25 + */ 20.26 + 20.27 +/* 20.28 + * @test 20.29 + * @bug 8024924 20.30 + * @summary Test non constant addExact 20.31 + * @compile AddExactILoopDependentTest.java Verify.java 20.32 + * @run main AddExactILoopDependentTest 20.33 + * 20.34 + */ 20.35 + 20.36 +public class AddExactILoopDependentTest { 20.37 + public static void main(String[] args) { 20.38 + Verify.LoopDependentTest.verify(new Verify.AddExactI()); 20.39 + } 20.40 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/compiler/intrinsics/mathexact/AddExactINonConstantTest.java Fri Oct 18 10:41:56 2013 +0200 21.3 @@ -0,0 +1,37 @@ 21.4 +/* 21.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. 21.11 + * 21.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.15 + * version 2 for more details (a copy is included in the LICENSE file that 21.16 + * accompanied this code). 21.17 + * 21.18 + * You should have received a copy of the GNU General Public License version 21.19 + * 2 along with this work; if not, write to the Free Software Foundation, 21.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.21 + * 21.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.23 + * or visit www.oracle.com if you need additional information or have any 21.24 + * questions. 21.25 + */ 21.26 + 21.27 +/* 21.28 + * @test 21.29 + * @bug 8024924 21.30 + * @summary Test non constant addExact 21.31 + * @compile AddExactINonConstantTest.java Verify.java 21.32 + * @run main AddExactINonConstantTest 21.33 + * 21.34 + */ 21.35 + 21.36 +public class AddExactINonConstantTest { 21.37 + public static void main(String[] args) { 21.38 + Verify.NonConstantTest.verify(new Verify.AddExactI()); 21.39 + } 21.40 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/compiler/intrinsics/mathexact/AddExactIRepeatTest.java Fri Oct 18 10:41:56 2013 +0200 22.3 @@ -0,0 +1,109 @@ 22.4 +/* 22.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. 22.11 + * 22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.15 + * version 2 for more details (a copy is included in the LICENSE file that 22.16 + * accompanied this code). 22.17 + * 22.18 + * You should have received a copy of the GNU General Public License version 22.19 + * 2 along with this work; if not, write to the Free Software Foundation, 22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.21 + * 22.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.23 + * or visit www.oracle.com if you need additional information or have any 22.24 + * questions. 22.25 + */ 22.26 + 22.27 +/* 22.28 + * @test 22.29 + * @bug 8025657 22.30 + * @summary Test repeating addExact 22.31 + * @compile AddExactIRepeatTest.java Verify.java 22.32 + * @run main AddExactIRepeatTest 22.33 + * 22.34 + */ 22.35 + 22.36 +public class AddExactIRepeatTest { 22.37 + public static void main(String[] args) { 22.38 + runTest(new Verify.AddExactI()); 22.39 + } 22.40 + 22.41 + public static int nonExact(int x, int y, Verify.BinaryMethod method) { 22.42 + int result = method.unchecked(x, y); 22.43 + result += method.unchecked(x, y); 22.44 + result += method.unchecked(x, y); 22.45 + result += method.unchecked(x, y); 22.46 + return result; 22.47 + } 22.48 + 22.49 + public static void runTest(Verify.BinaryMethod method) { 22.50 + java.util.Random rnd = new java.util.Random(); 22.51 + for (int i = 0; i < 50000; ++i) { 22.52 + int x = Integer.MAX_VALUE - 10; 22.53 + int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5); 22.54 + 22.55 + int c = rnd.nextInt() / 2; 22.56 + int d = rnd.nextInt() / 2; 22.57 + 22.58 + int a = catchingExact(x, y, method); 22.59 + 22.60 + if (a != 36) { 22.61 + throw new RuntimeException("a != 36 : " + a); 22.62 + } 22.63 + 22.64 + int b = nonExact(c, d, method); 22.65 + int n = exact(c, d, method); 22.66 + 22.67 + 22.68 + if (n != b) { 22.69 + throw new RuntimeException("n != b : " + n + " != " + b); 22.70 + } 22.71 + } 22.72 + } 22.73 + 22.74 + public static int exact(int x, int y, Verify.BinaryMethod method) { 22.75 + int result = 0; 22.76 + result += method.checkMethod(x, y); 22.77 + result += method.checkMethod(x, y); 22.78 + result += method.checkMethod(x, y); 22.79 + result += method.checkMethod(x, y); 22.80 + return result; 22.81 + } 22.82 + 22.83 + public static int catchingExact(int x, int y, Verify.BinaryMethod method) { 22.84 + int result = 0; 22.85 + try { 22.86 + result += 5; 22.87 + result = method.checkMethod(x, y); 22.88 + } catch (ArithmeticException e) { 22.89 + result += 1; 22.90 + } 22.91 + try { 22.92 + result += 6; 22.93 + 22.94 + result += method.checkMethod(x, y); 22.95 + } catch (ArithmeticException e) { 22.96 + result += 2; 22.97 + } 22.98 + try { 22.99 + result += 7; 22.100 + result += method.checkMethod(x, y); 22.101 + } catch (ArithmeticException e) { 22.102 + result += 3; 22.103 + } 22.104 + try { 22.105 + result += 8; 22.106 + result += method.checkMethod(x, y); 22.107 + } catch (ArithmeticException e) { 22.108 + result += 4; 22.109 + } 22.110 + return result; 22.111 + } 22.112 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/compiler/intrinsics/mathexact/AddExactLConstantTest.java Fri Oct 18 10:41:56 2013 +0200 23.3 @@ -0,0 +1,37 @@ 23.4 +/* 23.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 + * 23.8 + * This code is free software; you can redistribute it and/or modify it 23.9 + * under the terms of the GNU General Public License version 2 only, as 23.10 + * published by the Free Software Foundation. 23.11 + * 23.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 23.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.15 + * version 2 for more details (a copy is included in the LICENSE file that 23.16 + * accompanied this code). 23.17 + * 23.18 + * You should have received a copy of the GNU General Public License version 23.19 + * 2 along with this work; if not, write to the Free Software Foundation, 23.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.21 + * 23.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23.23 + * or visit www.oracle.com if you need additional information or have any 23.24 + * questions. 23.25 + */ 23.26 + 23.27 +/* 23.28 + * @test 23.29 + * @bug 8026844 23.30 + * @summary Test constant addExact 23.31 + * @compile AddExactLConstantTest.java Verify.java 23.32 + * @run main AddExactLConstantTest 23.33 + * 23.34 + */ 23.35 + 23.36 +public class AddExactLConstantTest { 23.37 + public static void main(String[] args) { 23.38 + Verify.ConstantLongTest.verify(new Verify.AddExactL()); 23.39 + } 23.40 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/compiler/intrinsics/mathexact/AddExactLNonConstantTest.java Fri Oct 18 10:41:56 2013 +0200 24.3 @@ -0,0 +1,37 @@ 24.4 +/* 24.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.7 + * 24.8 + * This code is free software; you can redistribute it and/or modify it 24.9 + * under the terms of the GNU General Public License version 2 only, as 24.10 + * published by the Free Software Foundation. 24.11 + * 24.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 24.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24.15 + * version 2 for more details (a copy is included in the LICENSE file that 24.16 + * accompanied this code). 24.17 + * 24.18 + * You should have received a copy of the GNU General Public License version 24.19 + * 2 along with this work; if not, write to the Free Software Foundation, 24.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24.21 + * 24.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24.23 + * or visit www.oracle.com if you need additional information or have any 24.24 + * questions. 24.25 + */ 24.26 + 24.27 +/* 24.28 + * @test 24.29 + * @bug 8026844 24.30 + * @summary Test non constant addExact 24.31 + * @compile AddExactLNonConstantTest.java Verify.java 24.32 + * @run main AddExactLNonConstantTest 24.33 + * 24.34 + */ 24.35 + 24.36 +public class AddExactLNonConstantTest { 24.37 + public static void main(String[] args) { 24.38 + Verify.NonConstantLongTest.verify(new Verify.AddExactL()); 24.39 + } 24.40 +}
25.1 --- a/test/compiler/intrinsics/mathexact/CondTest.java Wed Oct 23 16:25:48 2013 -0700 25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 25.3 @@ -1,59 +0,0 @@ 25.4 -/* 25.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 25.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.7 - * 25.8 - * This code is free software; you can redistribute it and/or modify it 25.9 - * under the terms of the GNU General Public License version 2 only, as 25.10 - * published by the Free Software Foundation. 25.11 - * 25.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 25.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25.15 - * version 2 for more details (a copy is included in the LICENSE file that 25.16 - * accompanied this code). 25.17 - * 25.18 - * You should have received a copy of the GNU General Public License version 25.19 - * 2 along with this work; if not, write to the Free Software Foundation, 25.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 25.21 - * 25.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25.23 - * or visit www.oracle.com if you need additional information or have any 25.24 - * questions. 25.25 - */ 25.26 - 25.27 -/* 25.28 - * @test 25.29 - * @bug 8024924 25.30 - * @summary Test non constant addExact 25.31 - * @compile CondTest.java Verify.java 25.32 - * @run main CondTest 25.33 - * 25.34 - */ 25.35 - 25.36 -import java.lang.ArithmeticException; 25.37 - 25.38 -public class CondTest { 25.39 - public static int result = 0; 25.40 - 25.41 - public static void main(String[] args) { 25.42 - for (int i = 0; i < 50000; ++i) { 25.43 - runTest(); 25.44 - } 25.45 - } 25.46 - 25.47 - public static void runTest() { 25.48 - int i = 7; 25.49 - while (java.lang.Math.addExact(i, result) < 89361) { 25.50 - if ((java.lang.Math.addExact(i, i) & 1) == 1) { 25.51 - i += 3; 25.52 - } else if ((i & 5) == 4) { 25.53 - i += 7; 25.54 - } else if ((i & 0xf) == 6) { 25.55 - i += 2; 25.56 - } else { 25.57 - i += 1; 25.58 - } 25.59 - result += 2; 25.60 - } 25.61 - } 25.62 -}
26.1 --- a/test/compiler/intrinsics/mathexact/ConstantTest.java Wed Oct 23 16:25:48 2013 -0700 26.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 26.3 @@ -1,47 +0,0 @@ 26.4 -/* 26.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 26.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.7 - * 26.8 - * This code is free software; you can redistribute it and/or modify it 26.9 - * under the terms of the GNU General Public License version 2 only, as 26.10 - * published by the Free Software Foundation. 26.11 - * 26.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 26.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.15 - * version 2 for more details (a copy is included in the LICENSE file that 26.16 - * accompanied this code). 26.17 - * 26.18 - * You should have received a copy of the GNU General Public License version 26.19 - * 2 along with this work; if not, write to the Free Software Foundation, 26.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.21 - * 26.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 26.23 - * or visit www.oracle.com if you need additional information or have any 26.24 - * questions. 26.25 - */ 26.26 - 26.27 -/* 26.28 - * @test 26.29 - * @bug 8024924 26.30 - * @summary Test constant addExact 26.31 - * @compile ConstantTest.java Verify.java 26.32 - * @run main ConstantTest 26.33 - * 26.34 - */ 26.35 - 26.36 -import java.lang.ArithmeticException; 26.37 - 26.38 -public class ConstantTest { 26.39 - public static void main(String[] args) { 26.40 - for (int i = 0; i < 50000; ++i) { 26.41 - Verify.verify(5, 7); 26.42 - Verify.verify(Integer.MAX_VALUE, 1); 26.43 - Verify.verify(Integer.MIN_VALUE, -1); 26.44 - Verify.verify(Integer.MAX_VALUE, -1); 26.45 - Verify.verify(Integer.MIN_VALUE, 1); 26.46 - Verify.verify(Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2); 26.47 - Verify.verify(Integer.MAX_VALUE / 2, (Integer.MAX_VALUE / 2) + 3); 26.48 - } 26.49 - } 26.50 -}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/compiler/intrinsics/mathexact/DecExactITest.java Fri Oct 18 10:41:56 2013 +0200 27.3 @@ -0,0 +1,53 @@ 27.4 +/* 27.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.7 + * 27.8 + * This code is free software; you can redistribute it and/or modify it 27.9 + * under the terms of the GNU General Public License version 2 only, as 27.10 + * published by the Free Software Foundation. 27.11 + * 27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.15 + * version 2 for more details (a copy is included in the LICENSE file that 27.16 + * accompanied this code). 27.17 + * 27.18 + * You should have received a copy of the GNU General Public License version 27.19 + * 2 along with this work; if not, write to the Free Software Foundation, 27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.21 + * 27.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27.23 + * or visit www.oracle.com if you need additional information or have any 27.24 + * questions. 27.25 + */ 27.26 + 27.27 +/* 27.28 + * @test 27.29 + * @bug 8026844 27.30 + * @summary Test decrementExact 27.31 + * @compile DecExactITest.java Verify.java 27.32 + * @run main DecExactITest 27.33 + * 27.34 + */ 27.35 + 27.36 +public class DecExactITest { 27.37 + public static int[] values = {1, 1, 1, 1}; 27.38 + public static int[] minvalues = {Integer.MIN_VALUE, Integer.MIN_VALUE}; 27.39 + 27.40 + public static void main(String[] args) { 27.41 + runTest(new Verify.DecExactI()); 27.42 + } 27.43 + 27.44 + public static void runTest(Verify.UnaryMethod method) { 27.45 + for (int i = 0; i < 20000; ++i) { 27.46 + Verify.verifyUnary(Integer.MIN_VALUE, method); 27.47 + Verify.verifyUnary(minvalues[0], method); 27.48 + Verify.verifyUnary(Integer.MIN_VALUE - values[2], method); 27.49 + Verify.verifyUnary(0, method); 27.50 + Verify.verifyUnary(values[2], method); 27.51 + Verify.verifyUnary(Integer.MAX_VALUE, method); 27.52 + Verify.verifyUnary(Integer.MIN_VALUE - values[0] + values[3], method); 27.53 + Verify.verifyUnary(Integer.MIN_VALUE + 1 - values[0], method); 27.54 + } 27.55 + } 27.56 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/compiler/intrinsics/mathexact/DecExactLTest.java Fri Oct 18 10:41:56 2013 +0200 28.3 @@ -0,0 +1,53 @@ 28.4 +/* 28.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.7 + * 28.8 + * This code is free software; you can redistribute it and/or modify it 28.9 + * under the terms of the GNU General Public License version 2 only, as 28.10 + * published by the Free Software Foundation. 28.11 + * 28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28.15 + * version 2 for more details (a copy is included in the LICENSE file that 28.16 + * accompanied this code). 28.17 + * 28.18 + * You should have received a copy of the GNU General Public License version 28.19 + * 2 along with this work; if not, write to the Free Software Foundation, 28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 28.21 + * 28.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 28.23 + * or visit www.oracle.com if you need additional information or have any 28.24 + * questions. 28.25 + */ 28.26 + 28.27 +/* 28.28 + * @test 28.29 + * @bug 8026844 28.30 + * @summary Test decrementExact 28.31 + * @compile DecExactITest.java Verify.java 28.32 + * @run main DecExactITest 28.33 + * 28.34 + */ 28.35 + 28.36 +public class DecExactLTest { 28.37 + public static long[] values = {1, 1, 1, 1}; 28.38 + public static long[] minvalues = {Long.MIN_VALUE, Long.MIN_VALUE}; 28.39 + 28.40 + public static void main(String[] args) { 28.41 + runTest(new Verify.DecExactL()); 28.42 + } 28.43 + 28.44 + public static void runTest(Verify.UnaryLongMethod method) { 28.45 + for (int i = 0; i < 20000; ++i) { 28.46 + Verify.verifyUnary(Long.MIN_VALUE, method); 28.47 + Verify.verifyUnary(minvalues[0], method); 28.48 + Verify.verifyUnary(Long.MIN_VALUE - values[2], method); 28.49 + Verify.verifyUnary(0, method); 28.50 + Verify.verifyUnary(values[2], method); 28.51 + Verify.verifyUnary(Long.MAX_VALUE, method); 28.52 + Verify.verifyUnary(Long.MIN_VALUE - values[0] + values[3], method); 28.53 + Verify.verifyUnary(Long.MIN_VALUE + 1 - values[0], method); 28.54 + } 28.55 + } 28.56 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/test/compiler/intrinsics/mathexact/IncExactITest.java Fri Oct 18 10:41:56 2013 +0200 29.3 @@ -0,0 +1,51 @@ 29.4 +/* 29.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.7 + * 29.8 + * This code is free software; you can redistribute it and/or modify it 29.9 + * under the terms of the GNU General Public License version 2 only, as 29.10 + * published by the Free Software Foundation. 29.11 + * 29.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.15 + * version 2 for more details (a copy is included in the LICENSE file that 29.16 + * accompanied this code). 29.17 + * 29.18 + * You should have received a copy of the GNU General Public License version 29.19 + * 2 along with this work; if not, write to the Free Software Foundation, 29.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.21 + * 29.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 29.23 + * or visit www.oracle.com if you need additional information or have any 29.24 + * questions. 29.25 + */ 29.26 + 29.27 +/* 29.28 + * @test 29.29 + * @bug 8026844 29.30 + * @summary Test incrementExact 29.31 + * @compile IncExactITest.java Verify.java 29.32 + * @run main IncExactITest 29.33 + * 29.34 + */ 29.35 + 29.36 + 29.37 +public class IncExactITest { 29.38 + public static int[] values = {1, 1, 1, 1}; 29.39 + public static void main(String[] args) { 29.40 + runTest(new Verify.IncExactI()); 29.41 + } 29.42 + 29.43 + public static void runTest(Verify.UnaryMethod method) { 29.44 + for (int i = 0; i < 20000; ++i) { 29.45 + Verify.verifyUnary(Integer.MIN_VALUE, method); 29.46 + Verify.verifyUnary(Integer.MAX_VALUE - 1, method); 29.47 + Verify.verifyUnary(0, method); 29.48 + Verify.verifyUnary(values[1], method); 29.49 + Verify.verifyUnary(Integer.MAX_VALUE, method); 29.50 + Verify.verifyUnary(Integer.MAX_VALUE - values[0] + values[3], method); 29.51 + Verify.verifyUnary(Integer.MAX_VALUE - 1 + values[0], method); 29.52 + } 29.53 + } 29.54 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/test/compiler/intrinsics/mathexact/IncExactLTest.java Fri Oct 18 10:41:56 2013 +0200 30.3 @@ -0,0 +1,50 @@ 30.4 +/* 30.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.7 + * 30.8 + * This code is free software; you can redistribute it and/or modify it 30.9 + * under the terms of the GNU General Public License version 2 only, as 30.10 + * published by the Free Software Foundation. 30.11 + * 30.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 30.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 30.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 30.15 + * version 2 for more details (a copy is included in the LICENSE file that 30.16 + * accompanied this code). 30.17 + * 30.18 + * You should have received a copy of the GNU General Public License version 30.19 + * 2 along with this work; if not, write to the Free Software Foundation, 30.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 30.21 + * 30.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 30.23 + * or visit www.oracle.com if you need additional information or have any 30.24 + * questions. 30.25 + */ 30.26 + 30.27 +/* 30.28 + * @test 30.29 + * @bug 8026844 30.30 + * @summary Test incrementExact 30.31 + * @compile IncExactLTest.java Verify.java 30.32 + * @run main IncExactLTest 30.33 + * 30.34 + */ 30.35 + 30.36 +public class IncExactLTest { 30.37 + public static long[] values = {1, 1, 1, 1}; 30.38 + public static void main(String[] args) { 30.39 + runTest(new Verify.IncExactL()); 30.40 + } 30.41 + 30.42 + public static void runTest(Verify.UnaryLongMethod method) { 30.43 + for (int i = 0; i < 20000; ++i) { 30.44 + Verify.verifyUnary(Long.MIN_VALUE, method); 30.45 + Verify.verifyUnary(Long.MAX_VALUE - 1, method); 30.46 + Verify.verifyUnary(0, method); 30.47 + Verify.verifyUnary(values[1], method); 30.48 + Verify.verifyUnary(Long.MAX_VALUE, method); 30.49 + Verify.verifyUnary(Long.MAX_VALUE - values[0] + values[3], method); 30.50 + Verify.verifyUnary(Long.MAX_VALUE - 1 + values[0], method); 30.51 + } 30.52 + } 30.53 +}
31.1 --- a/test/compiler/intrinsics/mathexact/LoadTest.java Wed Oct 23 16:25:48 2013 -0700 31.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 31.3 @@ -1,55 +0,0 @@ 31.4 -/* 31.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 31.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.7 - * 31.8 - * This code is free software; you can redistribute it and/or modify it 31.9 - * under the terms of the GNU General Public License version 2 only, as 31.10 - * published by the Free Software Foundation. 31.11 - * 31.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 31.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 31.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 31.15 - * version 2 for more details (a copy is included in the LICENSE file that 31.16 - * accompanied this code). 31.17 - * 31.18 - * You should have received a copy of the GNU General Public License version 31.19 - * 2 along with this work; if not, write to the Free Software Foundation, 31.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 31.21 - * 31.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 31.23 - * or visit www.oracle.com if you need additional information or have any 31.24 - * questions. 31.25 - */ 31.26 - 31.27 -/* 31.28 - * @test 31.29 - * @bug 8024924 31.30 - * @summary Test non constant addExact 31.31 - * @compile LoadTest.java Verify.java 31.32 - * @run main LoadTest 31.33 - * 31.34 - */ 31.35 - 31.36 -import java.lang.ArithmeticException; 31.37 - 31.38 -public class LoadTest { 31.39 - public static java.util.Random rnd = new java.util.Random(); 31.40 - public static int[] values = new int[256]; 31.41 - 31.42 - public static void main(String[] args) { 31.43 - for (int i = 0; i < values.length; ++i) { 31.44 - values[i] = rnd.nextInt(); 31.45 - } 31.46 - 31.47 - for (int i = 0; i < 50000; ++i) { 31.48 - Verify.verify(values[i & 255], values[i & 255] - i); 31.49 - Verify.verify(values[i & 255] + i, values[i & 255] - i); 31.50 - Verify.verify(values[i & 255], values[i & 255]); 31.51 - if ((i & 1) == 1 && i > 5) { 31.52 - Verify.verify(values[i & 255] + i, values[i & 255] - i); 31.53 - } else { 31.54 - Verify.verify(values[i & 255] - i, values[i & 255] + i); 31.55 - } 31.56 - } 31.57 - } 31.58 -}
32.1 --- a/test/compiler/intrinsics/mathexact/LoopDependentTest.java Wed Oct 23 16:25:48 2013 -0700 32.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 32.3 @@ -1,48 +0,0 @@ 32.4 -/* 32.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 32.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.7 - * 32.8 - * This code is free software; you can redistribute it and/or modify it 32.9 - * under the terms of the GNU General Public License version 2 only, as 32.10 - * published by the Free Software Foundation. 32.11 - * 32.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 32.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.15 - * version 2 for more details (a copy is included in the LICENSE file that 32.16 - * accompanied this code). 32.17 - * 32.18 - * You should have received a copy of the GNU General Public License version 32.19 - * 2 along with this work; if not, write to the Free Software Foundation, 32.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.21 - * 32.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 32.23 - * or visit www.oracle.com if you need additional information or have any 32.24 - * questions. 32.25 - */ 32.26 - 32.27 -/* 32.28 - * @test 32.29 - * @bug 8024924 32.30 - * @summary Test non constant addExact 32.31 - * @compile LoopDependentTest.java Verify.java 32.32 - * @run main LoopDependentTest 32.33 - * 32.34 - */ 32.35 - 32.36 -import java.lang.ArithmeticException; 32.37 - 32.38 -public class LoopDependentTest { 32.39 - public static java.util.Random rnd = new java.util.Random(); 32.40 - 32.41 - public static void main(String[] args) { 32.42 - int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt(); 32.43 - for (int i = 0; i < 50000; ++i) { 32.44 - Verify.verify(rnd1 + i, rnd2 + i); 32.45 - Verify.verify(rnd1 + i, rnd2 + (i & 0xff)); 32.46 - Verify.verify(rnd1 - i, rnd2 - (i & 0xff)); 32.47 - Verify.verify(rnd1 + i + 1, rnd2 + i + 2); 32.48 - Verify.verify(rnd1 + i * 2, rnd2 + i); 32.49 - } 32.50 - } 32.51 -}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/compiler/intrinsics/mathexact/MulExactICondTest.java Fri Oct 18 10:41:56 2013 +0200 33.3 @@ -0,0 +1,57 @@ 33.4 +/* 33.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.7 + * 33.8 + * This code is free software; you can redistribute it and/or modify it 33.9 + * under the terms of the GNU General Public License version 2 only, as 33.10 + * published by the Free Software Foundation. 33.11 + * 33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 33.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33.15 + * version 2 for more details (a copy is included in the LICENSE file that 33.16 + * accompanied this code). 33.17 + * 33.18 + * You should have received a copy of the GNU General Public License version 33.19 + * 2 along with this work; if not, write to the Free Software Foundation, 33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 33.21 + * 33.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 33.23 + * or visit www.oracle.com if you need additional information or have any 33.24 + * questions. 33.25 + */ 33.26 + 33.27 +/* 33.28 + * @test 33.29 + * @bug 8026844 33.30 + * @summary Test multiplyExact as condition 33.31 + * @compile MulExactICondTest.java 33.32 + * @run main MulExactICondTest 33.33 + * 33.34 + */ 33.35 + 33.36 +public class MulExactICondTest { 33.37 + public static int result = 0; 33.38 + 33.39 + public static void main(String[] args) { 33.40 + for (int i = 0; i < 50000; ++i) { 33.41 + runTest(); 33.42 + } 33.43 + } 33.44 + 33.45 + public static void runTest() { 33.46 + int i = 7; 33.47 + while (java.lang.Math.multiplyExact(i, result) < 89361) { 33.48 + if ((java.lang.Math.multiplyExact(i, i) & 1) == 1) { 33.49 + i += 3; 33.50 + } else if ((i & 5) == 4) { 33.51 + i += 7; 33.52 + } else if ((i & 0xf) == 6) { 33.53 + i += 2; 33.54 + } else { 33.55 + i += 1; 33.56 + } 33.57 + result += 2; 33.58 + } 33.59 + } 33.60 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/compiler/intrinsics/mathexact/MulExactIConstantTest.java Fri Oct 18 10:41:56 2013 +0200 34.3 @@ -0,0 +1,37 @@ 34.4 +/* 34.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 + * 34.8 + * This code is free software; you can redistribute it and/or modify it 34.9 + * under the terms of the GNU General Public License version 2 only, as 34.10 + * published by the Free Software Foundation. 34.11 + * 34.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 34.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.15 + * version 2 for more details (a copy is included in the LICENSE file that 34.16 + * accompanied this code). 34.17 + * 34.18 + * You should have received a copy of the GNU General Public License version 34.19 + * 2 along with this work; if not, write to the Free Software Foundation, 34.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.21 + * 34.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 34.23 + * or visit www.oracle.com if you need additional information or have any 34.24 + * questions. 34.25 + */ 34.26 + 34.27 +/* 34.28 + * @test 34.29 + * @bug 8026844 34.30 + * @summary Test constant multiplyExact 34.31 + * @compile MulExactIConstantTest.java Verify.java 34.32 + * @run main MulExactIConstantTest 34.33 + * 34.34 + */ 34.35 + 34.36 +public class MulExactIConstantTest { 34.37 + public static void main(String[] args) { 34.38 + Verify.ConstantTest.verify(new Verify.MulExactI()); 34.39 + } 34.40 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/compiler/intrinsics/mathexact/MulExactILoadTest.java Fri Oct 18 10:41:56 2013 +0200 35.3 @@ -0,0 +1,38 @@ 35.4 +/* 35.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. 35.11 + * 35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.15 + * version 2 for more details (a copy is included in the LICENSE file that 35.16 + * accompanied this code). 35.17 + * 35.18 + * You should have received a copy of the GNU General Public License version 35.19 + * 2 along with this work; if not, write to the Free Software Foundation, 35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.21 + * 35.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 35.23 + * or visit www.oracle.com if you need additional information or have any 35.24 + * questions. 35.25 + */ 35.26 + 35.27 +/* 35.28 + * @test 35.29 + * @bug 8026844 35.30 + * @summary Test multiplyExact 35.31 + * @compile MulExactILoadTest.java Verify.java 35.32 + * @run main MulExactILoadTest 35.33 + * 35.34 + */ 35.35 + 35.36 +public class MulExactILoadTest { 35.37 + public static void main(String[] args) { 35.38 + Verify.LoadTest.init(); 35.39 + Verify.LoadTest.verify(new Verify.MulExactI()); 35.40 + } 35.41 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/compiler/intrinsics/mathexact/MulExactILoopDependentTest.java Fri Oct 18 10:41:56 2013 +0200 36.3 @@ -0,0 +1,36 @@ 36.4 +/* 36.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.7 + * 36.8 + * This code is free software; you can redistribute it and/or modify it 36.9 + * under the terms of the GNU General Public License version 2 only, as 36.10 + * published by the Free Software Foundation. 36.11 + * 36.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 36.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 36.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36.15 + * version 2 for more details (a copy is included in the LICENSE file that 36.16 + * accompanied this code). 36.17 + * 36.18 + * You should have received a copy of the GNU General Public License version 36.19 + * 2 along with this work; if not, write to the Free Software Foundation, 36.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 36.21 + * 36.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 36.23 + * or visit www.oracle.com if you need additional information or have any 36.24 + * questions. 36.25 + */ 36.26 + 36.27 +/* 36.28 + * @test 36.29 + * @bug 8026844 36.30 + * @summary Test loop dependent multiplyExact 36.31 + * @compile MulExactILoopDependentTest.java Verify.java 36.32 + * @run main MulExactILoopDependentTest 36.33 + * 36.34 + */ 36.35 +public class MulExactILoopDependentTest { 36.36 + public static void main(String[] args) { 36.37 + Verify.LoopDependentTest.verify(new Verify.MulExactI()); 36.38 + } 36.39 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/test/compiler/intrinsics/mathexact/MulExactINonConstantTest.java Fri Oct 18 10:41:56 2013 +0200 37.3 @@ -0,0 +1,38 @@ 37.4 +/* 37.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.7 + * 37.8 + * This code is free software; you can redistribute it and/or modify it 37.9 + * under the terms of the GNU General Public License version 2 only, as 37.10 + * published by the Free Software Foundation. 37.11 + * 37.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 37.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 37.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 37.15 + * version 2 for more details (a copy is included in the LICENSE file that 37.16 + * accompanied this code). 37.17 + * 37.18 + * You should have received a copy of the GNU General Public License version 37.19 + * 2 along with this work; if not, write to the Free Software Foundation, 37.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 37.21 + * 37.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 37.23 + * or visit www.oracle.com if you need additional information or have any 37.24 + * questions. 37.25 + */ 37.26 + 37.27 +/* 37.28 + * @test 37.29 + * @bug 8026844 37.30 + * @summary Test non constant multiplyExact 37.31 + * @compile MulExactINonConstantTest.java Verify.java 37.32 + * @run main MulExactINonConstantTest 37.33 + * 37.34 + */ 37.35 + 37.36 +public class MulExactINonConstantTest { 37.37 + public static void main(String[] args) { 37.38 + Verify.NonConstantTest.verify(new Verify.MulExactI()); 37.39 + Verify.LoadTest.verify(new Verify.MulExactI()); 37.40 + } 37.41 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/compiler/intrinsics/mathexact/MulExactIRepeatTest.java Fri Oct 18 10:41:56 2013 +0200 38.3 @@ -0,0 +1,109 @@ 38.4 +/* 38.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.7 + * 38.8 + * This code is free software; you can redistribute it and/or modify it 38.9 + * under the terms of the GNU General Public License version 2 only, as 38.10 + * published by the Free Software Foundation. 38.11 + * 38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 38.15 + * version 2 for more details (a copy is included in the LICENSE file that 38.16 + * accompanied this code). 38.17 + * 38.18 + * You should have received a copy of the GNU General Public License version 38.19 + * 2 along with this work; if not, write to the Free Software Foundation, 38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 38.21 + * 38.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 38.23 + * or visit www.oracle.com if you need additional information or have any 38.24 + * questions. 38.25 + */ 38.26 + 38.27 +/* 38.28 + * @test 38.29 + * @bug 8026844 38.30 + * @summary Test repeating multiplyExact 38.31 + * @compile MulExactIRepeatTest.java Verify.java 38.32 + * @run main MulExactIRepeatTest 38.33 + * 38.34 + */ 38.35 + 38.36 +public class MulExactIRepeatTest { 38.37 + public static void main(String[] args) { 38.38 + runTest(new Verify.MulExactI()); 38.39 + } 38.40 + 38.41 + public static int nonExact(int x, int y, Verify.BinaryMethod method) { 38.42 + int result = method.unchecked(x, y); 38.43 + result += method.unchecked(x, y); 38.44 + result += method.unchecked(x, y); 38.45 + result += method.unchecked(x, y); 38.46 + return result; 38.47 + } 38.48 + 38.49 + public static void runTest(Verify.BinaryMethod method) { 38.50 + java.util.Random rnd = new java.util.Random(); 38.51 + for (int i = 0; i < 50000; ++i) { 38.52 + int x = Integer.MAX_VALUE - 10; 38.53 + int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5); 38.54 + 38.55 + int c = rnd.nextInt() / 10; 38.56 + int d = rnd.nextInt(9); 38.57 + 38.58 + int a = catchingExact(x, y, method); 38.59 + 38.60 + if (a != 36) { 38.61 + throw new RuntimeException("a != 36 : " + a); 38.62 + } 38.63 + 38.64 + int b = nonExact(c, d, method); 38.65 + int n = exact(c, d, method); 38.66 + 38.67 + 38.68 + if (n != b) { 38.69 + throw new RuntimeException("n != b : " + n + " != " + b); 38.70 + } 38.71 + } 38.72 + } 38.73 + 38.74 + public static int exact(int x, int y, Verify.BinaryMethod method) { 38.75 + int result = 0; 38.76 + result += method.checkMethod(x, y); 38.77 + result += method.checkMethod(x, y); 38.78 + result += method.checkMethod(x, y); 38.79 + result += method.checkMethod(x, y); 38.80 + return result; 38.81 + } 38.82 + 38.83 + public static int catchingExact(int x, int y, Verify.BinaryMethod method) { 38.84 + int result = 0; 38.85 + try { 38.86 + result += 5; 38.87 + result = method.checkMethod(x, y); 38.88 + } catch (ArithmeticException e) { 38.89 + result += 1; 38.90 + } 38.91 + try { 38.92 + result += 6; 38.93 + 38.94 + result += method.checkMethod(x, y); 38.95 + } catch (ArithmeticException e) { 38.96 + result += 2; 38.97 + } 38.98 + try { 38.99 + result += 7; 38.100 + result += method.checkMethod(x, y); 38.101 + } catch (ArithmeticException e) { 38.102 + result += 3; 38.103 + } 38.104 + try { 38.105 + result += 8; 38.106 + result += method.checkMethod(x, y); 38.107 + } catch (ArithmeticException e) { 38.108 + result += 4; 38.109 + } 38.110 + return result; 38.111 + } 38.112 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/compiler/intrinsics/mathexact/MulExactLConstantTest.java Fri Oct 18 10:41:56 2013 +0200 39.3 @@ -0,0 +1,37 @@ 39.4 +/* 39.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.7 + * 39.8 + * This code is free software; you can redistribute it and/or modify it 39.9 + * under the terms of the GNU General Public License version 2 only, as 39.10 + * published by the Free Software Foundation. 39.11 + * 39.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.15 + * version 2 for more details (a copy is included in the LICENSE file that 39.16 + * accompanied this code). 39.17 + * 39.18 + * You should have received a copy of the GNU General Public License version 39.19 + * 2 along with this work; if not, write to the Free Software Foundation, 39.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.21 + * 39.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 39.23 + * or visit www.oracle.com if you need additional information or have any 39.24 + * questions. 39.25 + */ 39.26 + 39.27 +/* 39.28 + * @test 39.29 + * @bug 8026844 39.30 + * @summary Test constant mulExact 39.31 + * @compile MulExactLConstantTest.java Verify.java 39.32 + * @run main MulExactLConstantTest 39.33 + * 39.34 + */ 39.35 + 39.36 +public class MulExactLConstantTest { 39.37 + public static void main(String[] args) { 39.38 + Verify.ConstantLongTest.verify(new Verify.MulExactL()); 39.39 + } 39.40 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/compiler/intrinsics/mathexact/MulExactLNonConstantTest.java Fri Oct 18 10:41:56 2013 +0200 40.3 @@ -0,0 +1,37 @@ 40.4 +/* 40.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40.7 + * 40.8 + * This code is free software; you can redistribute it and/or modify it 40.9 + * under the terms of the GNU General Public License version 2 only, as 40.10 + * published by the Free Software Foundation. 40.11 + * 40.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 40.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40.15 + * version 2 for more details (a copy is included in the LICENSE file that 40.16 + * accompanied this code). 40.17 + * 40.18 + * You should have received a copy of the GNU General Public License version 40.19 + * 2 along with this work; if not, write to the Free Software Foundation, 40.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 40.21 + * 40.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 40.23 + * or visit www.oracle.com if you need additional information or have any 40.24 + * questions. 40.25 + */ 40.26 + 40.27 +/* 40.28 + * @test 40.29 + * @bug 8026844 40.30 + * @summary Test non constant mulExact 40.31 + * @compile MulExactLNonConstantTest.java Verify.java 40.32 + * @run main MulExactLNonConstantTest 40.33 + * 40.34 + */ 40.35 + 40.36 +public class MulExactLNonConstantTest { 40.37 + public static void main(String[] args) { 40.38 + Verify.NonConstantLongTest.verify(new Verify.MulExactL()); 40.39 + } 40.40 +}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/test/compiler/intrinsics/mathexact/NegExactIConstantTest.java Fri Oct 18 10:41:56 2013 +0200 41.3 @@ -0,0 +1,37 @@ 41.4 +/* 41.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41.7 + * 41.8 + * This code is free software; you can redistribute it and/or modify it 41.9 + * under the terms of the GNU General Public License version 2 only, as 41.10 + * published by the Free Software Foundation. 41.11 + * 41.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 41.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 41.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 41.15 + * version 2 for more details (a copy is included in the LICENSE file that 41.16 + * accompanied this code). 41.17 + * 41.18 + * You should have received a copy of the GNU General Public License version 41.19 + * 2 along with this work; if not, write to the Free Software Foundation, 41.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 41.21 + * 41.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 41.23 + * or visit www.oracle.com if you need additional information or have any 41.24 + * questions. 41.25 + */ 41.26 + 41.27 +/* 41.28 + * @test 41.29 + * @bug 8026844 41.30 + * @summary Test constant negExact 41.31 + * @compile NegExactIConstantTest.java Verify.java 41.32 + * @run main NegExactIConstantTest 41.33 + * 41.34 + */ 41.35 + 41.36 +public class NegExactIConstantTest { 41.37 + public static void main(String[] args) { 41.38 + Verify.ConstantTest.verify(new Verify.UnaryToBinary(new Verify.NegExactI())); 41.39 + } 41.40 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/test/compiler/intrinsics/mathexact/NegExactILoadTest.java Fri Oct 18 10:41:56 2013 +0200 42.3 @@ -0,0 +1,39 @@ 42.4 +/* 42.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42.7 + * 42.8 + * This code is free software; you can redistribute it and/or modify it 42.9 + * under the terms of the GNU General Public License version 2 only, as 42.10 + * published by the Free Software Foundation. 42.11 + * 42.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 42.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 42.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 42.15 + * version 2 for more details (a copy is included in the LICENSE file that 42.16 + * accompanied this code). 42.17 + * 42.18 + * You should have received a copy of the GNU General Public License version 42.19 + * 2 along with this work; if not, write to the Free Software Foundation, 42.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 42.21 + * 42.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 42.23 + * or visit www.oracle.com if you need additional information or have any 42.24 + * questions. 42.25 + */ 42.26 + 42.27 +/* 42.28 + * @test 42.29 + * @bug 8026844 42.30 + * @summary Test negExact 42.31 + * @compile NegExactILoadTest.java Verify.java 42.32 + * @run main NegExactILoadTest 42.33 + * 42.34 + */ 42.35 + 42.36 +public class NegExactILoadTest { 42.37 + public static void main(String[] args) { 42.38 + Verify.LoadTest.init(); 42.39 + Verify.LoadTest.verify(new Verify.UnaryToBinary(new Verify.NegExactI())); 42.40 + } 42.41 + 42.42 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/compiler/intrinsics/mathexact/NegExactILoopDependentTest.java Fri Oct 18 10:41:56 2013 +0200 43.3 @@ -0,0 +1,36 @@ 43.4 +/* 43.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43.7 + * 43.8 + * This code is free software; you can redistribute it and/or modify it 43.9 + * under the terms of the GNU General Public License version 2 only, as 43.10 + * published by the Free Software Foundation. 43.11 + * 43.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 43.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 43.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 43.15 + * version 2 for more details (a copy is included in the LICENSE file that 43.16 + * accompanied this code). 43.17 + * 43.18 + * You should have received a copy of the GNU General Public License version 43.19 + * 2 along with this work; if not, write to the Free Software Foundation, 43.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 43.21 + * 43.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 43.23 + * or visit www.oracle.com if you need additional information or have any 43.24 + * questions. 43.25 + */ 43.26 + 43.27 +/* 43.28 + * @test 43.29 + * @bug 8026844 43.30 + * @summary Test negExact loop dependent 43.31 + * @compile NegExactILoopDependentTest.java Verify.java 43.32 + * @run main NegExactILoopDependentTest 43.33 + * 43.34 + */ 43.35 +public class NegExactILoopDependentTest { 43.36 + public static void main(String[] args) { 43.37 + Verify.LoopDependentTest.verify(new Verify.UnaryToBinary(new Verify.NegExactI())); 43.38 + } 43.39 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/compiler/intrinsics/mathexact/NegExactINonConstantTest.java Fri Oct 18 10:41:56 2013 +0200 44.3 @@ -0,0 +1,37 @@ 44.4 +/* 44.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 44.7 + * 44.8 + * This code is free software; you can redistribute it and/or modify it 44.9 + * under the terms of the GNU General Public License version 2 only, as 44.10 + * published by the Free Software Foundation. 44.11 + * 44.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 44.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 44.15 + * version 2 for more details (a copy is included in the LICENSE file that 44.16 + * accompanied this code). 44.17 + * 44.18 + * You should have received a copy of the GNU General Public License version 44.19 + * 2 along with this work; if not, write to the Free Software Foundation, 44.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 44.21 + * 44.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 44.23 + * or visit www.oracle.com if you need additional information or have any 44.24 + * questions. 44.25 + */ 44.26 + 44.27 +/* 44.28 + * @test 44.29 + * @bug 8026844 44.30 + * @summary Test non constant negExact 44.31 + * @compile NegExactINonConstantTest.java Verify.java 44.32 + * @run main NegExactINonConstantTest 44.33 + * 44.34 + */ 44.35 + 44.36 +public class NegExactINonConstantTest { 44.37 + public static void main(String[] args) { 44.38 + Verify.NonConstantTest.verify(new Verify.UnaryToBinary(new Verify.NegExactI())); 44.39 + } 44.40 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/test/compiler/intrinsics/mathexact/NegExactLConstantTest.java Fri Oct 18 10:41:56 2013 +0200 45.3 @@ -0,0 +1,37 @@ 45.4 +/* 45.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 45.7 + * 45.8 + * This code is free software; you can redistribute it and/or modify it 45.9 + * under the terms of the GNU General Public License version 2 only, as 45.10 + * published by the Free Software Foundation. 45.11 + * 45.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 45.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 45.15 + * version 2 for more details (a copy is included in the LICENSE file that 45.16 + * accompanied this code). 45.17 + * 45.18 + * You should have received a copy of the GNU General Public License version 45.19 + * 2 along with this work; if not, write to the Free Software Foundation, 45.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 45.21 + * 45.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 45.23 + * or visit www.oracle.com if you need additional information or have any 45.24 + * questions. 45.25 + */ 45.26 + 45.27 +/* 45.28 + * @test 45.29 + * @bug 8026844 45.30 + * @summary Test constant negExact 45.31 + * @compile NegExactLConstantTest.java Verify.java 45.32 + * @run main NegExactLConstantTest 45.33 + * 45.34 + */ 45.35 + 45.36 +public class NegExactLConstantTest { 45.37 + public static void main(String[] args) { 45.38 + Verify.ConstantLongTest.verify(new Verify.UnaryToBinaryLong(new Verify.NegExactL())); 45.39 + } 45.40 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/compiler/intrinsics/mathexact/NegExactLNonConstantTest.java Fri Oct 18 10:41:56 2013 +0200 46.3 @@ -0,0 +1,37 @@ 46.4 +/* 46.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 46.7 + * 46.8 + * This code is free software; you can redistribute it and/or modify it 46.9 + * under the terms of the GNU General Public License version 2 only, as 46.10 + * published by the Free Software Foundation. 46.11 + * 46.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 46.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 46.15 + * version 2 for more details (a copy is included in the LICENSE file that 46.16 + * accompanied this code). 46.17 + * 46.18 + * You should have received a copy of the GNU General Public License version 46.19 + * 2 along with this work; if not, write to the Free Software Foundation, 46.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 46.21 + * 46.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 46.23 + * or visit www.oracle.com if you need additional information or have any 46.24 + * questions. 46.25 + */ 46.26 + 46.27 +/* 46.28 + * @test 46.29 + * @bug 8026844 46.30 + * @summary Test constant negExact 46.31 + * @compile NegExactLNonConstantTest.java Verify.java 46.32 + * @run main NegExactLNonConstantTest 46.33 + * 46.34 + */ 46.35 + 46.36 +public class NegExactLNonConstantTest { 46.37 + public static void main(String[] args) { 46.38 + Verify.NonConstantLongTest.verify(new Verify.UnaryToBinaryLong(new Verify.NegExactL())); 46.39 + } 46.40 +}
47.1 --- a/test/compiler/intrinsics/mathexact/NonConstantTest.java Wed Oct 23 16:25:48 2013 -0700 47.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 47.3 @@ -1,48 +0,0 @@ 47.4 -/* 47.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 47.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 - * 47.8 - * This code is free software; you can redistribute it and/or modify it 47.9 - * under the terms of the GNU General Public License version 2 only, as 47.10 - * published by the Free Software Foundation. 47.11 - * 47.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 47.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.15 - * version 2 for more details (a copy is included in the LICENSE file that 47.16 - * accompanied this code). 47.17 - * 47.18 - * You should have received a copy of the GNU General Public License version 47.19 - * 2 along with this work; if not, write to the Free Software Foundation, 47.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.21 - * 47.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 47.23 - * or visit www.oracle.com if you need additional information or have any 47.24 - * questions. 47.25 - */ 47.26 - 47.27 -/* 47.28 - * @test 47.29 - * @bug 8024924 47.30 - * @summary Test non constant addExact 47.31 - * @compile NonConstantTest.java Verify.java 47.32 - * @run main NonConstantTest 47.33 - * 47.34 - */ 47.35 - 47.36 -import java.lang.ArithmeticException; 47.37 - 47.38 -public class NonConstantTest { 47.39 - public static java.util.Random rnd = new java.util.Random(); 47.40 - 47.41 - public static void main(String[] args) { 47.42 - for (int i = 0; i < 50000; ++i) { 47.43 - int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt(); 47.44 - Verify.verify(rnd1, rnd2); 47.45 - Verify.verify(rnd1, rnd2 + 1); 47.46 - Verify.verify(rnd1 + 1, rnd2); 47.47 - Verify.verify(rnd1 - 1, rnd2); 47.48 - Verify.verify(rnd1, rnd2 - 1); 47.49 - } 47.50 - } 47.51 -}
48.1 --- a/test/compiler/intrinsics/mathexact/RepeatTest.java Wed Oct 23 16:25:48 2013 -0700 48.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 48.3 @@ -1,107 +0,0 @@ 48.4 -/* 48.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 48.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 - * 48.8 - * This code is free software; you can redistribute it and/or modify it 48.9 - * under the terms of the GNU General Public License version 2 only, as 48.10 - * published by the Free Software Foundation. 48.11 - * 48.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 48.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.15 - * version 2 for more details (a copy is included in the LICENSE file that 48.16 - * accompanied this code). 48.17 - * 48.18 - * You should have received a copy of the GNU General Public License version 48.19 - * 2 along with this work; if not, write to the Free Software Foundation, 48.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.21 - * 48.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 48.23 - * or visit www.oracle.com if you need additional information or have any 48.24 - * questions. 48.25 - */ 48.26 - 48.27 -/* 48.28 - * @test 48.29 - * @bug 8025657 48.30 - * @summary Test repeating addExact 48.31 - * @compile RepeatTest.java 48.32 - * @run main RepeatTest 48.33 - * 48.34 - */ 48.35 - 48.36 -import java.lang.ArithmeticException; 48.37 - 48.38 -public class RepeatTest { 48.39 - public static void main(String[] args) { 48.40 - java.util.Random rnd = new java.util.Random(); 48.41 - for (int i = 0; i < 50000; ++i) { 48.42 - int x = Integer.MAX_VALUE - 10; 48.43 - int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5); //rnd.nextInt() / 2; 48.44 - 48.45 - int c = rnd.nextInt() / 2; 48.46 - int d = rnd.nextInt() / 2; 48.47 - 48.48 - int a = addExact(x, y); 48.49 - 48.50 - if (a != 36) { 48.51 - throw new RuntimeException("a != 0 : " + a); 48.52 - } 48.53 - 48.54 - int b = nonExact(c, d); 48.55 - int n = addExact2(c, d); 48.56 - 48.57 - 48.58 - if (n != b) { 48.59 - throw new RuntimeException("n != b : " + n + " != " + b); 48.60 - } 48.61 - } 48.62 - } 48.63 - 48.64 - public static int addExact2(int x, int y) { 48.65 - int result = 0; 48.66 - result += java.lang.Math.addExact(x, y); 48.67 - result += java.lang.Math.addExact(x, y); 48.68 - result += java.lang.Math.addExact(x, y); 48.69 - result += java.lang.Math.addExact(x, y); 48.70 - return result; 48.71 - } 48.72 - 48.73 - public static int addExact(int x, int y) { 48.74 - int result = 0; 48.75 - try { 48.76 - result += 5; 48.77 - result = java.lang.Math.addExact(x, y); 48.78 - } catch (ArithmeticException e) { 48.79 - result += 1; 48.80 - } 48.81 - try { 48.82 - result += 6; 48.83 - 48.84 - result += java.lang.Math.addExact(x, y); 48.85 - } catch (ArithmeticException e) { 48.86 - result += 2; 48.87 - } 48.88 - try { 48.89 - result += 7; 48.90 - result += java.lang.Math.addExact(x, y); 48.91 - } catch (ArithmeticException e) { 48.92 - result += 3; 48.93 - } 48.94 - try { 48.95 - result += 8; 48.96 - result += java.lang.Math.addExact(x, y); 48.97 - } catch (ArithmeticException e) { 48.98 - result += 4; 48.99 - } 48.100 - return result; 48.101 - } 48.102 - 48.103 - public static int nonExact(int x, int y) { 48.104 - int result = x + y; 48.105 - result += x + y; 48.106 - result += x + y; 48.107 - result += x + y; 48.108 - return result; 48.109 - } 48.110 -}
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/compiler/intrinsics/mathexact/SubExactICondTest.java Fri Oct 18 10:41:56 2013 +0200 49.3 @@ -0,0 +1,57 @@ 49.4 +/* 49.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. 49.11 + * 49.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.15 + * version 2 for more details (a copy is included in the LICENSE file that 49.16 + * accompanied this code). 49.17 + * 49.18 + * You should have received a copy of the GNU General Public License version 49.19 + * 2 along with this work; if not, write to the Free Software Foundation, 49.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.21 + * 49.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.23 + * or visit www.oracle.com if you need additional information or have any 49.24 + * questions. 49.25 + */ 49.26 + 49.27 +/* 49.28 + * @test 49.29 + * @bug 8026844 49.30 + * @summary Test subtractExact as condition 49.31 + * @compile SubExactICondTest.java Verify.java 49.32 + * @run main SubExactICondTest 49.33 + * 49.34 + */ 49.35 + 49.36 +public class SubExactICondTest { 49.37 + public static int result = 0; 49.38 + 49.39 + public static void main(String[] args) { 49.40 + for (int i = 0; i < 50000; ++i) { 49.41 + runTest(); 49.42 + } 49.43 + } 49.44 + 49.45 + public static void runTest() { 49.46 + int i = 7; 49.47 + while (java.lang.Math.subtractExact(i, result) > -31361) { 49.48 + if ((java.lang.Math.subtractExact(i, i) & 1) == 1) { 49.49 + i -= 3; 49.50 + } else if ((i & 5) == 4) { 49.51 + i -= 7; 49.52 + } else if ((i & 0xf) == 6) { 49.53 + i -= 2; 49.54 + } else { 49.55 + i -= 1; 49.56 + } 49.57 + result += 2; 49.58 + } 49.59 + } 49.60 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/compiler/intrinsics/mathexact/SubExactIConstantTest.java Fri Oct 18 10:41:56 2013 +0200 50.3 @@ -0,0 +1,37 @@ 50.4 +/* 50.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. 50.11 + * 50.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.15 + * version 2 for more details (a copy is included in the LICENSE file that 50.16 + * accompanied this code). 50.17 + * 50.18 + * You should have received a copy of the GNU General Public License version 50.19 + * 2 along with this work; if not, write to the Free Software Foundation, 50.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.21 + * 50.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 50.23 + * or visit www.oracle.com if you need additional information or have any 50.24 + * questions. 50.25 + */ 50.26 + 50.27 +/* 50.28 + * @test 50.29 + * @bug 8026844 50.30 + * @summary Test constant subtractExact 50.31 + * @compile SubExactIConstantTest.java Verify.java 50.32 + * @run main SubExactIConstantTest 50.33 + * 50.34 + */ 50.35 + 50.36 +public class SubExactIConstantTest { 50.37 + public static void main(String[] args) { 50.38 + Verify.ConstantTest.verify(new Verify.SubExactI()); 50.39 + } 50.40 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/compiler/intrinsics/mathexact/SubExactILoadTest.java Fri Oct 18 10:41:56 2013 +0200 51.3 @@ -0,0 +1,38 @@ 51.4 +/* 51.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 + * 51.8 + * This code is free software; you can redistribute it and/or modify it 51.9 + * under the terms of the GNU General Public License version 2 only, as 51.10 + * published by the Free Software Foundation. 51.11 + * 51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.15 + * version 2 for more details (a copy is included in the LICENSE file that 51.16 + * accompanied this code). 51.17 + * 51.18 + * You should have received a copy of the GNU General Public License version 51.19 + * 2 along with this work; if not, write to the Free Software Foundation, 51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.21 + * 51.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 51.23 + * or visit www.oracle.com if you need additional information or have any 51.24 + * questions. 51.25 + */ 51.26 + 51.27 +/* 51.28 + * @test 51.29 + * @bug 8026844 51.30 + * @summary Test non constant subtractExact 51.31 + * @compile SubExactILoadTest.java Verify.java 51.32 + * @run main SubExactILoadTest 51.33 + * 51.34 + */ 51.35 + 51.36 +public class SubExactILoadTest { 51.37 + public static void main(String[] args) { 51.38 + Verify.LoadTest.init(); 51.39 + Verify.LoadTest.verify(new Verify.SubExactI()); 51.40 + } 51.41 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/test/compiler/intrinsics/mathexact/SubExactILoopDependentTest.java Fri Oct 18 10:41:56 2013 +0200 52.3 @@ -0,0 +1,37 @@ 52.4 +/* 52.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 52.7 + * 52.8 + * This code is free software; you can redistribute it and/or modify it 52.9 + * under the terms of the GNU General Public License version 2 only, as 52.10 + * published by the Free Software Foundation. 52.11 + * 52.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 52.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 52.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 52.15 + * version 2 for more details (a copy is included in the LICENSE file that 52.16 + * accompanied this code). 52.17 + * 52.18 + * You should have received a copy of the GNU General Public License version 52.19 + * 2 along with this work; if not, write to the Free Software Foundation, 52.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 52.21 + * 52.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 52.23 + * or visit www.oracle.com if you need additional information or have any 52.24 + * questions. 52.25 + */ 52.26 + 52.27 +/* 52.28 + * @test 52.29 + * @bug 8026844 52.30 + * @summary Test non constant subtractExact 52.31 + * @compile SubExactILoopDependentTest.java Verify.java 52.32 + * @run main SubExactILoopDependentTest 52.33 + * 52.34 + */ 52.35 + 52.36 +public class SubExactILoopDependentTest { 52.37 + public static void main(String[] args) { 52.38 + Verify.LoopDependentTest.verify(new Verify.SubExactI()); 52.39 + } 52.40 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/test/compiler/intrinsics/mathexact/SubExactINonConstantTest.java Fri Oct 18 10:41:56 2013 +0200 53.3 @@ -0,0 +1,37 @@ 53.4 +/* 53.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.7 + * 53.8 + * This code is free software; you can redistribute it and/or modify it 53.9 + * under the terms of the GNU General Public License version 2 only, as 53.10 + * published by the Free Software Foundation. 53.11 + * 53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 53.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 53.15 + * version 2 for more details (a copy is included in the LICENSE file that 53.16 + * accompanied this code). 53.17 + * 53.18 + * You should have received a copy of the GNU General Public License version 53.19 + * 2 along with this work; if not, write to the Free Software Foundation, 53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 53.21 + * 53.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 53.23 + * or visit www.oracle.com if you need additional information or have any 53.24 + * questions. 53.25 + */ 53.26 + 53.27 +/* 53.28 + * @test 53.29 + * @bug 8026844 53.30 + * @summary Test non constant subtractExact 53.31 + * @compile SubExactINonConstantTest.java Verify.java 53.32 + * @run main SubExactINonConstantTest 53.33 + * 53.34 + */ 53.35 + 53.36 +public class SubExactINonConstantTest { 53.37 + public static void main(String[] args) { 53.38 + Verify.NonConstantTest.verify(new Verify.SubExactI()); 53.39 + } 53.40 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/test/compiler/intrinsics/mathexact/SubExactIRepeatTest.java Fri Oct 18 10:41:56 2013 +0200 54.3 @@ -0,0 +1,111 @@ 54.4 +/* 54.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. 54.11 + * 54.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.15 + * version 2 for more details (a copy is included in the LICENSE file that 54.16 + * accompanied this code). 54.17 + * 54.18 + * You should have received a copy of the GNU General Public License version 54.19 + * 2 along with this work; if not, write to the Free Software Foundation, 54.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.21 + * 54.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 54.23 + * or visit www.oracle.com if you need additional information or have any 54.24 + * questions. 54.25 + */ 54.26 + 54.27 +/* 54.28 + * @test 54.29 + * @bug 8026844 54.30 + * @summary Test repeating subtractExact 54.31 + * @compile SubExactIRepeatTest.java Verify.java 54.32 + * @run main SubExactIRepeatTest 54.33 + * 54.34 + */ 54.35 + 54.36 +import java.lang.ArithmeticException; 54.37 + 54.38 +public class SubExactIRepeatTest { 54.39 + public static void main(String[] args) { 54.40 + runTest(new Verify.SubExactI()); 54.41 + } 54.42 + 54.43 + public static int nonExact(int x, int y, Verify.BinaryMethod method) { 54.44 + int result = method.unchecked(x, y); 54.45 + result += method.unchecked(x, y); 54.46 + result += method.unchecked(x, y); 54.47 + result += method.unchecked(x, y); 54.48 + return result; 54.49 + } 54.50 + 54.51 + public static void runTest(Verify.BinaryMethod method) { 54.52 + java.util.Random rnd = new java.util.Random(); 54.53 + for (int i = 0; i < 50000; ++i) { 54.54 + int x = Integer.MIN_VALUE + 10; 54.55 + int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5); 54.56 + 54.57 + int c = rnd.nextInt() / 2; 54.58 + int d = rnd.nextInt() / 2; 54.59 + 54.60 + int a = catchingExact(x, y, method); 54.61 + 54.62 + if (a != 36) { 54.63 + throw new RuntimeException("a != 36 : " + a); 54.64 + } 54.65 + 54.66 + int b = nonExact(c, d, method); 54.67 + int n = exact(c, d, method); 54.68 + 54.69 + 54.70 + if (n != b) { 54.71 + throw new RuntimeException("n != b : " + n + " != " + b); 54.72 + } 54.73 + } 54.74 + } 54.75 + 54.76 + public static int exact(int x, int y, Verify.BinaryMethod method) { 54.77 + int result = 0; 54.78 + result += method.checkMethod(x, y); 54.79 + result += method.checkMethod(x, y); 54.80 + result += method.checkMethod(x, y); 54.81 + result += method.checkMethod(x, y); 54.82 + return result; 54.83 + } 54.84 + 54.85 + public static int catchingExact(int x, int y, Verify.BinaryMethod method) { 54.86 + int result = 0; 54.87 + try { 54.88 + result += 5; 54.89 + result = method.checkMethod(x, y); 54.90 + } catch (ArithmeticException e) { 54.91 + result += 1; 54.92 + } 54.93 + try { 54.94 + result += 6; 54.95 + 54.96 + result += method.checkMethod(x, y); 54.97 + } catch (ArithmeticException e) { 54.98 + result += 2; 54.99 + } 54.100 + try { 54.101 + result += 7; 54.102 + result += method.checkMethod(x, y); 54.103 + } catch (ArithmeticException e) { 54.104 + result += 3; 54.105 + } 54.106 + try { 54.107 + result += 8; 54.108 + result += method.checkMethod(x, y); 54.109 + } catch (ArithmeticException e) { 54.110 + result += 4; 54.111 + } 54.112 + return result; 54.113 + } 54.114 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/compiler/intrinsics/mathexact/SubExactLConstantTest.java Fri Oct 18 10:41:56 2013 +0200 55.3 @@ -0,0 +1,37 @@ 55.4 +/* 55.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 + * 55.8 + * This code is free software; you can redistribute it and/or modify it 55.9 + * under the terms of the GNU General Public License version 2 only, as 55.10 + * published by the Free Software Foundation. 55.11 + * 55.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 55.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.15 + * version 2 for more details (a copy is included in the LICENSE file that 55.16 + * accompanied this code). 55.17 + * 55.18 + * You should have received a copy of the GNU General Public License version 55.19 + * 2 along with this work; if not, write to the Free Software Foundation, 55.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.21 + * 55.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 55.23 + * or visit www.oracle.com if you need additional information or have any 55.24 + * questions. 55.25 + */ 55.26 + 55.27 +/* 55.28 + * @test 55.29 + * @bug 8026844 55.30 + * @summary Test constant subtractExact 55.31 + * @compile SubExactLConstantTest.java Verify.java 55.32 + * @run main SubExactLConstantTest 55.33 + * 55.34 + */ 55.35 + 55.36 +public class SubExactLConstantTest { 55.37 + public static void main(String[] args) { 55.38 + Verify.ConstantLongTest.verify(new Verify.SubExactL()); 55.39 + } 55.40 +}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/test/compiler/intrinsics/mathexact/SubExactLNonConstantTest.java Fri Oct 18 10:41:56 2013 +0200 56.3 @@ -0,0 +1,37 @@ 56.4 +/* 56.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 56.7 + * 56.8 + * This code is free software; you can redistribute it and/or modify it 56.9 + * under the terms of the GNU General Public License version 2 only, as 56.10 + * published by the Free Software Foundation. 56.11 + * 56.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 56.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 56.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 56.15 + * version 2 for more details (a copy is included in the LICENSE file that 56.16 + * accompanied this code). 56.17 + * 56.18 + * You should have received a copy of the GNU General Public License version 56.19 + * 2 along with this work; if not, write to the Free Software Foundation, 56.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 56.21 + * 56.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 56.23 + * or visit www.oracle.com if you need additional information or have any 56.24 + * questions. 56.25 + */ 56.26 + 56.27 +/* 56.28 + * @test 56.29 + * @bug 8026844 56.30 + * @summary Test non constant subtractExact 56.31 + * @compile SubExactLNonConstantTest.java Verify.java 56.32 + * @run main SubExactLNonConstantTest 56.33 + * 56.34 + */ 56.35 + 56.36 +public class SubExactLNonConstantTest { 56.37 + public static void main(String[] args) { 56.38 + Verify.NonConstantLongTest.verify(new Verify.SubExactL()); 56.39 + } 56.40 +}
57.1 --- a/test/compiler/intrinsics/mathexact/Verify.java Wed Oct 23 16:25:48 2013 -0700 57.2 +++ b/test/compiler/intrinsics/mathexact/Verify.java Fri Oct 18 10:41:56 2013 +0200 57.3 @@ -22,47 +22,641 @@ 57.4 */ 57.5 57.6 public class Verify { 57.7 - public static String throwWord(boolean threw) { 57.8 - return (threw ? "threw" : "didn't throw"); 57.9 - } 57.10 - 57.11 - public static void verify(int a, int b) { 57.12 - boolean exception1 = false, exception2 = false; 57.13 - int result1 = 0, result2 = 0; 57.14 - try { 57.15 - result1 = testIntrinsic(a, b); 57.16 - } catch (ArithmeticException e) { 57.17 - exception1 = true; 57.18 - } 57.19 - try { 57.20 - result2 = testNonIntrinsic(a, b); 57.21 - } catch (ArithmeticException e) { 57.22 - exception2 = true; 57.23 + public static String throwWord(boolean threw) { 57.24 + return (threw ? "threw" : "didn't throw"); 57.25 } 57.26 57.27 - if (exception1 != exception2) { 57.28 - throw new RuntimeException("Intrinsic version " + throwWord(exception1) + " exception, NonIntrinsic version " + throwWord(exception2) + " for: " + a + " + " + b); 57.29 + public static void verifyResult(UnaryMethod method, int result1, int result2, boolean exception1, boolean exception2, int value) { 57.30 + if (exception1 != exception2) { 57.31 + throw new RuntimeException("Intrinsic version [" + method.name() + "]" + throwWord(exception1) + " exception, NonIntrinsic version" + throwWord(exception2) + " for: " + value); 57.32 + } 57.33 + if (result1 != result2) { 57.34 + throw new RuntimeException("Intrinsic version [" + method.name() + "] returned: " + result1 + " while NonIntrinsic version returned: " + result2); 57.35 + } 57.36 } 57.37 - if (result1 != result2) { 57.38 - throw new RuntimeException("Intrinsic version returned: " + a + " while NonIntrinsic version returned: " + b); 57.39 + 57.40 + public static void verifyResult(UnaryLongMethod method, long result1, long result2, boolean exception1, boolean exception2, long value) { 57.41 + if (exception1 != exception2) { 57.42 + throw new RuntimeException("Intrinsic version [" + method.name() + "]" + throwWord(exception1) + " exception, NonIntrinsic version" + throwWord(exception2) + " for: " + value); 57.43 + } 57.44 + if (result1 != result2) { 57.45 + throw new RuntimeException("Intrinsic version [" + method.name() + "] returned: " + result1 + " while NonIntrinsic version returned: " + result2); 57.46 + } 57.47 } 57.48 - } 57.49 57.50 - public static int testIntrinsic(int a, int b) { 57.51 - return java.lang.Math.addExact(a, b); 57.52 - } 57.53 + private static void verifyResult(BinaryMethod method, int result1, int result2, boolean exception1, boolean exception2, int a, int b) { 57.54 + if (exception1 != exception2) { 57.55 + throw new RuntimeException("Intrinsic version [" + method.name() + "]" + throwWord(exception1) + " exception, NonIntrinsic version " + throwWord(exception2) + " for: " + a + " + " + b); 57.56 + } 57.57 + if (result1 != result2) { 57.58 + throw new RuntimeException("Intrinsic version [" + method.name() + "] returned: " + result1 + " while NonIntrinsic version returned: " + result2); 57.59 + } 57.60 + } 57.61 57.62 - public static int testNonIntrinsic(int a, int b) { 57.63 - return safeAddExact(a, b); 57.64 - } 57.65 + private static void verifyResult(BinaryLongMethod method, long result1, long result2, boolean exception1, boolean exception2, long a, long b) { 57.66 + if (exception1 != exception2) { 57.67 + throw new RuntimeException("Intrinsic version [" + method.name() + "]" + throwWord(exception1) + " exception, NonIntrinsic version " + throwWord(exception2) + " for: " + a + " + " + b); 57.68 + } 57.69 + if (result1 != result2) { 57.70 + throw new RuntimeException("Intrinsic version [" + method.name() + "] returned: " + result1 + " while NonIntrinsic version returned: " + result2); 57.71 + } 57.72 + } 57.73 57.74 - // Copied java.lang.Math.addExact to avoid intrinsification 57.75 - public static int safeAddExact(int x, int y) { 57.76 - int r = x + y; 57.77 - // HD 2-12 Overflow iff both arguments have the opposite sign of the result 57.78 - if (((x ^ r) & (y ^ r)) < 0) { 57.79 - throw new ArithmeticException("integer overflow"); 57.80 + 57.81 + public static void verifyUnary(int a, UnaryMethod method) { 57.82 + boolean exception1 = false, exception2 = false; 57.83 + int result1 = 0, result2 = 0; 57.84 + try { 57.85 + result1 = method.checkMethod(a); 57.86 + } catch (ArithmeticException e) { 57.87 + exception1 = true; 57.88 + } 57.89 + try { 57.90 + result2 = method.safeMethod(a); 57.91 + } catch (ArithmeticException e) { 57.92 + exception2 = true; 57.93 + } 57.94 + 57.95 + verifyResult(method, result1, result2, exception1, exception2, a); 57.96 } 57.97 - return r; 57.98 - } 57.99 + 57.100 + public static void verifyUnary(long a, UnaryLongMethod method) { 57.101 + boolean exception1 = false, exception2 = false; 57.102 + long result1 = 0, result2 = 0; 57.103 + try { 57.104 + result1 = method.checkMethod(a); 57.105 + } catch (ArithmeticException e) { 57.106 + exception1 = true; 57.107 + } 57.108 + try { 57.109 + result2 = method.safeMethod(a); 57.110 + } catch (ArithmeticException e) { 57.111 + exception2 = true; 57.112 + } 57.113 + 57.114 + verifyResult(method, result1, result2, exception1, exception2, a); 57.115 + } 57.116 + 57.117 + 57.118 + public static void verifyBinary(int a, int b, BinaryMethod method) { 57.119 + boolean exception1 = false, exception2 = false; 57.120 + int result1 = 0, result2 = 0; 57.121 + try { 57.122 + result1 = method.checkMethod(a, b); 57.123 + } catch (ArithmeticException e) { 57.124 + exception1 = true; 57.125 + } 57.126 + try { 57.127 + result2 = method.safeMethod(a, b); 57.128 + } catch (ArithmeticException e) { 57.129 + exception2 = true; 57.130 + } 57.131 + 57.132 + verifyResult(method, result1, result2, exception1, exception2, a, b); 57.133 + } 57.134 + 57.135 + public static void verifyBinary(long a, long b, BinaryLongMethod method) { 57.136 + boolean exception1 = false, exception2 = false; 57.137 + long result1 = 0, result2 = 0; 57.138 + try { 57.139 + result1 = method.checkMethod(a, b); 57.140 + } catch (ArithmeticException e) { 57.141 + exception1 = true; 57.142 + } 57.143 + try { 57.144 + result2 = method.safeMethod(a, b); 57.145 + } catch (ArithmeticException e) { 57.146 + exception2 = true; 57.147 + } 57.148 + 57.149 + verifyResult(method, result1, result2, exception1, exception2, a, b); 57.150 + } 57.151 + 57.152 + 57.153 + public static class LoadTest { 57.154 + public static java.util.Random rnd = new java.util.Random(); 57.155 + public static int[] values = new int[256]; 57.156 + 57.157 + public static void init() { 57.158 + for (int i = 0; i < values.length; ++i) { 57.159 + values[i] = rnd.nextInt(); 57.160 + } 57.161 + } 57.162 + 57.163 + public static void verify(BinaryMethod method) { 57.164 + for (int i = 0; i < 50000; ++i) { 57.165 + Verify.verifyBinary(values[i & 255], values[i & 255] - i, method); 57.166 + Verify.verifyBinary(values[i & 255] + i, values[i & 255] - i, method); 57.167 + Verify.verifyBinary(values[i & 255], values[i & 255], method); 57.168 + if ((i & 1) == 1 && i > 5) { 57.169 + Verify.verifyBinary(values[i & 255] + i, values[i & 255] - i, method); 57.170 + } else { 57.171 + Verify.verifyBinary(values[i & 255] - i, values[i & 255] + i, method); 57.172 + } 57.173 + Verify.verifyBinary(values[i & 255], values[(i + 1) & 255], method); 57.174 + } 57.175 + } 57.176 + } 57.177 + 57.178 + public static class NonConstantTest { 57.179 + public static java.util.Random rnd = new java.util.Random(); 57.180 + 57.181 + public static void verify(BinaryMethod method) { 57.182 + for (int i = 0; i < 50000; ++i) { 57.183 + int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt(); 57.184 + Verify.verifyBinary(rnd1, rnd2, method); 57.185 + Verify.verifyBinary(rnd1, rnd2 + 1, method); 57.186 + Verify.verifyBinary(rnd1 + 1, rnd2, method); 57.187 + Verify.verifyBinary(rnd1 - 1, rnd2, method); 57.188 + Verify.verifyBinary(rnd1, rnd2 - 1, method); 57.189 + } 57.190 + } 57.191 + } 57.192 + 57.193 + public static class NonConstantLongTest { 57.194 + public static long[] values = { Long.MIN_VALUE, Long.MAX_VALUE, 0, Long.MAX_VALUE - 1831 }; 57.195 + public static java.util.Random rnd = new java.util.Random(); 57.196 + 57.197 + public static void verify(BinaryLongMethod method) { 57.198 + for (int i = 0; i < 50000; ++i) { 57.199 + long rnd1 = rnd.nextLong(), rnd2 = rnd.nextLong(); 57.200 + Verify.verifyBinary(rnd1, rnd2, method); 57.201 + Verify.verifyBinary(rnd1, rnd2 + 1, method); 57.202 + Verify.verifyBinary(rnd1 + 1, rnd2, method); 57.203 + Verify.verifyBinary(rnd1 - 1, rnd2, method); 57.204 + Verify.verifyBinary(rnd1, rnd2 - 1, method); 57.205 + Verify.verifyBinary(rnd1 + Long.MAX_VALUE - rnd2, rnd2 + 1, method); 57.206 + Verify.verifyBinary(values[0], values[2], method); 57.207 + Verify.verifyBinary(values[1], values[2], method); 57.208 + Verify.verifyBinary(values[3], 74L, method); 57.209 + } 57.210 + } 57.211 + } 57.212 + 57.213 + public static class LoopDependentTest { 57.214 + public static java.util.Random rnd = new java.util.Random(); 57.215 + 57.216 + public static void verify(BinaryMethod method) { 57.217 + int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt(); 57.218 + runTest(rnd1, rnd2, method); 57.219 + } 57.220 + 57.221 + private static void runTest(int rnd1, int rnd2, BinaryMethod method) { 57.222 + for (int i = 0; i < 50000; ++i) { 57.223 + Verify.verifyBinary(rnd1 + i, rnd2 + i, method); 57.224 + Verify.verifyBinary(rnd1 + i, rnd2 + (i & 0xff), method); 57.225 + Verify.verifyBinary(rnd1 - i, rnd2 - (i & 0xff), method); 57.226 + Verify.verifyBinary(rnd1 + i + 1, rnd2 + i + 2, method); 57.227 + Verify.verifyBinary(rnd1 + i * 2, rnd2 + i, method); 57.228 + } 57.229 + } 57.230 + } 57.231 + 57.232 + public static class ConstantTest { 57.233 + public static void verify(BinaryMethod method) { 57.234 + for (int i = 0; i < 50000; ++i) { 57.235 + Verify.verifyBinary(5, 7, method); 57.236 + Verify.verifyBinary(Integer.MAX_VALUE, 1, method); 57.237 + Verify.verifyBinary(Integer.MIN_VALUE, -1, method); 57.238 + Verify.verifyBinary(Integer.MAX_VALUE, -1, method); 57.239 + Verify.verifyBinary(Integer.MIN_VALUE, 1, method); 57.240 + Verify.verifyBinary(Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2, method); 57.241 + Verify.verifyBinary(Integer.MAX_VALUE / 2, (Integer.MAX_VALUE / 2) + 3, method); 57.242 + Verify.verifyBinary(Integer.MAX_VALUE, Integer.MIN_VALUE, method); 57.243 + } 57.244 + } 57.245 + } 57.246 + 57.247 + public static class ConstantLongTest { 57.248 + public static void verify(BinaryLongMethod method) { 57.249 + for (int i = 0; i < 50000; ++i) { 57.250 + Verify.verifyBinary(5, 7, method); 57.251 + Verify.verifyBinary(Long.MAX_VALUE, 1, method); 57.252 + Verify.verifyBinary(Long.MIN_VALUE, -1, method); 57.253 + Verify.verifyBinary(Long.MAX_VALUE, -1, method); 57.254 + Verify.verifyBinary(Long.MIN_VALUE, 1, method); 57.255 + Verify.verifyBinary(Long.MAX_VALUE / 2, Long.MAX_VALUE / 2, method); 57.256 + Verify.verifyBinary(Long.MAX_VALUE / 2, (Long.MAX_VALUE / 2) + 3, method); 57.257 + Verify.verifyBinary(Long.MAX_VALUE, Long.MIN_VALUE, method); 57.258 + } 57.259 + } 57.260 + } 57.261 + 57.262 + public static interface BinaryMethod { 57.263 + int safeMethod(int a, int b); 57.264 + int checkMethod(int a, int b); 57.265 + int unchecked(int a, int b); 57.266 + String name(); 57.267 + } 57.268 + 57.269 + public static interface UnaryMethod { 57.270 + int safeMethod(int value); 57.271 + int checkMethod(int value); 57.272 + int unchecked(int value); 57.273 + String name(); 57.274 + } 57.275 + 57.276 + public static interface BinaryLongMethod { 57.277 + long safeMethod(long a, long b); 57.278 + long checkMethod(long a, long b); 57.279 + long unchecked(long a, long b); 57.280 + String name(); 57.281 + } 57.282 + 57.283 + public static interface UnaryLongMethod { 57.284 + long safeMethod(long value); 57.285 + long checkMethod(long value); 57.286 + long unchecked(long value); 57.287 + String name(); 57.288 + } 57.289 + 57.290 + public static class UnaryToBinary implements BinaryMethod { 57.291 + private final UnaryMethod method; 57.292 + public UnaryToBinary(UnaryMethod method) { 57.293 + this.method = method; 57.294 + } 57.295 + 57.296 + @Override 57.297 + public int safeMethod(int a, int b) { 57.298 + return method.safeMethod(a); 57.299 + } 57.300 + 57.301 + @Override 57.302 + public int checkMethod(int a, int b) { 57.303 + return method.checkMethod(a); 57.304 + } 57.305 + 57.306 + @Override 57.307 + public int unchecked(int a, int b) { 57.308 + return method.unchecked(a); 57.309 + 57.310 + } 57.311 + 57.312 + @Override 57.313 + public String name() { 57.314 + return method.name(); 57.315 + } 57.316 + } 57.317 + 57.318 + public static class UnaryToBinaryLong implements BinaryLongMethod { 57.319 + private final UnaryLongMethod method; 57.320 + public UnaryToBinaryLong(UnaryLongMethod method) { 57.321 + this.method = method; 57.322 + } 57.323 + 57.324 + @Override 57.325 + public long safeMethod(long a, long b) { 57.326 + return method.safeMethod(a); 57.327 + } 57.328 + 57.329 + @Override 57.330 + public long checkMethod(long a, long b) { 57.331 + return method.checkMethod(a); 57.332 + } 57.333 + 57.334 + @Override 57.335 + public long unchecked(long a, long b) { 57.336 + return method.unchecked(a); 57.337 + 57.338 + } 57.339 + 57.340 + @Override 57.341 + public String name() { 57.342 + return method.name(); 57.343 + } 57.344 + } 57.345 + 57.346 + 57.347 + public static class AddExactI implements BinaryMethod { 57.348 + @Override 57.349 + public int safeMethod(int x, int y) { 57.350 + int r = x + y; 57.351 + // HD 2-12 Overflow iff both arguments have the opposite sign of the result 57.352 + if (((x ^ r) & (y ^ r)) < 0) { 57.353 + throw new ArithmeticException("integer overflow"); 57.354 + } 57.355 + return r; 57.356 + 57.357 + } 57.358 + 57.359 + @Override 57.360 + public int checkMethod(int a, int b) { 57.361 + return Math.addExact(a, b); 57.362 + } 57.363 + 57.364 + @Override 57.365 + public String name() { 57.366 + return "addExact"; 57.367 + } 57.368 + 57.369 + @Override 57.370 + public int unchecked(int a, int b) { 57.371 + return a + b; 57.372 + } 57.373 + } 57.374 + 57.375 + public static class AddExactL implements BinaryLongMethod { 57.376 + @Override 57.377 + public long safeMethod(long x, long y) { 57.378 + long r = x + y; 57.379 + // HD 2-12 Overflow iff both arguments have the opposite sign of the result 57.380 + if (((x ^ r) & (y ^ r)) < 0) { 57.381 + throw new ArithmeticException("integer overflow"); 57.382 + } 57.383 + return r; 57.384 + 57.385 + } 57.386 + 57.387 + @Override 57.388 + public long checkMethod(long a, long b) { 57.389 + return Math.addExact(a, b); 57.390 + } 57.391 + 57.392 + @Override 57.393 + public String name() { 57.394 + return "addExactLong"; 57.395 + } 57.396 + 57.397 + @Override 57.398 + public long unchecked(long a, long b) { 57.399 + return a + b; 57.400 + } 57.401 + } 57.402 + 57.403 + public static class MulExactI implements BinaryMethod { 57.404 + @Override 57.405 + public int safeMethod(int x, int y) { 57.406 + long r = (long)x * (long)y; 57.407 + if ((int)r != r) { 57.408 + throw new ArithmeticException("integer overflow"); 57.409 + } 57.410 + return (int)r; 57.411 + 57.412 + } 57.413 + 57.414 + @Override 57.415 + public int checkMethod(int a, int b) { 57.416 + return Math.multiplyExact(a, b); 57.417 + } 57.418 + 57.419 + @Override 57.420 + public int unchecked(int a, int b) { 57.421 + return a * b; 57.422 + } 57.423 + 57.424 + @Override 57.425 + public String name() { 57.426 + return "multiplyExact"; 57.427 + } 57.428 + } 57.429 + 57.430 + public static class MulExactL implements BinaryLongMethod { 57.431 + @Override 57.432 + public long safeMethod(long x, long y) { 57.433 + long r = x * y; 57.434 + long ax = Math.abs(x); 57.435 + long ay = Math.abs(y); 57.436 + if (((ax | ay) >>> 31 != 0)) { 57.437 + // Some bits greater than 2^31 that might cause overflow 57.438 + // Check the result using the divide operator 57.439 + // and check for the special case of Long.MIN_VALUE * -1 57.440 + if (((y != 0) && (r / y != x)) || 57.441 + (x == Long.MIN_VALUE && y == -1)) { 57.442 + throw new ArithmeticException("long overflow"); 57.443 + } 57.444 + } 57.445 + return r; 57.446 + } 57.447 + 57.448 + @Override 57.449 + public long checkMethod(long a, long b) { 57.450 + return Math.multiplyExact(a, b); 57.451 + } 57.452 + 57.453 + @Override 57.454 + public long unchecked(long a, long b) { 57.455 + return a * b; 57.456 + } 57.457 + 57.458 + @Override 57.459 + public String name() { 57.460 + return "multiplyExact"; 57.461 + } 57.462 + } 57.463 + 57.464 + public static class NegExactL implements UnaryLongMethod { 57.465 + @Override 57.466 + public long safeMethod(long a) { 57.467 + if (a == Long.MIN_VALUE) { 57.468 + throw new ArithmeticException("long overflow"); 57.469 + } 57.470 + 57.471 + return -a; 57.472 + 57.473 + } 57.474 + 57.475 + @Override 57.476 + public long checkMethod(long value) { 57.477 + return Math.negateExact(value); 57.478 + } 57.479 + 57.480 + @Override 57.481 + public long unchecked(long value) { 57.482 + return -value; 57.483 + } 57.484 + 57.485 + @Override 57.486 + public String name() { 57.487 + return "negateExactLong"; 57.488 + } 57.489 + } 57.490 + 57.491 + public static class NegExactI implements UnaryMethod { 57.492 + @Override 57.493 + public int safeMethod(int a) { 57.494 + if (a == Integer.MIN_VALUE) { 57.495 + throw new ArithmeticException("integer overflow"); 57.496 + } 57.497 + 57.498 + return -a; 57.499 + 57.500 + } 57.501 + 57.502 + @Override 57.503 + public int checkMethod(int value) { 57.504 + return Math.negateExact(value); 57.505 + } 57.506 + 57.507 + @Override 57.508 + public int unchecked(int value) { 57.509 + return -value; 57.510 + } 57.511 + 57.512 + @Override 57.513 + public String name() { 57.514 + return "negateExact"; 57.515 + } 57.516 + } 57.517 + 57.518 + public static class SubExactI implements BinaryMethod { 57.519 + @Override 57.520 + public int safeMethod(int x, int y) { 57.521 + int r = x - y; 57.522 + // HD 2-12 Overflow iff the arguments have different signs and 57.523 + // the sign of the result is different than the sign of x 57.524 + if (((x ^ y) & (x ^ r)) < 0) { 57.525 + throw new ArithmeticException("integer overflow"); 57.526 + } 57.527 + return r; 57.528 + } 57.529 + 57.530 + @Override 57.531 + public int checkMethod(int a, int b) { 57.532 + return Math.subtractExact(a, b); 57.533 + } 57.534 + 57.535 + @Override 57.536 + public int unchecked(int a, int b) { 57.537 + return a - b; 57.538 + } 57.539 + 57.540 + @Override 57.541 + public String name() { 57.542 + return "subtractExact"; 57.543 + } 57.544 + } 57.545 + 57.546 + public static class SubExactL implements BinaryLongMethod { 57.547 + @Override 57.548 + public long safeMethod(long x, long y) { 57.549 + long r = x - y; 57.550 + // HD 2-12 Overflow iff the arguments have different signs and 57.551 + // the sign of the result is different than the sign of x 57.552 + if (((x ^ y) & (x ^ r)) < 0) { 57.553 + throw new ArithmeticException("integer overflow"); 57.554 + } 57.555 + return r; 57.556 + } 57.557 + 57.558 + @Override 57.559 + public long checkMethod(long a, long b) { 57.560 + return Math.subtractExact(a, b); 57.561 + } 57.562 + 57.563 + @Override 57.564 + public long unchecked(long a, long b) { 57.565 + return a - b; 57.566 + } 57.567 + 57.568 + @Override 57.569 + public String name() { 57.570 + return "subtractExactLong"; 57.571 + } 57.572 + } 57.573 + 57.574 + static class IncExactL implements UnaryLongMethod { 57.575 + @Override 57.576 + public long safeMethod(long a) { 57.577 + if (a == Long.MAX_VALUE) { 57.578 + throw new ArithmeticException("long overflow"); 57.579 + } 57.580 + 57.581 + return a + 1L; 57.582 + 57.583 + } 57.584 + 57.585 + @Override 57.586 + public long checkMethod(long value) { 57.587 + return Math.incrementExact(value); 57.588 + } 57.589 + 57.590 + @Override 57.591 + public long unchecked(long value) { 57.592 + return value + 1; 57.593 + } 57.594 + 57.595 + @Override 57.596 + public String name() { 57.597 + return "incrementExactLong"; 57.598 + } 57.599 + } 57.600 + 57.601 + static class IncExactI implements UnaryMethod { 57.602 + @Override 57.603 + public int safeMethod(int a) { 57.604 + if (a == Integer.MAX_VALUE) { 57.605 + throw new ArithmeticException("integer overflow"); 57.606 + } 57.607 + 57.608 + return a + 1; 57.609 + } 57.610 + 57.611 + @Override 57.612 + public int checkMethod(int value) { 57.613 + return Math.incrementExact(value); 57.614 + } 57.615 + 57.616 + @Override 57.617 + public int unchecked(int value) { 57.618 + return value + 1; 57.619 + } 57.620 + 57.621 + @Override 57.622 + public String name() { 57.623 + return "incrementExact"; 57.624 + } 57.625 + } 57.626 + 57.627 + static class DecExactL implements UnaryLongMethod { 57.628 + @Override 57.629 + public long safeMethod(long a) { 57.630 + if (a == Long.MIN_VALUE) { 57.631 + throw new ArithmeticException("long overflow"); 57.632 + } 57.633 + 57.634 + return a - 1L; 57.635 + } 57.636 + 57.637 + @Override 57.638 + public long checkMethod(long value) { 57.639 + return Math.decrementExact(value); 57.640 + } 57.641 + 57.642 + @Override 57.643 + public long unchecked(long value) { 57.644 + return value - 1; 57.645 + } 57.646 + 57.647 + @Override 57.648 + public String name() { 57.649 + return "decExactLong"; 57.650 + } 57.651 + } 57.652 + 57.653 + static class DecExactI implements UnaryMethod { 57.654 + @Override 57.655 + public int safeMethod(int a) { 57.656 + if (a == Integer.MIN_VALUE) { 57.657 + throw new ArithmeticException("integer overflow"); 57.658 + } 57.659 + 57.660 + return a - 1; 57.661 + } 57.662 + 57.663 + @Override 57.664 + public int checkMethod(int value) { 57.665 + return Math.decrementExact(value); 57.666 + } 57.667 + 57.668 + @Override 57.669 + public int unchecked(int value) { 57.670 + return value - 1; 57.671 + } 57.672 + 57.673 + @Override 57.674 + public String name() { 57.675 + return "decrementExact"; 57.676 + } 57.677 + } 57.678 + 57.679 }