Skip to content

Commit af7c56b

Browse files
vamsi-parasaSandhya Viswanathan
authored andcommitted
8275167: x86 intrinsic for unsignedMultiplyHigh
Reviewed-by: kvn, sviswanathan
1 parent cea3f01 commit af7c56b

File tree

11 files changed

+61
-2
lines changed

11 files changed

+61
-2
lines changed

src/hotspot/cpu/x86/x86_64.ad

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8527,6 +8527,19 @@ instruct mulHiL_rReg(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
85278527
ins_pipe(ialu_reg_reg_alu0);
85288528
%}
85298529

8530+
instruct umulHiL_rReg(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
8531+
%{
8532+
match(Set dst (UMulHiL src rax));
8533+
effect(USE_KILL rax, KILL cr);
8534+
8535+
ins_cost(300);
8536+
format %{ "mulq RDX:RAX, RAX, $src\t# umulhi" %}
8537+
ins_encode %{
8538+
__ mulq($src$$Register);
8539+
%}
8540+
ins_pipe(ialu_reg_reg_alu0);
8541+
%}
8542+
85308543
instruct divI_rReg(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div,
85318544
rFlagsReg cr)
85328545
%{

src/hotspot/share/classfile/vmIntrinsics.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class methodHandle;
140140
do_name(incrementExact_name,"incrementExact") \
141141
do_name(multiplyExact_name,"multiplyExact") \
142142
do_name(multiplyHigh_name,"multiplyHigh") \
143+
do_name(unsignedMultiplyHigh_name,"unsignedMultiplyHigh") \
143144
do_name(negateExact_name,"negateExact") \
144145
do_name(subtractExact_name,"subtractExact") \
145146
do_name(fma_name, "fma") \
@@ -173,6 +174,7 @@ class methodHandle;
173174
do_intrinsic(_multiplyExactI, java_lang_Math, multiplyExact_name, int2_int_signature, F_S) \
174175
do_intrinsic(_multiplyExactL, java_lang_Math, multiplyExact_name, long2_long_signature, F_S) \
175176
do_intrinsic(_multiplyHigh, java_lang_Math, multiplyHigh_name, long2_long_signature, F_S) \
177+
do_intrinsic(_unsignedMultiplyHigh, java_lang_Math, unsignedMultiplyHigh_name, long2_long_signature, F_S) \
176178
do_intrinsic(_negateExactI, java_lang_Math, negateExact_name, int_int_signature, F_S) \
177179
do_intrinsic(_negateExactL, java_lang_Math, negateExact_name, long_long_signature, F_S) \
178180
do_intrinsic(_subtractExactI, java_lang_Math, subtractExact_name, int2_int_signature, F_S) \

src/hotspot/share/opto/c2compiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ bool C2Compiler::is_intrinsic_supported(const methodHandle& method, bool is_virt
426426
case vmIntrinsics::_multiplyHigh:
427427
if (!Matcher::match_rule_supported(Op_MulHiL)) return false;
428428
break;
429+
case vmIntrinsics::_unsignedMultiplyHigh:
430+
if (!Matcher::match_rule_supported(Op_UMulHiL)) return false;
431+
break;
429432
case vmIntrinsics::_getCallerClass:
430433
if (vmClasses::reflect_CallerSensitive_klass() == NULL) return false;
431434
break;

src/hotspot/share/opto/classes.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ macro(MoveD2L)
238238
macro(MulD)
239239
macro(MulF)
240240
macro(MulHiL)
241+
macro(UMulHiL)
241242
macro(MulI)
242243
macro(MulL)
243244
macro(Multi)

src/hotspot/share/opto/library_call.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ bool LibraryCallKit::try_to_inline(int predicate) {
286286
case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI();
287287
case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL();
288288
case vmIntrinsics::_multiplyHigh: return inline_math_multiplyHigh();
289+
case vmIntrinsics::_unsignedMultiplyHigh: return inline_math_unsignedMultiplyHigh();
289290
case vmIntrinsics::_negateExactI: return inline_math_negateExactI();
290291
case vmIntrinsics::_negateExactL: return inline_math_negateExactL();
291292
case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */);
@@ -1867,6 +1868,11 @@ bool LibraryCallKit::inline_math_multiplyHigh() {
18671868
return true;
18681869
}
18691870

1871+
bool LibraryCallKit::inline_math_unsignedMultiplyHigh() {
1872+
set_result(_gvn.transform(new UMulHiLNode(argument(0), argument(2))));
1873+
return true;
1874+
}
1875+
18701876
Node*
18711877
LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) {
18721878
// These are the candidate return value:

src/hotspot/share/opto/library_call.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class LibraryCallKit : public GraphKit {
210210
bool inline_math_multiplyExactI();
211211
bool inline_math_multiplyExactL();
212212
bool inline_math_multiplyHigh();
213+
bool inline_math_unsignedMultiplyHigh();
213214
bool inline_math_negateExactI();
214215
bool inline_math_negateExactL();
215216
bool inline_math_subtractExactI(bool is_decrement);

src/hotspot/share/opto/mulnode.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,26 @@ const Type *MulDNode::mul_ring(const Type *t0, const Type *t1) const {
432432
//=============================================================================
433433
//------------------------------Value------------------------------------------
434434
const Type* MulHiLNode::Value(PhaseGVN* phase) const {
435-
// Either input is TOP ==> the result is TOP
436435
const Type *t1 = phase->type( in(1) );
437436
const Type *t2 = phase->type( in(2) );
437+
const Type *bot = bottom_type();
438+
return MulHiValue(t1, t2, bot);
439+
}
440+
441+
const Type* UMulHiLNode::Value(PhaseGVN* phase) const {
442+
const Type *t1 = phase->type( in(1) );
443+
const Type *t2 = phase->type( in(2) );
444+
const Type *bot = bottom_type();
445+
return MulHiValue(t1, t2, bot);
446+
}
447+
448+
// A common routine used by UMulHiLNode and MulHiLNode
449+
const Type* MulHiValue(const Type *t1, const Type *t2, const Type *bot) {
450+
// Either input is TOP ==> the result is TOP
438451
if( t1 == Type::TOP ) return Type::TOP;
439452
if( t2 == Type::TOP ) return Type::TOP;
440453

441454
// Either input is BOTTOM ==> the result is the local BOTTOM
442-
const Type *bot = bottom_type();
443455
if( (t1 == bot) || (t2 == bot) ||
444456
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
445457
return bot;

src/hotspot/share/opto/mulnode.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class MulDNode : public MulNode {
154154
};
155155

156156
//-------------------------------MulHiLNode------------------------------------
157+
const Type* MulHiValue(const Type *t1, const Type *t2, const Type *bot);
158+
157159
// Upper 64 bits of a 64 bit by 64 bit multiply
158160
class MulHiLNode : public Node {
159161
public:
@@ -162,6 +164,18 @@ class MulHiLNode : public Node {
162164
virtual const Type* Value(PhaseGVN* phase) const;
163165
const Type *bottom_type() const { return TypeLong::LONG; }
164166
virtual uint ideal_reg() const { return Op_RegL; }
167+
friend const Type* MulHiValue(const Type *t1, const Type *t2, const Type *bot);
168+
};
169+
170+
// Upper 64 bits of a 64 bit by 64 bit unsigned multiply
171+
class UMulHiLNode : public Node {
172+
public:
173+
UMulHiLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
174+
virtual int Opcode() const;
175+
virtual const Type* Value(PhaseGVN* phase) const;
176+
const Type *bottom_type() const { return TypeLong::LONG; }
177+
virtual uint ideal_reg() const { return Op_RegL; }
178+
friend const Type* MulHiValue(const Type *t1, const Type *t2, const Type *bot);
165179
};
166180

167181
//------------------------------AndINode---------------------------------------

src/hotspot/share/runtime/vmStructs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,7 @@
16701670
declare_c2_type(MulFNode, MulNode) \
16711671
declare_c2_type(MulDNode, MulNode) \
16721672
declare_c2_type(MulHiLNode, Node) \
1673+
declare_c2_type(UMulHiLNode, Node) \
16731674
declare_c2_type(AndINode, MulINode) \
16741675
declare_c2_type(AndLNode, MulLNode) \
16751676
declare_c2_type(LShiftINode, Node) \

src/java.base/share/classes/java/lang/Math.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@ public static long multiplyHigh(long x, long y) {
13901390
* @see #multiplyHigh
13911391
* @since 18
13921392
*/
1393+
@IntrinsicCandidate
13931394
public static long unsignedMultiplyHigh(long x, long y) {
13941395
// Compute via multiplyHigh() to leverage the intrinsic
13951396
long result = Math.multiplyHigh(x, y);

0 commit comments

Comments
 (0)