Skip to content

Commit

Permalink
8314056: Remove runtime platform check from frem/drem
Browse files Browse the repository at this point in the history
Reviewed-by: sviswanathan, jbhateja
  • Loading branch information
Scott Gibbons authored and Jatin Bhateja committed Aug 30, 2023
1 parent 1c598c2 commit ce2a7ea
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 129 deletions.
72 changes: 39 additions & 33 deletions src/hotspot/cpu/x86/assembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6232,11 +6232,17 @@ void Assembler::subss(XMMRegister dst, Address src) {
emit_operand(dst, src, 0);
}

void Assembler::testb(Register dst, int imm8) {
void Assembler::testb(Register dst, int imm8, bool use_ral) {
NOT_LP64(assert(dst->has_byte_register(), "must have byte register"));
if (dst == rax) {
emit_int8((unsigned char)0xA8);
emit_int8(imm8);
if (use_ral) {
emit_int8((unsigned char)0xA8);
emit_int8(imm8);
} else {
emit_int8((unsigned char)0xF6);
emit_int8((unsigned char)0xC4);
emit_int8(imm8);
}
} else {
(void) prefix_and_encode(dst->encoding(), true);
emit_arith_b(0xF6, 0xC0, dst, imm8);
Expand Down Expand Up @@ -10967,6 +10973,36 @@ void Assembler::emit_operand32(Register reg, Address adr, int post_addr_length)
emit_operand(reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec, post_addr_length);
}

void Assembler::fld_d(Address adr) {
InstructionMark im(this);
emit_int8((unsigned char)0xDD);
emit_operand32(rax, adr, 0);
}

void Assembler::fprem() {
emit_int16((unsigned char)0xD9, (unsigned char)0xF8);
}

void Assembler::fnstsw_ax() {
emit_int16((unsigned char)0xDF, (unsigned char)0xE0);
}

void Assembler::fstp_d(Address adr) {
InstructionMark im(this);
emit_int8((unsigned char)0xDD);
emit_operand32(rbx, adr, 0);
}

void Assembler::fstp_d(int index) {
emit_farith(0xDD, 0xD8, index);
}

void Assembler::emit_farith(int b1, int b2, int i) {
assert(isByte(b1) && isByte(b2), "wrong opcode");
assert(0 <= i && i < 8, "illegal stack offset");
emit_int16(b1, b2 + i);
}

#ifndef _LP64
// 32bit only pieces of the assembler

Expand Down Expand Up @@ -11010,12 +11046,6 @@ void Assembler::decl(Register dst) {

// 64bit doesn't use the x87

void Assembler::emit_farith(int b1, int b2, int i) {
assert(isByte(b1) && isByte(b2), "wrong opcode");
assert(0 <= i && i < 8, "illegal stack offset");
emit_int16(b1, b2 + i);
}

void Assembler::fabs() {
emit_int16((unsigned char)0xD9, (unsigned char)0xE1);
}
Expand Down Expand Up @@ -11177,12 +11207,6 @@ void Assembler::fld1() {
emit_int16((unsigned char)0xD9, (unsigned char)0xE8);
}

void Assembler::fld_d(Address adr) {
InstructionMark im(this);
emit_int8((unsigned char)0xDD);
emit_operand32(rax, adr, 0);
}

void Assembler::fld_s(Address adr) {
InstructionMark im(this);
emit_int8((unsigned char)0xD9);
Expand Down Expand Up @@ -11266,14 +11290,6 @@ void Assembler::fnstcw(Address src) {
emit_operand32(rdi, src, 0);
}

void Assembler::fnstsw_ax() {
emit_int16((unsigned char)0xDF, (unsigned char)0xE0);
}

void Assembler::fprem() {
emit_int16((unsigned char)0xD9, (unsigned char)0xF8);
}

void Assembler::fprem1() {
emit_int16((unsigned char)0xD9, (unsigned char)0xF5);
}
Expand Down Expand Up @@ -11304,16 +11320,6 @@ void Assembler::fst_s(Address adr) {
emit_operand32(rdx, adr, 0);
}

void Assembler::fstp_d(Address adr) {
InstructionMark im(this);
emit_int8((unsigned char)0xDD);
emit_operand32(rbx, adr, 0);
}

void Assembler::fstp_d(int index) {
emit_farith(0xDD, 0xD8, index);
}

void Assembler::fstp_s(Address adr) {
InstructionMark im(this);
emit_int8((unsigned char)0xD9);
Expand Down
17 changes: 8 additions & 9 deletions src/hotspot/cpu/x86/assembler_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,12 +1245,18 @@ class Assembler : public AbstractAssembler {
void divss(XMMRegister dst, XMMRegister src);


#ifndef _LP64
void fnstsw_ax();
void fprem();
void fld_d(Address adr);
void fstp_d(Address adr);
void fstp_d(int index);

private:

void emit_farith(int b1, int b2, int i);

public:
#ifndef _LP64
void emms();

void fabs();
Expand Down Expand Up @@ -1309,7 +1315,6 @@ class Assembler : public AbstractAssembler {

void fld1();

void fld_d(Address adr);
void fld_s(Address adr);
void fld_s(int index);

Expand Down Expand Up @@ -1338,10 +1343,6 @@ class Assembler : public AbstractAssembler {
void fnsave(Address dst);

void fnstcw(Address src);

void fnstsw_ax();

void fprem();
void fprem1();

void frstor(Address src);
Expand All @@ -1353,8 +1354,6 @@ class Assembler : public AbstractAssembler {
void fst_d(Address adr);
void fst_s(Address adr);

void fstp_d(Address adr);
void fstp_d(int index);
void fstp_s(Address adr);

void fsub(int i);
Expand Down Expand Up @@ -2184,7 +2183,7 @@ class Assembler : public AbstractAssembler {
void subss(XMMRegister dst, XMMRegister src);

void testb(Address dst, int imm8);
void testb(Register dst, int imm8);
void testb(Register dst, int imm8, bool use_ral = true);

void testl(Address dst, int32_t imm32);
void testl(Register dst, int32_t imm32);
Expand Down
50 changes: 8 additions & 42 deletions src/hotspot/cpu/x86/sharedRuntime_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,52 +84,18 @@ void SharedRuntime::inline_check_hashcode_from_object_header(MacroAssembler* mas
}
#endif //COMPILER1

#if defined(TARGET_COMPILER_gcc) && !defined(_WIN64)
JRT_LEAF(jfloat, SharedRuntime::frem(jfloat x, jfloat y))
jfloat retval;
const bool is_LP64 = LP64_ONLY(true) NOT_LP64(false);
if (!is_LP64 || UseAVX < 1 || !UseFMA) {
asm ("\
1: \n\
fprem \n\
fnstsw %%ax \n\
test $0x4,%%ah \n\
jne 1b \n\
"
:"=t"(retval)
:"0"(x), "u"(y)
:"cc", "ax");
} else {
assert(StubRoutines::fmod() != nullptr, "");
jdouble (*addr)(jdouble, jdouble) = (double (*)(double, double))StubRoutines::fmod();
jdouble dx = (jdouble) x;
jdouble dy = (jdouble) y;
assert(StubRoutines::fmod() != nullptr, "");
jdouble (*addr)(jdouble, jdouble) = (double (*)(double, double))StubRoutines::fmod();
jdouble dx = (jdouble) x;
jdouble dy = (jdouble) y;

retval = (jfloat) (*addr)(dx, dy);
}
return retval;
return (jfloat) (*addr)(dx, dy);
JRT_END

JRT_LEAF(jdouble, SharedRuntime::drem(jdouble x, jdouble y))
jdouble retval;
const bool is_LP64 = LP64_ONLY(true) NOT_LP64(false);
if (!is_LP64 || UseAVX < 1 || !UseFMA) {
asm ("\
1: \n\
fprem \n\
fnstsw %%ax \n\
test $0x4,%%ah \n\
jne 1b \n\
"
:"=t"(retval)
:"0"(x), "u"(y)
:"cc", "ax");
} else {
assert(StubRoutines::fmod() != nullptr, "");
jdouble (*addr)(jdouble, jdouble) = (double (*)(double, double))StubRoutines::fmod();
assert(StubRoutines::fmod() != nullptr, "");
jdouble (*addr)(jdouble, jdouble) = (double (*)(double, double))StubRoutines::fmod();

retval = (*addr)(x, y);
}
return retval;
return (*addr)(x, y);
JRT_END
#endif // TARGET_COMPILER_gcc && !_WIN64
6 changes: 3 additions & 3 deletions src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3897,6 +3897,8 @@ address StubGenerator::generate_throw_exception(const char* name,
void StubGenerator::create_control_words() {
// Round to nearest, 64-bit mode, exceptions masked
StubRoutines::x86::_mxcsr_std = 0x1F80;
// Round to zero, 64-bit mode, exceptions masked
StubRoutines::x86::_mxcsr_rz = 0x7F80;
}

// Initialization
Expand Down Expand Up @@ -3979,9 +3981,7 @@ void StubGenerator::generate_initial_stubs() {

generate_libm_stubs();

if ((UseAVX >= 1) && (VM_Version::supports_avx512vlbwdq() || VM_Version::supports_fma())) {
StubRoutines::_fmod = generate_libmFmod(); // from stubGenerator_x86_64_fmod.cpp
}
StubRoutines::_fmod = generate_libmFmod(); // from stubGenerator_x86_64_fmod.cpp
}

void StubGenerator::generate_continuation_stubs() {
Expand Down
Loading

1 comment on commit ce2a7ea

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.