assembler_x86.cpp revision 1047
0N/A/*
624N/A * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A#include "incls/_precompiled.incl"
304N/A#include "incls/_assembler_x86.cpp.incl"
0N/A
0N/A// Implementation of AddressLiteral
0N/A
0N/AAddressLiteral::AddressLiteral(address target, relocInfo::relocType rtype) {
0N/A _is_lval = false;
0N/A _target = target;
0N/A switch (rtype) {
0N/A case relocInfo::oop_type:
0N/A // Oops are a special case. Normally they would be their own section
0N/A // but in cases like icBuffer they are literals in the code stream that
0N/A // we don't have a section for. We use none so that we get a literal address
0N/A // which is always patchable.
0N/A break;
0N/A case relocInfo::external_word_type:
0N/A _rspec = external_word_Relocation::spec(target);
0N/A break;
0N/A case relocInfo::internal_word_type:
0N/A _rspec = internal_word_Relocation::spec(target);
0N/A break;
0N/A case relocInfo::opt_virtual_call_type:
0N/A _rspec = opt_virtual_call_Relocation::spec();
0N/A break;
0N/A case relocInfo::static_call_type:
0N/A _rspec = static_call_Relocation::spec();
0N/A break;
0N/A case relocInfo::runtime_call_type:
0N/A _rspec = runtime_call_Relocation::spec();
0N/A break;
0N/A case relocInfo::poll_type:
0N/A case relocInfo::poll_return_type:
0N/A _rspec = Relocation::spec_simple(rtype);
0N/A break;
0N/A case relocInfo::none:
0N/A break;
0N/A default:
0N/A ShouldNotReachHere();
0N/A break;
0N/A }
0N/A}
0N/A
0N/A// Implementation of Address
0N/A
304N/A#ifdef _LP64
304N/A
0N/AAddress Address::make_array(ArrayAddress adr) {
0N/A // Not implementable on 64bit machines
0N/A // Should have been handled higher up the call chain.
0N/A ShouldNotReachHere();
304N/A return Address();
304N/A}
304N/A
304N/A// exceedingly dangerous constructor
304N/AAddress::Address(int disp, address loc, relocInfo::relocType rtype) {
304N/A _base = noreg;
304N/A _index = noreg;
304N/A _scale = no_scale;
304N/A _disp = disp;
304N/A switch (rtype) {
304N/A case relocInfo::external_word_type:
304N/A _rspec = external_word_Relocation::spec(loc);
304N/A break;
304N/A case relocInfo::internal_word_type:
304N/A _rspec = internal_word_Relocation::spec(loc);
304N/A break;
304N/A case relocInfo::runtime_call_type:
304N/A // HMM
304N/A _rspec = runtime_call_Relocation::spec();
304N/A break;
304N/A case relocInfo::poll_type:
304N/A case relocInfo::poll_return_type:
304N/A _rspec = Relocation::spec_simple(rtype);
304N/A break;
304N/A case relocInfo::none:
304N/A break;
304N/A default:
304N/A ShouldNotReachHere();
304N/A }
304N/A}
304N/A#else // LP64
304N/A
304N/AAddress Address::make_array(ArrayAddress adr) {
0N/A AddressLiteral base = adr.base();
0N/A Address index = adr.index();
0N/A assert(index._disp == 0, "must not have disp"); // maybe it can?
0N/A Address array(index._base, index._index, index._scale, (intptr_t) base.target());
0N/A array._rspec = base._rspec;
0N/A return array;
304N/A}
0N/A
0N/A// exceedingly dangerous constructor
0N/AAddress::Address(address loc, RelocationHolder spec) {
0N/A _base = noreg;
0N/A _index = noreg;
0N/A _scale = no_scale;
0N/A _disp = (intptr_t) loc;
0N/A _rspec = spec;
0N/A}
304N/A
0N/A#endif // _LP64
0N/A
304N/A
304N/A
0N/A// Convert the raw encoding form into the form expected by the constructor for
0N/A// Address. An index of 4 (rsp) corresponds to having no index, so convert
0N/A// that to noreg for the Address constructor.
624N/AAddress Address::make_raw(int base, int index, int scale, int disp, bool disp_is_oop) {
624N/A RelocationHolder rspec;
624N/A if (disp_is_oop) {
624N/A rspec = Relocation::spec_simple(relocInfo::oop_type);
624N/A }
0N/A bool valid_index = index != rsp->encoding();
0N/A if (valid_index) {
0N/A Address madr(as_Register(base), as_Register(index), (Address::ScaleFactor)scale, in_ByteSize(disp));
624N/A madr._rspec = rspec;
0N/A return madr;
0N/A } else {
0N/A Address madr(as_Register(base), noreg, Address::no_scale, in_ByteSize(disp));
624N/A madr._rspec = rspec;
0N/A return madr;
0N/A }
0N/A}
0N/A
0N/A// Implementation of Assembler
0N/A
0N/Aint AbstractAssembler::code_fill_byte() {
0N/A return (u_char)'\xF4'; // hlt
0N/A}
0N/A
0N/A// make this go away someday
0N/Avoid Assembler::emit_data(jint data, relocInfo::relocType rtype, int format) {
0N/A if (rtype == relocInfo::none)
0N/A emit_long(data);
0N/A else emit_data(data, Relocation::spec_simple(rtype), format);
0N/A}
0N/A
0N/Avoid Assembler::emit_data(jint data, RelocationHolder const& rspec, int format) {
304N/A assert(imm_operand == 0, "default format must be immediate in this file");
0N/A assert(inst_mark() != NULL, "must be inside InstructionMark");
0N/A if (rspec.type() != relocInfo::none) {
0N/A #ifdef ASSERT
0N/A check_relocation(rspec, format);
0N/A #endif
0N/A // Do not use AbstractAssembler::relocate, which is not intended for
0N/A // embedded words. Instead, relocate to the enclosing instruction.
0N/A
0N/A // hack. call32 is too wide for mask so use disp32
0N/A if (format == call32_operand)
0N/A code_section()->relocate(inst_mark(), rspec, disp32_operand);
0N/A else
0N/A code_section()->relocate(inst_mark(), rspec, format);
0N/A }
0N/A emit_long(data);
0N/A}
0N/A
304N/Astatic int encode(Register r) {
304N/A int enc = r->encoding();
304N/A if (enc >= 8) {
304N/A enc -= 8;
304N/A }
304N/A return enc;
304N/A}
304N/A
304N/Astatic int encode(XMMRegister r) {
304N/A int enc = r->encoding();
304N/A if (enc >= 8) {
304N/A enc -= 8;
304N/A }
304N/A return enc;
304N/A}
0N/A
0N/Avoid Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) {
0N/A assert(dst->has_byte_register(), "must have byte register");
0N/A assert(isByte(op1) && isByte(op2), "wrong opcode");
0N/A assert(isByte(imm8), "not a byte");
0N/A assert((op1 & 0x01) == 0, "should be 8bit operation");
0N/A emit_byte(op1);
304N/A emit_byte(op2 | encode(dst));
0N/A emit_byte(imm8);
0N/A}
0N/A
0N/A
304N/Avoid Assembler::emit_arith(int op1, int op2, Register dst, int32_t imm32) {
0N/A assert(isByte(op1) && isByte(op2), "wrong opcode");
0N/A assert((op1 & 0x01) == 1, "should be 32bit operation");
0N/A assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
0N/A if (is8bit(imm32)) {
0N/A emit_byte(op1 | 0x02); // set sign bit
304N/A emit_byte(op2 | encode(dst));
0N/A emit_byte(imm32 & 0xFF);
0N/A } else {
0N/A emit_byte(op1);
304N/A emit_byte(op2 | encode(dst));
0N/A emit_long(imm32);
0N/A }
0N/A}
0N/A
0N/A// immediate-to-memory forms
304N/Avoid Assembler::emit_arith_operand(int op1, Register rm, Address adr, int32_t imm32) {
0N/A assert((op1 & 0x01) == 1, "should be 32bit operation");
0N/A assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
0N/A if (is8bit(imm32)) {
0N/A emit_byte(op1 | 0x02); // set sign bit
304N/A emit_operand(rm, adr, 1);
0N/A emit_byte(imm32 & 0xFF);
0N/A } else {
0N/A emit_byte(op1);
304N/A emit_operand(rm, adr, 4);
0N/A emit_long(imm32);
0N/A }
0N/A}
0N/A
0N/Avoid Assembler::emit_arith(int op1, int op2, Register dst, jobject obj) {
304N/A LP64_ONLY(ShouldNotReachHere());
0N/A assert(isByte(op1) && isByte(op2), "wrong opcode");
0N/A assert((op1 & 0x01) == 1, "should be 32bit operation");
0N/A assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
0N/A InstructionMark im(this);
0N/A emit_byte(op1);
304N/A emit_byte(op2 | encode(dst));
304N/A emit_data((intptr_t)obj, relocInfo::oop_type, 0);
0N/A}
0N/A
0N/A
0N/Avoid Assembler::emit_arith(int op1, int op2, Register dst, Register src) {
0N/A assert(isByte(op1) && isByte(op2), "wrong opcode");
0N/A emit_byte(op1);
304N/A emit_byte(op2 | encode(dst) << 3 | encode(src));
304N/A}
304N/A
304N/A
304N/Avoid Assembler::emit_operand(Register reg, Register base, Register index,
304N/A Address::ScaleFactor scale, int disp,
304N/A RelocationHolder const& rspec,
304N/A int rip_relative_correction) {
0N/A relocInfo::relocType rtype = (relocInfo::relocType) rspec.type();
304N/A
304N/A // Encode the registers as needed in the fields they are used in
304N/A
304N/A int regenc = encode(reg) << 3;
304N/A int indexenc = index->is_valid() ? encode(index) << 3 : 0;
304N/A int baseenc = base->is_valid() ? encode(base) : 0;
304N/A
0N/A if (base->is_valid()) {
0N/A if (index->is_valid()) {
0N/A assert(scale != Address::no_scale, "inconsistent address");
0N/A // [base + index*scale + disp]
304N/A if (disp == 0 && rtype == relocInfo::none &&
304N/A base != rbp LP64_ONLY(&& base != r13)) {
0N/A // [base + index*scale]
0N/A // [00 reg 100][ss index base]
0N/A assert(index != rsp, "illegal addressing mode");
304N/A emit_byte(0x04 | regenc);
304N/A emit_byte(scale << 6 | indexenc | baseenc);
0N/A } else if (is8bit(disp) && rtype == relocInfo::none) {
0N/A // [base + index*scale + imm8]
0N/A // [01 reg 100][ss index base] imm8
0N/A assert(index != rsp, "illegal addressing mode");
304N/A emit_byte(0x44 | regenc);
304N/A emit_byte(scale << 6 | indexenc | baseenc);
0N/A emit_byte(disp & 0xFF);
0N/A } else {
304N/A // [base + index*scale + disp32]
304N/A // [10 reg 100][ss index base] disp32
0N/A assert(index != rsp, "illegal addressing mode");
304N/A emit_byte(0x84 | regenc);
304N/A emit_byte(scale << 6 | indexenc | baseenc);
0N/A emit_data(disp, rspec, disp32_operand);
0N/A }
304N/A } else if (base == rsp LP64_ONLY(|| base == r12)) {
304N/A // [rsp + disp]
0N/A if (disp == 0 && rtype == relocInfo::none) {
304N/A // [rsp]
0N/A // [00 reg 100][00 100 100]
304N/A emit_byte(0x04 | regenc);
0N/A emit_byte(0x24);
0N/A } else if (is8bit(disp) && rtype == relocInfo::none) {
304N/A // [rsp + imm8]
304N/A // [01 reg 100][00 100 100] disp8
304N/A emit_byte(0x44 | regenc);
0N/A emit_byte(0x24);
0N/A emit_byte(disp & 0xFF);
0N/A } else {
304N/A // [rsp + imm32]
304N/A // [10 reg 100][00 100 100] disp32
304N/A emit_byte(0x84 | regenc);
0N/A emit_byte(0x24);
0N/A emit_data(disp, rspec, disp32_operand);
0N/A }
0N/A } else {
0N/A // [base + disp]
304N/A assert(base != rsp LP64_ONLY(&& base != r12), "illegal addressing mode");
304N/A if (disp == 0 && rtype == relocInfo::none &&
304N/A base != rbp LP64_ONLY(&& base != r13)) {
0N/A // [base]
0N/A // [00 reg base]
304N/A emit_byte(0x00 | regenc | baseenc);
0N/A } else if (is8bit(disp) && rtype == relocInfo::none) {
304N/A // [base + disp8]
304N/A // [01 reg base] disp8
304N/A emit_byte(0x40 | regenc | baseenc);
0N/A emit_byte(disp & 0xFF);
0N/A } else {
304N/A // [base + disp32]
304N/A // [10 reg base] disp32
304N/A emit_byte(0x80 | regenc | baseenc);
0N/A emit_data(disp, rspec, disp32_operand);
0N/A }
0N/A }
0N/A } else {
0N/A if (index->is_valid()) {
0N/A assert(scale != Address::no_scale, "inconsistent address");
0N/A // [index*scale + disp]
304N/A // [00 reg 100][ss index 101] disp32
0N/A assert(index != rsp, "illegal addressing mode");
304N/A emit_byte(0x04 | regenc);
304N/A emit_byte(scale << 6 | indexenc | 0x05);
0N/A emit_data(disp, rspec, disp32_operand);
304N/A } else if (rtype != relocInfo::none ) {
304N/A // [disp] (64bit) RIP-RELATIVE (32bit) abs
304N/A // [00 000 101] disp32
304N/A
304N/A emit_byte(0x05 | regenc);
304N/A // Note that the RIP-rel. correction applies to the generated
304N/A // disp field, but _not_ to the target address in the rspec.
304N/A
304N/A // disp was created by converting the target address minus the pc
304N/A // at the start of the instruction. That needs more correction here.
304N/A // intptr_t disp = target - next_ip;
304N/A assert(inst_mark() != NULL, "must be inside InstructionMark");
304N/A address next_ip = pc() + sizeof(int32_t) + rip_relative_correction;
304N/A int64_t adjusted = disp;
304N/A // Do rip-rel adjustment for 64bit
304N/A LP64_ONLY(adjusted -= (next_ip - inst_mark()));
304N/A assert(is_simm32(adjusted),
304N/A "must be 32bit offset (RIP relative address)");
304N/A emit_data((int32_t) adjusted, rspec, disp32_operand);
304N/A
0N/A } else {
304N/A // 32bit never did this, did everything as the rip-rel/disp code above
304N/A // [disp] ABSOLUTE
304N/A // [00 reg 100][00 100 101] disp32
304N/A emit_byte(0x04 | regenc);
304N/A emit_byte(0x25);
0N/A emit_data(disp, rspec, disp32_operand);
0N/A }
0N/A }
0N/A}
0N/A
304N/Avoid Assembler::emit_operand(XMMRegister reg, Register base, Register index,
304N/A Address::ScaleFactor scale, int disp,
304N/A RelocationHolder const& rspec) {
304N/A emit_operand((Register)reg, base, index, scale, disp, rspec);
304N/A}
304N/A
0N/A// Secret local extension to Assembler::WhichOperand:
0N/A#define end_pc_operand (_WhichOperand_limit)
0N/A
0N/Aaddress Assembler::locate_operand(address inst, WhichOperand which) {
0N/A // Decode the given instruction, and return the address of
0N/A // an embedded 32-bit operand word.
0N/A
0N/A // If "which" is disp32_operand, selects the displacement portion
0N/A // of an effective address specifier.
304N/A // If "which" is imm64_operand, selects the trailing immediate constant.
0N/A // If "which" is call32_operand, selects the displacement of a call or jump.
0N/A // Caller is responsible for ensuring that there is such an operand,
304N/A // and that it is 32/64 bits wide.
0N/A
0N/A // If "which" is end_pc_operand, find the end of the instruction.
0N/A
0N/A address ip = inst;
304N/A bool is_64bit = false;
304N/A
304N/A debug_only(bool has_disp32 = false);
304N/A int tail_size = 0; // other random bytes (#32, #16, etc.) at end of insn
304N/A
304N/A again_after_prefix:
0N/A switch (0xFF & *ip++) {
0N/A
0N/A // These convenience macros generate groups of "case" labels for the switch.
304N/A#define REP4(x) (x)+0: case (x)+1: case (x)+2: case (x)+3
304N/A#define REP8(x) (x)+0: case (x)+1: case (x)+2: case (x)+3: \
0N/A case (x)+4: case (x)+5: case (x)+6: case (x)+7
304N/A#define REP16(x) REP8((x)+0): \
0N/A case REP8((x)+8)
0N/A
0N/A case CS_segment:
0N/A case SS_segment:
0N/A case DS_segment:
0N/A case ES_segment:
0N/A case FS_segment:
0N/A case GS_segment:
304N/A // Seems dubious
304N/A LP64_ONLY(assert(false, "shouldn't have that prefix"));
0N/A assert(ip == inst+1, "only one prefix allowed");
0N/A goto again_after_prefix;
0N/A
304N/A case 0x67:
304N/A case REX:
304N/A case REX_B:
304N/A case REX_X:
304N/A case REX_XB:
304N/A case REX_R:
304N/A case REX_RB:
304N/A case REX_RX:
304N/A case REX_RXB:
304N/A NOT_LP64(assert(false, "64bit prefixes"));
304N/A goto again_after_prefix;
304N/A
304N/A case REX_W:
304N/A case REX_WB:
304N/A case REX_WX:
304N/A case REX_WXB:
304N/A case REX_WR:
304N/A case REX_WRB:
304N/A case REX_WRX:
304N/A case REX_WRXB:
304N/A NOT_LP64(assert(false, "64bit prefixes"));
304N/A is_64bit = true;
304N/A goto again_after_prefix;
304N/A
304N/A case 0xFF: // pushq a; decl a; incl a; call a; jmp a
0N/A case 0x88: // movb a, r
0N/A case 0x89: // movl a, r
0N/A case 0x8A: // movb r, a
0N/A case 0x8B: // movl r, a
0N/A case 0x8F: // popl a
304N/A debug_only(has_disp32 = true);
0N/A break;
0N/A
304N/A case 0x68: // pushq #32
304N/A if (which == end_pc_operand) {
304N/A return ip + 4;
304N/A }
304N/A assert(which == imm_operand && !is_64bit, "pushl has no disp32 or 64bit immediate");
0N/A return ip; // not produced by emit_operand
0N/A
0N/A case 0x66: // movw ... (size prefix)
304N/A again_after_size_prefix2:
0N/A switch (0xFF & *ip++) {
304N/A case REX:
304N/A case REX_B:
304N/A case REX_X:
304N/A case REX_XB:
304N/A case REX_R:
304N/A case REX_RB:
304N/A case REX_RX:
304N/A case REX_RXB:
304N/A case REX_W:
304N/A case REX_WB:
304N/A case REX_WX:
304N/A case REX_WXB:
304N/A case REX_WR:
304N/A case REX_WRB:
304N/A case REX_WRX:
304N/A case REX_WRXB:
304N/A NOT_LP64(assert(false, "64bit prefix found"));
304N/A goto again_after_size_prefix2;
0N/A case 0x8B: // movw r, a
0N/A case 0x89: // movw a, r
304N/A debug_only(has_disp32 = true);
0N/A break;
0N/A case 0xC7: // movw a, #16
304N/A debug_only(has_disp32 = true);
0N/A tail_size = 2; // the imm16
0N/A break;
0N/A case 0x0F: // several SSE/SSE2 variants
0N/A ip--; // reparse the 0x0F
0N/A goto again_after_prefix;
0N/A default:
0N/A ShouldNotReachHere();
0N/A }
0N/A break;
0N/A
304N/A case REP8(0xB8): // movl/q r, #32/#64(oop?)
304N/A if (which == end_pc_operand) return ip + (is_64bit ? 8 : 4);
304N/A // these asserts are somewhat nonsensical
304N/A#ifndef _LP64
304N/A assert(which == imm_operand || which == disp32_operand, "");
304N/A#else
304N/A assert((which == call32_operand || which == imm_operand) && is_64bit ||
304N/A which == narrow_oop_operand && !is_64bit, "");
304N/A#endif // _LP64
0N/A return ip;
0N/A
0N/A case 0x69: // imul r, a, #32
0N/A case 0xC7: // movl a, #32(oop?)
0N/A tail_size = 4;
304N/A debug_only(has_disp32 = true); // has both kinds of operands!
0N/A break;
0N/A
0N/A case 0x0F: // movx..., etc.
0N/A switch (0xFF & *ip++) {
0N/A case 0x12: // movlps
0N/A case 0x28: // movaps
0N/A case 0x2E: // ucomiss
0N/A case 0x2F: // comiss
0N/A case 0x54: // andps
0N/A case 0x55: // andnps
0N/A case 0x56: // orps
0N/A case 0x57: // xorps
0N/A case 0x6E: // movd
0N/A case 0x7E: // movd
0N/A case 0xAE: // ldmxcsr a
304N/A // 64bit side says it these have both operands but that doesn't
304N/A // appear to be true
304N/A debug_only(has_disp32 = true);
0N/A break;
0N/A
0N/A case 0xAD: // shrd r, a, %cl
0N/A case 0xAF: // imul r, a
304N/A case 0xBE: // movsbl r, a (movsxb)
304N/A case 0xBF: // movswl r, a (movsxw)
304N/A case 0xB6: // movzbl r, a (movzxb)
304N/A case 0xB7: // movzwl r, a (movzxw)
0N/A case REP16(0x40): // cmovl cc, r, a
0N/A case 0xB0: // cmpxchgb
0N/A case 0xB1: // cmpxchg
0N/A case 0xC1: // xaddl
0N/A case 0xC7: // cmpxchg8
0N/A case REP16(0x90): // setcc a
304N/A debug_only(has_disp32 = true);
0N/A // fall out of the switch to decode the address
0N/A break;
304N/A
0N/A case 0xAC: // shrd r, a, #8
304N/A debug_only(has_disp32 = true);
0N/A tail_size = 1; // the imm8
0N/A break;
304N/A
0N/A case REP16(0x80): // jcc rdisp32
0N/A if (which == end_pc_operand) return ip + 4;
304N/A assert(which == call32_operand, "jcc has no disp32 or imm");
0N/A return ip;
0N/A default:
0N/A ShouldNotReachHere();
0N/A }
0N/A break;
0N/A
0N/A case 0x81: // addl a, #32; addl r, #32
0N/A // also: orl, adcl, sbbl, andl, subl, xorl, cmpl
304N/A // on 32bit in the case of cmpl, the imm might be an oop
0N/A tail_size = 4;
304N/A debug_only(has_disp32 = true); // has both kinds of operands!
0N/A break;
0N/A
0N/A case 0x83: // addl a, #8; addl r, #8
0N/A // also: orl, adcl, sbbl, andl, subl, xorl, cmpl
304N/A debug_only(has_disp32 = true); // has both kinds of operands!
0N/A tail_size = 1;
0N/A break;
0N/A
0N/A case 0x9B:
0N/A switch (0xFF & *ip++) {
0N/A case 0xD9: // fnstcw a
304N/A debug_only(has_disp32 = true);
0N/A break;
0N/A default:
0N/A ShouldNotReachHere();
0N/A }
0N/A break;
0N/A
0N/A case REP4(0x00): // addb a, r; addl a, r; addb r, a; addl r, a
0N/A case REP4(0x10): // adc...
0N/A case REP4(0x20): // and...
0N/A case REP4(0x30): // xor...
0N/A case REP4(0x08): // or...
0N/A case REP4(0x18): // sbb...
0N/A case REP4(0x28): // sub...
304N/A case 0xF7: // mull a
304N/A case 0x8D: // lea r, a
304N/A case 0x87: // xchg r, a
0N/A case REP4(0x38): // cmp...
304N/A case 0x85: // test r, a
304N/A debug_only(has_disp32 = true); // has both kinds of operands!
0N/A break;
0N/A
0N/A case 0xC1: // sal a, #8; sar a, #8; shl a, #8; shr a, #8
0N/A case 0xC6: // movb a, #8
0N/A case 0x80: // cmpb a, #8
0N/A case 0x6B: // imul r, a, #8
304N/A debug_only(has_disp32 = true); // has both kinds of operands!
0N/A tail_size = 1; // the imm8
0N/A break;
0N/A
0N/A case 0xE8: // call rdisp32
0N/A case 0xE9: // jmp rdisp32
0N/A if (which == end_pc_operand) return ip + 4;
304N/A assert(which == call32_operand, "call has no disp32 or imm");
0N/A return ip;
0N/A
0N/A case 0xD1: // sal a, 1; sar a, 1; shl a, 1; shr a, 1
0N/A case 0xD3: // sal a, %cl; sar a, %cl; shl a, %cl; shr a, %cl
0N/A case 0xD9: // fld_s a; fst_s a; fstp_s a; fldcw a
0N/A case 0xDD: // fld_d a; fst_d a; fstp_d a
0N/A case 0xDB: // fild_s a; fistp_s a; fld_x a; fstp_x a
0N/A case 0xDF: // fild_d a; fistp_d a
0N/A case 0xD8: // fadd_s a; fsubr_s a; fmul_s a; fdivr_s a; fcomp_s a
0N/A case 0xDC: // fadd_d a; fsubr_d a; fmul_d a; fdivr_d a; fcomp_d a
0N/A case 0xDE: // faddp_d a; fsubrp_d a; fmulp_d a; fdivrp_d a; fcompp_d a
304N/A debug_only(has_disp32 = true);
0N/A break;
0N/A
420N/A case 0xF0: // Lock
420N/A assert(os::is_MP(), "only on MP");
420N/A goto again_after_prefix;
420N/A
0N/A case 0xF3: // For SSE
0N/A case 0xF2: // For SSE2
304N/A switch (0xFF & *ip++) {
304N/A case REX:
304N/A case REX_B:
304N/A case REX_X:
304N/A case REX_XB:
304N/A case REX_R:
304N/A case REX_RB:
304N/A case REX_RX:
304N/A case REX_RXB:
304N/A case REX_W:
304N/A case REX_WB:
304N/A case REX_WX:
304N/A case REX_WXB:
304N/A case REX_WR:
304N/A case REX_WRB:
304N/A case REX_WRX:
304N/A case REX_WRXB:
304N/A NOT_LP64(assert(false, "found 64bit prefix"));
304N/A ip++;
304N/A default:
304N/A ip++;
304N/A }
304N/A debug_only(has_disp32 = true); // has both kinds of operands!
0N/A break;
0N/A
0N/A default:
0N/A ShouldNotReachHere();
0N/A
304N/A#undef REP8
304N/A#undef REP16
0N/A }
0N/A
0N/A assert(which != call32_operand, "instruction is not a call, jmp, or jcc");
304N/A#ifdef _LP64
304N/A assert(which != imm_operand, "instruction is not a movq reg, imm64");
304N/A#else
304N/A // assert(which != imm_operand || has_imm32, "instruction has no imm32 field");
304N/A assert(which != imm_operand || has_disp32, "instruction has no imm32 field");
304N/A#endif // LP64
304N/A assert(which != disp32_operand || has_disp32, "instruction has no disp32 field");
0N/A
0N/A // parse the output of emit_operand
0N/A int op2 = 0xFF & *ip++;
0N/A int base = op2 & 0x07;
0N/A int op3 = -1;
0N/A const int b100 = 4;
0N/A const int b101 = 5;
0N/A if (base == b100 && (op2 >> 6) != 3) {
0N/A op3 = 0xFF & *ip++;
0N/A base = op3 & 0x07; // refetch the base
0N/A }
0N/A // now ip points at the disp (if any)
0N/A
0N/A switch (op2 >> 6) {
0N/A case 0:
0N/A // [00 reg 100][ss index base]
304N/A // [00 reg 100][00 100 esp]
0N/A // [00 reg base]
0N/A // [00 reg 100][ss index 101][disp32]
0N/A // [00 reg 101] [disp32]
0N/A
0N/A if (base == b101) {
0N/A if (which == disp32_operand)
0N/A return ip; // caller wants the disp32
0N/A ip += 4; // skip the disp32
0N/A }
0N/A break;
0N/A
0N/A case 1:
0N/A // [01 reg 100][ss index base][disp8]
304N/A // [01 reg 100][00 100 esp][disp8]
0N/A // [01 reg base] [disp8]
0N/A ip += 1; // skip the disp8
0N/A break;
0N/A
0N/A case 2:
0N/A // [10 reg 100][ss index base][disp32]
304N/A // [10 reg 100][00 100 esp][disp32]
0N/A // [10 reg base] [disp32]
0N/A if (which == disp32_operand)
0N/A return ip; // caller wants the disp32
0N/A ip += 4; // skip the disp32
0N/A break;
0N/A
0N/A case 3:
0N/A // [11 reg base] (not a memory addressing mode)
0N/A break;
0N/A }
0N/A
0N/A if (which == end_pc_operand) {
0N/A return ip + tail_size;
0N/A }
0N/A
304N/A#ifdef _LP64
642N/A assert(which == narrow_oop_operand && !is_64bit, "instruction is not a movl adr, imm32");
304N/A#else
304N/A assert(which == imm_operand, "instruction has only an imm field");
304N/A#endif // LP64
0N/A return ip;
0N/A}
0N/A
0N/Aaddress Assembler::locate_next_instruction(address inst) {
0N/A // Secretly share code with locate_operand:
0N/A return locate_operand(inst, end_pc_operand);
0N/A}
0N/A
0N/A
0N/A#ifdef ASSERT
0N/Avoid Assembler::check_relocation(RelocationHolder const& rspec, int format) {
0N/A address inst = inst_mark();
0N/A assert(inst != NULL && inst < pc(), "must point to beginning of instruction");
0N/A address opnd;
0N/A
0N/A Relocation* r = rspec.reloc();
0N/A if (r->type() == relocInfo::none) {
0N/A return;
0N/A } else if (r->is_call() || format == call32_operand) {
0N/A // assert(format == imm32_operand, "cannot specify a nonzero format");
0N/A opnd = locate_operand(inst, call32_operand);
0N/A } else if (r->is_data()) {
304N/A assert(format == imm_operand || format == disp32_operand
304N/A LP64_ONLY(|| format == narrow_oop_operand), "format ok");
0N/A opnd = locate_operand(inst, (WhichOperand)format);
0N/A } else {
304N/A assert(format == imm_operand, "cannot specify a format");
0N/A return;
0N/A }
0N/A assert(opnd == pc(), "must put operand where relocs can find it");
0N/A}
304N/A#endif // ASSERT
304N/A
304N/Avoid Assembler::emit_operand32(Register reg, Address adr) {
304N/A assert(reg->encoding() < 8, "no extended registers");
304N/A assert(!adr.base_needs_rex() && !adr.index_needs_rex(), "no extended registers");
304N/A emit_operand(reg, adr._base, adr._index, adr._scale, adr._disp,
304N/A adr._rspec);
304N/A}
304N/A
304N/Avoid Assembler::emit_operand(Register reg, Address adr,
304N/A int rip_relative_correction) {
304N/A emit_operand(reg, adr._base, adr._index, adr._scale, adr._disp,
304N/A adr._rspec,
304N/A rip_relative_correction);
304N/A}
304N/A
304N/Avoid Assembler::emit_operand(XMMRegister reg, Address adr) {
304N/A emit_operand(reg, adr._base, adr._index, adr._scale, adr._disp,
304N/A adr._rspec);
304N/A}
304N/A
304N/A// MMX operations
304N/Avoid Assembler::emit_operand(MMXRegister reg, Address adr) {
304N/A assert(!adr.base_needs_rex() && !adr.index_needs_rex(), "no extended registers");
304N/A emit_operand((Register)reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
304N/A}
304N/A
304N/A// work around gcc (3.2.1-7a) bug
304N/Avoid Assembler::emit_operand(Address adr, MMXRegister reg) {
304N/A assert(!adr.base_needs_rex() && !adr.index_needs_rex(), "no extended registers");
304N/A emit_operand((Register)reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
0N/A}
0N/A
0N/A
0N/Avoid Assembler::emit_farith(int b1, int b2, int i) {
0N/A assert(isByte(b1) && isByte(b2), "wrong opcode");
0N/A assert(0 <= i && i < 8, "illegal stack offset");
0N/A emit_byte(b1);
0N/A emit_byte(b2 + i);
0N/A}
0N/A
0N/A
304N/A// Now the Assembler instruction (identical for 32/64 bits)
304N/A
304N/Avoid Assembler::adcl(Register dst, int32_t imm32) {
304N/A prefix(dst);
0N/A emit_arith(0x81, 0xD0, dst, imm32);
0N/A}
0N/A
0N/Avoid Assembler::adcl(Register dst, Address src) {
0N/A InstructionMark im(this);
304N/A prefix(src, dst);
0N/A emit_byte(0x13);
0N/A emit_operand(dst, src);
0N/A}
0N/A
0N/Avoid Assembler::adcl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
0N/A emit_arith(0x13, 0xC0, dst, src);
0N/A}
0N/A
304N/Avoid Assembler::addl(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_arith_operand(0x81, rax, dst, imm32);
304N/A}
0N/A
0N/Avoid Assembler::addl(Address dst, Register src) {
0N/A InstructionMark im(this);
304N/A prefix(dst, src);
0N/A emit_byte(0x01);
0N/A emit_operand(src, dst);
0N/A}
0N/A
304N/Avoid Assembler::addl(Register dst, int32_t imm32) {
304N/A prefix(dst);
0N/A emit_arith(0x81, 0xC0, dst, imm32);
0N/A}
0N/A
0N/Avoid Assembler::addl(Register dst, Address src) {
0N/A InstructionMark im(this);
304N/A prefix(src, dst);
0N/A emit_byte(0x03);
0N/A emit_operand(dst, src);
0N/A}
0N/A
0N/Avoid Assembler::addl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
0N/A emit_arith(0x03, 0xC0, dst, src);
0N/A}
0N/A
0N/Avoid Assembler::addr_nop_4() {
0N/A // 4 bytes: NOP DWORD PTR [EAX+0]
0N/A emit_byte(0x0F);
0N/A emit_byte(0x1F);
0N/A emit_byte(0x40); // emit_rm(cbuf, 0x1, EAX_enc, EAX_enc);
0N/A emit_byte(0); // 8-bits offset (1 byte)
0N/A}
0N/A
0N/Avoid Assembler::addr_nop_5() {
0N/A // 5 bytes: NOP DWORD PTR [EAX+EAX*0+0] 8-bits offset
0N/A emit_byte(0x0F);
0N/A emit_byte(0x1F);
0N/A emit_byte(0x44); // emit_rm(cbuf, 0x1, EAX_enc, 0x4);
0N/A emit_byte(0x00); // emit_rm(cbuf, 0x0, EAX_enc, EAX_enc);
0N/A emit_byte(0); // 8-bits offset (1 byte)
0N/A}
0N/A
0N/Avoid Assembler::addr_nop_7() {
0N/A // 7 bytes: NOP DWORD PTR [EAX+0] 32-bits offset
0N/A emit_byte(0x0F);
0N/A emit_byte(0x1F);
0N/A emit_byte(0x80); // emit_rm(cbuf, 0x2, EAX_enc, EAX_enc);
0N/A emit_long(0); // 32-bits offset (4 bytes)
0N/A}
0N/A
0N/Avoid Assembler::addr_nop_8() {
0N/A // 8 bytes: NOP DWORD PTR [EAX+EAX*0+0] 32-bits offset
0N/A emit_byte(0x0F);
0N/A emit_byte(0x1F);
0N/A emit_byte(0x84); // emit_rm(cbuf, 0x2, EAX_enc, 0x4);
0N/A emit_byte(0x00); // emit_rm(cbuf, 0x0, EAX_enc, EAX_enc);
0N/A emit_long(0); // 32-bits offset (4 bytes)
0N/A}
0N/A
304N/Avoid Assembler::addsd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x58);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::addsd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF2);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x58);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::addss(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x58);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::addss(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF3);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x58);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::andl(Register dst, int32_t imm32) {
304N/A prefix(dst);
304N/A emit_arith(0x81, 0xE0, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::andl(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x23);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::andl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x23, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::andpd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x54);
304N/A emit_operand(dst, src);
304N/A}
304N/A
775N/Avoid Assembler::bsfl(Register dst, Register src) {
775N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
775N/A emit_byte(0x0F);
775N/A emit_byte(0xBC);
775N/A emit_byte(0xC0 | encode);
775N/A}
775N/A
775N/Avoid Assembler::bsrl(Register dst, Register src) {
775N/A assert(!VM_Version::supports_lzcnt(), "encoding is treated as LZCNT");
775N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
775N/A emit_byte(0x0F);
775N/A emit_byte(0xBD);
775N/A emit_byte(0xC0 | encode);
775N/A}
775N/A
304N/Avoid Assembler::bswapl(Register reg) { // bswap
304N/A int encode = prefix_and_encode(reg->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0xC8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::call(Label& L, relocInfo::relocType rtype) {
304N/A // suspect disp32 is always good
304N/A int operand = LP64_ONLY(disp32_operand) NOT_LP64(imm_operand);
304N/A
304N/A if (L.is_bound()) {
304N/A const int long_size = 5;
304N/A int offs = (int)( target(L) - pc() );
304N/A assert(offs <= 0, "assembler error");
304N/A InstructionMark im(this);
304N/A // 1110 1000 #32-bit disp
304N/A emit_byte(0xE8);
304N/A emit_data(offs - long_size, rtype, operand);
304N/A } else {
304N/A InstructionMark im(this);
304N/A // 1110 1000 #32-bit disp
304N/A L.add_patch_at(code(), locator());
304N/A
304N/A emit_byte(0xE8);
304N/A emit_data(int(0), rtype, operand);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::call(Register dst) {
304N/A // This was originally using a 32bit register encoding
304N/A // and surely we want 64bit!
304N/A // this is a 32bit encoding but in 64bit mode the default
304N/A // operand size is 64bit so there is no need for the
304N/A // wide prefix. So prefix only happens if we use the
304N/A // new registers. Much like push/pop.
304N/A int x = offset();
304N/A // this may be true but dbx disassembles it as if it
304N/A // were 32bits...
304N/A // int encode = prefix_and_encode(dst->encoding());
304N/A // if (offset() != x) assert(dst->encoding() >= 8, "what?");
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A
304N/A emit_byte(0xFF);
304N/A emit_byte(0xD0 | encode);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::call(Address adr) {
304N/A InstructionMark im(this);
304N/A prefix(adr);
304N/A emit_byte(0xFF);
304N/A emit_operand(rdx, adr);
304N/A}
304N/A
304N/Avoid Assembler::call_literal(address entry, RelocationHolder const& rspec) {
304N/A assert(entry != NULL, "call most probably wrong");
304N/A InstructionMark im(this);
304N/A emit_byte(0xE8);
304N/A intptr_t disp = entry - (_code_pos + sizeof(int32_t));
304N/A assert(is_simm32(disp), "must be 32bit offset (call2)");
304N/A // Technically, should use call32_operand, but this format is
304N/A // implied by the fact that we're emitting a call instruction.
304N/A
304N/A int operand = LP64_ONLY(disp32_operand) NOT_LP64(call32_operand);
304N/A emit_data((int) disp, rspec, operand);
304N/A}
304N/A
304N/Avoid Assembler::cdql() {
304N/A emit_byte(0x99);
304N/A}
304N/A
304N/Avoid Assembler::cmovl(Condition cc, Register dst, Register src) {
304N/A NOT_LP64(guarantee(VM_Version::supports_cmov(), "illegal instruction"));
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x40 | cc);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::cmovl(Condition cc, Register dst, Address src) {
304N/A NOT_LP64(guarantee(VM_Version::supports_cmov(), "illegal instruction"));
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x40 | cc);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::cmpb(Address dst, int imm8) {
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0x80);
304N/A emit_operand(rdi, dst, 1);
304N/A emit_byte(imm8);
304N/A}
304N/A
304N/Avoid Assembler::cmpl(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0x81);
304N/A emit_operand(rdi, dst, 4);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::cmpl(Register dst, int32_t imm32) {
304N/A prefix(dst);
304N/A emit_arith(0x81, 0xF8, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::cmpl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x3B, 0xC0, dst, src);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::cmpl(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x3B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::cmpw(Address dst, int imm16) {
304N/A InstructionMark im(this);
304N/A assert(!dst.base_needs_rex() && !dst.index_needs_rex(), "no extended registers");
304N/A emit_byte(0x66);
304N/A emit_byte(0x81);
304N/A emit_operand(rdi, dst, 2);
304N/A emit_word(imm16);
304N/A}
304N/A
304N/A// The 32-bit cmpxchg compares the value at adr with the contents of rax,
304N/A// and stores reg into adr if so; otherwise, the value at adr is loaded into rax,.
304N/A// The ZF is set if the compared values were equal, and cleared otherwise.
304N/Avoid Assembler::cmpxchgl(Register reg, Address adr) { // cmpxchg
304N/A if (Atomics & 2) {
304N/A // caveat: no instructionmark, so this isn't relocatable.
304N/A // Emit a synthetic, non-atomic, CAS equivalent.
304N/A // Beware. The synthetic form sets all ICCs, not just ZF.
304N/A // cmpxchg r,[m] is equivalent to rax, = CAS (m, rax, r)
304N/A cmpl(rax, adr);
304N/A movl(rax, adr);
304N/A if (reg != rax) {
304N/A Label L ;
304N/A jcc(Assembler::notEqual, L);
304N/A movl(adr, reg);
304N/A bind(L);
304N/A }
304N/A } else {
304N/A InstructionMark im(this);
304N/A prefix(adr, reg);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xB1);
304N/A emit_operand(reg, adr);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::comisd(XMMRegister dst, Address src) {
304N/A // NOTE: dbx seems to decode this as comiss even though the
304N/A // 0x66 is there. Strangly ucomisd comes out correct
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0x66);
304N/A comiss(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::comiss(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2F);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::cvtdq2pd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0xE6);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvtdq2ps(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5B);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvtsd2ss(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5A);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvtsi2sdl(XMMRegister dst, Register src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2A);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvtsi2ssl(XMMRegister dst, Register src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2A);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvtss2sd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5A);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvttsd2sil(Register dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2C);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvttss2sil(Register dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2C);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::decl(Address dst) {
304N/A // Don't use it directly. Use MacroAssembler::decrement() instead.
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0xFF);
304N/A emit_operand(rcx, dst);
304N/A}
304N/A
304N/Avoid Assembler::divsd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF2);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5E);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::divsd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5E);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::divss(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF3);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5E);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::divss(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5E);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::emms() {
304N/A NOT_LP64(assert(VM_Version::supports_mmx(), ""));
304N/A emit_byte(0x0F);
304N/A emit_byte(0x77);
304N/A}
304N/A
304N/Avoid Assembler::hlt() {
304N/A emit_byte(0xF4);
304N/A}
304N/A
304N/Avoid Assembler::idivl(Register src) {
304N/A int encode = prefix_and_encode(src->encoding());
304N/A emit_byte(0xF7);
304N/A emit_byte(0xF8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::imull(Register dst, Register src) {
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0xAF);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::imull(Register dst, Register src, int value) {
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A if (is8bit(value)) {
304N/A emit_byte(0x6B);
304N/A emit_byte(0xC0 | encode);
304N/A emit_byte(value);
304N/A } else {
304N/A emit_byte(0x69);
304N/A emit_byte(0xC0 | encode);
304N/A emit_long(value);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::incl(Address dst) {
304N/A // Don't use it directly. Use MacroAssembler::increment() instead.
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0xFF);
304N/A emit_operand(rax, dst);
304N/A}
304N/A
304N/Avoid Assembler::jcc(Condition cc, Label& L, relocInfo::relocType rtype) {
304N/A InstructionMark im(this);
304N/A relocate(rtype);
304N/A assert((0 <= cc) && (cc < 16), "illegal cc");
304N/A if (L.is_bound()) {
304N/A address dst = target(L);
304N/A assert(dst != NULL, "jcc most probably wrong");
304N/A
304N/A const int short_size = 2;
304N/A const int long_size = 6;
304N/A intptr_t offs = (intptr_t)dst - (intptr_t)_code_pos;
304N/A if (rtype == relocInfo::none && is8bit(offs - short_size)) {
304N/A // 0111 tttn #8-bit disp
304N/A emit_byte(0x70 | cc);
304N/A emit_byte((offs - short_size) & 0xFF);
304N/A } else {
304N/A // 0000 1111 1000 tttn #32-bit disp
304N/A assert(is_simm32(offs - long_size),
304N/A "must be 32bit offset (call4)");
304N/A emit_byte(0x0F);
304N/A emit_byte(0x80 | cc);
304N/A emit_long(offs - long_size);
304N/A }
304N/A } else {
304N/A // Note: could eliminate cond. jumps to this jump if condition
304N/A // is the same however, seems to be rather unlikely case.
304N/A // Note: use jccb() if label to be bound is very close to get
304N/A // an 8-bit displacement
304N/A L.add_patch_at(code(), locator());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x80 | cc);
304N/A emit_long(0);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::jccb(Condition cc, Label& L) {
304N/A if (L.is_bound()) {
304N/A const int short_size = 2;
304N/A address entry = target(L);
304N/A assert(is8bit((intptr_t)entry - ((intptr_t)_code_pos + short_size)),
304N/A "Dispacement too large for a short jmp");
304N/A intptr_t offs = (intptr_t)entry - (intptr_t)_code_pos;
304N/A // 0111 tttn #8-bit disp
304N/A emit_byte(0x70 | cc);
304N/A emit_byte((offs - short_size) & 0xFF);
304N/A } else {
304N/A InstructionMark im(this);
304N/A L.add_patch_at(code(), locator());
304N/A emit_byte(0x70 | cc);
304N/A emit_byte(0);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::jmp(Address adr) {
304N/A InstructionMark im(this);
304N/A prefix(adr);
304N/A emit_byte(0xFF);
304N/A emit_operand(rsp, adr);
304N/A}
304N/A
304N/Avoid Assembler::jmp(Label& L, relocInfo::relocType rtype) {
304N/A if (L.is_bound()) {
304N/A address entry = target(L);
304N/A assert(entry != NULL, "jmp most probably wrong");
304N/A InstructionMark im(this);
304N/A const int short_size = 2;
304N/A const int long_size = 5;
304N/A intptr_t offs = entry - _code_pos;
304N/A if (rtype == relocInfo::none && is8bit(offs - short_size)) {
304N/A emit_byte(0xEB);
304N/A emit_byte((offs - short_size) & 0xFF);
304N/A } else {
304N/A emit_byte(0xE9);
304N/A emit_long(offs - long_size);
304N/A }
304N/A } else {
304N/A // By default, forward jumps are always 32-bit displacements, since
304N/A // we can't yet know where the label will be bound. If you're sure that
304N/A // the forward jump will not run beyond 256 bytes, use jmpb to
304N/A // force an 8-bit displacement.
304N/A InstructionMark im(this);
304N/A relocate(rtype);
304N/A L.add_patch_at(code(), locator());
304N/A emit_byte(0xE9);
304N/A emit_long(0);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::jmp(Register entry) {
304N/A int encode = prefix_and_encode(entry->encoding());
304N/A emit_byte(0xFF);
304N/A emit_byte(0xE0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::jmp_literal(address dest, RelocationHolder const& rspec) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xE9);
304N/A assert(dest != NULL, "must have a target");
304N/A intptr_t disp = dest - (_code_pos + sizeof(int32_t));
304N/A assert(is_simm32(disp), "must be 32bit offset (jmp)");
304N/A emit_data(disp, rspec.reloc(), call32_operand);
304N/A}
304N/A
304N/Avoid Assembler::jmpb(Label& L) {
304N/A if (L.is_bound()) {
304N/A const int short_size = 2;
304N/A address entry = target(L);
304N/A assert(is8bit((entry - _code_pos) + short_size),
304N/A "Dispacement too large for a short jmp");
304N/A assert(entry != NULL, "jmp most probably wrong");
304N/A intptr_t offs = entry - _code_pos;
304N/A emit_byte(0xEB);
304N/A emit_byte((offs - short_size) & 0xFF);
304N/A } else {
304N/A InstructionMark im(this);
304N/A L.add_patch_at(code(), locator());
304N/A emit_byte(0xEB);
304N/A emit_byte(0);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::ldmxcsr( Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A prefix(src);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xAE);
304N/A emit_operand(as_Register(2), src);
304N/A}
304N/A
304N/Avoid Assembler::leal(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A#ifdef _LP64
304N/A emit_byte(0x67); // addr32
304N/A prefix(src, dst);
304N/A#endif // LP64
304N/A emit_byte(0x8D);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::lock() {
304N/A if (Atomics & 1) {
304N/A // Emit either nothing, a NOP, or a NOP: prefix
304N/A emit_byte(0x90) ;
304N/A } else {
304N/A emit_byte(0xF0);
304N/A }
304N/A}
304N/A
775N/Avoid Assembler::lzcntl(Register dst, Register src) {
775N/A assert(VM_Version::supports_lzcnt(), "encoding is treated as BSR");
775N/A emit_byte(0xF3);
775N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
775N/A emit_byte(0x0F);
775N/A emit_byte(0xBD);
775N/A emit_byte(0xC0 | encode);
775N/A}
775N/A
671N/A// Emit mfence instruction
304N/Avoid Assembler::mfence() {
671N/A NOT_LP64(assert(VM_Version::supports_sse2(), "unsupported");)
671N/A emit_byte( 0x0F );
671N/A emit_byte( 0xAE );
671N/A emit_byte( 0xF0 );
304N/A}
304N/A
304N/Avoid Assembler::mov(Register dst, Register src) {
304N/A LP64_ONLY(movq(dst, src)) NOT_LP64(movl(dst, src));
304N/A}
304N/A
304N/Avoid Assembler::movapd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A int dstenc = dst->encoding();
304N/A int srcenc = src->encoding();
304N/A emit_byte(0x66);
304N/A if (dstenc < 8) {
304N/A if (srcenc >= 8) {
304N/A prefix(REX_B);
304N/A srcenc -= 8;
304N/A }
304N/A } else {
304N/A if (srcenc < 8) {
304N/A prefix(REX_R);
304N/A } else {
304N/A prefix(REX_RB);
304N/A srcenc -= 8;
304N/A }
304N/A dstenc -= 8;
304N/A }
304N/A emit_byte(0x0F);
304N/A emit_byte(0x28);
304N/A emit_byte(0xC0 | dstenc << 3 | srcenc);
304N/A}
304N/A
304N/Avoid Assembler::movaps(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A int dstenc = dst->encoding();
304N/A int srcenc = src->encoding();
304N/A if (dstenc < 8) {
304N/A if (srcenc >= 8) {
304N/A prefix(REX_B);
304N/A srcenc -= 8;
304N/A }
304N/A } else {
304N/A if (srcenc < 8) {
304N/A prefix(REX_R);
304N/A } else {
304N/A prefix(REX_RB);
304N/A srcenc -= 8;
304N/A }
304N/A dstenc -= 8;
304N/A }
304N/A emit_byte(0x0F);
304N/A emit_byte(0x28);
304N/A emit_byte(0xC0 | dstenc << 3 | srcenc);
304N/A}
304N/A
304N/Avoid Assembler::movb(Register dst, Address src) {
304N/A NOT_LP64(assert(dst->has_byte_register(), "must have byte register"));
304N/A InstructionMark im(this);
304N/A prefix(src, dst, true);
304N/A emit_byte(0x8A);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::movb(Address dst, int imm8) {
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0xC6);
304N/A emit_operand(rax, dst, 1);
304N/A emit_byte(imm8);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::movb(Address dst, Register src) {
304N/A assert(src->has_byte_register(), "must have byte register");
304N/A InstructionMark im(this);
304N/A prefix(dst, src, true);
304N/A emit_byte(0x88);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::movdl(XMMRegister dst, Register src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0x66);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x6E);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movdl(Register dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0x66);
304N/A // swap src/dst to get correct prefix
304N/A int encode = prefix_and_encode(src->encoding(), dst->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x7E);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movdqa(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x6F);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movdqa(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0x66);
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x6F);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movdqa(Address dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(dst, src);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x7F);
304N/A emit_operand(src, dst);
304N/A}
304N/A
405N/Avoid Assembler::movdqu(XMMRegister dst, Address src) {
405N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
405N/A InstructionMark im(this);
405N/A emit_byte(0xF3);
405N/A prefix(src, dst);
405N/A emit_byte(0x0F);
405N/A emit_byte(0x6F);
405N/A emit_operand(dst, src);
405N/A}
405N/A
405N/Avoid Assembler::movdqu(XMMRegister dst, XMMRegister src) {
405N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
405N/A emit_byte(0xF3);
405N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
405N/A emit_byte(0x0F);
405N/A emit_byte(0x6F);
405N/A emit_byte(0xC0 | encode);
405N/A}
405N/A
405N/Avoid Assembler::movdqu(Address dst, XMMRegister src) {
405N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
405N/A InstructionMark im(this);
405N/A emit_byte(0xF3);
405N/A prefix(dst, src);
405N/A emit_byte(0x0F);
405N/A emit_byte(0x7F);
405N/A emit_operand(src, dst);
405N/A}
405N/A
304N/A// Uses zero extension on 64bit
304N/A
304N/Avoid Assembler::movl(Register dst, int32_t imm32) {
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xB8 | encode);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::movl(Register dst, Register src) {
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x8B);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movl(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x8B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movl(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0xC7);
304N/A emit_operand(rax, dst, 4);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::movl(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A prefix(dst, src);
304N/A emit_byte(0x89);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/A// New cpus require to use movsd and movss to avoid partial register stall
304N/A// when loading from memory. But for old Opteron use movlpd instead of movsd.
304N/A// The selection is done in MacroAssembler::movdbl() and movflt().
304N/Avoid Assembler::movlpd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x12);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movq( MMXRegister dst, Address src ) {
304N/A assert( VM_Version::supports_mmx(), "" );
304N/A emit_byte(0x0F);
304N/A emit_byte(0x6F);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movq( Address dst, MMXRegister src ) {
304N/A assert( VM_Version::supports_mmx(), "" );
304N/A emit_byte(0x0F);
304N/A emit_byte(0x7F);
304N/A // workaround gcc (3.2.1-7a) bug
304N/A // In that version of gcc with only an emit_operand(MMX, Address)
304N/A // gcc will tail jump and try and reverse the parameters completely
304N/A // obliterating dst in the process. By having a version available
304N/A // that doesn't need to swap the args at the tail jump the bug is
304N/A // avoided.
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movq(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF3);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x7E);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movq(Address dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(dst, src);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xD6);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::movsbl(Register dst, Address src) { // movsxb
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xBE);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movsbl(Register dst, Register src) { // movsxb
304N/A NOT_LP64(assert(src->has_byte_register(), "must have byte register"));
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding(), true);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xBE);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movsd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x10);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movsd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF2);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x10);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movsd(Address dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF2);
304N/A prefix(dst, src);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x11);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::movss(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x10);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movss(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF3);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x10);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movss(Address dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF3);
304N/A prefix(dst, src);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x11);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::movswl(Register dst, Address src) { // movsxw
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xBF);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movswl(Register dst, Register src) { // movsxw
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0xBF);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movw(Address dst, int imm16) {
304N/A InstructionMark im(this);
304N/A
304N/A emit_byte(0x66); // switch to 16-bit mode
304N/A prefix(dst);
304N/A emit_byte(0xC7);
304N/A emit_operand(rax, dst, 2);
304N/A emit_word(imm16);
304N/A}
304N/A
304N/Avoid Assembler::movw(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(src, dst);
304N/A emit_byte(0x8B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movw(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(dst, src);
304N/A emit_byte(0x89);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::movzbl(Register dst, Address src) { // movzxb
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xB6);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movzbl(Register dst, Register src) { // movzxb
304N/A NOT_LP64(assert(src->has_byte_register(), "must have byte register"));
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding(), true);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xB6);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movzwl(Register dst, Address src) { // movzxw
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xB7);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movzwl(Register dst, Register src) { // movzxw
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0xB7);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::mull(Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src);
304N/A emit_byte(0xF7);
304N/A emit_operand(rsp, src);
304N/A}
304N/A
304N/Avoid Assembler::mull(Register src) {
304N/A int encode = prefix_and_encode(src->encoding());
304N/A emit_byte(0xF7);
304N/A emit_byte(0xE0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::mulsd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF2);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x59);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::mulsd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x59);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::mulss(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF3);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x59);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::mulss(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x59);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::negl(Register dst) {
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xF7);
304N/A emit_byte(0xD8 | encode);
304N/A}
304N/A
0N/Avoid Assembler::nop(int i) {
304N/A#ifdef ASSERT
0N/A assert(i > 0, " ");
304N/A // The fancy nops aren't currently recognized by debuggers making it a
304N/A // pain to disassemble code while debugging. If asserts are on clearly
304N/A // speed is not an issue so simply use the single byte traditional nop
304N/A // to do alignment.
304N/A
304N/A for (; i > 0 ; i--) emit_byte(0x90);
304N/A return;
304N/A
304N/A#endif // ASSERT
304N/A
0N/A if (UseAddressNop && VM_Version::is_intel()) {
0N/A //
0N/A // Using multi-bytes nops "0x0F 0x1F [address]" for Intel
0N/A // 1: 0x90
0N/A // 2: 0x66 0x90
0N/A // 3: 0x66 0x66 0x90 (don't use "0x0F 0x1F 0x00" - need patching safe padding)
0N/A // 4: 0x0F 0x1F 0x40 0x00
0N/A // 5: 0x0F 0x1F 0x44 0x00 0x00
0N/A // 6: 0x66 0x0F 0x1F 0x44 0x00 0x00
0N/A // 7: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
0N/A // 8: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A // 9: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A // 10: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A // 11: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A
0N/A // The rest coding is Intel specific - don't use consecutive address nops
0N/A
0N/A // 12: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
0N/A // 13: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
0N/A // 14: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
0N/A // 15: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
0N/A
0N/A while(i >= 15) {
0N/A // For Intel don't generate consecutive addess nops (mix with regular nops)
0N/A i -= 15;
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66); // size prefix
0N/A addr_nop_8();
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x90); // nop
0N/A }
0N/A switch (i) {
0N/A case 14:
0N/A emit_byte(0x66); // size prefix
0N/A case 13:
0N/A emit_byte(0x66); // size prefix
0N/A case 12:
0N/A addr_nop_8();
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x90); // nop
0N/A break;
0N/A case 11:
0N/A emit_byte(0x66); // size prefix
0N/A case 10:
0N/A emit_byte(0x66); // size prefix
0N/A case 9:
0N/A emit_byte(0x66); // size prefix
0N/A case 8:
0N/A addr_nop_8();
0N/A break;
0N/A case 7:
0N/A addr_nop_7();
0N/A break;
0N/A case 6:
0N/A emit_byte(0x66); // size prefix
0N/A case 5:
0N/A addr_nop_5();
0N/A break;
0N/A case 4:
0N/A addr_nop_4();
0N/A break;
0N/A case 3:
0N/A // Don't use "0x0F 0x1F 0x00" - need patching safe padding
0N/A emit_byte(0x66); // size prefix
0N/A case 2:
0N/A emit_byte(0x66); // size prefix
0N/A case 1:
0N/A emit_byte(0x90); // nop
0N/A break;
0N/A default:
0N/A assert(i == 0, " ");
0N/A }
0N/A return;
0N/A }
0N/A if (UseAddressNop && VM_Version::is_amd()) {
0N/A //
0N/A // Using multi-bytes nops "0x0F 0x1F [address]" for AMD.
0N/A // 1: 0x90
0N/A // 2: 0x66 0x90
0N/A // 3: 0x66 0x66 0x90 (don't use "0x0F 0x1F 0x00" - need patching safe padding)
0N/A // 4: 0x0F 0x1F 0x40 0x00
0N/A // 5: 0x0F 0x1F 0x44 0x00 0x00
0N/A // 6: 0x66 0x0F 0x1F 0x44 0x00 0x00
0N/A // 7: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
0N/A // 8: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A // 9: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A // 10: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A // 11: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A
0N/A // The rest coding is AMD specific - use consecutive address nops
0N/A
0N/A // 12: 0x66 0x0F 0x1F 0x44 0x00 0x00 0x66 0x0F 0x1F 0x44 0x00 0x00
0N/A // 13: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00 0x66 0x0F 0x1F 0x44 0x00 0x00
0N/A // 14: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
0N/A // 15: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
0N/A // 16: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
0N/A // Size prefixes (0x66) are added for larger sizes
0N/A
0N/A while(i >= 22) {
0N/A i -= 11;
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66); // size prefix
0N/A addr_nop_8();
0N/A }
0N/A // Generate first nop for size between 21-12
0N/A switch (i) {
0N/A case 21:
0N/A i -= 1;
0N/A emit_byte(0x66); // size prefix
0N/A case 20:
0N/A case 19:
0N/A i -= 1;
0N/A emit_byte(0x66); // size prefix
0N/A case 18:
0N/A case 17:
0N/A i -= 1;
0N/A emit_byte(0x66); // size prefix
0N/A case 16:
0N/A case 15:
0N/A i -= 8;
0N/A addr_nop_8();
0N/A break;
0N/A case 14:
0N/A case 13:
0N/A i -= 7;
0N/A addr_nop_7();
0N/A break;
0N/A case 12:
0N/A i -= 6;
0N/A emit_byte(0x66); // size prefix
0N/A addr_nop_5();
0N/A break;
0N/A default:
0N/A assert(i < 12, " ");
0N/A }
0N/A
0N/A // Generate second nop for size between 11-1
0N/A switch (i) {
0N/A case 11:
0N/A emit_byte(0x66); // size prefix
0N/A case 10:
0N/A emit_byte(0x66); // size prefix
0N/A case 9:
0N/A emit_byte(0x66); // size prefix
0N/A case 8:
0N/A addr_nop_8();
0N/A break;
0N/A case 7:
0N/A addr_nop_7();
0N/A break;
0N/A case 6:
0N/A emit_byte(0x66); // size prefix
0N/A case 5:
0N/A addr_nop_5();
0N/A break;
0N/A case 4:
0N/A addr_nop_4();
0N/A break;
0N/A case 3:
0N/A // Don't use "0x0F 0x1F 0x00" - need patching safe padding
0N/A emit_byte(0x66); // size prefix
0N/A case 2:
0N/A emit_byte(0x66); // size prefix
0N/A case 1:
0N/A emit_byte(0x90); // nop
0N/A break;
0N/A default:
0N/A assert(i == 0, " ");
0N/A }
0N/A return;
0N/A }
0N/A
0N/A // Using nops with size prefixes "0x66 0x90".
0N/A // From AMD Optimization Guide:
0N/A // 1: 0x90
0N/A // 2: 0x66 0x90
0N/A // 3: 0x66 0x66 0x90
0N/A // 4: 0x66 0x66 0x66 0x90
0N/A // 5: 0x66 0x66 0x90 0x66 0x90
0N/A // 6: 0x66 0x66 0x90 0x66 0x66 0x90
0N/A // 7: 0x66 0x66 0x66 0x90 0x66 0x66 0x90
0N/A // 8: 0x66 0x66 0x66 0x90 0x66 0x66 0x66 0x90
0N/A // 9: 0x66 0x66 0x90 0x66 0x66 0x90 0x66 0x66 0x90
0N/A // 10: 0x66 0x66 0x66 0x90 0x66 0x66 0x90 0x66 0x66 0x90
0N/A //
0N/A while(i > 12) {
0N/A i -= 4;
0N/A emit_byte(0x66); // size prefix
0N/A emit_byte(0x66);
0N/A emit_byte(0x66);
0N/A emit_byte(0x90); // nop
0N/A }
0N/A // 1 - 12 nops
0N/A if(i > 8) {
0N/A if(i > 9) {
0N/A i -= 1;
0N/A emit_byte(0x66);
0N/A }
0N/A i -= 3;
0N/A emit_byte(0x66);
0N/A emit_byte(0x66);
0N/A emit_byte(0x90);
0N/A }
0N/A // 1 - 8 nops
0N/A if(i > 4) {
0N/A if(i > 6) {
0N/A i -= 1;
0N/A emit_byte(0x66);
0N/A }
0N/A i -= 3;
0N/A emit_byte(0x66);
0N/A emit_byte(0x66);
0N/A emit_byte(0x90);
0N/A }
0N/A switch (i) {
0N/A case 4:
0N/A emit_byte(0x66);
0N/A case 3:
0N/A emit_byte(0x66);
0N/A case 2:
0N/A emit_byte(0x66);
0N/A case 1:
0N/A emit_byte(0x90);
0N/A break;
0N/A default:
0N/A assert(i == 0, " ");
0N/A }
0N/A}
0N/A
304N/Avoid Assembler::notl(Register dst) {
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xF7);
304N/A emit_byte(0xD0 | encode );
304N/A}
304N/A
304N/Avoid Assembler::orl(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0x81);
304N/A emit_operand(rcx, dst, 4);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::orl(Register dst, int32_t imm32) {
304N/A prefix(dst);
304N/A emit_arith(0x81, 0xC8, dst, imm32);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::orl(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x0B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::orl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x0B, 0xC0, dst, src);
304N/A}
304N/A
681N/Avoid Assembler::pcmpestri(XMMRegister dst, Address src, int imm8) {
681N/A assert(VM_Version::supports_sse4_2(), "");
681N/A
681N/A InstructionMark im(this);
681N/A emit_byte(0x66);
681N/A prefix(src, dst);
681N/A emit_byte(0x0F);
681N/A emit_byte(0x3A);
681N/A emit_byte(0x61);
681N/A emit_operand(dst, src);
681N/A emit_byte(imm8);
681N/A}
681N/A
681N/Avoid Assembler::pcmpestri(XMMRegister dst, XMMRegister src, int imm8) {
681N/A assert(VM_Version::supports_sse4_2(), "");
681N/A
681N/A emit_byte(0x66);
681N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
681N/A emit_byte(0x0F);
681N/A emit_byte(0x3A);
681N/A emit_byte(0x61);
681N/A emit_byte(0xC0 | encode);
681N/A emit_byte(imm8);
681N/A}
681N/A
304N/A// generic
304N/Avoid Assembler::pop(Register dst) {
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0x58 | encode);
304N/A}
304N/A
643N/Avoid Assembler::popcntl(Register dst, Address src) {
643N/A assert(VM_Version::supports_popcnt(), "must support");
643N/A InstructionMark im(this);
643N/A emit_byte(0xF3);
643N/A prefix(src, dst);
643N/A emit_byte(0x0F);
643N/A emit_byte(0xB8);
643N/A emit_operand(dst, src);
643N/A}
643N/A
643N/Avoid Assembler::popcntl(Register dst, Register src) {
643N/A assert(VM_Version::supports_popcnt(), "must support");
643N/A emit_byte(0xF3);
643N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
643N/A emit_byte(0x0F);
643N/A emit_byte(0xB8);
643N/A emit_byte(0xC0 | encode);
643N/A}
643N/A
304N/Avoid Assembler::popf() {
304N/A emit_byte(0x9D);
304N/A}
304N/A
304N/Avoid Assembler::popl(Address dst) {
304N/A // NOTE: this will adjust stack by 8byte on 64bits
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0x8F);
304N/A emit_operand(rax, dst);
304N/A}
304N/A
304N/Avoid Assembler::prefetch_prefix(Address src) {
304N/A prefix(src);
304N/A emit_byte(0x0F);
304N/A}
304N/A
304N/Avoid Assembler::prefetchnta(Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), "must support"));
304N/A InstructionMark im(this);
304N/A prefetch_prefix(src);
304N/A emit_byte(0x18);
304N/A emit_operand(rax, src); // 0, src
304N/A}
304N/A
304N/Avoid Assembler::prefetchr(Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_3dnow(), "must support"));
304N/A InstructionMark im(this);
304N/A prefetch_prefix(src);
304N/A emit_byte(0x0D);
304N/A emit_operand(rax, src); // 0, src
304N/A}
304N/A
304N/Avoid Assembler::prefetcht0(Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), "must support"));
304N/A InstructionMark im(this);
304N/A prefetch_prefix(src);
304N/A emit_byte(0x18);
304N/A emit_operand(rcx, src); // 1, src
304N/A}
304N/A
304N/Avoid Assembler::prefetcht1(Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), "must support"));
304N/A InstructionMark im(this);
304N/A prefetch_prefix(src);
304N/A emit_byte(0x18);
304N/A emit_operand(rdx, src); // 2, src
304N/A}
304N/A
304N/Avoid Assembler::prefetcht2(Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), "must support"));
304N/A InstructionMark im(this);
304N/A prefetch_prefix(src);
304N/A emit_byte(0x18);
304N/A emit_operand(rbx, src); // 3, src
304N/A}
304N/A
304N/Avoid Assembler::prefetchw(Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_3dnow(), "must support"));
304N/A InstructionMark im(this);
304N/A prefetch_prefix(src);
304N/A emit_byte(0x0D);
304N/A emit_operand(rcx, src); // 1, src
304N/A}
304N/A
304N/Avoid Assembler::prefix(Prefix p) {
304N/A a_byte(p);
304N/A}
304N/A
304N/Avoid Assembler::pshufd(XMMRegister dst, XMMRegister src, int mode) {
304N/A assert(isByte(mode), "invalid value");
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A
304N/A emit_byte(0x66);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x70);
304N/A emit_byte(0xC0 | encode);
304N/A emit_byte(mode & 0xFF);
304N/A
304N/A}
304N/A
304N/Avoid Assembler::pshufd(XMMRegister dst, Address src, int mode) {
304N/A assert(isByte(mode), "invalid value");
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x70);
304N/A emit_operand(dst, src);
304N/A emit_byte(mode & 0xFF);
304N/A}
304N/A
304N/Avoid Assembler::pshuflw(XMMRegister dst, XMMRegister src, int mode) {
304N/A assert(isByte(mode), "invalid value");
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x70);
304N/A emit_byte(0xC0 | encode);
304N/A emit_byte(mode & 0xFF);
304N/A}
304N/A
304N/Avoid Assembler::pshuflw(XMMRegister dst, Address src, int mode) {
304N/A assert(isByte(mode), "invalid value");
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A
304N/A InstructionMark im(this);
304N/A emit_byte(0xF2);
304N/A prefix(src, dst); // QQ new
304N/A emit_byte(0x0F);
304N/A emit_byte(0x70);
304N/A emit_operand(dst, src);
304N/A emit_byte(mode & 0xFF);
304N/A}
304N/A
304N/Avoid Assembler::psrlq(XMMRegister dst, int shift) {
304N/A // HMM Table D-1 says sse2 or mmx
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A
304N/A int encode = prefixq_and_encode(xmm2->encoding(), dst->encoding());
304N/A emit_byte(0x66);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x73);
304N/A emit_byte(0xC0 | encode);
304N/A emit_byte(shift);
304N/A}
304N/A
681N/Avoid Assembler::ptest(XMMRegister dst, Address src) {
681N/A assert(VM_Version::supports_sse4_1(), "");
681N/A
681N/A InstructionMark im(this);
681N/A emit_byte(0x66);
681N/A prefix(src, dst);
681N/A emit_byte(0x0F);
681N/A emit_byte(0x38);
681N/A emit_byte(0x17);
681N/A emit_operand(dst, src);
681N/A}
681N/A
681N/Avoid Assembler::ptest(XMMRegister dst, XMMRegister src) {
681N/A assert(VM_Version::supports_sse4_1(), "");
681N/A
681N/A emit_byte(0x66);
681N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
681N/A emit_byte(0x0F);
681N/A emit_byte(0x38);
681N/A emit_byte(0x17);
681N/A emit_byte(0xC0 | encode);
681N/A}
681N/A
304N/Avoid Assembler::punpcklbw(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0x66);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x60);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::push(int32_t imm32) {
304N/A // in 64bits we push 64bits onto the stack but only
304N/A // take a 32bit immediate
304N/A emit_byte(0x68);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::push(Register src) {
304N/A int encode = prefix_and_encode(src->encoding());
304N/A
304N/A emit_byte(0x50 | encode);
304N/A}
304N/A
304N/Avoid Assembler::pushf() {
304N/A emit_byte(0x9C);
304N/A}
304N/A
304N/Avoid Assembler::pushl(Address src) {
304N/A // Note this will push 64bit on 64bit
304N/A InstructionMark im(this);
304N/A prefix(src);
304N/A emit_byte(0xFF);
304N/A emit_operand(rsi, src);
304N/A}
304N/A
304N/Avoid Assembler::pxor(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xEF);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::pxor(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0xEF);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::rcll(Register dst, int imm8) {
304N/A assert(isShiftCount(imm8), "illegal shift count");
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A if (imm8 == 1) {
304N/A emit_byte(0xD1);
304N/A emit_byte(0xD0 | encode);
304N/A } else {
304N/A emit_byte(0xC1);
304N/A emit_byte(0xD0 | encode);
304N/A emit_byte(imm8);
304N/A }
304N/A}
304N/A
304N/A// copies data from [esi] to [edi] using rcx pointer sized words
304N/A// generic
304N/Avoid Assembler::rep_mov() {
304N/A emit_byte(0xF3);
304N/A // MOVSQ
304N/A LP64_ONLY(prefix(REX_W));
304N/A emit_byte(0xA5);
304N/A}
304N/A
304N/A// sets rcx pointer sized words with rax, value at [edi]
304N/A// generic
304N/Avoid Assembler::rep_set() { // rep_set
304N/A emit_byte(0xF3);
304N/A // STOSQ
304N/A LP64_ONLY(prefix(REX_W));
304N/A emit_byte(0xAB);
304N/A}
304N/A
304N/A// scans rcx pointer sized words at [edi] for occurance of rax,
304N/A// generic
304N/Avoid Assembler::repne_scan() { // repne_scan
304N/A emit_byte(0xF2);
304N/A // SCASQ
304N/A LP64_ONLY(prefix(REX_W));
304N/A emit_byte(0xAF);
304N/A}
304N/A
304N/A#ifdef _LP64
304N/A// scans rcx 4 byte words at [edi] for occurance of rax,
304N/A// generic
304N/Avoid Assembler::repne_scanl() { // repne_scan
304N/A emit_byte(0xF2);
304N/A // SCASL
304N/A emit_byte(0xAF);
304N/A}
304N/A#endif
304N/A
0N/Avoid Assembler::ret(int imm16) {
0N/A if (imm16 == 0) {
0N/A emit_byte(0xC3);
0N/A } else {
0N/A emit_byte(0xC2);
0N/A emit_word(imm16);
0N/A }
0N/A}
0N/A
304N/Avoid Assembler::sahf() {
304N/A#ifdef _LP64
304N/A // Not supported in 64bit mode
304N/A ShouldNotReachHere();
304N/A#endif
304N/A emit_byte(0x9E);
304N/A}
304N/A
304N/Avoid Assembler::sarl(Register dst, int imm8) {
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A assert(isShiftCount(imm8), "illegal shift count");
304N/A if (imm8 == 1) {
304N/A emit_byte(0xD1);
304N/A emit_byte(0xF8 | encode);
304N/A } else {
304N/A emit_byte(0xC1);
304N/A emit_byte(0xF8 | encode);
304N/A emit_byte(imm8);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::sarl(Register dst) {
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xD3);
304N/A emit_byte(0xF8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::sbbl(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_arith_operand(0x81, rbx, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::sbbl(Register dst, int32_t imm32) {
304N/A prefix(dst);
304N/A emit_arith(0x81, 0xD8, dst, imm32);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::sbbl(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x1B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::sbbl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x1B, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::setb(Condition cc, Register dst) {
304N/A assert(0 <= cc && cc < 16, "illegal cc");
304N/A int encode = prefix_and_encode(dst->encoding(), true);
0N/A emit_byte(0x0F);
304N/A emit_byte(0x90 | cc);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::shll(Register dst, int imm8) {
304N/A assert(isShiftCount(imm8), "illegal shift count");
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A if (imm8 == 1 ) {
304N/A emit_byte(0xD1);
304N/A emit_byte(0xE0 | encode);
304N/A } else {
304N/A emit_byte(0xC1);
304N/A emit_byte(0xE0 | encode);
304N/A emit_byte(imm8);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::shll(Register dst) {
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xD3);
304N/A emit_byte(0xE0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::shrl(Register dst, int imm8) {
304N/A assert(isShiftCount(imm8), "illegal shift count");
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xC1);
304N/A emit_byte(0xE8 | encode);
304N/A emit_byte(imm8);
304N/A}
304N/A
304N/Avoid Assembler::shrl(Register dst) {
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xD3);
304N/A emit_byte(0xE8 | encode);
304N/A}
0N/A
0N/A// copies a single word from [esi] to [edi]
0N/Avoid Assembler::smovl() {
0N/A emit_byte(0xA5);
0N/A}
0N/A
304N/Avoid Assembler::sqrtsd(XMMRegister dst, XMMRegister src) {
304N/A // HMM Table D-1 says sse2
304N/A // NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x51);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::stmxcsr( Address dst) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xAE);
304N/A emit_operand(as_Register(3), dst);
304N/A}
304N/A
304N/Avoid Assembler::subl(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefix(dst);
304N/A if (is8bit(imm32)) {
304N/A emit_byte(0x83);
304N/A emit_operand(rbp, dst, 1);
304N/A emit_byte(imm32 & 0xFF);
304N/A } else {
304N/A emit_byte(0x81);
304N/A emit_operand(rbp, dst, 4);
304N/A emit_long(imm32);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::subl(Register dst, int32_t imm32) {
304N/A prefix(dst);
304N/A emit_arith(0x81, 0xE8, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::subl(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A prefix(dst, src);
304N/A emit_byte(0x29);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::subl(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x2B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::subl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x2B, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::subsd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5C);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::subsd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF2);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5C);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::subss(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
0N/A emit_byte(0xF3);
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5C);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::subss(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0xF3);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x5C);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::testb(Register dst, int imm8) {
304N/A NOT_LP64(assert(dst->has_byte_register(), "must have byte register"));
304N/A (void) prefix_and_encode(dst->encoding(), true);
304N/A emit_arith_b(0xF6, 0xC0, dst, imm8);
304N/A}
304N/A
304N/Avoid Assembler::testl(Register dst, int32_t imm32) {
304N/A // not using emit_arith because test
304N/A // doesn't support sign-extension of
304N/A // 8bit operands
304N/A int encode = dst->encoding();
304N/A if (encode == 0) {
304N/A emit_byte(0xA9);
304N/A } else {
304N/A encode = prefix_and_encode(encode);
304N/A emit_byte(0xF7);
304N/A emit_byte(0xC0 | encode);
304N/A }
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::testl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x85, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::testl(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x85);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::ucomisd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0x66);
304N/A ucomiss(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::ucomisd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0x66);
304N/A ucomiss(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::ucomiss(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2E);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::ucomiss(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2E);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::xaddl(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A prefix(dst, src);
0N/A emit_byte(0x0F);
304N/A emit_byte(0xC1);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::xchgl(Register dst, Address src) { // xchg
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x87);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::xchgl(Register dst, Register src) {
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x87);
304N/A emit_byte(0xc0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::xorl(Register dst, int32_t imm32) {
304N/A prefix(dst);
304N/A emit_arith(0x81, 0xF0, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::xorl(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x33);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::xorl(Register dst, Register src) {
304N/A (void) prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x33, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::xorpd(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0x66);
304N/A xorps(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::xorpd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A InstructionMark im(this);
304N/A emit_byte(0x66);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x57);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::xorps(XMMRegister dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A int encode = prefix_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x57);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::xorps(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A InstructionMark im(this);
304N/A prefix(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x57);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/A#ifndef _LP64
304N/A// 32bit only pieces of the assembler
304N/A
304N/Avoid Assembler::cmp_literal32(Register src1, int32_t imm32, RelocationHolder const& rspec) {
304N/A // NO PREFIX AS NEVER 64BIT
304N/A InstructionMark im(this);
304N/A emit_byte(0x81);
304N/A emit_byte(0xF8 | src1->encoding());
304N/A emit_data(imm32, rspec, 0);
304N/A}
304N/A
304N/Avoid Assembler::cmp_literal32(Address src1, int32_t imm32, RelocationHolder const& rspec) {
304N/A // NO PREFIX AS NEVER 64BIT (not even 32bit versions of 64bit regs
304N/A InstructionMark im(this);
304N/A emit_byte(0x81);
304N/A emit_operand(rdi, src1);
304N/A emit_data(imm32, rspec, 0);
304N/A}
304N/A
304N/A// The 64-bit (32bit platform) cmpxchg compares the value at adr with the contents of rdx:rax,
304N/A// and stores rcx:rbx into adr if so; otherwise, the value at adr is loaded
304N/A// into rdx:rax. The ZF is set if the compared values were equal, and cleared otherwise.
304N/Avoid Assembler::cmpxchg8(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xc7);
304N/A emit_operand(rcx, adr);
304N/A}
304N/A
304N/Avoid Assembler::decl(Register dst) {
304N/A // Don't use it directly. Use MacroAssembler::decrementl() instead.
304N/A emit_byte(0x48 | dst->encoding());
304N/A}
304N/A
304N/A#endif // _LP64
304N/A
304N/A// 64bit typically doesn't use the x87 but needs to for the trig funcs
304N/A
304N/Avoid Assembler::fabs() {
304N/A emit_byte(0xD9);
304N/A emit_byte(0xE1);
304N/A}
304N/A
304N/Avoid Assembler::fadd(int i) {
304N/A emit_farith(0xD8, 0xC0, i);
304N/A}
304N/A
304N/Avoid Assembler::fadd_d(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDC);
304N/A emit_operand32(rax, src);
304N/A}
304N/A
304N/Avoid Assembler::fadd_s(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xD8);
304N/A emit_operand32(rax, src);
304N/A}
304N/A
304N/Avoid Assembler::fadda(int i) {
304N/A emit_farith(0xDC, 0xC0, i);
304N/A}
304N/A
304N/Avoid Assembler::faddp(int i) {
304N/A emit_farith(0xDE, 0xC0, i);
304N/A}
304N/A
304N/Avoid Assembler::fchs() {
304N/A emit_byte(0xD9);
304N/A emit_byte(0xE0);
304N/A}
304N/A
304N/Avoid Assembler::fcom(int i) {
304N/A emit_farith(0xD8, 0xD0, i);
304N/A}
304N/A
304N/Avoid Assembler::fcomp(int i) {
304N/A emit_farith(0xD8, 0xD8, i);
304N/A}
304N/A
304N/Avoid Assembler::fcomp_d(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDC);
304N/A emit_operand32(rbx, src);
304N/A}
304N/A
304N/Avoid Assembler::fcomp_s(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xD8);
304N/A emit_operand32(rbx, src);
304N/A}
304N/A
304N/Avoid Assembler::fcompp() {
304N/A emit_byte(0xDE);
304N/A emit_byte(0xD9);
304N/A}
304N/A
304N/Avoid Assembler::fcos() {
304N/A emit_byte(0xD9);
0N/A emit_byte(0xFF);
304N/A}
304N/A
304N/Avoid Assembler::fdecstp() {
304N/A emit_byte(0xD9);
304N/A emit_byte(0xF6);
304N/A}
304N/A
304N/Avoid Assembler::fdiv(int i) {
304N/A emit_farith(0xD8, 0xF0, i);
304N/A}
304N/A
304N/Avoid Assembler::fdiv_d(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDC);
304N/A emit_operand32(rsi, src);
304N/A}
304N/A
304N/Avoid Assembler::fdiv_s(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xD8);
304N/A emit_operand32(rsi, src);
304N/A}
304N/A
304N/Avoid Assembler::fdiva(int i) {
304N/A emit_farith(0xDC, 0xF8, i);
304N/A}
304N/A
304N/A// Note: The Intel manual (Pentium Processor User's Manual, Vol.3, 1994)
304N/A// is erroneous for some of the floating-point instructions below.
304N/A
304N/Avoid Assembler::fdivp(int i) {
304N/A emit_farith(0xDE, 0xF8, i); // ST(0) <- ST(0) / ST(1) and pop (Intel manual wrong)
304N/A}
304N/A
304N/Avoid Assembler::fdivr(int i) {
304N/A emit_farith(0xD8, 0xF8, i);
304N/A}
304N/A
304N/Avoid Assembler::fdivr_d(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDC);
304N/A emit_operand32(rdi, src);
304N/A}
304N/A
304N/Avoid Assembler::fdivr_s(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xD8);
304N/A emit_operand32(rdi, src);
304N/A}
304N/A
304N/Avoid Assembler::fdivra(int i) {
304N/A emit_farith(0xDC, 0xF0, i);
304N/A}
304N/A
304N/Avoid Assembler::fdivrp(int i) {
304N/A emit_farith(0xDE, 0xF0, i); // ST(0) <- ST(1) / ST(0) and pop (Intel manual wrong)
304N/A}
304N/A
304N/Avoid Assembler::ffree(int i) {
304N/A emit_farith(0xDD, 0xC0, i);
304N/A}
304N/A
304N/Avoid Assembler::fild_d(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDF);
304N/A emit_operand32(rbp, adr);
304N/A}
304N/A
304N/Avoid Assembler::fild_s(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDB);
304N/A emit_operand32(rax, adr);
304N/A}
304N/A
304N/Avoid Assembler::fincstp() {
304N/A emit_byte(0xD9);
304N/A emit_byte(0xF7);
304N/A}
304N/A
304N/Avoid Assembler::finit() {
304N/A emit_byte(0x9B);
304N/A emit_byte(0xDB);
304N/A emit_byte(0xE3);
304N/A}
304N/A
304N/Avoid Assembler::fist_s(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDB);
304N/A emit_operand32(rdx, adr);
304N/A}
304N/A
304N/Avoid Assembler::fistp_d(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDF);
304N/A emit_operand32(rdi, adr);
304N/A}
304N/A
304N/Avoid Assembler::fistp_s(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDB);
304N/A emit_operand32(rbx, adr);
304N/A}
0N/A
0N/Avoid Assembler::fld1() {
0N/A emit_byte(0xD9);
0N/A emit_byte(0xE8);
0N/A}
0N/A
304N/Avoid Assembler::fld_d(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDD);
304N/A emit_operand32(rax, adr);
304N/A}
0N/A
0N/Avoid Assembler::fld_s(Address adr) {
0N/A InstructionMark im(this);
0N/A emit_byte(0xD9);
304N/A emit_operand32(rax, adr);
304N/A}
304N/A
304N/A
304N/Avoid Assembler::fld_s(int index) {
0N/A emit_farith(0xD9, 0xC0, index);
0N/A}
0N/A
0N/Avoid Assembler::fld_x(Address adr) {
0N/A InstructionMark im(this);
0N/A emit_byte(0xDB);
304N/A emit_operand32(rbp, adr);
304N/A}
304N/A
304N/Avoid Assembler::fldcw(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xd9);
304N/A emit_operand32(rbp, src);
304N/A}
304N/A
304N/Avoid Assembler::fldenv(Address src) {
0N/A InstructionMark im(this);
0N/A emit_byte(0xD9);
304N/A emit_operand32(rsp, src);
304N/A}
304N/A
304N/Avoid Assembler::fldlg2() {
0N/A emit_byte(0xD9);
304N/A emit_byte(0xEC);
304N/A}
0N/A
0N/Avoid Assembler::fldln2() {
0N/A emit_byte(0xD9);
0N/A emit_byte(0xED);
0N/A}
0N/A
304N/Avoid Assembler::fldz() {
0N/A emit_byte(0xD9);
304N/A emit_byte(0xEE);
304N/A}
0N/A
0N/Avoid Assembler::flog() {
0N/A fldln2();
0N/A fxch();
0N/A fyl2x();
0N/A}
0N/A
0N/Avoid Assembler::flog10() {
0N/A fldlg2();
0N/A fxch();
0N/A fyl2x();
0N/A}
0N/A
304N/Avoid Assembler::fmul(int i) {
304N/A emit_farith(0xD8, 0xC8, i);
304N/A}
304N/A
304N/Avoid Assembler::fmul_d(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDC);
304N/A emit_operand32(rcx, src);
304N/A}
304N/A
304N/Avoid Assembler::fmul_s(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xD8);
304N/A emit_operand32(rcx, src);
304N/A}
304N/A
304N/Avoid Assembler::fmula(int i) {
304N/A emit_farith(0xDC, 0xC8, i);
304N/A}
304N/A
304N/Avoid Assembler::fmulp(int i) {
304N/A emit_farith(0xDE, 0xC8, i);
304N/A}
304N/A
304N/Avoid Assembler::fnsave(Address dst) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDD);
304N/A emit_operand32(rsi, dst);
304N/A}
304N/A
304N/Avoid Assembler::fnstcw(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0x9B);
304N/A emit_byte(0xD9);
304N/A emit_operand32(rdi, src);
304N/A}
304N/A
304N/Avoid Assembler::fnstsw_ax() {
304N/A emit_byte(0xdF);
304N/A emit_byte(0xE0);
304N/A}
304N/A
304N/Avoid Assembler::fprem() {
304N/A emit_byte(0xD9);
304N/A emit_byte(0xF8);
304N/A}
304N/A
304N/Avoid Assembler::fprem1() {
304N/A emit_byte(0xD9);
304N/A emit_byte(0xF5);
304N/A}
304N/A
304N/Avoid Assembler::frstor(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDD);
304N/A emit_operand32(rsp, src);
304N/A}
0N/A
0N/Avoid Assembler::fsin() {
0N/A emit_byte(0xD9);
0N/A emit_byte(0xFE);
0N/A}
0N/A
304N/Avoid Assembler::fsqrt() {
304N/A emit_byte(0xD9);
304N/A emit_byte(0xFA);
304N/A}
304N/A
304N/Avoid Assembler::fst_d(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDD);
304N/A emit_operand32(rdx, adr);
304N/A}
304N/A
304N/Avoid Assembler::fst_s(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xD9);
304N/A emit_operand32(rdx, adr);
304N/A}
304N/A
304N/Avoid Assembler::fstp_d(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDD);
304N/A emit_operand32(rbx, adr);
304N/A}
304N/A
304N/Avoid Assembler::fstp_d(int index) {
304N/A emit_farith(0xDD, 0xD8, index);
304N/A}
304N/A
304N/Avoid Assembler::fstp_s(Address adr) {
304N/A InstructionMark im(this);
0N/A emit_byte(0xD9);
304N/A emit_operand32(rbx, adr);
304N/A}
304N/A
304N/Avoid Assembler::fstp_x(Address adr) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDB);
304N/A emit_operand32(rdi, adr);
304N/A}
304N/A
304N/Avoid Assembler::fsub(int i) {
304N/A emit_farith(0xD8, 0xE0, i);
304N/A}
304N/A
304N/Avoid Assembler::fsub_d(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDC);
304N/A emit_operand32(rsp, src);
304N/A}
304N/A
304N/Avoid Assembler::fsub_s(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xD8);
304N/A emit_operand32(rsp, src);
304N/A}
304N/A
304N/Avoid Assembler::fsuba(int i) {
304N/A emit_farith(0xDC, 0xE8, i);
304N/A}
304N/A
304N/Avoid Assembler::fsubp(int i) {
304N/A emit_farith(0xDE, 0xE8, i); // ST(0) <- ST(0) - ST(1) and pop (Intel manual wrong)
304N/A}
304N/A
304N/Avoid Assembler::fsubr(int i) {
304N/A emit_farith(0xD8, 0xE8, i);
304N/A}
304N/A
304N/Avoid Assembler::fsubr_d(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xDC);
304N/A emit_operand32(rbp, src);
304N/A}
304N/A
304N/Avoid Assembler::fsubr_s(Address src) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xD8);
304N/A emit_operand32(rbp, src);
304N/A}
304N/A
304N/Avoid Assembler::fsubra(int i) {
304N/A emit_farith(0xDC, 0xE0, i);
304N/A}
304N/A
304N/Avoid Assembler::fsubrp(int i) {
304N/A emit_farith(0xDE, 0xE0, i); // ST(0) <- ST(1) - ST(0) and pop (Intel manual wrong)
0N/A}
0N/A
0N/Avoid Assembler::ftan() {
0N/A emit_byte(0xD9);
0N/A emit_byte(0xF2);
0N/A emit_byte(0xDD);
0N/A emit_byte(0xD8);
0N/A}
0N/A
304N/Avoid Assembler::ftst() {
0N/A emit_byte(0xD9);
304N/A emit_byte(0xE4);
304N/A}
0N/A
0N/Avoid Assembler::fucomi(int i) {
0N/A // make sure the instruction is supported (introduced for P6, together with cmov)
0N/A guarantee(VM_Version::supports_cmov(), "illegal instruction");
0N/A emit_farith(0xDB, 0xE8, i);
0N/A}
0N/A
0N/Avoid Assembler::fucomip(int i) {
0N/A // make sure the instruction is supported (introduced for P6, together with cmov)
0N/A guarantee(VM_Version::supports_cmov(), "illegal instruction");
0N/A emit_farith(0xDF, 0xE8, i);
0N/A}
0N/A
0N/Avoid Assembler::fwait() {
0N/A emit_byte(0x9B);
0N/A}
0N/A
304N/Avoid Assembler::fxch(int i) {
304N/A emit_farith(0xD9, 0xC8, i);
304N/A}
304N/A
304N/Avoid Assembler::fyl2x() {
0N/A emit_byte(0xD9);
304N/A emit_byte(0xF1);
304N/A}
304N/A
304N/A
304N/A#ifndef _LP64
304N/A
304N/Avoid Assembler::incl(Register dst) {
304N/A // Don't use it directly. Use MacroAssembler::incrementl() instead.
304N/A emit_byte(0x40 | dst->encoding());
304N/A}
304N/A
304N/Avoid Assembler::lea(Register dst, Address src) {
304N/A leal(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::mov_literal32(Address dst, int32_t imm32, RelocationHolder const& rspec) {
304N/A InstructionMark im(this);
304N/A emit_byte(0xC7);
304N/A emit_operand(rax, dst);
304N/A emit_data((int)imm32, rspec, 0);
304N/A}
304N/A
642N/Avoid Assembler::mov_literal32(Register dst, int32_t imm32, RelocationHolder const& rspec) {
642N/A InstructionMark im(this);
642N/A int encode = prefix_and_encode(dst->encoding());
642N/A emit_byte(0xB8 | encode);
642N/A emit_data((int)imm32, rspec, 0);
642N/A}
304N/A
304N/Avoid Assembler::popa() { // 32bit
304N/A emit_byte(0x61);
304N/A}
304N/A
304N/Avoid Assembler::push_literal32(int32_t imm32, RelocationHolder const& rspec) {
304N/A InstructionMark im(this);
304N/A emit_byte(0x68);
304N/A emit_data(imm32, rspec, 0);
304N/A}
304N/A
304N/Avoid Assembler::pusha() { // 32bit
304N/A emit_byte(0x60);
304N/A}
304N/A
304N/Avoid Assembler::set_byte_if_not_zero(Register dst) {
0N/A emit_byte(0x0F);
304N/A emit_byte(0x95);
304N/A emit_byte(0xE0 | dst->encoding());
304N/A}
304N/A
304N/Avoid Assembler::shldl(Register dst, Register src) {
0N/A emit_byte(0x0F);
304N/A emit_byte(0xA5);
304N/A emit_byte(0xC0 | src->encoding() << 3 | dst->encoding());
304N/A}
304N/A
304N/Avoid Assembler::shrdl(Register dst, Register src) {
0N/A emit_byte(0x0F);
304N/A emit_byte(0xAD);
304N/A emit_byte(0xC0 | src->encoding() << 3 | dst->encoding());
304N/A}
304N/A
304N/A#else // LP64
304N/A
304N/A// 64bit only pieces of the assembler
304N/A// This should only be used by 64bit instructions that can use rip-relative
304N/A// it cannot be used by instructions that want an immediate value.
304N/A
304N/Abool Assembler::reachable(AddressLiteral adr) {
304N/A int64_t disp;
304N/A // None will force a 64bit literal to the code stream. Likely a placeholder
304N/A // for something that will be patched later and we need to certain it will
304N/A // always be reachable.
304N/A if (adr.reloc() == relocInfo::none) {
304N/A return false;
304N/A }
304N/A if (adr.reloc() == relocInfo::internal_word_type) {
304N/A // This should be rip relative and easily reachable.
304N/A return true;
304N/A }
304N/A if (adr.reloc() == relocInfo::virtual_call_type ||
304N/A adr.reloc() == relocInfo::opt_virtual_call_type ||
304N/A adr.reloc() == relocInfo::static_call_type ||
304N/A adr.reloc() == relocInfo::static_stub_type ) {
304N/A // This should be rip relative within the code cache and easily
304N/A // reachable until we get huge code caches. (At which point
304N/A // ic code is going to have issues).
304N/A return true;
304N/A }
304N/A if (adr.reloc() != relocInfo::external_word_type &&
304N/A adr.reloc() != relocInfo::poll_return_type && // these are really external_word but need special
304N/A adr.reloc() != relocInfo::poll_type && // relocs to identify them
304N/A adr.reloc() != relocInfo::runtime_call_type ) {
304N/A return false;
304N/A }
304N/A
304N/A // Stress the correction code
304N/A if (ForceUnreachable) {
304N/A // Must be runtimecall reloc, see if it is in the codecache
304N/A // Flipping stuff in the codecache to be unreachable causes issues
304N/A // with things like inline caches where the additional instructions
304N/A // are not handled.
304N/A if (CodeCache::find_blob(adr._target) == NULL) {
304N/A return false;
304N/A }
304N/A }
304N/A // For external_word_type/runtime_call_type if it is reachable from where we
304N/A // are now (possibly a temp buffer) and where we might end up
304N/A // anywhere in the codeCache then we are always reachable.
304N/A // This would have to change if we ever save/restore shared code
304N/A // to be more pessimistic.
304N/A
304N/A disp = (int64_t)adr._target - ((int64_t)CodeCache::low_bound() + sizeof(int));
304N/A if (!is_simm32(disp)) return false;
304N/A disp = (int64_t)adr._target - ((int64_t)CodeCache::high_bound() + sizeof(int));
304N/A if (!is_simm32(disp)) return false;
304N/A
304N/A disp = (int64_t)adr._target - ((int64_t)_code_pos + sizeof(int));
304N/A
304N/A // Because rip relative is a disp + address_of_next_instruction and we
304N/A // don't know the value of address_of_next_instruction we apply a fudge factor
304N/A // to make sure we will be ok no matter the size of the instruction we get placed into.
304N/A // We don't have to fudge the checks above here because they are already worst case.
304N/A
304N/A // 12 == override/rex byte, opcode byte, rm byte, sib byte, a 4-byte disp , 4-byte literal
304N/A // + 4 because better safe than sorry.
304N/A const int fudge = 12 + 4;
304N/A if (disp < 0) {
304N/A disp -= fudge;
304N/A } else {
304N/A disp += fudge;
304N/A }
304N/A return is_simm32(disp);
304N/A}
304N/A
304N/Avoid Assembler::emit_data64(jlong data,
304N/A relocInfo::relocType rtype,
304N/A int format) {
304N/A if (rtype == relocInfo::none) {
304N/A emit_long64(data);
304N/A } else {
304N/A emit_data64(data, Relocation::spec_simple(rtype), format);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::emit_data64(jlong data,
304N/A RelocationHolder const& rspec,
304N/A int format) {
304N/A assert(imm_operand == 0, "default format must be immediate in this file");
304N/A assert(imm_operand == format, "must be immediate");
304N/A assert(inst_mark() != NULL, "must be inside InstructionMark");
304N/A // Do not use AbstractAssembler::relocate, which is not intended for
304N/A // embedded words. Instead, relocate to the enclosing instruction.
304N/A code_section()->relocate(inst_mark(), rspec, format);
304N/A#ifdef ASSERT
304N/A check_relocation(rspec, format);
304N/A#endif
304N/A emit_long64(data);
304N/A}
304N/A
304N/Aint Assembler::prefix_and_encode(int reg_enc, bool byteinst) {
304N/A if (reg_enc >= 8) {
304N/A prefix(REX_B);
304N/A reg_enc -= 8;
304N/A } else if (byteinst && reg_enc >= 4) {
304N/A prefix(REX);
304N/A }
304N/A return reg_enc;
304N/A}
304N/A
304N/Aint Assembler::prefixq_and_encode(int reg_enc) {
304N/A if (reg_enc < 8) {
304N/A prefix(REX_W);
304N/A } else {
304N/A prefix(REX_WB);
304N/A reg_enc -= 8;
304N/A }
304N/A return reg_enc;
304N/A}
304N/A
304N/Aint Assembler::prefix_and_encode(int dst_enc, int src_enc, bool byteinst) {
304N/A if (dst_enc < 8) {
304N/A if (src_enc >= 8) {
304N/A prefix(REX_B);
304N/A src_enc -= 8;
304N/A } else if (byteinst && src_enc >= 4) {
304N/A prefix(REX);
304N/A }
304N/A } else {
304N/A if (src_enc < 8) {
304N/A prefix(REX_R);
304N/A } else {
304N/A prefix(REX_RB);
304N/A src_enc -= 8;
304N/A }
304N/A dst_enc -= 8;
304N/A }
304N/A return dst_enc << 3 | src_enc;
304N/A}
304N/A
304N/Aint Assembler::prefixq_and_encode(int dst_enc, int src_enc) {
304N/A if (dst_enc < 8) {
304N/A if (src_enc < 8) {
304N/A prefix(REX_W);
304N/A } else {
304N/A prefix(REX_WB);
304N/A src_enc -= 8;
304N/A }
304N/A } else {
304N/A if (src_enc < 8) {
304N/A prefix(REX_WR);
304N/A } else {
304N/A prefix(REX_WRB);
304N/A src_enc -= 8;
304N/A }
304N/A dst_enc -= 8;
304N/A }
304N/A return dst_enc << 3 | src_enc;
304N/A}
304N/A
304N/Avoid Assembler::prefix(Register reg) {
304N/A if (reg->encoding() >= 8) {
304N/A prefix(REX_B);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::prefix(Address adr) {
304N/A if (adr.base_needs_rex()) {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_XB);
304N/A } else {
304N/A prefix(REX_B);
304N/A }
304N/A } else {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_X);
304N/A }
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::prefixq(Address adr) {
304N/A if (adr.base_needs_rex()) {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_WXB);
304N/A } else {
304N/A prefix(REX_WB);
304N/A }
304N/A } else {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_WX);
304N/A } else {
304N/A prefix(REX_W);
304N/A }
304N/A }
304N/A}
304N/A
304N/A
304N/Avoid Assembler::prefix(Address adr, Register reg, bool byteinst) {
304N/A if (reg->encoding() < 8) {
304N/A if (adr.base_needs_rex()) {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_XB);
304N/A } else {
304N/A prefix(REX_B);
304N/A }
304N/A } else {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_X);
304N/A } else if (reg->encoding() >= 4 ) {
304N/A prefix(REX);
304N/A }
304N/A }
304N/A } else {
304N/A if (adr.base_needs_rex()) {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_RXB);
304N/A } else {
304N/A prefix(REX_RB);
304N/A }
304N/A } else {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_RX);
304N/A } else {
304N/A prefix(REX_R);
304N/A }
304N/A }
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::prefixq(Address adr, Register src) {
304N/A if (src->encoding() < 8) {
304N/A if (adr.base_needs_rex()) {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_WXB);
304N/A } else {
304N/A prefix(REX_WB);
304N/A }
304N/A } else {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_WX);
304N/A } else {
304N/A prefix(REX_W);
304N/A }
304N/A }
304N/A } else {
304N/A if (adr.base_needs_rex()) {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_WRXB);
304N/A } else {
304N/A prefix(REX_WRB);
304N/A }
304N/A } else {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_WRX);
304N/A } else {
304N/A prefix(REX_WR);
304N/A }
304N/A }
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::prefix(Address adr, XMMRegister reg) {
304N/A if (reg->encoding() < 8) {
304N/A if (adr.base_needs_rex()) {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_XB);
304N/A } else {
304N/A prefix(REX_B);
304N/A }
304N/A } else {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_X);
304N/A }
304N/A }
304N/A } else {
304N/A if (adr.base_needs_rex()) {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_RXB);
304N/A } else {
304N/A prefix(REX_RB);
304N/A }
304N/A } else {
304N/A if (adr.index_needs_rex()) {
304N/A prefix(REX_RX);
304N/A } else {
304N/A prefix(REX_R);
304N/A }
304N/A }
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::adcq(Register dst, int32_t imm32) {
304N/A (void) prefixq_and_encode(dst->encoding());
304N/A emit_arith(0x81, 0xD0, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::adcq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x13);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::adcq(Register dst, Register src) {
304N/A (int) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x13, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::addq(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A emit_arith_operand(0x81, rax, dst,imm32);
304N/A}
304N/A
304N/Avoid Assembler::addq(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A prefixq(dst, src);
304N/A emit_byte(0x01);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::addq(Register dst, int32_t imm32) {
304N/A (void) prefixq_and_encode(dst->encoding());
304N/A emit_arith(0x81, 0xC0, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::addq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x03);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::addq(Register dst, Register src) {
304N/A (void) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x03, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::andq(Register dst, int32_t imm32) {
304N/A (void) prefixq_and_encode(dst->encoding());
304N/A emit_arith(0x81, 0xE0, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::andq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x23);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::andq(Register dst, Register src) {
304N/A (int) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x23, 0xC0, dst, src);
304N/A}
304N/A
775N/Avoid Assembler::bsfq(Register dst, Register src) {
775N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
775N/A emit_byte(0x0F);
775N/A emit_byte(0xBC);
775N/A emit_byte(0xC0 | encode);
775N/A}
775N/A
775N/Avoid Assembler::bsrq(Register dst, Register src) {
775N/A assert(!VM_Version::supports_lzcnt(), "encoding is treated as LZCNT");
775N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
775N/A emit_byte(0x0F);
775N/A emit_byte(0xBD);
775N/A emit_byte(0xC0 | encode);
775N/A}
775N/A
304N/Avoid Assembler::bswapq(Register reg) {
304N/A int encode = prefixq_and_encode(reg->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0xC8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cdqq() {
304N/A prefix(REX_W);
304N/A emit_byte(0x99);
304N/A}
304N/A
304N/Avoid Assembler::clflush(Address adr) {
304N/A prefix(adr);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xAE);
304N/A emit_operand(rdi, adr);
304N/A}
304N/A
304N/Avoid Assembler::cmovq(Condition cc, Register dst, Register src) {
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x40 | cc);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cmovq(Condition cc, Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0x40 | cc);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::cmpq(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A emit_byte(0x81);
304N/A emit_operand(rdi, dst, 4);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::cmpq(Register dst, int32_t imm32) {
304N/A (void) prefixq_and_encode(dst->encoding());
304N/A emit_arith(0x81, 0xF8, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::cmpq(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A prefixq(dst, src);
304N/A emit_byte(0x3B);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::cmpq(Register dst, Register src) {
304N/A (void) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x3B, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::cmpq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x3B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::cmpxchgq(Register reg, Address adr) {
304N/A InstructionMark im(this);
304N/A prefixq(adr, reg);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xB1);
304N/A emit_operand(reg, adr);
304N/A}
304N/A
304N/Avoid Assembler::cvtsi2sdq(XMMRegister dst, Register src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2A);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvtsi2ssq(XMMRegister dst, Register src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2A);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvttsd2siq(Register dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
304N/A emit_byte(0xF2);
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2C);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::cvttss2siq(Register dst, XMMRegister src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse(), ""));
304N/A emit_byte(0xF3);
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0x2C);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::decl(Register dst) {
304N/A // Don't use it directly. Use MacroAssembler::decrementl() instead.
304N/A // Use two-byte form (one-byte form is a REX prefix in 64-bit mode)
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xFF);
304N/A emit_byte(0xC8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::decq(Register dst) {
304N/A // Don't use it directly. Use MacroAssembler::decrementq() instead.
304N/A // Use two-byte form (one-byte from is a REX prefix in 64-bit mode)
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xFF);
304N/A emit_byte(0xC8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::decq(Address dst) {
304N/A // Don't use it directly. Use MacroAssembler::decrementq() instead.
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A emit_byte(0xFF);
304N/A emit_operand(rcx, dst);
304N/A}
304N/A
304N/Avoid Assembler::fxrstor(Address src) {
304N/A prefixq(src);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xAE);
304N/A emit_operand(as_Register(1), src);
304N/A}
304N/A
304N/Avoid Assembler::fxsave(Address dst) {
304N/A prefixq(dst);
304N/A emit_byte(0x0F);
304N/A emit_byte(0xAE);
304N/A emit_operand(as_Register(0), dst);
304N/A}
304N/A
304N/Avoid Assembler::idivq(Register src) {
304N/A int encode = prefixq_and_encode(src->encoding());
304N/A emit_byte(0xF7);
304N/A emit_byte(0xF8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::imulq(Register dst, Register src) {
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x0F);
304N/A emit_byte(0xAF);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::imulq(Register dst, Register src, int value) {
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A if (is8bit(value)) {
304N/A emit_byte(0x6B);
304N/A emit_byte(0xC0 | encode);
304N/A emit_byte(value);
304N/A } else {
304N/A emit_byte(0x69);
304N/A emit_byte(0xC0 | encode);
304N/A emit_long(value);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::incl(Register dst) {
304N/A // Don't use it directly. Use MacroAssembler::incrementl() instead.
304N/A // Use two-byte form (one-byte from is a REX prefix in 64-bit mode)
304N/A int encode = prefix_and_encode(dst->encoding());
304N/A emit_byte(0xFF);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::incq(Register dst) {
304N/A // Don't use it directly. Use MacroAssembler::incrementq() instead.
304N/A // Use two-byte form (one-byte from is a REX prefix in 64-bit mode)
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xFF);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::incq(Address dst) {
304N/A // Don't use it directly. Use MacroAssembler::incrementq() instead.
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A emit_byte(0xFF);
304N/A emit_operand(rax, dst);
304N/A}
304N/A
304N/Avoid Assembler::lea(Register dst, Address src) {
304N/A leaq(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::leaq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x8D);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::mov64(Register dst, int64_t imm64) {
304N/A InstructionMark im(this);
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xB8 | encode);
304N/A emit_long64(imm64);
304N/A}
304N/A
304N/Avoid Assembler::mov_literal64(Register dst, intptr_t imm64, RelocationHolder const& rspec) {
304N/A InstructionMark im(this);
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xB8 | encode);
304N/A emit_data64(imm64, rspec);
304N/A}
304N/A
642N/Avoid Assembler::mov_narrow_oop(Register dst, int32_t imm32, RelocationHolder const& rspec) {
642N/A InstructionMark im(this);
642N/A int encode = prefix_and_encode(dst->encoding());
642N/A emit_byte(0xB8 | encode);
642N/A emit_data((int)imm32, rspec, narrow_oop_operand);
642N/A}
642N/A
642N/Avoid Assembler::mov_narrow_oop(Address dst, int32_t imm32, RelocationHolder const& rspec) {
642N/A InstructionMark im(this);
642N/A prefix(dst);
642N/A emit_byte(0xC7);
642N/A emit_operand(rax, dst, 4);
642N/A emit_data((int)imm32, rspec, narrow_oop_operand);
642N/A}
642N/A
642N/Avoid Assembler::cmp_narrow_oop(Register src1, int32_t imm32, RelocationHolder const& rspec) {
642N/A InstructionMark im(this);
642N/A int encode = prefix_and_encode(src1->encoding());
642N/A emit_byte(0x81);
642N/A emit_byte(0xF8 | encode);
642N/A emit_data((int)imm32, rspec, narrow_oop_operand);
642N/A}
642N/A
642N/Avoid Assembler::cmp_narrow_oop(Address src1, int32_t imm32, RelocationHolder const& rspec) {
642N/A InstructionMark im(this);
642N/A prefix(src1);
642N/A emit_byte(0x81);
642N/A emit_operand(rax, src1, 4);
642N/A emit_data((int)imm32, rspec, narrow_oop_operand);
642N/A}
642N/A
775N/Avoid Assembler::lzcntq(Register dst, Register src) {
775N/A assert(VM_Version::supports_lzcnt(), "encoding is treated as BSR");
775N/A emit_byte(0xF3);
775N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
775N/A emit_byte(0x0F);
775N/A emit_byte(0xBD);
775N/A emit_byte(0xC0 | encode);
775N/A}
775N/A
304N/Avoid Assembler::movdq(XMMRegister dst, Register src) {
304N/A // table D-1 says MMX/SSE2
304N/A NOT_LP64(assert(VM_Version::supports_sse2() || VM_Version::supports_mmx(), ""));
0N/A emit_byte(0x66);
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
0N/A emit_byte(0x0F);
304N/A emit_byte(0x6E);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movdq(Register dst, XMMRegister src) {
304N/A // table D-1 says MMX/SSE2
304N/A NOT_LP64(assert(VM_Version::supports_sse2() || VM_Version::supports_mmx(), ""));
0N/A emit_byte(0x66);
304N/A // swap src/dst to get correct prefix
304N/A int encode = prefixq_and_encode(src->encoding(), dst->encoding());
0N/A emit_byte(0x0F);
0N/A emit_byte(0x7E);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movq(Register dst, Register src) {
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x8B);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::movq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x8B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movq(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A prefixq(dst, src);
304N/A emit_byte(0x89);
304N/A emit_operand(src, dst);
304N/A}
304N/A
624N/Avoid Assembler::movsbq(Register dst, Address src) {
624N/A InstructionMark im(this);
624N/A prefixq(src, dst);
624N/A emit_byte(0x0F);
624N/A emit_byte(0xBE);
624N/A emit_operand(dst, src);
624N/A}
624N/A
624N/Avoid Assembler::movsbq(Register dst, Register src) {
624N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
624N/A emit_byte(0x0F);
624N/A emit_byte(0xBE);
624N/A emit_byte(0xC0 | encode);
624N/A}
624N/A
304N/Avoid Assembler::movslq(Register dst, int32_t imm32) {
304N/A // dbx shows movslq(rcx, 3) as movq $0x0000000049000000,(%rbx)
304N/A // and movslq(r8, 3); as movl $0x0000000048000000,(%rbx)
304N/A // as a result we shouldn't use until tested at runtime...
304N/A ShouldNotReachHere();
304N/A InstructionMark im(this);
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xC7 | encode);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::movslq(Address dst, int32_t imm32) {
304N/A assert(is_simm32(imm32), "lost bits");
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A emit_byte(0xC7);
304N/A emit_operand(rax, dst, 4);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::movslq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x63);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::movslq(Register dst, Register src) {
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x63);
304N/A emit_byte(0xC0 | encode);
304N/A}
304N/A
624N/Avoid Assembler::movswq(Register dst, Address src) {
624N/A InstructionMark im(this);
624N/A prefixq(src, dst);
624N/A emit_byte(0x0F);
624N/A emit_byte(0xBF);
624N/A emit_operand(dst, src);
624N/A}
624N/A
624N/Avoid Assembler::movswq(Register dst, Register src) {
624N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
624N/A emit_byte(0x0F);
624N/A emit_byte(0xBF);
624N/A emit_byte(0xC0 | encode);
624N/A}
624N/A
624N/Avoid Assembler::movzbq(Register dst, Address src) {
624N/A InstructionMark im(this);
624N/A prefixq(src, dst);
624N/A emit_byte(0x0F);
624N/A emit_byte(0xB6);
624N/A emit_operand(dst, src);
624N/A}
624N/A
624N/Avoid Assembler::movzbq(Register dst, Register src) {
624N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
624N/A emit_byte(0x0F);
624N/A emit_byte(0xB6);
624N/A emit_byte(0xC0 | encode);
624N/A}
624N/A
624N/Avoid Assembler::movzwq(Register dst, Address src) {
624N/A InstructionMark im(this);
624N/A prefixq(src, dst);
624N/A emit_byte(0x0F);
624N/A emit_byte(0xB7);
624N/A emit_operand(dst, src);
624N/A}
624N/A
624N/Avoid Assembler::movzwq(Register dst, Register src) {
624N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
624N/A emit_byte(0x0F);
624N/A emit_byte(0xB7);
624N/A emit_byte(0xC0 | encode);
624N/A}
624N/A
304N/Avoid Assembler::negq(Register dst) {
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xF7);
304N/A emit_byte(0xD8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::notq(Register dst) {
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xF7);
304N/A emit_byte(0xD0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::orq(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A emit_byte(0x81);
304N/A emit_operand(rcx, dst, 4);
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::orq(Register dst, int32_t imm32) {
304N/A (void) prefixq_and_encode(dst->encoding());
304N/A emit_arith(0x81, 0xC8, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::orq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x0B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::orq(Register dst, Register src) {
304N/A (void) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x0B, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::popa() { // 64bit
304N/A movq(r15, Address(rsp, 0));
304N/A movq(r14, Address(rsp, wordSize));
304N/A movq(r13, Address(rsp, 2 * wordSize));
304N/A movq(r12, Address(rsp, 3 * wordSize));
304N/A movq(r11, Address(rsp, 4 * wordSize));
304N/A movq(r10, Address(rsp, 5 * wordSize));
304N/A movq(r9, Address(rsp, 6 * wordSize));
304N/A movq(r8, Address(rsp, 7 * wordSize));
304N/A movq(rdi, Address(rsp, 8 * wordSize));
304N/A movq(rsi, Address(rsp, 9 * wordSize));
304N/A movq(rbp, Address(rsp, 10 * wordSize));
304N/A // skip rsp
304N/A movq(rbx, Address(rsp, 12 * wordSize));
304N/A movq(rdx, Address(rsp, 13 * wordSize));
304N/A movq(rcx, Address(rsp, 14 * wordSize));
304N/A movq(rax, Address(rsp, 15 * wordSize));
304N/A
304N/A addq(rsp, 16 * wordSize);
304N/A}
304N/A
643N/Avoid Assembler::popcntq(Register dst, Address src) {
643N/A assert(VM_Version::supports_popcnt(), "must support");
643N/A InstructionMark im(this);
643N/A emit_byte(0xF3);
643N/A prefixq(src, dst);
643N/A emit_byte(0x0F);
643N/A emit_byte(0xB8);
643N/A emit_operand(dst, src);
643N/A}
643N/A
643N/Avoid Assembler::popcntq(Register dst, Register src) {
643N/A assert(VM_Version::supports_popcnt(), "must support");
643N/A emit_byte(0xF3);
643N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
643N/A emit_byte(0x0F);
643N/A emit_byte(0xB8);
643N/A emit_byte(0xC0 | encode);
643N/A}
643N/A
304N/Avoid Assembler::popq(Address dst) {
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A emit_byte(0x8F);
304N/A emit_operand(rax, dst);
304N/A}
304N/A
304N/Avoid Assembler::pusha() { // 64bit
304N/A // we have to store original rsp. ABI says that 128 bytes
304N/A // below rsp are local scratch.
304N/A movq(Address(rsp, -5 * wordSize), rsp);
304N/A
304N/A subq(rsp, 16 * wordSize);
304N/A
304N/A movq(Address(rsp, 15 * wordSize), rax);
304N/A movq(Address(rsp, 14 * wordSize), rcx);
304N/A movq(Address(rsp, 13 * wordSize), rdx);
304N/A movq(Address(rsp, 12 * wordSize), rbx);
304N/A // skip rsp
304N/A movq(Address(rsp, 10 * wordSize), rbp);
304N/A movq(Address(rsp, 9 * wordSize), rsi);
304N/A movq(Address(rsp, 8 * wordSize), rdi);
304N/A movq(Address(rsp, 7 * wordSize), r8);
304N/A movq(Address(rsp, 6 * wordSize), r9);
304N/A movq(Address(rsp, 5 * wordSize), r10);
304N/A movq(Address(rsp, 4 * wordSize), r11);
304N/A movq(Address(rsp, 3 * wordSize), r12);
304N/A movq(Address(rsp, 2 * wordSize), r13);
304N/A movq(Address(rsp, wordSize), r14);
304N/A movq(Address(rsp, 0), r15);
304N/A}
304N/A
304N/Avoid Assembler::pushq(Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src);
304N/A emit_byte(0xFF);
304N/A emit_operand(rsi, src);
304N/A}
304N/A
304N/Avoid Assembler::rclq(Register dst, int imm8) {
304N/A assert(isShiftCount(imm8 >> 1), "illegal shift count");
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A if (imm8 == 1) {
304N/A emit_byte(0xD1);
304N/A emit_byte(0xD0 | encode);
304N/A } else {
304N/A emit_byte(0xC1);
304N/A emit_byte(0xD0 | encode);
304N/A emit_byte(imm8);
304N/A }
304N/A}
304N/Avoid Assembler::sarq(Register dst, int imm8) {
304N/A assert(isShiftCount(imm8 >> 1), "illegal shift count");
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A if (imm8 == 1) {
304N/A emit_byte(0xD1);
304N/A emit_byte(0xF8 | encode);
304N/A } else {
304N/A emit_byte(0xC1);
304N/A emit_byte(0xF8 | encode);
304N/A emit_byte(imm8);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::sarq(Register dst) {
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xD3);
304N/A emit_byte(0xF8 | encode);
304N/A}
304N/Avoid Assembler::sbbq(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A emit_arith_operand(0x81, rbx, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::sbbq(Register dst, int32_t imm32) {
304N/A (void) prefixq_and_encode(dst->encoding());
304N/A emit_arith(0x81, 0xD8, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::sbbq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x1B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::sbbq(Register dst, Register src) {
304N/A (void) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x1B, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::shlq(Register dst, int imm8) {
304N/A assert(isShiftCount(imm8 >> 1), "illegal shift count");
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A if (imm8 == 1) {
304N/A emit_byte(0xD1);
304N/A emit_byte(0xE0 | encode);
304N/A } else {
304N/A emit_byte(0xC1);
304N/A emit_byte(0xE0 | encode);
304N/A emit_byte(imm8);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::shlq(Register dst) {
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xD3);
304N/A emit_byte(0xE0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::shrq(Register dst, int imm8) {
304N/A assert(isShiftCount(imm8 >> 1), "illegal shift count");
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xC1);
304N/A emit_byte(0xE8 | encode);
304N/A emit_byte(imm8);
304N/A}
304N/A
304N/Avoid Assembler::shrq(Register dst) {
304N/A int encode = prefixq_and_encode(dst->encoding());
304N/A emit_byte(0xD3);
304N/A emit_byte(0xE8 | encode);
304N/A}
304N/A
304N/Avoid Assembler::sqrtsd(XMMRegister dst, Address src) {
304N/A NOT_LP64(assert(VM_Version::supports_sse2(), ""));
0N/A InstructionMark im(this);
0N/A emit_byte(0xF2);
304N/A prefix(src, dst);
0N/A emit_byte(0x0F);
304N/A emit_byte(0x51);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::subq(Address dst, int32_t imm32) {
304N/A InstructionMark im(this);
304N/A prefixq(dst);
304N/A if (is8bit(imm32)) {
304N/A emit_byte(0x83);
304N/A emit_operand(rbp, dst, 1);
304N/A emit_byte(imm32 & 0xFF);
304N/A } else {
304N/A emit_byte(0x81);
304N/A emit_operand(rbp, dst, 4);
304N/A emit_long(imm32);
304N/A }
304N/A}
304N/A
304N/Avoid Assembler::subq(Register dst, int32_t imm32) {
304N/A (void) prefixq_and_encode(dst->encoding());
304N/A emit_arith(0x81, 0xE8, dst, imm32);
304N/A}
304N/A
304N/Avoid Assembler::subq(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A prefixq(dst, src);
304N/A emit_byte(0x29);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::subq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x2B);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::subq(Register dst, Register src) {
304N/A (void) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x2B, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::testq(Register dst, int32_t imm32) {
304N/A // not using emit_arith because test
304N/A // doesn't support sign-extension of
304N/A // 8bit operands
304N/A int encode = dst->encoding();
304N/A if (encode == 0) {
304N/A prefix(REX_W);
304N/A emit_byte(0xA9);
304N/A } else {
304N/A encode = prefixq_and_encode(encode);
304N/A emit_byte(0xF7);
304N/A emit_byte(0xC0 | encode);
304N/A }
304N/A emit_long(imm32);
304N/A}
304N/A
304N/Avoid Assembler::testq(Register dst, Register src) {
304N/A (void) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x85, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::xaddq(Address dst, Register src) {
304N/A InstructionMark im(this);
304N/A prefixq(dst, src);
71N/A emit_byte(0x0F);
304N/A emit_byte(0xC1);
304N/A emit_operand(src, dst);
304N/A}
304N/A
304N/Avoid Assembler::xchgq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x87);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/Avoid Assembler::xchgq(Register dst, Register src) {
304N/A int encode = prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_byte(0x87);
304N/A emit_byte(0xc0 | encode);
304N/A}
304N/A
304N/Avoid Assembler::xorq(Register dst, Register src) {
304N/A (void) prefixq_and_encode(dst->encoding(), src->encoding());
304N/A emit_arith(0x33, 0xC0, dst, src);
304N/A}
304N/A
304N/Avoid Assembler::xorq(Register dst, Address src) {
304N/A InstructionMark im(this);
304N/A prefixq(src, dst);
304N/A emit_byte(0x33);
304N/A emit_operand(dst, src);
304N/A}
304N/A
304N/A#endif // !LP64
304N/A
304N/Astatic Assembler::Condition reverse[] = {
304N/A Assembler::noOverflow /* overflow = 0x0 */ ,
304N/A Assembler::overflow /* noOverflow = 0x1 */ ,
304N/A Assembler::aboveEqual /* carrySet = 0x2, below = 0x2 */ ,
304N/A Assembler::below /* aboveEqual = 0x3, carryClear = 0x3 */ ,
304N/A Assembler::notZero /* zero = 0x4, equal = 0x4 */ ,
304N/A Assembler::zero /* notZero = 0x5, notEqual = 0x5 */ ,
304N/A Assembler::above /* belowEqual = 0x6 */ ,
304N/A Assembler::belowEqual /* above = 0x7 */ ,
304N/A Assembler::positive /* negative = 0x8 */ ,
304N/A Assembler::negative /* positive = 0x9 */ ,
304N/A Assembler::noParity /* parity = 0xa */ ,
304N/A Assembler::parity /* noParity = 0xb */ ,
304N/A Assembler::greaterEqual /* less = 0xc */ ,
304N/A Assembler::less /* greaterEqual = 0xd */ ,
304N/A Assembler::greater /* lessEqual = 0xe */ ,
304N/A Assembler::lessEqual /* greater = 0xf, */
304N/A
304N/A};
304N/A
0N/A
0N/A// Implementation of MacroAssembler
0N/A
304N/A// First all the versions that have distinct versions depending on 32/64 bit
304N/A// Unless the difference is trivial (1 line or so).
304N/A
304N/A#ifndef _LP64
304N/A
304N/A// 32bit versions
304N/A
0N/AAddress MacroAssembler::as_Address(AddressLiteral adr) {
0N/A return Address(adr.target(), adr.rspec());
0N/A}
0N/A
0N/AAddress MacroAssembler::as_Address(ArrayAddress adr) {
0N/A return Address::make_array(adr);
0N/A}
0N/A
304N/Aint MacroAssembler::biased_locking_enter(Register lock_reg,
304N/A Register obj_reg,
304N/A Register swap_reg,
304N/A Register tmp_reg,
304N/A bool swap_reg_contains_mark,
304N/A Label& done,
304N/A Label* slow_case,
304N/A BiasedLockingCounters* counters) {
304N/A assert(UseBiasedLocking, "why call this otherwise?");
304N/A assert(swap_reg == rax, "swap_reg must be rax, for cmpxchg");
304N/A assert_different_registers(lock_reg, obj_reg, swap_reg);
304N/A
304N/A if (PrintBiasedLockingStatistics && counters == NULL)
304N/A counters = BiasedLocking::counters();
304N/A
304N/A bool need_tmp_reg = false;
304N/A if (tmp_reg == noreg) {
304N/A need_tmp_reg = true;
304N/A tmp_reg = lock_reg;
304N/A } else {
304N/A assert_different_registers(lock_reg, obj_reg, swap_reg, tmp_reg);
304N/A }
304N/A assert(markOopDesc::age_shift == markOopDesc::lock_bits + markOopDesc::biased_lock_bits, "biased locking makes assumptions about bit layout");
304N/A Address mark_addr (obj_reg, oopDesc::mark_offset_in_bytes());
304N/A Address klass_addr (obj_reg, oopDesc::klass_offset_in_bytes());
304N/A Address saved_mark_addr(lock_reg, 0);
304N/A
304N/A // Biased locking
304N/A // See whether the lock is currently biased toward our thread and
304N/A // whether the epoch is still valid
304N/A // Note that the runtime guarantees sufficient alignment of JavaThread
304N/A // pointers to allow age to be placed into low bits
304N/A // First check to see whether biasing is even enabled for this object
304N/A Label cas_label;
304N/A int null_check_offset = -1;
304N/A if (!swap_reg_contains_mark) {
304N/A null_check_offset = offset();
304N/A movl(swap_reg, mark_addr);
304N/A }
304N/A if (need_tmp_reg) {
304N/A push(tmp_reg);
304N/A }
304N/A movl(tmp_reg, swap_reg);
304N/A andl(tmp_reg, markOopDesc::biased_lock_mask_in_place);
304N/A cmpl(tmp_reg, markOopDesc::biased_lock_pattern);
304N/A if (need_tmp_reg) {
304N/A pop(tmp_reg);
304N/A }
304N/A jcc(Assembler::notEqual, cas_label);
304N/A // The bias pattern is present in the object's header. Need to check
304N/A // whether the bias owner and the epoch are both still current.
304N/A // Note that because there is no current thread register on x86 we
304N/A // need to store off the mark word we read out of the object to
304N/A // avoid reloading it and needing to recheck invariants below. This
304N/A // store is unfortunate but it makes the overall code shorter and
304N/A // simpler.
304N/A movl(saved_mark_addr, swap_reg);
304N/A if (need_tmp_reg) {
304N/A push(tmp_reg);
304N/A }
304N/A get_thread(tmp_reg);
304N/A xorl(swap_reg, tmp_reg);
304N/A if (swap_reg_contains_mark) {
304N/A null_check_offset = offset();
304N/A }
304N/A movl(tmp_reg, klass_addr);
304N/A xorl(swap_reg, Address(tmp_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
304N/A andl(swap_reg, ~((int) markOopDesc::age_mask_in_place));
304N/A if (need_tmp_reg) {
304N/A pop(tmp_reg);
304N/A }
304N/A if (counters != NULL) {
304N/A cond_inc32(Assembler::zero,
304N/A ExternalAddress((address)counters->biased_lock_entry_count_addr()));
304N/A }
304N/A jcc(Assembler::equal, done);
304N/A
304N/A Label try_revoke_bias;
304N/A Label try_rebias;
304N/A
304N/A // At this point we know that the header has the bias pattern and
304N/A // that we are not the bias owner in the current epoch. We need to
304N/A // figure out more details about the state of the header in order to
304N/A // know what operations can be legally performed on the object's
304N/A // header.
304N/A
304N/A // If the low three bits in the xor result aren't clear, that means
304N/A // the prototype header is no longer biased and we have to revoke
304N/A // the bias on this object.
304N/A testl(swap_reg, markOopDesc::biased_lock_mask_in_place);
304N/A jcc(Assembler::notZero, try_revoke_bias);
304N/A
304N/A // Biasing is still enabled for this data type. See whether the
304N/A // epoch of the current bias is still valid, meaning that the epoch
304N/A // bits of the mark word are equal to the epoch bits of the
304N/A // prototype header. (Note that the prototype header's epoch bits
304N/A // only change at a safepoint.) If not, attempt to rebias the object
304N/A // toward the current thread. Note that we must be absolutely sure
304N/A // that the current epoch is invalid in order to do this because
304N/A // otherwise the manipulations it performs on the mark word are
304N/A // illegal.
304N/A testl(swap_reg, markOopDesc::epoch_mask_in_place);
304N/A jcc(Assembler::notZero, try_rebias);
304N/A
304N/A // The epoch of the current bias is still valid but we know nothing
304N/A // about the owner; it might be set or it might be clear. Try to
304N/A // acquire the bias of the object using an atomic operation. If this
304N/A // fails we will go in to the runtime to revoke the object's bias.
304N/A // Note that we first construct the presumed unbiased header so we
304N/A // don't accidentally blow away another thread's valid bias.
304N/A movl(swap_reg, saved_mark_addr);
304N/A andl(swap_reg,
304N/A markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | markOopDesc::epoch_mask_in_place);
304N/A if (need_tmp_reg) {
304N/A push(tmp_reg);
304N/A }
304N/A get_thread(tmp_reg);
304N/A orl(tmp_reg, swap_reg);
304N/A if (os::is_MP()) {
304N/A lock();
304N/A }
304N/A cmpxchgptr(tmp_reg, Address(obj_reg, 0));
304N/A if (need_tmp_reg) {
304N/A pop(tmp_reg);
304N/A }
304N/A // If the biasing toward our thread failed, this means that
304N/A // another thread succeeded in biasing it toward itself and we
304N/A // need to revoke that bias. The revocation will occur in the
304N/A // interpreter runtime in the slow case.
304N/A if (counters != NULL) {
304N/A cond_inc32(Assembler::zero,
304N/A ExternalAddress((address)counters->anonymously_biased_lock_entry_count_addr()));
304N/A }
304N/A if (slow_case != NULL) {
304N/A jcc(Assembler::notZero, *slow_case);
304N/A }
304N/A jmp(done);
304N/A
304N/A bind(try_rebias);
304N/A // At this point we know the epoch has expired, meaning that the
304N/A // current "bias owner", if any, is actually invalid. Under these
304N/A // circumstances _only_, we are allowed to use the current header's
304N/A // value as the comparison value when doing the cas to acquire the
304N/A // bias in the current epoch. In other words, we allow transfer of
304N/A // the bias from one thread to another directly in this situation.
304N/A //
304N/A // FIXME: due to a lack of registers we currently blow away the age
304N/A // bits in this situation. Should attempt to preserve them.
304N/A if (need_tmp_reg) {
304N/A push(tmp_reg);
304N/A }
304N/A get_thread(tmp_reg);
304N/A movl(swap_reg, klass_addr);
304N/A orl(tmp_reg, Address(swap_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
304N/A movl(swap_reg, saved_mark_addr);
304N/A if (os::is_MP()) {
304N/A lock();
304N/A }
304N/A cmpxchgptr(tmp_reg, Address(obj_reg, 0));
304N/A if (need_tmp_reg) {
304N/A pop(tmp_reg);
304N/A }
304N/A // If the biasing toward our thread failed, then another thread
304N/A // succeeded in biasing it toward itself and we need to revoke that
304N/A // bias. The revocation will occur in the runtime in the slow case.
304N/A if (counters != NULL) {
304N/A cond_inc32(Assembler::zero,
304N/A ExternalAddress((address)counters->rebiased_lock_entry_count_addr()));
304N/A }
304N/A if (slow_case != NULL) {
304N/A jcc(Assembler::notZero, *slow_case);
304N/A }
304N/A jmp(done);
304N/A
304N/A bind(try_revoke_bias);
304N/A // The prototype mark in the klass doesn't have the bias bit set any
304N/A // more, indicating that objects of this data type are not supposed
304N/A // to be biased any more. We are going to try to reset the mark of
304N/A // this object to the prototype value and fall through to the
304N/A // CAS-based locking scheme. Note that if our CAS fails, it means
304N/A // that another thread raced us for the privilege of revoking the
304N/A // bias of this particular object, so it's okay to continue in the
304N/A // normal locking code.
304N/A //
304N/A // FIXME: due to a lack of registers we currently blow away the age
304N/A // bits in this situation. Should attempt to preserve them.
304N/A movl(swap_reg, saved_mark_addr);
304N/A if (need_tmp_reg) {
304N/A push(tmp_reg);
304N/A }
304N/A movl(tmp_reg, klass_addr);
304N/A movl(tmp_reg, Address(tmp_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
304N/A if (os::is_MP()) {
304N/A lock();
304N/A }
304N/A cmpxchgptr(tmp_reg, Address(obj_reg, 0));
304N/A if (need_tmp_reg) {
304N/A pop(tmp_reg);
304N/A }
304N/A // Fall through to the normal CAS-based lock, because no matter what
304N/A // the result of the above CAS, some thread must have succeeded in
304N/A // removing the bias bit from the object's header.
304N/A if (counters != NULL) {
304N/A cond_inc32(Assembler::zero,
304N/A ExternalAddress((address)counters->revoked_lock_entry_count_addr()));
304N/A }
304N/A
304N/A bind(cas_label);
304N/A
304N/A return null_check_offset;
304N/A}
304N/Avoid MacroAssembler::call_VM_leaf_base(address entry_point,
304N/A int number_of_arguments) {
304N/A call(RuntimeAddress(entry_point));
304N/A increment(rsp, number_of_arguments * wordSize);
304N/A}
304N/A
304N/Avoid MacroAssembler::cmpoop(Address src1, jobject obj) {
304N/A cmp_literal32(src1, (int32_t)obj, oop_Relocation::spec_for_immediate());
304N/A}
304N/A
304N/Avoid MacroAssembler::cmpoop(Register src1, jobject obj) {
304N/A cmp_literal32(src1, (int32_t)obj, oop_Relocation::spec_for_immediate());
304N/A}
304N/A
304N/Avoid MacroAssembler::extend_sign(Register hi, Register lo) {
304N/A // According to Intel Doc. AP-526, "Integer Divide", p.18.
304N/A if (VM_Version::is_P6() && hi == rdx && lo == rax) {
304N/A cdql();
304N/A } else {
304N/A movl(hi, lo);
304N/A sarl(hi, 31);
304N/A }
304N/A}
304N/A
0N/Avoid MacroAssembler::fat_nop() {
0N/A // A 5 byte nop that is safe for patching (see patch_verified_entry)
0N/A emit_byte(0x26); // es:
0N/A emit_byte(0x2e); // cs:
0N/A emit_byte(0x64); // fs:
0N/A emit_byte(0x65); // gs:
0N/A emit_byte(0x90);
0N/A}
0N/A
304N/Avoid MacroAssembler::jC2(Register tmp, Label& L) {
304N/A // set parity bit if FPU flag C2 is set (via rax)
304N/A save_rax(tmp);
304N/A fwait(); fnstsw_ax();
304N/A sahf();
304N/A restore_rax(tmp);
304N/A // branch
304N/A jcc(Assembler::parity, L);
304N/A}
304N/A
304N/Avoid MacroAssembler::jnC2(Register tmp, Label& L) {
304N/A // set parity bit if FPU flag C2 is set (via rax)
304N/A save_rax(tmp);
304N/A fwait(); fnstsw_ax();
304N/A sahf();
304N/A restore_rax(tmp);
304N/A // branch
304N/A jcc(Assembler::noParity, L);
304N/A}
304N/A
0N/A// 32bit can do a case table jump in one instruction but we no longer allow the base
0N/A// to be installed in the Address class
0N/Avoid MacroAssembler::jump(ArrayAddress entry) {
0N/A jmp(as_Address(entry));
0N/A}
0N/A
304N/A// Note: y_lo will be destroyed
304N/Avoid MacroAssembler::lcmp2int(Register x_hi, Register x_lo, Register y_hi, Register y_lo) {
304N/A // Long compare for Java (semantics as described in JVM spec.)
304N/A Label high, low, done;
304N/A
304N/A cmpl(x_hi, y_hi);
304N/A jcc(Assembler::less, low);
304N/A jcc(Assembler::greater, high);
304N/A // x_hi is the return register
304N/A xorl(x_hi, x_hi);
304N/A cmpl(x_lo, y_lo);
304N/A jcc(Assembler::below, low);
304N/A jcc(Assembler::equal, done);
304N/A
304N/A bind(high);
304N/A xorl(x_hi, x_hi);
304N/A increment(x_hi);
304N/A jmp(done);
304N/A
304N/A bind(low);
304N/A xorl(x_hi, x_hi);
304N/A decrementl(x_hi);
304N/A
304N/A bind(done);
304N/A}
304N/A
304N/Avoid MacroAssembler::lea(Register dst, AddressLiteral src) {
304N/A mov_literal32(dst, (int32_t)src.target(), src.rspec());
0N/A}
0N/A
0N/Avoid MacroAssembler::lea(Address dst, AddressLiteral adr) {
0N/A // leal(dst, as_Address(adr));
304N/A // see note in movl as to why we must use a move
0N/A mov_literal32(dst, (int32_t) adr.target(), adr.rspec());
0N/A}
0N/A
0N/Avoid MacroAssembler::leave() {
304N/A mov(rsp, rbp);
304N/A pop(rbp);
304N/A}
0N/A
0N/Avoid MacroAssembler::lmul(int x_rsp_offset, int y_rsp_offset) {
0N/A // Multiplication of two Java long values stored on the stack
0N/A // as illustrated below. Result is in rdx:rax.
0N/A //
0N/A // rsp ---> [ ?? ] \ \
0N/A // .... | y_rsp_offset |
0N/A // [ y_lo ] / (in bytes) | x_rsp_offset
0N/A // [ y_hi ] | (in bytes)
0N/A // .... |
0N/A // [ x_lo ] /
0N/A // [ x_hi ]
0N/A // ....
0N/A //
0N/A // Basic idea: lo(result) = lo(x_lo * y_lo)
0N/A // hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
0N/A Address x_hi(rsp, x_rsp_offset + wordSize); Address x_lo(rsp, x_rsp_offset);
0N/A Address y_hi(rsp, y_rsp_offset + wordSize); Address y_lo(rsp, y_rsp_offset);
0N/A Label quick;
0N/A // load x_hi, y_hi and check if quick
0N/A // multiplication is possible
0N/A movl(rbx, x_hi);
0N/A movl(rcx, y_hi);
0N/A movl(rax, rbx);
0N/A orl(rbx, rcx); // rbx, = 0 <=> x_hi = 0 and y_hi = 0
0N/A jcc(Assembler::zero, quick); // if rbx, = 0 do quick multiply
0N/A // do full multiplication
0N/A // 1st step
0N/A mull(y_lo); // x_hi * y_lo
0N/A movl(rbx, rax); // save lo(x_hi * y_lo) in rbx,
0N/A // 2nd step
0N/A movl(rax, x_lo);
0N/A mull(rcx); // x_lo * y_hi
0N/A addl(rbx, rax); // add lo(x_lo * y_hi) to rbx,
0N/A // 3rd step
0N/A bind(quick); // note: rbx, = 0 if quick multiply!
0N/A movl(rax, x_lo);
0N/A mull(y_lo); // x_lo * y_lo
0N/A addl(rdx, rbx); // correct hi(x_lo * y_lo)
0N/A}
0N/A
304N/Avoid MacroAssembler::lneg(Register hi, Register lo) {
304N/A negl(lo);
304N/A adcl(hi, 0);
304N/A negl(hi);
304N/A}
0N/A
0N/Avoid MacroAssembler::lshl(Register hi, Register lo) {
0N/A // Java shift left long support (semantics as described in JVM spec., p.305)
0N/A // (basic idea for shift counts s >= n: x << s == (x << n) << (s - n))
0N/A // shift value is in rcx !
0N/A assert(hi != rcx, "must not use rcx");
0N/A assert(lo != rcx, "must not use rcx");
0N/A const Register s = rcx; // shift count
0N/A const int n = BitsPerWord;
0N/A Label L;
0N/A andl(s, 0x3f); // s := s & 0x3f (s < 0x40)
0N/A cmpl(s, n); // if (s < n)
0N/A jcc(Assembler::less, L); // else (s >= n)
0N/A movl(hi, lo); // x := x << n
0N/A xorl(lo, lo);
0N/A // Note: subl(s, n) is not needed since the Intel shift instructions work rcx mod n!
0N/A bind(L); // s (mod n) < n
0N/A shldl(hi, lo); // x := x << s
0N/A shll(lo);
0N/A}
0N/A
0N/A
0N/Avoid MacroAssembler::lshr(Register hi, Register lo, bool sign_extension) {
0N/A // Java shift right long support (semantics as described in JVM spec., p.306 & p.310)
0N/A // (basic idea for shift counts s >= n: x >> s == (x >> n) >> (s - n))
0N/A assert(hi != rcx, "must not use rcx");
0N/A assert(lo != rcx, "must not use rcx");
0N/A const Register s = rcx; // shift count
0N/A const int n = BitsPerWord;
0N/A Label L;
0N/A andl(s, 0x3f); // s := s & 0x3f (s < 0x40)
0N/A cmpl(s, n); // if (s < n)
0N/A jcc(Assembler::less, L); // else (s >= n)
0N/A movl(lo, hi); // x := x >> n
0N/A if (sign_extension) sarl(hi, 31);
0N/A else xorl(hi, hi);
0N/A // Note: subl(s, n) is not needed since the Intel shift instructions work rcx mod n!
0N/A bind(L); // s (mod n) < n
0N/A shrdl(lo, hi); // x := x >> s
0N/A if (sign_extension) sarl(hi);
0N/A else shrl(hi);
0N/A}
0N/A
304N/Avoid MacroAssembler::movoop(Register dst, jobject obj) {
304N/A mov_literal32(dst, (int32_t)obj, oop_Relocation::spec_for_immediate());
304N/A}
304N/A
304N/Avoid MacroAssembler::movoop(Address dst, jobject obj) {
304N/A mov_literal32(dst, (int32_t)obj, oop_Relocation::spec_for_immediate());
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(Register dst, AddressLiteral src) {
304N/A if (src.is_lval()) {
304N/A mov_literal32(dst, (intptr_t)src.target(), src.rspec());
304N/A } else {
304N/A movl(dst, as_Address(src));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(ArrayAddress dst, Register src) {
304N/A movl(as_Address(dst), src);
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(Register dst, ArrayAddress src) {
304N/A movl(dst, as_Address(src));
304N/A}
304N/A
304N/A// src should NEVER be a real pointer. Use AddressLiteral for true pointers
304N/Avoid MacroAssembler::movptr(Address dst, intptr_t src) {
304N/A movl(dst, src);
304N/A}
304N/A
304N/A
304N/Avoid MacroAssembler::movsd(XMMRegister dst, AddressLiteral src) {
304N/A movsd(dst, as_Address(src));
304N/A}
304N/A
304N/Avoid MacroAssembler::pop_callee_saved_registers() {
304N/A pop(rcx);
304N/A pop(rdx);
304N/A pop(rdi);
304N/A pop(rsi);
304N/A}
304N/A
304N/Avoid MacroAssembler::pop_fTOS() {
304N/A fld_d(Address(rsp, 0));
304N/A addl(rsp, 2 * wordSize);
304N/A}
304N/A
304N/Avoid MacroAssembler::push_callee_saved_registers() {
304N/A push(rsi);
304N/A push(rdi);
304N/A push(rdx);
304N/A push(rcx);
304N/A}
304N/A
304N/Avoid MacroAssembler::push_fTOS() {
304N/A subl(rsp, 2 * wordSize);
304N/A fstp_d(Address(rsp, 0));
304N/A}
304N/A
304N/A
304N/Avoid MacroAssembler::pushoop(jobject obj) {
304N/A push_literal32((int32_t)obj, oop_Relocation::spec_for_immediate());
304N/A}
304N/A
304N/A
304N/Avoid MacroAssembler::pushptr(AddressLiteral src) {
304N/A if (src.is_lval()) {
304N/A push_literal32((int32_t)src.target(), src.rspec());
304N/A } else {
304N/A pushl(as_Address(src));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::set_word_if_not_zero(Register dst) {
304N/A xorl(dst, dst);
304N/A set_byte_if_not_zero(dst);
304N/A}
304N/A
304N/Astatic void pass_arg0(MacroAssembler* masm, Register arg) {
304N/A masm->push(arg);
304N/A}
304N/A
304N/Astatic void pass_arg1(MacroAssembler* masm, Register arg) {
304N/A masm->push(arg);
304N/A}
304N/A
304N/Astatic void pass_arg2(MacroAssembler* masm, Register arg) {
304N/A masm->push(arg);
304N/A}
304N/A
304N/Astatic void pass_arg3(MacroAssembler* masm, Register arg) {
304N/A masm->push(arg);
304N/A}
304N/A
304N/A#ifndef PRODUCT
304N/Aextern "C" void findpc(intptr_t x);
304N/A#endif
304N/A
304N/Avoid MacroAssembler::debug32(int rdi, int rsi, int rbp, int rsp, int rbx, int rdx, int rcx, int rax, int eip, char* msg) {
304N/A // In order to get locks to work, we need to fake a in_VM state
304N/A JavaThread* thread = JavaThread::current();
304N/A JavaThreadState saved_state = thread->thread_state();
304N/A thread->set_thread_state(_thread_in_vm);
304N/A if (ShowMessageBoxOnError) {
304N/A JavaThread* thread = JavaThread::current();
304N/A JavaThreadState saved_state = thread->thread_state();
304N/A thread->set_thread_state(_thread_in_vm);
304N/A if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
304N/A ttyLocker ttyl;
304N/A BytecodeCounter::print();
304N/A }
304N/A // To see where a verify_oop failed, get $ebx+40/X for this frame.
304N/A // This is the value of eip which points to where verify_oop will return.
304N/A if (os::message_box(msg, "Execution stopped, print registers?")) {
304N/A ttyLocker ttyl;
304N/A tty->print_cr("eip = 0x%08x", eip);
304N/A#ifndef PRODUCT
304N/A tty->cr();
304N/A findpc(eip);
304N/A tty->cr();
304N/A#endif
304N/A tty->print_cr("rax, = 0x%08x", rax);
304N/A tty->print_cr("rbx, = 0x%08x", rbx);
304N/A tty->print_cr("rcx = 0x%08x", rcx);
304N/A tty->print_cr("rdx = 0x%08x", rdx);
304N/A tty->print_cr("rdi = 0x%08x", rdi);
304N/A tty->print_cr("rsi = 0x%08x", rsi);
304N/A tty->print_cr("rbp, = 0x%08x", rbp);
304N/A tty->print_cr("rsp = 0x%08x", rsp);
304N/A BREAKPOINT;
304N/A }
304N/A } else {
304N/A ttyLocker ttyl;
304N/A ::tty->print_cr("=============== DEBUG MESSAGE: %s ================\n", msg);
304N/A assert(false, "DEBUG MESSAGE");
304N/A }
304N/A ThreadStateTransition::transition(thread, _thread_in_vm, saved_state);
304N/A}
304N/A
304N/Avoid MacroAssembler::stop(const char* msg) {
304N/A ExternalAddress message((address)msg);
304N/A // push address of message
304N/A pushptr(message.addr());
304N/A { Label L; call(L, relocInfo::none); bind(L); } // push eip
304N/A pusha(); // push registers
304N/A call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug32)));
304N/A hlt();
304N/A}
304N/A
304N/Avoid MacroAssembler::warn(const char* msg) {
304N/A push_CPU_state();
304N/A
304N/A ExternalAddress message((address) msg);
304N/A // push address of message
304N/A pushptr(message.addr());
304N/A
304N/A call(RuntimeAddress(CAST_FROM_FN_PTR(address, warning)));
304N/A addl(rsp, wordSize); // discard argument
304N/A pop_CPU_state();
304N/A}
304N/A
304N/A#else // _LP64
304N/A
304N/A// 64 bit versions
304N/A
304N/AAddress MacroAssembler::as_Address(AddressLiteral adr) {
304N/A // amd64 always does this as a pc-rel
304N/A // we can be absolute or disp based on the instruction type
304N/A // jmp/call are displacements others are absolute
304N/A assert(!adr.is_lval(), "must be rval");
304N/A assert(reachable(adr), "must be");
304N/A return Address((int32_t)(intptr_t)(adr.target() - pc()), adr.target(), adr.reloc());
304N/A
304N/A}
304N/A
304N/AAddress MacroAssembler::as_Address(ArrayAddress adr) {
304N/A AddressLiteral base = adr.base();
304N/A lea(rscratch1, base);
304N/A Address index = adr.index();
304N/A assert(index._disp == 0, "must not have disp"); // maybe it can?
304N/A Address array(rscratch1, index._index, index._scale, index._disp);
304N/A return array;
304N/A}
304N/A
304N/Aint MacroAssembler::biased_locking_enter(Register lock_reg,
304N/A Register obj_reg,
304N/A Register swap_reg,
304N/A Register tmp_reg,
304N/A bool swap_reg_contains_mark,
304N/A Label& done,
304N/A Label* slow_case,
304N/A BiasedLockingCounters* counters) {
304N/A assert(UseBiasedLocking, "why call this otherwise?");
304N/A assert(swap_reg == rax, "swap_reg must be rax for cmpxchgq");
304N/A assert(tmp_reg != noreg, "tmp_reg must be supplied");
304N/A assert_different_registers(lock_reg, obj_reg, swap_reg, tmp_reg);
304N/A assert(markOopDesc::age_shift == markOopDesc::lock_bits + markOopDesc::biased_lock_bits, "biased locking makes assumptions about bit layout");
304N/A Address mark_addr (obj_reg, oopDesc::mark_offset_in_bytes());
304N/A Address saved_mark_addr(lock_reg, 0);
304N/A
304N/A if (PrintBiasedLockingStatistics && counters == NULL)
304N/A counters = BiasedLocking::counters();
304N/A
304N/A // Biased locking
304N/A // See whether the lock is currently biased toward our thread and
304N/A // whether the epoch is still valid
304N/A // Note that the runtime guarantees sufficient alignment of JavaThread
304N/A // pointers to allow age to be placed into low bits
304N/A // First check to see whether biasing is even enabled for this object
304N/A Label cas_label;
304N/A int null_check_offset = -1;
304N/A if (!swap_reg_contains_mark) {
304N/A null_check_offset = offset();
304N/A movq(swap_reg, mark_addr);
304N/A }
304N/A movq(tmp_reg, swap_reg);
304N/A andq(tmp_reg, markOopDesc::biased_lock_mask_in_place);
304N/A cmpq(tmp_reg, markOopDesc::biased_lock_pattern);
304N/A jcc(Assembler::notEqual, cas_label);
304N/A // The bias pattern is present in the object's header. Need to check
304N/A // whether the bias owner and the epoch are both still current.
304N/A load_prototype_header(tmp_reg, obj_reg);
304N/A orq(tmp_reg, r15_thread);
304N/A xorq(tmp_reg, swap_reg);
304N/A andq(tmp_reg, ~((int) markOopDesc::age_mask_in_place));
304N/A if (counters != NULL) {
304N/A cond_inc32(Assembler::zero,
304N/A ExternalAddress((address) counters->anonymously_biased_lock_entry_count_addr()));
304N/A }
0N/A jcc(Assembler::equal, done);
0N/A
304N/A Label try_revoke_bias;
304N/A Label try_rebias;
304N/A
304N/A // At this point we know that the header has the bias pattern and
304N/A // that we are not the bias owner in the current epoch. We need to
304N/A // figure out more details about the state of the header in order to
304N/A // know what operations can be legally performed on the object's
304N/A // header.
304N/A
304N/A // If the low three bits in the xor result aren't clear, that means
304N/A // the prototype header is no longer biased and we have to revoke
304N/A // the bias on this object.
304N/A testq(tmp_reg, markOopDesc::biased_lock_mask_in_place);
304N/A jcc(Assembler::notZero, try_revoke_bias);
304N/A
304N/A // Biasing is still enabled for this data type. See whether the
304N/A // epoch of the current bias is still valid, meaning that the epoch
304N/A // bits of the mark word are equal to the epoch bits of the
304N/A // prototype header. (Note that the prototype header's epoch bits
304N/A // only change at a safepoint.) If not, attempt to rebias the object
304N/A // toward the current thread. Note that we must be absolutely sure
304N/A // that the current epoch is invalid in order to do this because
304N/A // otherwise the manipulations it performs on the mark word are
304N/A // illegal.
304N/A testq(tmp_reg, markOopDesc::epoch_mask_in_place);
304N/A jcc(Assembler::notZero, try_rebias);
304N/A
304N/A // The epoch of the current bias is still valid but we know nothing
304N/A // about the owner; it might be set or it might be clear. Try to
304N/A // acquire the bias of the object using an atomic operation. If this
304N/A // fails we will go in to the runtime to revoke the object's bias.
304N/A // Note that we first construct the presumed unbiased header so we
304N/A // don't accidentally blow away another thread's valid bias.
304N/A andq(swap_reg,
304N/A markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | markOopDesc::epoch_mask_in_place);
304N/A movq(tmp_reg, swap_reg);
304N/A orq(tmp_reg, r15_thread);
304N/A if (os::is_MP()) {
304N/A lock();
304N/A }
304N/A cmpxchgq(tmp_reg, Address(obj_reg, 0));
304N/A // If the biasing toward our thread failed, this means that
304N/A // another thread succeeded in biasing it toward itself and we
304N/A // need to revoke that bias. The revocation will occur in the
304N/A // interpreter runtime in the slow case.
304N/A if (counters != NULL) {
304N/A cond_inc32(Assembler::zero,
304N/A ExternalAddress((address) counters->anonymously_biased_lock_entry_count_addr()));
304N/A }
304N/A if (slow_case != NULL) {
304N/A jcc(Assembler::notZero, *slow_case);
304N/A }
0N/A jmp(done);
0N/A
304N/A bind(try_rebias);
304N/A // At this point we know the epoch has expired, meaning that the
304N/A // current "bias owner", if any, is actually invalid. Under these
304N/A // circumstances _only_, we are allowed to use the current header's
304N/A // value as the comparison value when doing the cas to acquire the
304N/A // bias in the current epoch. In other words, we allow transfer of
304N/A // the bias from one thread to another directly in this situation.
304N/A //
304N/A // FIXME: due to a lack of registers we currently blow away the age
304N/A // bits in this situation. Should attempt to preserve them.
304N/A load_prototype_header(tmp_reg, obj_reg);
304N/A orq(tmp_reg, r15_thread);
304N/A if (os::is_MP()) {
304N/A lock();
304N/A }
304N/A cmpxchgq(tmp_reg, Address(obj_reg, 0));
304N/A // If the biasing toward our thread failed, then another thread
304N/A // succeeded in biasing it toward itself and we need to revoke that
304N/A // bias. The revocation will occur in the runtime in the slow case.
304N/A if (counters != NULL) {
304N/A cond_inc32(Assembler::zero,
304N/A ExternalAddress((address) counters->rebiased_lock_entry_count_addr()));
304N/A }
304N/A if (slow_case != NULL) {
304N/A jcc(Assembler::notZero, *slow_case);
0N/A }
0N/A jmp(done);
0N/A
304N/A bind(try_revoke_bias);
304N/A // The prototype mark in the klass doesn't have the bias bit set any
304N/A // more, indicating that objects of this data type are not supposed
304N/A // to be biased any more. We are going to try to reset the mark of
304N/A // this object to the prototype value and fall through to the
304N/A // CAS-based locking scheme. Note that if our CAS fails, it means
304N/A // that another thread raced us for the privilege of revoking the
304N/A // bias of this particular object, so it's okay to continue in the
304N/A // normal locking code.
304N/A //
304N/A // FIXME: due to a lack of registers we currently blow away the age
304N/A // bits in this situation. Should attempt to preserve them.
304N/A load_prototype_header(tmp_reg, obj_reg);
304N/A if (os::is_MP()) {
304N/A lock();
304N/A }
304N/A cmpxchgq(tmp_reg, Address(obj_reg, 0));
304N/A // Fall through to the normal CAS-based lock, because no matter what
304N/A // the result of the above CAS, some thread must have succeeded in
304N/A // removing the bias bit from the object's header.
304N/A if (counters != NULL) {
304N/A cond_inc32(Assembler::zero,
304N/A ExternalAddress((address) counters->revoked_lock_entry_count_addr()));
304N/A }
304N/A
304N/A bind(cas_label);
304N/A
304N/A return null_check_offset;
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM_leaf_base(address entry_point, int num_args) {
304N/A Label L, E;
304N/A
304N/A#ifdef _WIN64
304N/A // Windows always allocates space for it's register args
304N/A assert(num_args <= 4, "only register arguments supported");
304N/A subq(rsp, frame::arg_reg_save_area_bytes);
304N/A#endif
304N/A
304N/A // Align stack if necessary
304N/A testl(rsp, 15);
304N/A jcc(Assembler::zero, L);
304N/A
304N/A subq(rsp, 8);
304N/A {
304N/A call(RuntimeAddress(entry_point));
304N/A }
304N/A addq(rsp, 8);
304N/A jmp(E);
304N/A
304N/A bind(L);
304N/A {
304N/A call(RuntimeAddress(entry_point));
304N/A }
304N/A
304N/A bind(E);
304N/A
304N/A#ifdef _WIN64
304N/A // restore stack pointer
304N/A addq(rsp, frame::arg_reg_save_area_bytes);
304N/A#endif
304N/A
304N/A}
304N/A
304N/Avoid MacroAssembler::cmp64(Register src1, AddressLiteral src2) {
304N/A assert(!src2.is_lval(), "should use cmpptr");
304N/A
304N/A if (reachable(src2)) {
304N/A cmpq(src1, as_Address(src2));
304N/A } else {
304N/A lea(rscratch1, src2);
304N/A Assembler::cmpq(src1, Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Aint MacroAssembler::corrected_idivq(Register reg) {
304N/A // Full implementation of Java ldiv and lrem; checks for special
304N/A // case as described in JVM spec., p.243 & p.271. The function
304N/A // returns the (pc) offset of the idivl instruction - may be needed
304N/A // for implicit exceptions.
304N/A //
304N/A // normal case special case
304N/A //
304N/A // input : rax: dividend min_long
304N/A // reg: divisor (may not be eax/edx) -1
304N/A //
304N/A // output: rax: quotient (= rax idiv reg) min_long
304N/A // rdx: remainder (= rax irem reg) 0
304N/A assert(reg != rax && reg != rdx, "reg cannot be rax or rdx register");
304N/A static const int64_t min_long = 0x8000000000000000;
304N/A Label normal_case, special_case;
304N/A
304N/A // check for special case
304N/A cmp64(rax, ExternalAddress((address) &min_long));
304N/A jcc(Assembler::notEqual, normal_case);
304N/A xorl(rdx, rdx); // prepare rdx for possible special case (where
304N/A // remainder = 0)
304N/A cmpq(reg, -1);
304N/A jcc(Assembler::equal, special_case);
304N/A
304N/A // handle normal case
304N/A bind(normal_case);
304N/A cdqq();
304N/A int idivq_offset = offset();
304N/A idivq(reg);
304N/A
304N/A // normal and special case exit
304N/A bind(special_case);
304N/A
304N/A return idivq_offset;
304N/A}
304N/A
304N/Avoid MacroAssembler::decrementq(Register reg, int value) {
304N/A if (value == min_jint) { subq(reg, value); return; }
304N/A if (value < 0) { incrementq(reg, -value); return; }
304N/A if (value == 0) { ; return; }
304N/A if (value == 1 && UseIncDec) { decq(reg) ; return; }
304N/A /* else */ { subq(reg, value) ; return; }
304N/A}
304N/A
304N/Avoid MacroAssembler::decrementq(Address dst, int value) {
304N/A if (value == min_jint) { subq(dst, value); return; }
304N/A if (value < 0) { incrementq(dst, -value); return; }
304N/A if (value == 0) { ; return; }
304N/A if (value == 1 && UseIncDec) { decq(dst) ; return; }
304N/A /* else */ { subq(dst, value) ; return; }
304N/A}
304N/A
304N/Avoid MacroAssembler::fat_nop() {
304N/A // A 5 byte nop that is safe for patching (see patch_verified_entry)
304N/A // Recommened sequence from 'Software Optimization Guide for the AMD
304N/A // Hammer Processor'
304N/A emit_byte(0x66);
304N/A emit_byte(0x66);
304N/A emit_byte(0x90);
304N/A emit_byte(0x66);
304N/A emit_byte(0x90);
304N/A}
304N/A
304N/Avoid MacroAssembler::incrementq(Register reg, int value) {
304N/A if (value == min_jint) { addq(reg, value); return; }
304N/A if (value < 0) { decrementq(reg, -value); return; }
304N/A if (value == 0) { ; return; }
304N/A if (value == 1 && UseIncDec) { incq(reg) ; return; }
304N/A /* else */ { addq(reg, value) ; return; }
304N/A}
304N/A
304N/Avoid MacroAssembler::incrementq(Address dst, int value) {
304N/A if (value == min_jint) { addq(dst, value); return; }
304N/A if (value < 0) { decrementq(dst, -value); return; }
304N/A if (value == 0) { ; return; }
304N/A if (value == 1 && UseIncDec) { incq(dst) ; return; }
304N/A /* else */ { addq(dst, value) ; return; }
304N/A}
304N/A
304N/A// 32bit can do a case table jump in one instruction but we no longer allow the base
304N/A// to be installed in the Address class
304N/Avoid MacroAssembler::jump(ArrayAddress entry) {
304N/A lea(rscratch1, entry.base());
304N/A Address dispatch = entry.index();
304N/A assert(dispatch._base == noreg, "must be");
304N/A dispatch._base = rscratch1;
304N/A jmp(dispatch);
304N/A}
304N/A
304N/Avoid MacroAssembler::lcmp2int(Register x_hi, Register x_lo, Register y_hi, Register y_lo) {
304N/A ShouldNotReachHere(); // 64bit doesn't use two regs
304N/A cmpq(x_lo, y_lo);
304N/A}
304N/A
304N/Avoid MacroAssembler::lea(Register dst, AddressLiteral src) {
304N/A mov_literal64(dst, (intptr_t)src.target(), src.rspec());
304N/A}
304N/A
304N/Avoid MacroAssembler::lea(Address dst, AddressLiteral adr) {
304N/A mov_literal64(rscratch1, (intptr_t)adr.target(), adr.rspec());
304N/A movptr(dst, rscratch1);
304N/A}
304N/A
304N/Avoid MacroAssembler::leave() {
304N/A // %%% is this really better? Why not on 32bit too?
304N/A emit_byte(0xC9); // LEAVE
304N/A}
304N/A
304N/Avoid MacroAssembler::lneg(Register hi, Register lo) {
304N/A ShouldNotReachHere(); // 64bit doesn't use two regs
304N/A negq(lo);
304N/A}
304N/A
304N/Avoid MacroAssembler::movoop(Register dst, jobject obj) {
304N/A mov_literal64(dst, (intptr_t)obj, oop_Relocation::spec_for_immediate());
304N/A}
304N/A
304N/Avoid MacroAssembler::movoop(Address dst, jobject obj) {
304N/A mov_literal64(rscratch1, (intptr_t)obj, oop_Relocation::spec_for_immediate());
304N/A movq(dst, rscratch1);
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(Register dst, AddressLiteral src) {
304N/A if (src.is_lval()) {
304N/A mov_literal64(dst, (intptr_t)src.target(), src.rspec());
304N/A } else {
304N/A if (reachable(src)) {
304N/A movq(dst, as_Address(src));
304N/A } else {
304N/A lea(rscratch1, src);
304N/A movq(dst, Address(rscratch1,0));
0N/A }
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(ArrayAddress dst, Register src) {
304N/A movq(as_Address(dst), src);
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(Register dst, ArrayAddress src) {
304N/A movq(dst, as_Address(src));
304N/A}
304N/A
304N/A// src should NEVER be a real pointer. Use AddressLiteral for true pointers
304N/Avoid MacroAssembler::movptr(Address dst, intptr_t src) {
304N/A mov64(rscratch1, src);
304N/A movq(dst, rscratch1);
304N/A}
304N/A
304N/A// These are mostly for initializing NULL
304N/Avoid MacroAssembler::movptr(Address dst, int32_t src) {
304N/A movslq(dst, src);
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(Register dst, int32_t src) {
304N/A mov64(dst, (intptr_t)src);
304N/A}
304N/A
304N/Avoid MacroAssembler::pushoop(jobject obj) {
304N/A movoop(rscratch1, obj);
304N/A push(rscratch1);
304N/A}
304N/A
304N/Avoid MacroAssembler::pushptr(AddressLiteral src) {
304N/A lea(rscratch1, src);
304N/A if (src.is_lval()) {
304N/A push(rscratch1);
304N/A } else {
304N/A pushq(Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::reset_last_Java_frame(bool clear_fp,
304N/A bool clear_pc) {
304N/A // we must set sp to zero to clear frame
512N/A movptr(Address(r15_thread, JavaThread::last_Java_sp_offset()), NULL_WORD);
304N/A // must clear fp, so that compiled frames are not confused; it is
304N/A // possible that we need it only for debugging
304N/A if (clear_fp) {
512N/A movptr(Address(r15_thread, JavaThread::last_Java_fp_offset()), NULL_WORD);
304N/A }
304N/A
304N/A if (clear_pc) {
512N/A movptr(Address(r15_thread, JavaThread::last_Java_pc_offset()), NULL_WORD);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::set_last_Java_frame(Register last_java_sp,
304N/A Register last_java_fp,
304N/A address last_java_pc) {
304N/A // determine last_java_sp register
304N/A if (!last_java_sp->is_valid()) {
304N/A last_java_sp = rsp;
304N/A }
304N/A
304N/A // last_java_fp is optional
304N/A if (last_java_fp->is_valid()) {
304N/A movptr(Address(r15_thread, JavaThread::last_Java_fp_offset()),
304N/A last_java_fp);
304N/A }
304N/A
304N/A // last_java_pc is optional
304N/A if (last_java_pc != NULL) {
304N/A Address java_pc(r15_thread,
304N/A JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset());
304N/A lea(rscratch1, InternalAddress(last_java_pc));
304N/A movptr(java_pc, rscratch1);
304N/A }
304N/A
304N/A movptr(Address(r15_thread, JavaThread::last_Java_sp_offset()), last_java_sp);
304N/A}
304N/A
304N/Astatic void pass_arg0(MacroAssembler* masm, Register arg) {
304N/A if (c_rarg0 != arg ) {
304N/A masm->mov(c_rarg0, arg);
304N/A }
304N/A}
304N/A
304N/Astatic void pass_arg1(MacroAssembler* masm, Register arg) {
304N/A if (c_rarg1 != arg ) {
304N/A masm->mov(c_rarg1, arg);
304N/A }
304N/A}
304N/A
304N/Astatic void pass_arg2(MacroAssembler* masm, Register arg) {
304N/A if (c_rarg2 != arg ) {
304N/A masm->mov(c_rarg2, arg);
304N/A }
304N/A}
304N/A
304N/Astatic void pass_arg3(MacroAssembler* masm, Register arg) {
304N/A if (c_rarg3 != arg ) {
304N/A masm->mov(c_rarg3, arg);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::stop(const char* msg) {
304N/A address rip = pc();
304N/A pusha(); // get regs on stack
304N/A lea(c_rarg0, ExternalAddress((address) msg));
304N/A lea(c_rarg1, InternalAddress(rip));
304N/A movq(c_rarg2, rsp); // pass pointer to regs array
304N/A andq(rsp, -16); // align stack as required by ABI
304N/A call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug64)));
304N/A hlt();
304N/A}
304N/A
304N/Avoid MacroAssembler::warn(const char* msg) {
304N/A push(r12);
304N/A movq(r12, rsp);
304N/A andq(rsp, -16); // align stack as required by push_CPU_state and call
304N/A
304N/A push_CPU_state(); // keeps alignment at 16 bytes
304N/A lea(c_rarg0, ExternalAddress((address) msg));
304N/A call_VM_leaf(CAST_FROM_FN_PTR(address, warning), c_rarg0);
304N/A pop_CPU_state();
304N/A
304N/A movq(rsp, r12);
304N/A pop(r12);
304N/A}
304N/A
304N/A#ifndef PRODUCT
304N/Aextern "C" void findpc(intptr_t x);
304N/A#endif
304N/A
304N/Avoid MacroAssembler::debug64(char* msg, int64_t pc, int64_t regs[]) {
304N/A // In order to get locks to work, we need to fake a in_VM state
304N/A if (ShowMessageBoxOnError ) {
304N/A JavaThread* thread = JavaThread::current();
304N/A JavaThreadState saved_state = thread->thread_state();
304N/A thread->set_thread_state(_thread_in_vm);
304N/A#ifndef PRODUCT
304N/A if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
304N/A ttyLocker ttyl;
304N/A BytecodeCounter::print();
0N/A }
304N/A#endif
304N/A // To see where a verify_oop failed, get $ebx+40/X for this frame.
304N/A // XXX correct this offset for amd64
304N/A // This is the value of eip which points to where verify_oop will return.
304N/A if (os::message_box(msg, "Execution stopped, print registers?")) {
304N/A ttyLocker ttyl;
304N/A tty->print_cr("rip = 0x%016lx", pc);
304N/A#ifndef PRODUCT
304N/A tty->cr();
304N/A findpc(pc);
304N/A tty->cr();
304N/A#endif
304N/A tty->print_cr("rax = 0x%016lx", regs[15]);
304N/A tty->print_cr("rbx = 0x%016lx", regs[12]);
304N/A tty->print_cr("rcx = 0x%016lx", regs[14]);
304N/A tty->print_cr("rdx = 0x%016lx", regs[13]);
304N/A tty->print_cr("rdi = 0x%016lx", regs[8]);
304N/A tty->print_cr("rsi = 0x%016lx", regs[9]);
304N/A tty->print_cr("rbp = 0x%016lx", regs[10]);
304N/A tty->print_cr("rsp = 0x%016lx", regs[11]);
304N/A tty->print_cr("r8 = 0x%016lx", regs[7]);
304N/A tty->print_cr("r9 = 0x%016lx", regs[6]);
304N/A tty->print_cr("r10 = 0x%016lx", regs[5]);
304N/A tty->print_cr("r11 = 0x%016lx", regs[4]);
304N/A tty->print_cr("r12 = 0x%016lx", regs[3]);
304N/A tty->print_cr("r13 = 0x%016lx", regs[2]);
304N/A tty->print_cr("r14 = 0x%016lx", regs[1]);
304N/A tty->print_cr("r15 = 0x%016lx", regs[0]);
304N/A BREAKPOINT;
0N/A }
304N/A ThreadStateTransition::transition(thread, _thread_in_vm, saved_state);
304N/A } else {
304N/A ttyLocker ttyl;
304N/A ::tty->print_cr("=============== DEBUG MESSAGE: %s ================\n",
304N/A msg);
304N/A }
304N/A}
304N/A
304N/A#endif // _LP64
304N/A
304N/A// Now versions that are common to 32/64 bit
304N/A
304N/Avoid MacroAssembler::addptr(Register dst, int32_t imm32) {
304N/A LP64_ONLY(addq(dst, imm32)) NOT_LP64(addl(dst, imm32));
304N/A}
304N/A
304N/Avoid MacroAssembler::addptr(Register dst, Register src) {
304N/A LP64_ONLY(addq(dst, src)) NOT_LP64(addl(dst, src));
304N/A}
304N/A
304N/Avoid MacroAssembler::addptr(Address dst, Register src) {
304N/A LP64_ONLY(addq(dst, src)) NOT_LP64(addl(dst, src));
304N/A}
304N/A
304N/Avoid MacroAssembler::align(int modulus) {
304N/A if (offset() % modulus != 0) {
304N/A nop(modulus - (offset() % modulus));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::andpd(XMMRegister dst, AddressLiteral src) {
304N/A andpd(dst, as_Address(src));
304N/A}
304N/A
304N/Avoid MacroAssembler::andptr(Register dst, int32_t imm32) {
304N/A LP64_ONLY(andq(dst, imm32)) NOT_LP64(andl(dst, imm32));
304N/A}
304N/A
304N/Avoid MacroAssembler::atomic_incl(AddressLiteral counter_addr) {
304N/A pushf();
304N/A if (os::is_MP())
304N/A lock();
304N/A incrementl(counter_addr);
304N/A popf();
304N/A}
304N/A
304N/A// Writes to stack successive pages until offset reached to check for
304N/A// stack overflow + shadow pages. This clobbers tmp.
304N/Avoid MacroAssembler::bang_stack_size(Register size, Register tmp) {
304N/A movptr(tmp, rsp);
304N/A // Bang stack for total size given plus shadow page size.
304N/A // Bang one page at a time because large size can bang beyond yellow and
304N/A // red zones.
304N/A Label loop;
304N/A bind(loop);
304N/A movl(Address(tmp, (-os::vm_page_size())), size );
304N/A subptr(tmp, os::vm_page_size());
304N/A subl(size, os::vm_page_size());
304N/A jcc(Assembler::greater, loop);
304N/A
304N/A // Bang down shadow pages too.
304N/A // The -1 because we already subtracted 1 page.
304N/A for (int i = 0; i< StackShadowPages-1; i++) {
304N/A // this could be any sized move but this is can be a debugging crumb
304N/A // so the bigger the better.
304N/A movptr(Address(tmp, (-i*os::vm_page_size())), size );
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::biased_locking_exit(Register obj_reg, Register temp_reg, Label& done) {
304N/A assert(UseBiasedLocking, "why call this otherwise?");
304N/A
304N/A // Check for biased locking unlock case, which is a no-op
304N/A // Note: we do not have to check the thread ID for two reasons.
304N/A // First, the interpreter checks for IllegalMonitorStateException at
304N/A // a higher level. Second, if the bias was revoked while we held the
304N/A // lock, the object could not be rebiased toward another thread, so
304N/A // the bias bit would be clear.
304N/A movptr(temp_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
304N/A andptr(temp_reg, markOopDesc::biased_lock_mask_in_place);
304N/A cmpptr(temp_reg, markOopDesc::biased_lock_pattern);
304N/A jcc(Assembler::equal, done);
304N/A}
304N/A
304N/Avoid MacroAssembler::c2bool(Register x) {
304N/A // implements x == 0 ? 0 : 1
304N/A // note: must only look at least-significant byte of x
304N/A // since C-style booleans are stored in one byte
304N/A // only! (was bug)
304N/A andl(x, 0xFF);
304N/A setb(Assembler::notZero, x);
304N/A}
304N/A
304N/A// Wouldn't need if AddressLiteral version had new name
304N/Avoid MacroAssembler::call(Label& L, relocInfo::relocType rtype) {
304N/A Assembler::call(L, rtype);
304N/A}
304N/A
304N/Avoid MacroAssembler::call(Register entry) {
304N/A Assembler::call(entry);
304N/A}
304N/A
304N/Avoid MacroAssembler::call(AddressLiteral entry) {
304N/A if (reachable(entry)) {
304N/A Assembler::call_literal(entry.target(), entry.rspec());
304N/A } else {
304N/A lea(rscratch1, entry);
304N/A Assembler::call(rscratch1);
304N/A }
304N/A}
304N/A
304N/A// Implementation of call_VM versions
304N/A
304N/Avoid MacroAssembler::call_VM(Register oop_result,
304N/A address entry_point,
304N/A bool check_exceptions) {
304N/A Label C, E;
304N/A call(C, relocInfo::none);
304N/A jmp(E);
304N/A
304N/A bind(C);
304N/A call_VM_helper(oop_result, entry_point, 0, check_exceptions);
304N/A ret(0);
304N/A
304N/A bind(E);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM(Register oop_result,
304N/A address entry_point,
304N/A Register arg_1,
304N/A bool check_exceptions) {
304N/A Label C, E;
304N/A call(C, relocInfo::none);
304N/A jmp(E);
304N/A
304N/A bind(C);
304N/A pass_arg1(this, arg_1);
304N/A call_VM_helper(oop_result, entry_point, 1, check_exceptions);
304N/A ret(0);
304N/A
304N/A bind(E);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM(Register oop_result,
304N/A address entry_point,
304N/A Register arg_1,
304N/A Register arg_2,
304N/A bool check_exceptions) {
304N/A Label C, E;
304N/A call(C, relocInfo::none);
304N/A jmp(E);
304N/A
304N/A bind(C);
304N/A
304N/A LP64_ONLY(assert(arg_1 != c_rarg2, "smashed arg"));
304N/A
304N/A pass_arg2(this, arg_2);
304N/A pass_arg1(this, arg_1);
304N/A call_VM_helper(oop_result, entry_point, 2, check_exceptions);
304N/A ret(0);
304N/A
304N/A bind(E);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM(Register oop_result,
304N/A address entry_point,
304N/A Register arg_1,
304N/A Register arg_2,
304N/A Register arg_3,
304N/A bool check_exceptions) {
304N/A Label C, E;
304N/A call(C, relocInfo::none);
304N/A jmp(E);
304N/A
304N/A bind(C);
304N/A
304N/A LP64_ONLY(assert(arg_1 != c_rarg3, "smashed arg"));
304N/A LP64_ONLY(assert(arg_2 != c_rarg3, "smashed arg"));
304N/A pass_arg3(this, arg_3);
304N/A
304N/A LP64_ONLY(assert(arg_1 != c_rarg2, "smashed arg"));
304N/A pass_arg2(this, arg_2);
304N/A
304N/A pass_arg1(this, arg_1);
304N/A call_VM_helper(oop_result, entry_point, 3, check_exceptions);
304N/A ret(0);
304N/A
304N/A bind(E);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM(Register oop_result,
304N/A Register last_java_sp,
304N/A address entry_point,
304N/A int number_of_arguments,
304N/A bool check_exceptions) {
304N/A Register thread = LP64_ONLY(r15_thread) NOT_LP64(noreg);
304N/A call_VM_base(oop_result, thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM(Register oop_result,
304N/A Register last_java_sp,
304N/A address entry_point,
304N/A Register arg_1,
304N/A bool check_exceptions) {
304N/A pass_arg1(this, arg_1);
304N/A call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM(Register oop_result,
304N/A Register last_java_sp,
304N/A address entry_point,
304N/A Register arg_1,
304N/A Register arg_2,
304N/A bool check_exceptions) {
304N/A
304N/A LP64_ONLY(assert(arg_1 != c_rarg2, "smashed arg"));
304N/A pass_arg2(this, arg_2);
304N/A pass_arg1(this, arg_1);
304N/A call_VM(oop_result, last_java_sp, entry_point, 2, check_exceptions);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM(Register oop_result,
304N/A Register last_java_sp,
304N/A address entry_point,
304N/A Register arg_1,
304N/A Register arg_2,
304N/A Register arg_3,
304N/A bool check_exceptions) {
304N/A LP64_ONLY(assert(arg_1 != c_rarg3, "smashed arg"));
304N/A LP64_ONLY(assert(arg_2 != c_rarg3, "smashed arg"));
304N/A pass_arg3(this, arg_3);
304N/A LP64_ONLY(assert(arg_1 != c_rarg2, "smashed arg"));
304N/A pass_arg2(this, arg_2);
304N/A pass_arg1(this, arg_1);
304N/A call_VM(oop_result, last_java_sp, entry_point, 3, check_exceptions);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM_base(Register oop_result,
304N/A Register java_thread,
304N/A Register last_java_sp,
304N/A address entry_point,
304N/A int number_of_arguments,
304N/A bool check_exceptions) {
304N/A // determine java_thread register
304N/A if (!java_thread->is_valid()) {
304N/A#ifdef _LP64
304N/A java_thread = r15_thread;
304N/A#else
304N/A java_thread = rdi;
304N/A get_thread(java_thread);
304N/A#endif // LP64
304N/A }
304N/A // determine last_java_sp register
304N/A if (!last_java_sp->is_valid()) {
304N/A last_java_sp = rsp;
304N/A }
304N/A // debugging support
304N/A assert(number_of_arguments >= 0 , "cannot have negative number of arguments");
304N/A LP64_ONLY(assert(java_thread == r15_thread, "unexpected register"));
304N/A assert(java_thread != oop_result , "cannot use the same register for java_thread & oop_result");
304N/A assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp");
304N/A
304N/A // push java thread (becomes first argument of C function)
304N/A
304N/A NOT_LP64(push(java_thread); number_of_arguments++);
304N/A LP64_ONLY(mov(c_rarg0, r15_thread));
304N/A
304N/A // set last Java frame before call
304N/A assert(last_java_sp != rbp, "can't use ebp/rbp");
304N/A
304N/A // Only interpreter should have to set fp
304N/A set_last_Java_frame(java_thread, last_java_sp, rbp, NULL);
304N/A
304N/A // do the call, remove parameters
304N/A MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
304N/A
304N/A // restore the thread (cannot use the pushed argument since arguments
304N/A // may be overwritten by C code generated by an optimizing compiler);
304N/A // however can use the register value directly if it is callee saved.
304N/A if (LP64_ONLY(true ||) java_thread == rdi || java_thread == rsi) {
304N/A // rdi & rsi (also r15) are callee saved -> nothing to do
304N/A#ifdef ASSERT
304N/A guarantee(java_thread != rax, "change this code");
304N/A push(rax);
304N/A { Label L;
304N/A get_thread(rax);
304N/A cmpptr(java_thread, rax);
304N/A jcc(Assembler::equal, L);
304N/A stop("MacroAssembler::call_VM_base: rdi not callee saved?");
304N/A bind(L);
0N/A }
304N/A pop(rax);
304N/A#endif
304N/A } else {
304N/A get_thread(java_thread);
304N/A }
304N/A // reset last Java frame
304N/A // Only interpreter should have to clear fp
304N/A reset_last_Java_frame(java_thread, true, false);
304N/A
304N/A#ifndef CC_INTERP
304N/A // C++ interp handles this in the interpreter
304N/A check_and_handle_popframe(java_thread);
304N/A check_and_handle_earlyret(java_thread);
304N/A#endif /* CC_INTERP */
304N/A
304N/A if (check_exceptions) {
304N/A // check for pending exceptions (java_thread is set upon return)
304N/A cmpptr(Address(java_thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD);
304N/A#ifndef _LP64
304N/A jump_cc(Assembler::notEqual,
304N/A RuntimeAddress(StubRoutines::forward_exception_entry()));
304N/A#else
304N/A // This used to conditionally jump to forward_exception however it is
304N/A // possible if we relocate that the branch will not reach. So we must jump
304N/A // around so we can always reach
304N/A
304N/A Label ok;
304N/A jcc(Assembler::equal, ok);
304N/A jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
304N/A bind(ok);
304N/A#endif // LP64
304N/A }
304N/A
304N/A // get oop result if there is one and reset the value in the thread
304N/A if (oop_result->is_valid()) {
304N/A movptr(oop_result, Address(java_thread, JavaThread::vm_result_offset()));
512N/A movptr(Address(java_thread, JavaThread::vm_result_offset()), NULL_WORD);
304N/A verify_oop(oop_result, "broken oop in call_VM_base");
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
304N/A
304N/A // Calculate the value for last_Java_sp
304N/A // somewhat subtle. call_VM does an intermediate call
304N/A // which places a return address on the stack just under the
304N/A // stack pointer as the user finsihed with it. This allows
304N/A // use to retrieve last_Java_pc from last_Java_sp[-1].
304N/A // On 32bit we then have to push additional args on the stack to accomplish
304N/A // the actual requested call. On 64bit call_VM only can use register args
304N/A // so the only extra space is the return address that call_VM created.
304N/A // This hopefully explains the calculations here.
304N/A
304N/A#ifdef _LP64
304N/A // We've pushed one address, correct last_Java_sp
304N/A lea(rax, Address(rsp, wordSize));
304N/A#else
304N/A lea(rax, Address(rsp, (1 + number_of_arguments) * wordSize));
304N/A#endif // LP64
304N/A
304N/A call_VM_base(oop_result, noreg, rax, entry_point, number_of_arguments, check_exceptions);
304N/A
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM_leaf(address entry_point, int number_of_arguments) {
304N/A call_VM_leaf_base(entry_point, number_of_arguments);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM_leaf(address entry_point, Register arg_0) {
304N/A pass_arg0(this, arg_0);
304N/A call_VM_leaf(entry_point, 1);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1) {
304N/A
304N/A LP64_ONLY(assert(arg_0 != c_rarg1, "smashed arg"));
304N/A pass_arg1(this, arg_1);
304N/A pass_arg0(this, arg_0);
304N/A call_VM_leaf(entry_point, 2);
304N/A}
304N/A
304N/Avoid MacroAssembler::call_VM_leaf(address entry_point, Register arg_0, Register arg_1, Register arg_2) {
304N/A LP64_ONLY(assert(arg_0 != c_rarg2, "smashed arg"));
304N/A LP64_ONLY(assert(arg_1 != c_rarg2, "smashed arg"));
304N/A pass_arg2(this, arg_2);
304N/A LP64_ONLY(assert(arg_0 != c_rarg1, "smashed arg"));
304N/A pass_arg1(this, arg_1);
304N/A pass_arg0(this, arg_0);
304N/A call_VM_leaf(entry_point, 3);
304N/A}
304N/A
304N/Avoid MacroAssembler::check_and_handle_earlyret(Register java_thread) {
304N/A}
304N/A
304N/Avoid MacroAssembler::check_and_handle_popframe(Register java_thread) {
304N/A}
304N/A
304N/Avoid MacroAssembler::cmp32(AddressLiteral src1, int32_t imm) {
304N/A if (reachable(src1)) {
304N/A cmpl(as_Address(src1), imm);
304N/A } else {
304N/A lea(rscratch1, src1);
304N/A cmpl(Address(rscratch1, 0), imm);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::cmp32(Register src1, AddressLiteral src2) {
304N/A assert(!src2.is_lval(), "use cmpptr");
304N/A if (reachable(src2)) {
304N/A cmpl(src1, as_Address(src2));
304N/A } else {
304N/A lea(rscratch1, src2);
304N/A cmpl(src1, Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::cmp32(Register src1, int32_t imm) {
304N/A Assembler::cmpl(src1, imm);
304N/A}
304N/A
304N/Avoid MacroAssembler::cmp32(Register src1, Address src2) {
304N/A Assembler::cmpl(src1, src2);
304N/A}
304N/A
304N/Avoid MacroAssembler::cmpsd2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less) {
304N/A ucomisd(opr1, opr2);
304N/A
304N/A Label L;
304N/A if (unordered_is_less) {
304N/A movl(dst, -1);
304N/A jcc(Assembler::parity, L);
304N/A jcc(Assembler::below , L);
304N/A movl(dst, 0);
304N/A jcc(Assembler::equal , L);
304N/A increment(dst);
304N/A } else { // unordered is greater
304N/A movl(dst, 1);
304N/A jcc(Assembler::parity, L);
304N/A jcc(Assembler::above , L);
304N/A movl(dst, 0);
304N/A jcc(Assembler::equal , L);
304N/A decrementl(dst);
304N/A }
304N/A bind(L);
304N/A}
304N/A
304N/Avoid MacroAssembler::cmpss2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less) {
304N/A ucomiss(opr1, opr2);
304N/A
304N/A Label L;
304N/A if (unordered_is_less) {
304N/A movl(dst, -1);
304N/A jcc(Assembler::parity, L);
304N/A jcc(Assembler::below , L);
304N/A movl(dst, 0);
304N/A jcc(Assembler::equal , L);
304N/A increment(dst);
304N/A } else { // unordered is greater
304N/A movl(dst, 1);
304N/A jcc(Assembler::parity, L);
304N/A jcc(Assembler::above , L);
304N/A movl(dst, 0);
304N/A jcc(Assembler::equal , L);
304N/A decrementl(dst);
304N/A }
304N/A bind(L);
304N/A}
304N/A
304N/A
304N/Avoid MacroAssembler::cmp8(AddressLiteral src1, int imm) {
304N/A if (reachable(src1)) {
304N/A cmpb(as_Address(src1), imm);
304N/A } else {
304N/A lea(rscratch1, src1);
304N/A cmpb(Address(rscratch1, 0), imm);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::cmpptr(Register src1, AddressLiteral src2) {
304N/A#ifdef _LP64
304N/A if (src2.is_lval()) {
304N/A movptr(rscratch1, src2);
304N/A Assembler::cmpq(src1, rscratch1);
304N/A } else if (reachable(src2)) {
304N/A cmpq(src1, as_Address(src2));
304N/A } else {
304N/A lea(rscratch1, src2);
304N/A Assembler::cmpq(src1, Address(rscratch1, 0));
304N/A }
304N/A#else
304N/A if (src2.is_lval()) {
304N/A cmp_literal32(src1, (int32_t) src2.target(), src2.rspec());
304N/A } else {
304N/A cmpl(src1, as_Address(src2));
304N/A }
304N/A#endif // _LP64
304N/A}
304N/A
304N/Avoid MacroAssembler::cmpptr(Address src1, AddressLiteral src2) {
304N/A assert(src2.is_lval(), "not a mem-mem compare");
304N/A#ifdef _LP64
304N/A // moves src2's literal address
304N/A movptr(rscratch1, src2);
304N/A Assembler::cmpq(src1, rscratch1);
304N/A#else
304N/A cmp_literal32(src1, (int32_t) src2.target(), src2.rspec());
304N/A#endif // _LP64
304N/A}
304N/A
304N/Avoid MacroAssembler::locked_cmpxchgptr(Register reg, AddressLiteral adr) {
304N/A if (reachable(adr)) {
304N/A if (os::is_MP())
304N/A lock();
304N/A cmpxchgptr(reg, as_Address(adr));
304N/A } else {
304N/A lea(rscratch1, adr);
304N/A if (os::is_MP())
304N/A lock();
304N/A cmpxchgptr(reg, Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::cmpxchgptr(Register reg, Address adr) {
304N/A LP64_ONLY(cmpxchgq(reg, adr)) NOT_LP64(cmpxchgl(reg, adr));
304N/A}
304N/A
304N/Avoid MacroAssembler::comisd(XMMRegister dst, AddressLiteral src) {
304N/A comisd(dst, as_Address(src));
304N/A}
304N/A
304N/Avoid MacroAssembler::comiss(XMMRegister dst, AddressLiteral src) {
304N/A comiss(dst, as_Address(src));
304N/A}
304N/A
304N/A
304N/Avoid MacroAssembler::cond_inc32(Condition cond, AddressLiteral counter_addr) {
304N/A Condition negated_cond = negate_condition(cond);
304N/A Label L;
304N/A jcc(negated_cond, L);
304N/A atomic_incl(counter_addr);
304N/A bind(L);
304N/A}
304N/A
304N/Aint MacroAssembler::corrected_idivl(Register reg) {
304N/A // Full implementation of Java idiv and irem; checks for
304N/A // special case as described in JVM spec., p.243 & p.271.
304N/A // The function returns the (pc) offset of the idivl
304N/A // instruction - may be needed for implicit exceptions.
304N/A //
304N/A // normal case special case
304N/A //
304N/A // input : rax,: dividend min_int
304N/A // reg: divisor (may not be rax,/rdx) -1
304N/A //
304N/A // output: rax,: quotient (= rax, idiv reg) min_int
304N/A // rdx: remainder (= rax, irem reg) 0
304N/A assert(reg != rax && reg != rdx, "reg cannot be rax, or rdx register");
304N/A const int min_int = 0x80000000;
304N/A Label normal_case, special_case;
304N/A
304N/A // check for special case
304N/A cmpl(rax, min_int);
304N/A jcc(Assembler::notEqual, normal_case);
304N/A xorl(rdx, rdx); // prepare rdx for possible special case (where remainder = 0)
304N/A cmpl(reg, -1);
304N/A jcc(Assembler::equal, special_case);
304N/A
304N/A // handle normal case
304N/A bind(normal_case);
304N/A cdql();
304N/A int idivl_offset = offset();
304N/A idivl(reg);
304N/A
304N/A // normal and special case exit
304N/A bind(special_case);
304N/A
304N/A return idivl_offset;
304N/A}
304N/A
304N/A
304N/A
304N/Avoid MacroAssembler::decrementl(Register reg, int value) {
304N/A if (value == min_jint) {subl(reg, value) ; return; }
304N/A if (value < 0) { incrementl(reg, -value); return; }
304N/A if (value == 0) { ; return; }
304N/A if (value == 1 && UseIncDec) { decl(reg) ; return; }
304N/A /* else */ { subl(reg, value) ; return; }
304N/A}
304N/A
304N/Avoid MacroAssembler::decrementl(Address dst, int value) {
304N/A if (value == min_jint) {subl(dst, value) ; return; }
304N/A if (value < 0) { incrementl(dst, -value); return; }
304N/A if (value == 0) { ; return; }
304N/A if (value == 1 && UseIncDec) { decl(dst) ; return; }
304N/A /* else */ { subl(dst, value) ; return; }
304N/A}
304N/A
304N/Avoid MacroAssembler::division_with_shift (Register reg, int shift_value) {
304N/A assert (shift_value > 0, "illegal shift value");
304N/A Label _is_positive;
304N/A testl (reg, reg);
304N/A jcc (Assembler::positive, _is_positive);
304N/A int offset = (1 << shift_value) - 1 ;
304N/A
304N/A if (offset == 1) {
304N/A incrementl(reg);
304N/A } else {
304N/A addl(reg, offset);
304N/A }
304N/A
304N/A bind (_is_positive);
304N/A sarl(reg, shift_value);
304N/A}
304N/A
304N/A// !defined(COMPILER2) is because of stupid core builds
304N/A#if !defined(_LP64) || defined(COMPILER1) || !defined(COMPILER2)
304N/Avoid MacroAssembler::empty_FPU_stack() {
304N/A if (VM_Version::supports_mmx()) {
304N/A emms();
304N/A } else {
304N/A for (int i = 8; i-- > 0; ) ffree(i);
304N/A }
304N/A}
304N/A#endif // !LP64 || C1 || !C2
304N/A
304N/A
304N/A// Defines obj, preserves var_size_in_bytes
304N/Avoid MacroAssembler::eden_allocate(Register obj,
304N/A Register var_size_in_bytes,
304N/A int con_size_in_bytes,
304N/A Register t1,
304N/A Label& slow_case) {
304N/A assert(obj == rax, "obj must be in rax, for cmpxchg");
304N/A assert_different_registers(obj, var_size_in_bytes, t1);
362N/A if (CMSIncrementalMode || !Universe::heap()->supports_inline_contig_alloc()) {
362N/A jmp(slow_case);
304N/A } else {
362N/A Register end = t1;
362N/A Label retry;
362N/A bind(retry);
362N/A ExternalAddress heap_top((address) Universe::heap()->top_addr());
362N/A movptr(obj, heap_top);
362N/A if (var_size_in_bytes == noreg) {
362N/A lea(end, Address(obj, con_size_in_bytes));
362N/A } else {
362N/A lea(end, Address(obj, var_size_in_bytes, Address::times_1));
362N/A }
362N/A // if end < obj then we wrapped around => object too long => slow case
362N/A cmpptr(end, obj);
362N/A jcc(Assembler::below, slow_case);
362N/A cmpptr(end, ExternalAddress((address) Universe::heap()->end_addr()));
362N/A jcc(Assembler::above, slow_case);
362N/A // Compare obj with the top addr, and if still equal, store the new top addr in
362N/A // end at the address of the top addr pointer. Sets ZF if was equal, and clears
362N/A // it otherwise. Use lock prefix for atomicity on MPs.
362N/A locked_cmpxchgptr(end, heap_top);
362N/A jcc(Assembler::notEqual, retry);
362N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::enter() {
304N/A push(rbp);
304N/A mov(rbp, rsp);
304N/A}
0N/A
0N/Avoid MacroAssembler::fcmp(Register tmp) {
0N/A fcmp(tmp, 1, true, true);
0N/A}
0N/A
0N/Avoid MacroAssembler::fcmp(Register tmp, int index, bool pop_left, bool pop_right) {
0N/A assert(!pop_right || pop_left, "usage error");
0N/A if (VM_Version::supports_cmov()) {
0N/A assert(tmp == noreg, "unneeded temp");
0N/A if (pop_left) {
0N/A fucomip(index);
0N/A } else {
0N/A fucomi(index);
0N/A }
0N/A if (pop_right) {
0N/A fpop();
0N/A }
0N/A } else {
0N/A assert(tmp != noreg, "need temp");
0N/A if (pop_left) {
0N/A if (pop_right) {
0N/A fcompp();
0N/A } else {
0N/A fcomp(index);
0N/A }
0N/A } else {
0N/A fcom(index);
0N/A }
0N/A // convert FPU condition into eflags condition via rax,
0N/A save_rax(tmp);
0N/A fwait(); fnstsw_ax();
0N/A sahf();
0N/A restore_rax(tmp);
0N/A }
0N/A // condition codes set as follows:
0N/A //
0N/A // CF (corresponds to C0) if x < y
0N/A // PF (corresponds to C2) if unordered
0N/A // ZF (corresponds to C3) if x = y
0N/A}
0N/A
0N/Avoid MacroAssembler::fcmp2int(Register dst, bool unordered_is_less) {
0N/A fcmp2int(dst, unordered_is_less, 1, true, true);
0N/A}
0N/A
0N/Avoid MacroAssembler::fcmp2int(Register dst, bool unordered_is_less, int index, bool pop_left, bool pop_right) {
0N/A fcmp(VM_Version::supports_cmov() ? noreg : dst, index, pop_left, pop_right);
0N/A Label L;
0N/A if (unordered_is_less) {
0N/A movl(dst, -1);
0N/A jcc(Assembler::parity, L);
0N/A jcc(Assembler::below , L);
0N/A movl(dst, 0);
0N/A jcc(Assembler::equal , L);
0N/A increment(dst);
0N/A } else { // unordered is greater
0N/A movl(dst, 1);
0N/A jcc(Assembler::parity, L);
0N/A jcc(Assembler::above , L);
0N/A movl(dst, 0);
0N/A jcc(Assembler::equal , L);
304N/A decrementl(dst);
0N/A }
0N/A bind(L);
0N/A}
0N/A
304N/Avoid MacroAssembler::fld_d(AddressLiteral src) {
304N/A fld_d(as_Address(src));
304N/A}
304N/A
304N/Avoid MacroAssembler::fld_s(AddressLiteral src) {
304N/A fld_s(as_Address(src));
304N/A}
304N/A
304N/Avoid MacroAssembler::fld_x(AddressLiteral src) {
304N/A Assembler::fld_x(as_Address(src));
304N/A}
304N/A
304N/Avoid MacroAssembler::fldcw(AddressLiteral src) {
304N/A Assembler::fldcw(as_Address(src));
304N/A}
0N/A
0N/Avoid MacroAssembler::fpop() {
0N/A ffree();
0N/A fincstp();
0N/A}
0N/A
304N/Avoid MacroAssembler::fremr(Register tmp) {
304N/A save_rax(tmp);
304N/A { Label L;
304N/A bind(L);
304N/A fprem();
304N/A fwait(); fnstsw_ax();
304N/A#ifdef _LP64
304N/A testl(rax, 0x400);
304N/A jcc(Assembler::notEqual, L);
304N/A#else
304N/A sahf();
304N/A jcc(Assembler::parity, L);
304N/A#endif // _LP64
304N/A }
304N/A restore_rax(tmp);
304N/A // Result is in ST0.
304N/A // Note: fxch & fpop to get rid of ST1
304N/A // (otherwise FPU stack could overflow eventually)
304N/A fxch(1);
304N/A fpop();
304N/A}
304N/A
304N/A
304N/Avoid MacroAssembler::incrementl(AddressLiteral dst) {
304N/A if (reachable(dst)) {
304N/A incrementl(as_Address(dst));
0N/A } else {
304N/A lea(rscratch1, dst);
304N/A incrementl(Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::incrementl(ArrayAddress dst) {
304N/A incrementl(as_Address(dst));
304N/A}
304N/A
304N/Avoid MacroAssembler::incrementl(Register reg, int value) {
304N/A if (value == min_jint) {addl(reg, value) ; return; }
304N/A if (value < 0) { decrementl(reg, -value); return; }
304N/A if (value == 0) { ; return; }
304N/A if (value == 1 && UseIncDec) { incl(reg) ; return; }
304N/A /* else */ { addl(reg, value) ; return; }
304N/A}
304N/A
304N/Avoid MacroAssembler::incrementl(Address dst, int value) {
304N/A if (value == min_jint) {addl(dst, value) ; return; }
304N/A if (value < 0) { decrementl(dst, -value); return; }
304N/A if (value == 0) { ; return; }
304N/A if (value == 1 && UseIncDec) { incl(dst) ; return; }
304N/A /* else */ { addl(dst, value) ; return; }
304N/A}
304N/A
304N/Avoid MacroAssembler::jump(AddressLiteral dst) {
304N/A if (reachable(dst)) {
304N/A jmp_literal(dst.target(), dst.rspec());
304N/A } else {
304N/A lea(rscratch1, dst);
304N/A jmp(rscratch1);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::jump_cc(Condition cc, AddressLiteral dst) {
304N/A if (reachable(dst)) {
304N/A InstructionMark im(this);
304N/A relocate(dst.reloc());
304N/A const int short_size = 2;
304N/A const int long_size = 6;
304N/A int offs = (intptr_t)dst.target() - ((intptr_t)_code_pos);
304N/A if (dst.reloc() == relocInfo::none && is8bit(offs - short_size)) {
304N/A // 0111 tttn #8-bit disp
304N/A emit_byte(0x70 | cc);
304N/A emit_byte((offs - short_size) & 0xFF);
304N/A } else {
304N/A // 0000 1111 1000 tttn #32-bit disp
304N/A emit_byte(0x0F);
304N/A emit_byte(0x80 | cc);
304N/A emit_long(offs - long_size);
304N/A }
0N/A } else {
304N/A#ifdef ASSERT
304N/A warning("reversing conditional branch");
304N/A#endif /* ASSERT */
304N/A Label skip;
304N/A jccb(reverse[cc], skip);
304N/A lea(rscratch1, dst);
304N/A Assembler::jmp(rscratch1);
304N/A bind(skip);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::ldmxcsr(AddressLiteral src) {
304N/A if (reachable(src)) {
304N/A Assembler::ldmxcsr(as_Address(src));
304N/A } else {
304N/A lea(rscratch1, src);
304N/A Assembler::ldmxcsr(Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Aint MacroAssembler::load_signed_byte(Register dst, Address src) {
304N/A int off;
304N/A if (LP64_ONLY(true ||) VM_Version::is_P6()) {
304N/A off = offset();
304N/A movsbl(dst, src); // movsxb
304N/A } else {
304N/A off = load_unsigned_byte(dst, src);
304N/A shll(dst, 24);
304N/A sarl(dst, 24);
304N/A }
304N/A return off;
304N/A}
304N/A
622N/A// Note: load_signed_short used to be called load_signed_word.
622N/A// Although the 'w' in x86 opcodes refers to the term "word" in the assembler
622N/A// manual, which means 16 bits, that usage is found nowhere in HotSpot code.
622N/A// The term "word" in HotSpot means a 32- or 64-bit machine word.
622N/Aint MacroAssembler::load_signed_short(Register dst, Address src) {
304N/A int off;
304N/A if (LP64_ONLY(true ||) VM_Version::is_P6()) {
304N/A // This is dubious to me since it seems safe to do a signed 16 => 64 bit
304N/A // version but this is what 64bit has always done. This seems to imply
304N/A // that users are only using 32bits worth.
304N/A off = offset();
304N/A movswl(dst, src); // movsxw
304N/A } else {
622N/A off = load_unsigned_short(dst, src);
304N/A shll(dst, 16);
304N/A sarl(dst, 16);
304N/A }
304N/A return off;
304N/A}
304N/A
304N/Aint MacroAssembler::load_unsigned_byte(Register dst, Address src) {
304N/A // According to Intel Doc. AP-526, "Zero-Extension of Short", p.16,
304N/A // and "3.9 Partial Register Penalties", p. 22).
304N/A int off;
304N/A if (LP64_ONLY(true || ) VM_Version::is_P6() || src.uses(dst)) {
304N/A off = offset();
304N/A movzbl(dst, src); // movzxb
304N/A } else {
304N/A xorl(dst, dst);
304N/A off = offset();
304N/A movb(dst, src);
304N/A }
304N/A return off;
304N/A}
304N/A
622N/A// Note: load_unsigned_short used to be called load_unsigned_word.
622N/Aint MacroAssembler::load_unsigned_short(Register dst, Address src) {
304N/A // According to Intel Doc. AP-526, "Zero-Extension of Short", p.16,
304N/A // and "3.9 Partial Register Penalties", p. 22).
304N/A int off;
304N/A if (LP64_ONLY(true ||) VM_Version::is_P6() || src.uses(dst)) {
304N/A off = offset();
304N/A movzwl(dst, src); // movzxw
304N/A } else {
304N/A xorl(dst, dst);
304N/A off = offset();
304N/A movw(dst, src);
304N/A }
304N/A return off;
304N/A}
304N/A
622N/Avoid MacroAssembler::load_sized_value(Register dst, Address src,
622N/A int size_in_bytes, bool is_signed) {
622N/A switch (size_in_bytes ^ (is_signed ? -1 : 0)) {
622N/A#ifndef _LP64
622N/A // For case 8, caller is responsible for manually loading
622N/A // the second word into another register.
622N/A case ~8: // fall through:
622N/A case 8: movl( dst, src ); break;
622N/A#else
622N/A case ~8: // fall through:
622N/A case 8: movq( dst, src ); break;
622N/A#endif
622N/A case ~4: // fall through:
622N/A case 4: movl( dst, src ); break;
622N/A case ~2: load_signed_short( dst, src ); break;
622N/A case 2: load_unsigned_short( dst, src ); break;
622N/A case ~1: load_signed_byte( dst, src ); break;
622N/A case 1: load_unsigned_byte( dst, src ); break;
622N/A default: ShouldNotReachHere();
622N/A }
622N/A}
622N/A
304N/Avoid MacroAssembler::mov32(AddressLiteral dst, Register src) {
304N/A if (reachable(dst)) {
304N/A movl(as_Address(dst), src);
304N/A } else {
304N/A lea(rscratch1, dst);
304N/A movl(Address(rscratch1, 0), src);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::mov32(Register dst, AddressLiteral src) {
304N/A if (reachable(src)) {
304N/A movl(dst, as_Address(src));
304N/A } else {
304N/A lea(rscratch1, src);
304N/A movl(dst, Address(rscratch1, 0));
304N/A }
0N/A}
0N/A
0N/A// C++ bool manipulation
0N/A
0N/Avoid MacroAssembler::movbool(Register dst, Address src) {
0N/A if(sizeof(bool) == 1)
0N/A movb(dst, src);
0N/A else if(sizeof(bool) == 2)
0N/A movw(dst, src);
0N/A else if(sizeof(bool) == 4)
0N/A movl(dst, src);
0N/A else
0N/A // unsupported
0N/A ShouldNotReachHere();
0N/A}
0N/A
0N/Avoid MacroAssembler::movbool(Address dst, bool boolconst) {
0N/A if(sizeof(bool) == 1)
0N/A movb(dst, (int) boolconst);
0N/A else if(sizeof(bool) == 2)
0N/A movw(dst, (int) boolconst);
0N/A else if(sizeof(bool) == 4)
0N/A movl(dst, (int) boolconst);
0N/A else
0N/A // unsupported
0N/A ShouldNotReachHere();
0N/A}
0N/A
0N/Avoid MacroAssembler::movbool(Address dst, Register src) {
0N/A if(sizeof(bool) == 1)
0N/A movb(dst, src);
0N/A else if(sizeof(bool) == 2)
0N/A movw(dst, src);
0N/A else if(sizeof(bool) == 4)
0N/A movl(dst, src);
0N/A else
0N/A // unsupported
0N/A ShouldNotReachHere();
0N/A}
0N/A
304N/Avoid MacroAssembler::movbyte(ArrayAddress dst, int src) {
304N/A movb(as_Address(dst), src);
304N/A}
304N/A
304N/Avoid MacroAssembler::movdbl(XMMRegister dst, AddressLiteral src) {
304N/A if (reachable(src)) {
304N/A if (UseXmmLoadAndClearUpper) {
304N/A movsd (dst, as_Address(src));
304N/A } else {
304N/A movlpd(dst, as_Address(src));
304N/A }
304N/A } else {
304N/A lea(rscratch1, src);
304N/A if (UseXmmLoadAndClearUpper) {
304N/A movsd (dst, Address(rscratch1, 0));
304N/A } else {
304N/A movlpd(dst, Address(rscratch1, 0));
304N/A }
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::movflt(XMMRegister dst, AddressLiteral src) {
304N/A if (reachable(src)) {
304N/A movss(dst, as_Address(src));
304N/A } else {
304N/A lea(rscratch1, src);
304N/A movss(dst, Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(Register dst, Register src) {
304N/A LP64_ONLY(movq(dst, src)) NOT_LP64(movl(dst, src));
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(Register dst, Address src) {
304N/A LP64_ONLY(movq(dst, src)) NOT_LP64(movl(dst, src));
304N/A}
304N/A
304N/A// src should NEVER be a real pointer. Use AddressLiteral for true pointers
304N/Avoid MacroAssembler::movptr(Register dst, intptr_t src) {
304N/A LP64_ONLY(mov64(dst, src)) NOT_LP64(movl(dst, src));
304N/A}
304N/A
304N/Avoid MacroAssembler::movptr(Address dst, Register src) {
304N/A LP64_ONLY(movq(dst, src)) NOT_LP64(movl(dst, src));
304N/A}
304N/A
304N/Avoid MacroAssembler::movss(XMMRegister dst, AddressLiteral src) {
304N/A if (reachable(src)) {
304N/A movss(dst, as_Address(src));
304N/A } else {
304N/A lea(rscratch1, src);
304N/A movss(dst, Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::null_check(Register reg, int offset) {
304N/A if (needs_explicit_null_check(offset)) {
304N/A // provoke OS NULL exception if reg = NULL by
304N/A // accessing M[reg] w/o changing any (non-CC) registers
304N/A // NOTE: cmpl is plenty here to provoke a segv
304N/A cmpptr(rax, Address(reg, 0));
304N/A // Note: should probably use testl(rax, Address(reg, 0));
304N/A // may be shorter code (however, this version of
304N/A // testl needs to be implemented first)
304N/A } else {
304N/A // nothing to do, (later) access of M[reg + offset]
304N/A // will provoke OS NULL exception if reg = NULL
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::os_breakpoint() {
304N/A // instead of directly emitting a breakpoint, call os:breakpoint for better debugability
304N/A // (e.g., MSVC can't call ps() otherwise)
304N/A call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
304N/A}
304N/A
304N/Avoid MacroAssembler::pop_CPU_state() {
304N/A pop_FPU_state();
304N/A pop_IU_state();
304N/A}
304N/A
304N/Avoid MacroAssembler::pop_FPU_state() {
304N/A NOT_LP64(frstor(Address(rsp, 0));)
304N/A LP64_ONLY(fxrstor(Address(rsp, 0));)
304N/A addptr(rsp, FPUStateSizeInWords * wordSize);
304N/A}
304N/A
304N/Avoid MacroAssembler::pop_IU_state() {
304N/A popa();
304N/A LP64_ONLY(addq(rsp, 8));
304N/A popf();
304N/A}
304N/A
304N/A// Save Integer and Float state
304N/A// Warning: Stack must be 16 byte aligned (64bit)
304N/Avoid MacroAssembler::push_CPU_state() {
304N/A push_IU_state();
304N/A push_FPU_state();
304N/A}
304N/A
304N/Avoid MacroAssembler::push_FPU_state() {
304N/A subptr(rsp, FPUStateSizeInWords * wordSize);
304N/A#ifndef _LP64
304N/A fnsave(Address(rsp, 0));
304N/A fwait();
304N/A#else
304N/A fxsave(Address(rsp, 0));
304N/A#endif // LP64
304N/A}
304N/A
304N/Avoid MacroAssembler::push_IU_state() {
304N/A // Push flags first because pusha kills them
304N/A pushf();
304N/A // Make sure rsp stays 16-byte aligned
304N/A LP64_ONLY(subq(rsp, 8));
304N/A pusha();
304N/A}
304N/A
304N/Avoid MacroAssembler::reset_last_Java_frame(Register java_thread, bool clear_fp, bool clear_pc) {
304N/A // determine java_thread register
304N/A if (!java_thread->is_valid()) {
304N/A java_thread = rdi;
304N/A get_thread(java_thread);
304N/A }
304N/A // we must set sp to zero to clear frame
512N/A movptr(Address(java_thread, JavaThread::last_Java_sp_offset()), NULL_WORD);
304N/A if (clear_fp) {
512N/A movptr(Address(java_thread, JavaThread::last_Java_fp_offset()), NULL_WORD);
304N/A }
304N/A
304N/A if (clear_pc)
512N/A movptr(Address(java_thread, JavaThread::last_Java_pc_offset()), NULL_WORD);
304N/A
304N/A}
304N/A
304N/Avoid MacroAssembler::restore_rax(Register tmp) {
304N/A if (tmp == noreg) pop(rax);
304N/A else if (tmp != rax) mov(rax, tmp);
304N/A}
304N/A
304N/Avoid MacroAssembler::round_to(Register reg, int modulus) {
304N/A addptr(reg, modulus - 1);
304N/A andptr(reg, -modulus);
304N/A}
304N/A
304N/Avoid MacroAssembler::save_rax(Register tmp) {
304N/A if (tmp == noreg) push(rax);
304N/A else if (tmp != rax) mov(tmp, rax);
304N/A}
304N/A
304N/A// Write serialization page so VM thread can do a pseudo remote membar.
304N/A// We use the current thread pointer to calculate a thread specific
304N/A// offset to write to within the page. This minimizes bus traffic
304N/A// due to cache line collision.
304N/Avoid MacroAssembler::serialize_memory(Register thread, Register tmp) {
304N/A movl(tmp, thread);
304N/A shrl(tmp, os::get_serialize_page_shift_count());
304N/A andl(tmp, (os::vm_page_size() - sizeof(int)));
304N/A
304N/A Address index(noreg, tmp, Address::times_1);
304N/A ExternalAddress page(os::get_memory_serialize_page());
304N/A
606N/A // Size of store must match masking code above
606N/A movl(as_Address(ArrayAddress(page, index)), tmp);
304N/A}
304N/A
304N/A// Calls to C land
304N/A//
304N/A// When entering C land, the rbp, & rsp of the last Java frame have to be recorded
304N/A// in the (thread-local) JavaThread object. When leaving C land, the last Java fp
304N/A// has to be reset to 0. This is required to allow proper stack traversal.
304N/Avoid MacroAssembler::set_last_Java_frame(Register java_thread,
304N/A Register last_java_sp,
304N/A Register last_java_fp,
304N/A address last_java_pc) {
304N/A // determine java_thread register
304N/A if (!java_thread->is_valid()) {
304N/A java_thread = rdi;
304N/A get_thread(java_thread);
304N/A }
304N/A // determine last_java_sp register
304N/A if (!last_java_sp->is_valid()) {
304N/A last_java_sp = rsp;
304N/A }
304N/A
304N/A // last_java_fp is optional
304N/A
304N/A if (last_java_fp->is_valid()) {
304N/A movptr(Address(java_thread, JavaThread::last_Java_fp_offset()), last_java_fp);
304N/A }
304N/A
304N/A // last_java_pc is optional
304N/A
304N/A if (last_java_pc != NULL) {
304N/A lea(Address(java_thread,
304N/A JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()),
304N/A InternalAddress(last_java_pc));
304N/A
304N/A }
304N/A movptr(Address(java_thread, JavaThread::last_Java_sp_offset()), last_java_sp);
304N/A}
304N/A
304N/Avoid MacroAssembler::shlptr(Register dst, int imm8) {
304N/A LP64_ONLY(shlq(dst, imm8)) NOT_LP64(shll(dst, imm8));
304N/A}
304N/A
304N/Avoid MacroAssembler::shrptr(Register dst, int imm8) {
304N/A LP64_ONLY(shrq(dst, imm8)) NOT_LP64(shrl(dst, imm8));
304N/A}
304N/A
304N/Avoid MacroAssembler::sign_extend_byte(Register reg) {
304N/A if (LP64_ONLY(true ||) (VM_Version::is_P6() && reg->has_byte_register())) {
304N/A movsbl(reg, reg); // movsxb
304N/A } else {
304N/A shll(reg, 24);
304N/A sarl(reg, 24);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::sign_extend_short(Register reg) {
304N/A if (LP64_ONLY(true ||) VM_Version::is_P6()) {
304N/A movswl(reg, reg); // movsxw
304N/A } else {
304N/A shll(reg, 16);
304N/A sarl(reg, 16);
304N/A }
304N/A}
304N/A
362N/A//////////////////////////////////////////////////////////////////////////////////
362N/A#ifndef SERIALGC
362N/A
362N/Avoid MacroAssembler::g1_write_barrier_pre(Register obj,
362N/A#ifndef _LP64
362N/A Register thread,
362N/A#endif
362N/A Register tmp,
362N/A Register tmp2,
362N/A bool tosca_live) {
362N/A LP64_ONLY(Register thread = r15_thread;)
362N/A Address in_progress(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
362N/A PtrQueue::byte_offset_of_active()));
362N/A
362N/A Address index(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
362N/A PtrQueue::byte_offset_of_index()));
362N/A Address buffer(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
362N/A PtrQueue::byte_offset_of_buf()));
362N/A
362N/A
362N/A Label done;
362N/A Label runtime;
362N/A
362N/A // if (!marking_in_progress) goto done;
362N/A if (in_bytes(PtrQueue::byte_width_of_active()) == 4) {
362N/A cmpl(in_progress, 0);
362N/A } else {
362N/A assert(in_bytes(PtrQueue::byte_width_of_active()) == 1, "Assumption");
362N/A cmpb(in_progress, 0);
362N/A }
362N/A jcc(Assembler::equal, done);
362N/A
362N/A // if (x.f == NULL) goto done;
845N/A#ifdef _LP64
845N/A load_heap_oop(tmp2, Address(obj, 0));
845N/A#else
845N/A movptr(tmp2, Address(obj, 0));
845N/A#endif
845N/A cmpptr(tmp2, (int32_t) NULL_WORD);
362N/A jcc(Assembler::equal, done);
362N/A
362N/A // Can we store original value in the thread's buffer?
362N/A
362N/A#ifdef _LP64
845N/A movslq(tmp, index);
362N/A cmpq(tmp, 0);
362N/A#else
362N/A cmpl(index, 0);
362N/A#endif
362N/A jcc(Assembler::equal, runtime);
362N/A#ifdef _LP64
362N/A subq(tmp, wordSize);
362N/A movl(index, tmp);
362N/A addq(tmp, buffer);
362N/A#else
362N/A subl(index, wordSize);
362N/A movl(tmp, buffer);
362N/A addl(tmp, index);
362N/A#endif
362N/A movptr(Address(tmp, 0), tmp2);
362N/A jmp(done);
362N/A bind(runtime);
362N/A // save the live input values
362N/A if(tosca_live) push(rax);
362N/A push(obj);
362N/A#ifdef _LP64
845N/A call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), tmp2, r15_thread);
362N/A#else
362N/A push(thread);
362N/A call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), tmp2, thread);
362N/A pop(thread);
362N/A#endif
362N/A pop(obj);
362N/A if(tosca_live) pop(rax);
362N/A bind(done);
362N/A
362N/A}
362N/A
362N/Avoid MacroAssembler::g1_write_barrier_post(Register store_addr,
362N/A Register new_val,
362N/A#ifndef _LP64
362N/A Register thread,
362N/A#endif
362N/A Register tmp,
362N/A Register tmp2) {
362N/A
362N/A LP64_ONLY(Register thread = r15_thread;)
362N/A Address queue_index(thread, in_bytes(JavaThread::dirty_card_queue_offset() +
362N/A PtrQueue::byte_offset_of_index()));
362N/A Address buffer(thread, in_bytes(JavaThread::dirty_card_queue_offset() +
362N/A PtrQueue::byte_offset_of_buf()));
362N/A BarrierSet* bs = Universe::heap()->barrier_set();
362N/A CardTableModRefBS* ct = (CardTableModRefBS*)bs;
362N/A Label done;
362N/A Label runtime;
362N/A
362N/A // Does store cross heap regions?
362N/A
362N/A movptr(tmp, store_addr);
362N/A xorptr(tmp, new_val);
362N/A shrptr(tmp, HeapRegion::LogOfHRGrainBytes);
362N/A jcc(Assembler::equal, done);
362N/A
362N/A // crosses regions, storing NULL?
362N/A
362N/A cmpptr(new_val, (int32_t) NULL_WORD);
362N/A jcc(Assembler::equal, done);
362N/A
362N/A // storing region crossing non-NULL, is card already dirty?
362N/A
362N/A ExternalAddress cardtable((address) ct->byte_map_base);
362N/A assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
362N/A#ifdef _LP64
362N/A const Register card_addr = tmp;
362N/A
362N/A movq(card_addr, store_addr);
362N/A shrq(card_addr, CardTableModRefBS::card_shift);
362N/A
362N/A lea(tmp2, cardtable);
362N/A
362N/A // get the address of the card
362N/A addq(card_addr, tmp2);
362N/A#else
362N/A const Register card_index = tmp;
362N/A
362N/A movl(card_index, store_addr);
362N/A shrl(card_index, CardTableModRefBS::card_shift);
362N/A
362N/A Address index(noreg, card_index, Address::times_1);
362N/A const Register card_addr = tmp;
362N/A lea(card_addr, as_Address(ArrayAddress(cardtable, index)));
362N/A#endif
362N/A cmpb(Address(card_addr, 0), 0);
362N/A jcc(Assembler::equal, done);
362N/A
362N/A // storing a region crossing, non-NULL oop, card is clean.
362N/A // dirty card and log.
362N/A
362N/A movb(Address(card_addr, 0), 0);
362N/A
362N/A cmpl(queue_index, 0);
362N/A jcc(Assembler::equal, runtime);
362N/A subl(queue_index, wordSize);
362N/A movptr(tmp2, buffer);
362N/A#ifdef _LP64
362N/A movslq(rscratch1, queue_index);
362N/A addq(tmp2, rscratch1);
362N/A movq(Address(tmp2, 0), card_addr);
362N/A#else
362N/A addl(tmp2, queue_index);
362N/A movl(Address(tmp2, 0), card_index);
362N/A#endif
362N/A jmp(done);
362N/A
362N/A bind(runtime);
362N/A // save the live input values
362N/A push(store_addr);
362N/A push(new_val);
362N/A#ifdef _LP64
362N/A call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), card_addr, r15_thread);
362N/A#else
362N/A push(thread);
362N/A call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), card_addr, thread);
362N/A pop(thread);
362N/A#endif
362N/A pop(new_val);
362N/A pop(store_addr);
362N/A
362N/A bind(done);
362N/A
362N/A}
362N/A
362N/A#endif // SERIALGC
362N/A//////////////////////////////////////////////////////////////////////////////////
362N/A
362N/A
304N/Avoid MacroAssembler::store_check(Register obj) {
304N/A // Does a store check for the oop in register obj. The content of
304N/A // register obj is destroyed afterwards.
304N/A store_check_part_1(obj);
304N/A store_check_part_2(obj);
304N/A}
304N/A
304N/Avoid MacroAssembler::store_check(Register obj, Address dst) {
304N/A store_check(obj);
304N/A}
304N/A
304N/A
304N/A// split the store check operation so that other instructions can be scheduled inbetween
304N/Avoid MacroAssembler::store_check_part_1(Register obj) {
304N/A BarrierSet* bs = Universe::heap()->barrier_set();
304N/A assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind");
304N/A shrptr(obj, CardTableModRefBS::card_shift);
304N/A}
304N/A
304N/Avoid MacroAssembler::store_check_part_2(Register obj) {
304N/A BarrierSet* bs = Universe::heap()->barrier_set();
304N/A assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind");
304N/A CardTableModRefBS* ct = (CardTableModRefBS*)bs;
304N/A assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
304N/A
304N/A // The calculation for byte_map_base is as follows:
304N/A // byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
304N/A // So this essentially converts an address to a displacement and
304N/A // it will never need to be relocated. On 64bit however the value may be too
304N/A // large for a 32bit displacement
304N/A
304N/A intptr_t disp = (intptr_t) ct->byte_map_base;
304N/A if (is_simm32(disp)) {
304N/A Address cardtable(noreg, obj, Address::times_1, disp);
304N/A movb(cardtable, 0);
304N/A } else {
304N/A // By doing it as an ExternalAddress disp could be converted to a rip-relative
304N/A // displacement and done in a single instruction given favorable mapping and
304N/A // a smarter version of as_Address. Worst case it is two instructions which
304N/A // is no worse off then loading disp into a register and doing as a simple
304N/A // Address() as above.
304N/A // We can't do as ExternalAddress as the only style since if disp == 0 we'll
304N/A // assert since NULL isn't acceptable in a reloci (see 6644928). In any case
304N/A // in some cases we'll get a single instruction version.
304N/A
304N/A ExternalAddress cardtable((address)disp);
304N/A Address index(noreg, obj, Address::times_1);
304N/A movb(as_Address(ArrayAddress(cardtable, index)), 0);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::subptr(Register dst, int32_t imm32) {
304N/A LP64_ONLY(subq(dst, imm32)) NOT_LP64(subl(dst, imm32));
304N/A}
304N/A
304N/Avoid MacroAssembler::subptr(Register dst, Register src) {
304N/A LP64_ONLY(subq(dst, src)) NOT_LP64(subl(dst, src));
304N/A}
304N/A
304N/Avoid MacroAssembler::test32(Register src1, AddressLiteral src2) {
304N/A // src2 must be rval
304N/A
304N/A if (reachable(src2)) {
304N/A testl(src1, as_Address(src2));
304N/A } else {
304N/A lea(rscratch1, src2);
304N/A testl(src1, Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/A// C++ bool manipulation
0N/Avoid MacroAssembler::testbool(Register dst) {
0N/A if(sizeof(bool) == 1)
304N/A testb(dst, 0xff);
0N/A else if(sizeof(bool) == 2) {
0N/A // testw implementation needed for two byte bools
0N/A ShouldNotReachHere();
0N/A } else if(sizeof(bool) == 4)
0N/A testl(dst, dst);
0N/A else
0N/A // unsupported
0N/A ShouldNotReachHere();
0N/A}
0N/A
304N/Avoid MacroAssembler::testptr(Register dst, Register src) {
304N/A LP64_ONLY(testq(dst, src)) NOT_LP64(testl(dst, src));
304N/A}
304N/A
304N/A// Defines obj, preserves var_size_in_bytes, okay for t2 == var_size_in_bytes.
304N/Avoid MacroAssembler::tlab_allocate(Register obj,
304N/A Register var_size_in_bytes,
304N/A int con_size_in_bytes,
304N/A Register t1,
304N/A Register t2,
304N/A Label& slow_case) {
304N/A assert_different_registers(obj, t1, t2);
304N/A assert_different_registers(obj, var_size_in_bytes, t1);
304N/A Register end = t2;
304N/A Register thread = NOT_LP64(t1) LP64_ONLY(r15_thread);
304N/A
304N/A verify_tlab();
304N/A
304N/A NOT_LP64(get_thread(thread));
304N/A
304N/A movptr(obj, Address(thread, JavaThread::tlab_top_offset()));
304N/A if (var_size_in_bytes == noreg) {
304N/A lea(end, Address(obj, con_size_in_bytes));
304N/A } else {
304N/A lea(end, Address(obj, var_size_in_bytes, Address::times_1));
304N/A }
304N/A cmpptr(end, Address(thread, JavaThread::tlab_end_offset()));
304N/A jcc(Assembler::above, slow_case);
304N/A
304N/A // update the tlab top pointer
304N/A movptr(Address(thread, JavaThread::tlab_top_offset()), end);
304N/A
304N/A // recover var_size_in_bytes if necessary
304N/A if (var_size_in_bytes == end) {
304N/A subptr(var_size_in_bytes, obj);
304N/A }
304N/A verify_tlab();
304N/A}
304N/A
304N/A// Preserves rbx, and rdx.
304N/Avoid MacroAssembler::tlab_refill(Label& retry,
304N/A Label& try_eden,
304N/A Label& slow_case) {
304N/A Register top = rax;
304N/A Register t1 = rcx;
304N/A Register t2 = rsi;
304N/A Register thread_reg = NOT_LP64(rdi) LP64_ONLY(r15_thread);
304N/A assert_different_registers(top, thread_reg, t1, t2, /* preserve: */ rbx, rdx);
304N/A Label do_refill, discard_tlab;
304N/A
304N/A if (CMSIncrementalMode || !Universe::heap()->supports_inline_contig_alloc()) {
304N/A // No allocation in the shared eden.
304N/A jmp(slow_case);
304N/A }
304N/A
304N/A NOT_LP64(get_thread(thread_reg));
304N/A
304N/A movptr(top, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
304N/A movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())));
304N/A
304N/A // calculate amount of free space
304N/A subptr(t1, top);
304N/A shrptr(t1, LogHeapWordSize);
304N/A
304N/A // Retain tlab and allocate object in shared space if
304N/A // the amount free in the tlab is too large to discard.
304N/A cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_refill_waste_limit_offset())));
304N/A jcc(Assembler::lessEqual, discard_tlab);
304N/A
304N/A // Retain
304N/A // %%% yuck as movptr...
304N/A movptr(t2, (int32_t) ThreadLocalAllocBuffer::refill_waste_limit_increment());
304N/A addptr(Address(thread_reg, in_bytes(JavaThread::tlab_refill_waste_limit_offset())), t2);
304N/A if (TLABStats) {
304N/A // increment number of slow_allocations
304N/A addl(Address(thread_reg, in_bytes(JavaThread::tlab_slow_allocations_offset())), 1);
304N/A }
304N/A jmp(try_eden);
304N/A
304N/A bind(discard_tlab);
304N/A if (TLABStats) {
304N/A // increment number of refills
304N/A addl(Address(thread_reg, in_bytes(JavaThread::tlab_number_of_refills_offset())), 1);
304N/A // accumulate wastage -- t1 is amount free in tlab
304N/A addl(Address(thread_reg, in_bytes(JavaThread::tlab_fast_refill_waste_offset())), t1);
304N/A }
304N/A
304N/A // if tlab is currently allocated (top or end != null) then
304N/A // fill [top, end + alignment_reserve) with array object
304N/A testptr (top, top);
304N/A jcc(Assembler::zero, do_refill);
304N/A
304N/A // set up the mark word
304N/A movptr(Address(top, oopDesc::mark_offset_in_bytes()), (intptr_t)markOopDesc::prototype()->copy_set_hash(0x2));
304N/A // set the length to the remaining space
304N/A subptr(t1, typeArrayOopDesc::header_size(T_INT));
304N/A addptr(t1, (int32_t)ThreadLocalAllocBuffer::alignment_reserve());
304N/A shlptr(t1, log2_intptr(HeapWordSize/sizeof(jint)));
304N/A movptr(Address(top, arrayOopDesc::length_offset_in_bytes()), t1);
304N/A // set klass to intArrayKlass
304N/A // dubious reloc why not an oop reloc?
304N/A movptr(t1, ExternalAddress((address) Universe::intArrayKlassObj_addr()));
304N/A // store klass last. concurrent gcs assumes klass length is valid if
304N/A // klass field is not null.
304N/A store_klass(top, t1);
304N/A
304N/A // refill the tlab with an eden allocation
304N/A bind(do_refill);
304N/A movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_size_offset())));
304N/A shlptr(t1, LogHeapWordSize);
304N/A // add object_size ??
304N/A eden_allocate(top, t1, 0, t2, slow_case);
304N/A
304N/A // Check that t1 was preserved in eden_allocate.
304N/A#ifdef ASSERT
304N/A if (UseTLAB) {
304N/A Label ok;
304N/A Register tsize = rsi;
304N/A assert_different_registers(tsize, thread_reg, t1);
304N/A push(tsize);
304N/A movptr(tsize, Address(thread_reg, in_bytes(JavaThread::tlab_size_offset())));
304N/A shlptr(tsize, LogHeapWordSize);
304N/A cmpptr(t1, tsize);
304N/A jcc(Assembler::equal, ok);
304N/A stop("assert(t1 != tlab size)");
304N/A should_not_reach_here();
304N/A
304N/A bind(ok);
304N/A pop(tsize);
304N/A }
304N/A#endif
304N/A movptr(Address(thread_reg, in_bytes(JavaThread::tlab_start_offset())), top);
304N/A movptr(Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())), top);
304N/A addptr(top, t1);
304N/A subptr(top, (int32_t)ThreadLocalAllocBuffer::alignment_reserve_in_bytes());
304N/A movptr(Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())), top);
304N/A verify_tlab();
304N/A jmp(retry);
304N/A}
304N/A
304N/Astatic const double pi_4 = 0.7853981633974483;
304N/A
304N/Avoid MacroAssembler::trigfunc(char trig, int num_fpu_regs_in_use) {
304N/A // A hand-coded argument reduction for values in fabs(pi/4, pi/2)
304N/A // was attempted in this code; unfortunately it appears that the
304N/A // switch to 80-bit precision and back causes this to be
304N/A // unprofitable compared with simply performing a runtime call if
304N/A // the argument is out of the (-pi/4, pi/4) range.
304N/A
304N/A Register tmp = noreg;
304N/A if (!VM_Version::supports_cmov()) {
304N/A // fcmp needs a temporary so preserve rbx,
304N/A tmp = rbx;
304N/A push(tmp);
304N/A }
304N/A
304N/A Label slow_case, done;
304N/A
520N/A ExternalAddress pi4_adr = (address)&pi_4;
520N/A if (reachable(pi4_adr)) {
520N/A // x ?<= pi/4
520N/A fld_d(pi4_adr);
520N/A fld_s(1); // Stack: X PI/4 X
520N/A fabs(); // Stack: |X| PI/4 X
520N/A fcmp(tmp);
520N/A jcc(Assembler::above, slow_case);
520N/A
520N/A // fastest case: -pi/4 <= x <= pi/4
520N/A switch(trig) {
520N/A case 's':
520N/A fsin();
520N/A break;
520N/A case 'c':
520N/A fcos();
520N/A break;
520N/A case 't':
520N/A ftan();
520N/A break;
520N/A default:
520N/A assert(false, "bad intrinsic");
520N/A break;
520N/A }
520N/A jmp(done);
520N/A }
304N/A
304N/A // slow case: runtime call
304N/A bind(slow_case);
304N/A // Preserve registers across runtime call
304N/A pusha();
304N/A int incoming_argument_and_return_value_offset = -1;
304N/A if (num_fpu_regs_in_use > 1) {
304N/A // Must preserve all other FPU regs (could alternatively convert
304N/A // SharedRuntime::dsin and dcos into assembly routines known not to trash
304N/A // FPU state, but can not trust C compiler)
304N/A NEEDS_CLEANUP;
304N/A // NOTE that in this case we also push the incoming argument to
304N/A // the stack and restore it later; we also use this stack slot to
304N/A // hold the return value from dsin or dcos.
304N/A for (int i = 0; i < num_fpu_regs_in_use; i++) {
304N/A subptr(rsp, sizeof(jdouble));
304N/A fstp_d(Address(rsp, 0));
304N/A }
304N/A incoming_argument_and_return_value_offset = sizeof(jdouble)*(num_fpu_regs_in_use-1);
304N/A fld_d(Address(rsp, incoming_argument_and_return_value_offset));
304N/A }
304N/A subptr(rsp, sizeof(jdouble));
304N/A fstp_d(Address(rsp, 0));
304N/A#ifdef _LP64
304N/A movdbl(xmm0, Address(rsp, 0));
304N/A#endif // _LP64
304N/A
304N/A // NOTE: we must not use call_VM_leaf here because that requires a
304N/A // complete interpreter frame in debug mode -- same bug as 4387334
304N/A // MacroAssembler::call_VM_leaf_base is perfectly safe and will
304N/A // do proper 64bit abi
304N/A
304N/A NEEDS_CLEANUP;
304N/A // Need to add stack banging before this runtime call if it needs to
304N/A // be taken; however, there is no generic stack banging routine at
304N/A // the MacroAssembler level
304N/A switch(trig) {
304N/A case 's':
304N/A {
304N/A MacroAssembler::call_VM_leaf_base(CAST_FROM_FN_PTR(address, SharedRuntime::dsin), 0);
304N/A }
304N/A break;
304N/A case 'c':
304N/A {
304N/A MacroAssembler::call_VM_leaf_base(CAST_FROM_FN_PTR(address, SharedRuntime::dcos), 0);
304N/A }
304N/A break;
304N/A case 't':
304N/A {
304N/A MacroAssembler::call_VM_leaf_base(CAST_FROM_FN_PTR(address, SharedRuntime::dtan), 0);
304N/A }
304N/A break;
304N/A default:
304N/A assert(false, "bad intrinsic");
304N/A break;
304N/A }
304N/A#ifdef _LP64
304N/A movsd(Address(rsp, 0), xmm0);
304N/A fld_d(Address(rsp, 0));
304N/A#endif // _LP64
304N/A addptr(rsp, sizeof(jdouble));
304N/A if (num_fpu_regs_in_use > 1) {
304N/A // Must save return value to stack and then restore entire FPU stack
304N/A fstp_d(Address(rsp, incoming_argument_and_return_value_offset));
304N/A for (int i = 0; i < num_fpu_regs_in_use; i++) {
304N/A fld_d(Address(rsp, 0));
304N/A addptr(rsp, sizeof(jdouble));
304N/A }
304N/A }
304N/A popa();
304N/A
304N/A // Come here with result in F-TOS
304N/A bind(done);
304N/A
304N/A if (tmp != noreg) {
304N/A pop(tmp);
304N/A }
304N/A}
304N/A
304N/A
623N/A// Look up the method for a megamorphic invokeinterface call.
623N/A// The target method is determined by <intf_klass, itable_index>.
623N/A// The receiver klass is in recv_klass.
623N/A// On success, the result will be in method_result, and execution falls through.
623N/A// On failure, execution transfers to the given label.
623N/Avoid MacroAssembler::lookup_interface_method(Register recv_klass,
623N/A Register intf_klass,
665N/A RegisterOrConstant itable_index,
623N/A Register method_result,
623N/A Register scan_temp,
623N/A Label& L_no_such_interface) {
623N/A assert_different_registers(recv_klass, intf_klass, method_result, scan_temp);
623N/A assert(itable_index.is_constant() || itable_index.as_register() == method_result,
623N/A "caller must use same register for non-constant itable index as for method");
623N/A
623N/A // Compute start of first itableOffsetEntry (which is at the end of the vtable)
623N/A int vtable_base = instanceKlass::vtable_start_offset() * wordSize;
623N/A int itentry_off = itableMethodEntry::method_offset_in_bytes();
623N/A int scan_step = itableOffsetEntry::size() * wordSize;
623N/A int vte_size = vtableEntry::size() * wordSize;
623N/A Address::ScaleFactor times_vte_scale = Address::times_ptr;
623N/A assert(vte_size == wordSize, "else adjust times_vte_scale");
623N/A
623N/A movl(scan_temp, Address(recv_klass, instanceKlass::vtable_length_offset() * wordSize));
623N/A
623N/A // %%% Could store the aligned, prescaled offset in the klassoop.
623N/A lea(scan_temp, Address(recv_klass, scan_temp, times_vte_scale, vtable_base));
623N/A if (HeapWordsPerLong > 1) {
623N/A // Round up to align_object_offset boundary
623N/A // see code for instanceKlass::start_of_itable!
623N/A round_to(scan_temp, BytesPerLong);
623N/A }
623N/A
623N/A // Adjust recv_klass by scaled itable_index, so we can free itable_index.
623N/A assert(itableMethodEntry::size() * wordSize == wordSize, "adjust the scaling in the code below");
623N/A lea(recv_klass, Address(recv_klass, itable_index, Address::times_ptr, itentry_off));
623N/A
623N/A // for (scan = klass->itable(); scan->interface() != NULL; scan += scan_step) {
623N/A // if (scan->interface() == intf) {
623N/A // result = (klass + scan->offset() + itable_index);
623N/A // }
623N/A // }
623N/A Label search, found_method;
623N/A
623N/A for (int peel = 1; peel >= 0; peel--) {
623N/A movptr(method_result, Address(scan_temp, itableOffsetEntry::interface_offset_in_bytes()));
623N/A cmpptr(intf_klass, method_result);
623N/A
623N/A if (peel) {
623N/A jccb(Assembler::equal, found_method);
623N/A } else {
623N/A jccb(Assembler::notEqual, search);
623N/A // (invert the test to fall through to found_method...)
623N/A }
623N/A
623N/A if (!peel) break;
623N/A
623N/A bind(search);
623N/A
623N/A // Check that the previous entry is non-null. A null entry means that
623N/A // the receiver class doesn't implement the interface, and wasn't the
623N/A // same as when the caller was compiled.
623N/A testptr(method_result, method_result);
623N/A jcc(Assembler::zero, L_no_such_interface);
623N/A addptr(scan_temp, scan_step);
623N/A }
623N/A
623N/A bind(found_method);
623N/A
623N/A // Got a hit.
623N/A movl(scan_temp, Address(scan_temp, itableOffsetEntry::offset_offset_in_bytes()));
623N/A movptr(method_result, Address(recv_klass, scan_temp, Address::times_1));
623N/A}
623N/A
623N/A
644N/Avoid MacroAssembler::check_klass_subtype(Register sub_klass,
644N/A Register super_klass,
644N/A Register temp_reg,
644N/A Label& L_success) {
644N/A Label L_failure;
644N/A check_klass_subtype_fast_path(sub_klass, super_klass, temp_reg, &L_success, &L_failure, NULL);
644N/A check_klass_subtype_slow_path(sub_klass, super_klass, temp_reg, noreg, &L_success, NULL);
644N/A bind(L_failure);
644N/A}
644N/A
644N/A
644N/Avoid MacroAssembler::check_klass_subtype_fast_path(Register sub_klass,
644N/A Register super_klass,
644N/A Register temp_reg,
644N/A Label* L_success,
644N/A Label* L_failure,
644N/A Label* L_slow_path,
665N/A RegisterOrConstant super_check_offset) {
644N/A assert_different_registers(sub_klass, super_klass, temp_reg);
644N/A bool must_load_sco = (super_check_offset.constant_or_zero() == -1);
644N/A if (super_check_offset.is_register()) {
644N/A assert_different_registers(sub_klass, super_klass,
644N/A super_check_offset.as_register());
644N/A } else if (must_load_sco) {
644N/A assert(temp_reg != noreg, "supply either a temp or a register offset");
644N/A }
644N/A
644N/A Label L_fallthrough;
644N/A int label_nulls = 0;
644N/A if (L_success == NULL) { L_success = &L_fallthrough; label_nulls++; }
644N/A if (L_failure == NULL) { L_failure = &L_fallthrough; label_nulls++; }
644N/A if (L_slow_path == NULL) { L_slow_path = &L_fallthrough; label_nulls++; }
644N/A assert(label_nulls <= 1, "at most one NULL in the batch");
644N/A
644N/A int sc_offset = (klassOopDesc::header_size() * HeapWordSize +
644N/A Klass::secondary_super_cache_offset_in_bytes());
644N/A int sco_offset = (klassOopDesc::header_size() * HeapWordSize +
644N/A Klass::super_check_offset_offset_in_bytes());
644N/A Address super_check_offset_addr(super_klass, sco_offset);
644N/A
644N/A // Hacked jcc, which "knows" that L_fallthrough, at least, is in
644N/A // range of a jccb. If this routine grows larger, reconsider at
644N/A // least some of these.
644N/A#define local_jcc(assembler_cond, label) \
644N/A if (&(label) == &L_fallthrough) jccb(assembler_cond, label); \
644N/A else jcc( assembler_cond, label) /*omit semi*/
644N/A
644N/A // Hacked jmp, which may only be used just before L_fallthrough.
644N/A#define final_jmp(label) \
644N/A if (&(label) == &L_fallthrough) { /*do nothing*/ } \
644N/A else jmp(label) /*omit semi*/
644N/A
644N/A // If the pointers are equal, we are done (e.g., String[] elements).
644N/A // This self-check enables sharing of secondary supertype arrays among
644N/A // non-primary types such as array-of-interface. Otherwise, each such
644N/A // type would need its own customized SSA.
644N/A // We move this check to the front of the fast path because many
644N/A // type checks are in fact trivially successful in this manner,
644N/A // so we get a nicely predicted branch right at the start of the check.
644N/A cmpptr(sub_klass, super_klass);
644N/A local_jcc(Assembler::equal, *L_success);
644N/A
644N/A // Check the supertype display:
644N/A if (must_load_sco) {
644N/A // Positive movl does right thing on LP64.
644N/A movl(temp_reg, super_check_offset_addr);
665N/A super_check_offset = RegisterOrConstant(temp_reg);
644N/A }
644N/A Address super_check_addr(sub_klass, super_check_offset, Address::times_1, 0);
644N/A cmpptr(super_klass, super_check_addr); // load displayed supertype
644N/A
644N/A // This check has worked decisively for primary supers.
644N/A // Secondary supers are sought in the super_cache ('super_cache_addr').
644N/A // (Secondary supers are interfaces and very deeply nested subtypes.)
644N/A // This works in the same check above because of a tricky aliasing
644N/A // between the super_cache and the primary super display elements.
644N/A // (The 'super_check_addr' can address either, as the case requires.)
644N/A // Note that the cache is updated below if it does not help us find
644N/A // what we need immediately.
644N/A // So if it was a primary super, we can just fail immediately.
644N/A // Otherwise, it's the slow path for us (no success at this point).
644N/A
644N/A if (super_check_offset.is_register()) {
644N/A local_jcc(Assembler::equal, *L_success);
644N/A cmpl(super_check_offset.as_register(), sc_offset);
644N/A if (L_failure == &L_fallthrough) {
644N/A local_jcc(Assembler::equal, *L_slow_path);
644N/A } else {
644N/A local_jcc(Assembler::notEqual, *L_failure);
644N/A final_jmp(*L_slow_path);
644N/A }
644N/A } else if (super_check_offset.as_constant() == sc_offset) {
644N/A // Need a slow path; fast failure is impossible.
644N/A if (L_slow_path == &L_fallthrough) {
644N/A local_jcc(Assembler::equal, *L_success);
644N/A } else {
644N/A local_jcc(Assembler::notEqual, *L_slow_path);
644N/A final_jmp(*L_success);
644N/A }
644N/A } else {
644N/A // No slow path; it's a fast decision.
644N/A if (L_failure == &L_fallthrough) {
644N/A local_jcc(Assembler::equal, *L_success);
644N/A } else {
644N/A local_jcc(Assembler::notEqual, *L_failure);
644N/A final_jmp(*L_success);
644N/A }
644N/A }
644N/A
644N/A bind(L_fallthrough);
644N/A
644N/A#undef local_jcc
644N/A#undef final_jmp
644N/A}
644N/A
644N/A
644N/Avoid MacroAssembler::check_klass_subtype_slow_path(Register sub_klass,
644N/A Register super_klass,
644N/A Register temp_reg,
644N/A Register temp2_reg,
644N/A Label* L_success,
644N/A Label* L_failure,
644N/A bool set_cond_codes) {
644N/A assert_different_registers(sub_klass, super_klass, temp_reg);
644N/A if (temp2_reg != noreg)
644N/A assert_different_registers(sub_klass, super_klass, temp_reg, temp2_reg);
644N/A#define IS_A_TEMP(reg) ((reg) == temp_reg || (reg) == temp2_reg)
644N/A
644N/A Label L_fallthrough;
644N/A int label_nulls = 0;
644N/A if (L_success == NULL) { L_success = &L_fallthrough; label_nulls++; }
644N/A if (L_failure == NULL) { L_failure = &L_fallthrough; label_nulls++; }
644N/A assert(label_nulls <= 1, "at most one NULL in the batch");
644N/A
644N/A // a couple of useful fields in sub_klass:
644N/A int ss_offset = (klassOopDesc::header_size() * HeapWordSize +
644N/A Klass::secondary_supers_offset_in_bytes());
644N/A int sc_offset = (klassOopDesc::header_size() * HeapWordSize +
644N/A Klass::secondary_super_cache_offset_in_bytes());
644N/A Address secondary_supers_addr(sub_klass, ss_offset);
644N/A Address super_cache_addr( sub_klass, sc_offset);
644N/A
644N/A // Do a linear scan of the secondary super-klass chain.
644N/A // This code is rarely used, so simplicity is a virtue here.
644N/A // The repne_scan instruction uses fixed registers, which we must spill.
644N/A // Don't worry too much about pre-existing connections with the input regs.
644N/A
644N/A assert(sub_klass != rax, "killed reg"); // killed by mov(rax, super)
644N/A assert(sub_klass != rcx, "killed reg"); // killed by lea(rcx, &pst_counter)
644N/A
644N/A // Get super_klass value into rax (even if it was in rdi or rcx).
644N/A bool pushed_rax = false, pushed_rcx = false, pushed_rdi = false;
644N/A if (super_klass != rax || UseCompressedOops) {
644N/A if (!IS_A_TEMP(rax)) { push(rax); pushed_rax = true; }
644N/A mov(rax, super_klass);
644N/A }
644N/A if (!IS_A_TEMP(rcx)) { push(rcx); pushed_rcx = true; }
644N/A if (!IS_A_TEMP(rdi)) { push(rdi); pushed_rdi = true; }
644N/A
644N/A#ifndef PRODUCT
644N/A int* pst_counter = &SharedRuntime::_partial_subtype_ctr;
644N/A ExternalAddress pst_counter_addr((address) pst_counter);
644N/A NOT_LP64( incrementl(pst_counter_addr) );
644N/A LP64_ONLY( lea(rcx, pst_counter_addr) );
644N/A LP64_ONLY( incrementl(Address(rcx, 0)) );
644N/A#endif //PRODUCT
644N/A
644N/A // We will consult the secondary-super array.
644N/A movptr(rdi, secondary_supers_addr);
644N/A // Load the array length. (Positive movl does right thing on LP64.)
644N/A movl(rcx, Address(rdi, arrayOopDesc::length_offset_in_bytes()));
644N/A // Skip to start of data.
644N/A addptr(rdi, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
644N/A
644N/A // Scan RCX words at [RDI] for an occurrence of RAX.
644N/A // Set NZ/Z based on last compare.
644N/A#ifdef _LP64
644N/A // This part is tricky, as values in supers array could be 32 or 64 bit wide
644N/A // and we store values in objArrays always encoded, thus we need to encode
644N/A // the value of rax before repne. Note that rax is dead after the repne.
644N/A if (UseCompressedOops) {
644N/A encode_heap_oop_not_null(rax);
644N/A // The superclass is never null; it would be a basic system error if a null
644N/A // pointer were to sneak in here. Note that we have already loaded the
644N/A // Klass::super_check_offset from the super_klass in the fast path,
644N/A // so if there is a null in that register, we are already in the afterlife.
644N/A repne_scanl();
644N/A } else
644N/A#endif // _LP64
644N/A repne_scan();
644N/A
644N/A // Unspill the temp. registers:
644N/A if (pushed_rdi) pop(rdi);
644N/A if (pushed_rcx) pop(rcx);
644N/A if (pushed_rax) pop(rax);
644N/A
644N/A if (set_cond_codes) {
644N/A // Special hack for the AD files: rdi is guaranteed non-zero.
644N/A assert(!pushed_rdi, "rdi must be left non-NULL");
644N/A // Also, the condition codes are properly set Z/NZ on succeed/failure.
644N/A }
644N/A
644N/A if (L_failure == &L_fallthrough)
644N/A jccb(Assembler::notEqual, *L_failure);
644N/A else jcc(Assembler::notEqual, *L_failure);
644N/A
644N/A // Success. Cache the super we found and proceed in triumph.
644N/A movptr(super_cache_addr, super_klass);
644N/A
644N/A if (L_success != &L_fallthrough) {
644N/A jmp(*L_success);
644N/A }
644N/A
644N/A#undef IS_A_TEMP
644N/A
644N/A bind(L_fallthrough);
644N/A}
644N/A
644N/A
304N/Avoid MacroAssembler::ucomisd(XMMRegister dst, AddressLiteral src) {
304N/A ucomisd(dst, as_Address(src));
304N/A}
304N/A
304N/Avoid MacroAssembler::ucomiss(XMMRegister dst, AddressLiteral src) {
304N/A ucomiss(dst, as_Address(src));
304N/A}
304N/A
304N/Avoid MacroAssembler::xorpd(XMMRegister dst, AddressLiteral src) {
304N/A if (reachable(src)) {
304N/A xorpd(dst, as_Address(src));
304N/A } else {
304N/A lea(rscratch1, src);
304N/A xorpd(dst, Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::xorps(XMMRegister dst, AddressLiteral src) {
304N/A if (reachable(src)) {
304N/A xorps(dst, as_Address(src));
304N/A } else {
304N/A lea(rscratch1, src);
304N/A xorps(dst, Address(rscratch1, 0));
304N/A }
304N/A}
304N/A
0N/Avoid MacroAssembler::verify_oop(Register reg, const char* s) {
0N/A if (!VerifyOops) return;
304N/A
0N/A // Pass register number to verify_oop_subroutine
0N/A char* b = new char[strlen(s) + 50];
0N/A sprintf(b, "verify_oop: %s: %s", reg->name(), s);
304N/A push(rax); // save rax,
304N/A push(reg); // pass register argument
0N/A ExternalAddress buffer((address) b);
304N/A // avoid using pushptr, as it modifies scratch registers
304N/A // and our contract is not to modify anything
304N/A movptr(rax, buffer.addr());
304N/A push(rax);
0N/A // call indirectly to solve generation ordering problem
0N/A movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
0N/A call(rax);
0N/A}
0N/A
0N/A
665N/ARegisterOrConstant MacroAssembler::delayed_value_impl(intptr_t* delayed_value_addr,
665N/A Register tmp,
665N/A int offset) {
622N/A intptr_t value = *delayed_value_addr;
622N/A if (value != 0)
665N/A return RegisterOrConstant(value + offset);
622N/A
622N/A // load indirectly to solve generation ordering problem
622N/A movptr(tmp, ExternalAddress((address) delayed_value_addr));
622N/A
622N/A#ifdef ASSERT
622N/A Label L;
622N/A testl(tmp, tmp);
622N/A jccb(Assembler::notZero, L);
622N/A hlt();
622N/A bind(L);
622N/A#endif
622N/A
622N/A if (offset != 0)
622N/A addptr(tmp, offset);
622N/A
665N/A return RegisterOrConstant(tmp);
622N/A}
622N/A
622N/A
710N/A// registers on entry:
710N/A// - rax ('check' register): required MethodType
710N/A// - rcx: method handle
710N/A// - rdx, rsi, or ?: killable temp
710N/Avoid MacroAssembler::check_method_handle_type(Register mtype_reg, Register mh_reg,
710N/A Register temp_reg,
710N/A Label& wrong_method_type) {
710N/A if (UseCompressedOops) unimplemented(); // field accesses must decode
710N/A // compare method type against that of the receiver
710N/A cmpptr(mtype_reg, Address(mh_reg, delayed_value(java_dyn_MethodHandle::type_offset_in_bytes, temp_reg)));
710N/A jcc(Assembler::notEqual, wrong_method_type);
710N/A}
710N/A
710N/A
710N/A// A method handle has a "vmslots" field which gives the size of its
710N/A// argument list in JVM stack slots. This field is either located directly
710N/A// in every method handle, or else is indirectly accessed through the
710N/A// method handle's MethodType. This macro hides the distinction.
710N/Avoid MacroAssembler::load_method_handle_vmslots(Register vmslots_reg, Register mh_reg,
710N/A Register temp_reg) {
710N/A if (UseCompressedOops) unimplemented(); // field accesses must decode
710N/A // load mh.type.form.vmslots
710N/A if (java_dyn_MethodHandle::vmslots_offset_in_bytes() != 0) {
710N/A // hoist vmslots into every mh to avoid dependent load chain
710N/A movl(vmslots_reg, Address(mh_reg, delayed_value(java_dyn_MethodHandle::vmslots_offset_in_bytes, temp_reg)));
710N/A } else {
710N/A Register temp2_reg = vmslots_reg;
710N/A movptr(temp2_reg, Address(mh_reg, delayed_value(java_dyn_MethodHandle::type_offset_in_bytes, temp_reg)));
710N/A movptr(temp2_reg, Address(temp2_reg, delayed_value(java_dyn_MethodType::form_offset_in_bytes, temp_reg)));
710N/A movl(vmslots_reg, Address(temp2_reg, delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, temp_reg)));
710N/A }
710N/A}
710N/A
710N/A
710N/A// registers on entry:
710N/A// - rcx: method handle
710N/A// - rdx: killable temp (interpreted only)
710N/A// - rax: killable temp (compiled only)
710N/Avoid MacroAssembler::jump_to_method_handle_entry(Register mh_reg, Register temp_reg) {
710N/A assert(mh_reg == rcx, "caller must put MH object in rcx");
710N/A assert_different_registers(mh_reg, temp_reg);
710N/A
710N/A if (UseCompressedOops) unimplemented(); // field accesses must decode
710N/A
710N/A // pick out the interpreted side of the handler
710N/A movptr(temp_reg, Address(mh_reg, delayed_value(java_dyn_MethodHandle::vmentry_offset_in_bytes, temp_reg)));
710N/A
710N/A // off we go...
710N/A jmp(Address(temp_reg, MethodHandleEntry::from_interpreted_entry_offset_in_bytes()));
710N/A
710N/A // for the various stubs which take control at this point,
710N/A // see MethodHandles::generate_method_handle_stub
710N/A}
710N/A
710N/A
710N/AAddress MacroAssembler::argument_address(RegisterOrConstant arg_slot,
710N/A int extra_slot_offset) {
710N/A // cf. TemplateTable::prepare_invoke(), if (load_receiver).
710N/A int stackElementSize = Interpreter::stackElementSize();
710N/A int offset = Interpreter::expr_offset_in_bytes(extra_slot_offset+0);
710N/A#ifdef ASSERT
710N/A int offset1 = Interpreter::expr_offset_in_bytes(extra_slot_offset+1);
710N/A assert(offset1 - offset == stackElementSize, "correct arithmetic");
710N/A#endif
710N/A Register scale_reg = noreg;
710N/A Address::ScaleFactor scale_factor = Address::no_scale;
710N/A if (arg_slot.is_constant()) {
710N/A offset += arg_slot.as_constant() * stackElementSize;
710N/A } else {
710N/A scale_reg = arg_slot.as_register();
710N/A scale_factor = Address::times(stackElementSize);
710N/A }
710N/A offset += wordSize; // return PC is on stack
710N/A return Address(rsp, scale_reg, scale_factor, offset);
710N/A}
710N/A
710N/A
0N/Avoid MacroAssembler::verify_oop_addr(Address addr, const char* s) {
0N/A if (!VerifyOops) return;
304N/A
0N/A // Address adjust(addr.base(), addr.index(), addr.scale(), addr.disp() + BytesPerWord);
0N/A // Pass register number to verify_oop_subroutine
0N/A char* b = new char[strlen(s) + 50];
0N/A sprintf(b, "verify_oop_addr: %s", s);
304N/A
304N/A push(rax); // save rax,
0N/A // addr may contain rsp so we will have to adjust it based on the push
0N/A // we just did
304N/A // NOTE: 64bit seemed to have had a bug in that it did movq(addr, rax); which
304N/A // stores rax into addr which is backwards of what was intended.
0N/A if (addr.uses(rsp)) {
304N/A lea(rax, addr);
304N/A pushptr(Address(rax, BytesPerWord));
0N/A } else {
304N/A pushptr(addr);
304N/A }
304N/A
0N/A ExternalAddress buffer((address) b);
0N/A // pass msg argument
304N/A // avoid using pushptr, as it modifies scratch registers
304N/A // and our contract is not to modify anything
304N/A movptr(rax, buffer.addr());
304N/A push(rax);
304N/A
0N/A // call indirectly to solve generation ordering problem
0N/A movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
0N/A call(rax);
0N/A // Caller pops the arguments and restores rax, from the stack
0N/A}
0N/A
304N/Avoid MacroAssembler::verify_tlab() {
304N/A#ifdef ASSERT
304N/A if (UseTLAB && VerifyOops) {
304N/A Label next, ok;
304N/A Register t1 = rsi;
304N/A Register thread_reg = NOT_LP64(rbx) LP64_ONLY(r15_thread);
304N/A
304N/A push(t1);
304N/A NOT_LP64(push(thread_reg));
304N/A NOT_LP64(get_thread(thread_reg));
304N/A
304N/A movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
304N/A cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_start_offset())));
304N/A jcc(Assembler::aboveEqual, next);
304N/A stop("assert(top >= start)");
304N/A should_not_reach_here();
304N/A
304N/A bind(next);
304N/A movptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())));
304N/A cmpptr(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
304N/A jcc(Assembler::aboveEqual, ok);
304N/A stop("assert(top <= end)");
304N/A should_not_reach_here();
304N/A
304N/A bind(ok);
304N/A NOT_LP64(pop(thread_reg));
304N/A pop(t1);
304N/A }
304N/A#endif
304N/A}
0N/A
0N/Aclass ControlWord {
0N/A public:
0N/A int32_t _value;
0N/A
0N/A int rounding_control() const { return (_value >> 10) & 3 ; }
0N/A int precision_control() const { return (_value >> 8) & 3 ; }
0N/A bool precision() const { return ((_value >> 5) & 1) != 0; }
0N/A bool underflow() const { return ((_value >> 4) & 1) != 0; }
0N/A bool overflow() const { return ((_value >> 3) & 1) != 0; }
0N/A bool zero_divide() const { return ((_value >> 2) & 1) != 0; }
0N/A bool denormalized() const { return ((_value >> 1) & 1) != 0; }
0N/A bool invalid() const { return ((_value >> 0) & 1) != 0; }
0N/A
0N/A void print() const {
0N/A // rounding control
0N/A const char* rc;
0N/A switch (rounding_control()) {
0N/A case 0: rc = "round near"; break;
0N/A case 1: rc = "round down"; break;
0N/A case 2: rc = "round up "; break;
0N/A case 3: rc = "chop "; break;
0N/A };
0N/A // precision control
0N/A const char* pc;
0N/A switch (precision_control()) {
0N/A case 0: pc = "24 bits "; break;
0N/A case 1: pc = "reserved"; break;
0N/A case 2: pc = "53 bits "; break;
0N/A case 3: pc = "64 bits "; break;
0N/A };
0N/A // flags
0N/A char f[9];
0N/A f[0] = ' ';
0N/A f[1] = ' ';
0N/A f[2] = (precision ()) ? 'P' : 'p';
0N/A f[3] = (underflow ()) ? 'U' : 'u';
0N/A f[4] = (overflow ()) ? 'O' : 'o';
0N/A f[5] = (zero_divide ()) ? 'Z' : 'z';
0N/A f[6] = (denormalized()) ? 'D' : 'd';
0N/A f[7] = (invalid ()) ? 'I' : 'i';
0N/A f[8] = '\x0';
0N/A // output
0N/A printf("%04x masks = %s, %s, %s", _value & 0xFFFF, f, rc, pc);
0N/A }
0N/A
0N/A};
0N/A
0N/Aclass StatusWord {
0N/A public:
0N/A int32_t _value;
0N/A
0N/A bool busy() const { return ((_value >> 15) & 1) != 0; }
0N/A bool C3() const { return ((_value >> 14) & 1) != 0; }
0N/A bool C2() const { return ((_value >> 10) & 1) != 0; }
0N/A bool C1() const { return ((_value >> 9) & 1) != 0; }
0N/A bool C0() const { return ((_value >> 8) & 1) != 0; }
0N/A int top() const { return (_value >> 11) & 7 ; }
0N/A bool error_status() const { return ((_value >> 7) & 1) != 0; }
0N/A bool stack_fault() const { return ((_value >> 6) & 1) != 0; }
0N/A bool precision() const { return ((_value >> 5) & 1) != 0; }
0N/A bool underflow() const { return ((_value >> 4) & 1) != 0; }
0N/A bool overflow() const { return ((_value >> 3) & 1) != 0; }
0N/A bool zero_divide() const { return ((_value >> 2) & 1) != 0; }
0N/A bool denormalized() const { return ((_value >> 1) & 1) != 0; }
0N/A bool invalid() const { return ((_value >> 0) & 1) != 0; }
0N/A
0N/A void print() const {
0N/A // condition codes
0N/A char c[5];
0N/A c[0] = (C3()) ? '3' : '-';
0N/A c[1] = (C2()) ? '2' : '-';
0N/A c[2] = (C1()) ? '1' : '-';
0N/A c[3] = (C0()) ? '0' : '-';
0N/A c[4] = '\x0';
0N/A // flags
0N/A char f[9];
0N/A f[0] = (error_status()) ? 'E' : '-';
0N/A f[1] = (stack_fault ()) ? 'S' : '-';
0N/A f[2] = (precision ()) ? 'P' : '-';
0N/A f[3] = (underflow ()) ? 'U' : '-';
0N/A f[4] = (overflow ()) ? 'O' : '-';
0N/A f[5] = (zero_divide ()) ? 'Z' : '-';
0N/A f[6] = (denormalized()) ? 'D' : '-';
0N/A f[7] = (invalid ()) ? 'I' : '-';
0N/A f[8] = '\x0';
0N/A // output
0N/A printf("%04x flags = %s, cc = %s, top = %d", _value & 0xFFFF, f, c, top());
0N/A }
0N/A
0N/A};
0N/A
0N/Aclass TagWord {
0N/A public:
0N/A int32_t _value;
0N/A
0N/A int tag_at(int i) const { return (_value >> (i*2)) & 3; }
0N/A
0N/A void print() const {
0N/A printf("%04x", _value & 0xFFFF);
0N/A }
0N/A
0N/A};
0N/A
0N/Aclass FPU_Register {
0N/A public:
0N/A int32_t _m0;
0N/A int32_t _m1;
0N/A int16_t _ex;
0N/A
0N/A bool is_indefinite() const {
0N/A return _ex == -1 && _m1 == (int32_t)0xC0000000 && _m0 == 0;
0N/A }
0N/A
0N/A void print() const {
0N/A char sign = (_ex < 0) ? '-' : '+';
0N/A const char* kind = (_ex == 0x7FFF || _ex == (int16_t)-1) ? "NaN" : " ";
0N/A printf("%c%04hx.%08x%08x %s", sign, _ex, _m1, _m0, kind);
0N/A };
0N/A
0N/A};
0N/A
0N/Aclass FPU_State {
0N/A public:
0N/A enum {
0N/A register_size = 10,
0N/A number_of_registers = 8,
0N/A register_mask = 7
0N/A };
0N/A
0N/A ControlWord _control_word;
0N/A StatusWord _status_word;
0N/A TagWord _tag_word;
0N/A int32_t _error_offset;
0N/A int32_t _error_selector;
0N/A int32_t _data_offset;
0N/A int32_t _data_selector;
0N/A int8_t _register[register_size * number_of_registers];
0N/A
0N/A int tag_for_st(int i) const { return _tag_word.tag_at((_status_word.top() + i) & register_mask); }
0N/A FPU_Register* st(int i) const { return (FPU_Register*)&_register[register_size * i]; }
0N/A
0N/A const char* tag_as_string(int tag) const {
0N/A switch (tag) {
0N/A case 0: return "valid";
0N/A case 1: return "zero";
0N/A case 2: return "special";
0N/A case 3: return "empty";
0N/A }
0N/A ShouldNotReachHere()
0N/A return NULL;
0N/A }
0N/A
0N/A void print() const {
0N/A // print computation registers
0N/A { int t = _status_word.top();
0N/A for (int i = 0; i < number_of_registers; i++) {
0N/A int j = (i - t) & register_mask;
0N/A printf("%c r%d = ST%d = ", (j == 0 ? '*' : ' '), i, j);
0N/A st(j)->print();
0N/A printf(" %s\n", tag_as_string(_tag_word.tag_at(i)));
0N/A }
0N/A }
0N/A printf("\n");
0N/A // print control registers
0N/A printf("ctrl = "); _control_word.print(); printf("\n");
0N/A printf("stat = "); _status_word .print(); printf("\n");
0N/A printf("tags = "); _tag_word .print(); printf("\n");
0N/A }
0N/A
0N/A};
0N/A
0N/Aclass Flag_Register {
0N/A public:
0N/A int32_t _value;
0N/A
0N/A bool overflow() const { return ((_value >> 11) & 1) != 0; }
0N/A bool direction() const { return ((_value >> 10) & 1) != 0; }
0N/A bool sign() const { return ((_value >> 7) & 1) != 0; }
0N/A bool zero() const { return ((_value >> 6) & 1) != 0; }
0N/A bool auxiliary_carry() const { return ((_value >> 4) & 1) != 0; }
0N/A bool parity() const { return ((_value >> 2) & 1) != 0; }
0N/A bool carry() const { return ((_value >> 0) & 1) != 0; }
0N/A
0N/A void print() const {
0N/A // flags
0N/A char f[8];
0N/A f[0] = (overflow ()) ? 'O' : '-';
0N/A f[1] = (direction ()) ? 'D' : '-';
0N/A f[2] = (sign ()) ? 'S' : '-';
0N/A f[3] = (zero ()) ? 'Z' : '-';
0N/A f[4] = (auxiliary_carry()) ? 'A' : '-';
0N/A f[5] = (parity ()) ? 'P' : '-';
0N/A f[6] = (carry ()) ? 'C' : '-';
0N/A f[7] = '\x0';
0N/A // output
0N/A printf("%08x flags = %s", _value, f);
0N/A }
0N/A
0N/A};
0N/A
0N/Aclass IU_Register {
0N/A public:
0N/A int32_t _value;
0N/A
0N/A void print() const {
0N/A printf("%08x %11d", _value, _value);
0N/A }
0N/A
0N/A};
0N/A
0N/Aclass IU_State {
0N/A public:
0N/A Flag_Register _eflags;
0N/A IU_Register _rdi;
0N/A IU_Register _rsi;
0N/A IU_Register _rbp;
0N/A IU_Register _rsp;
0N/A IU_Register _rbx;
0N/A IU_Register _rdx;
0N/A IU_Register _rcx;
0N/A IU_Register _rax;
0N/A
0N/A void print() const {
0N/A // computation registers
0N/A printf("rax, = "); _rax.print(); printf("\n");
0N/A printf("rbx, = "); _rbx.print(); printf("\n");
0N/A printf("rcx = "); _rcx.print(); printf("\n");
0N/A printf("rdx = "); _rdx.print(); printf("\n");
0N/A printf("rdi = "); _rdi.print(); printf("\n");
0N/A printf("rsi = "); _rsi.print(); printf("\n");
0N/A printf("rbp, = "); _rbp.print(); printf("\n");
0N/A printf("rsp = "); _rsp.print(); printf("\n");
0N/A printf("\n");
0N/A // control registers
0N/A printf("flgs = "); _eflags.print(); printf("\n");
0N/A }
0N/A};
0N/A
0N/A
0N/Aclass CPU_State {
0N/A public:
0N/A FPU_State _fpu_state;
0N/A IU_State _iu_state;
0N/A
0N/A void print() const {
0N/A printf("--------------------------------------------------\n");
0N/A _iu_state .print();
0N/A printf("\n");
0N/A _fpu_state.print();
0N/A printf("--------------------------------------------------\n");
0N/A }
0N/A
0N/A};
0N/A
0N/A
0N/Astatic void _print_CPU_state(CPU_State* state) {
0N/A state->print();
0N/A};
0N/A
0N/A
0N/Avoid MacroAssembler::print_CPU_state() {
0N/A push_CPU_state();
304N/A push(rsp); // pass CPU state
0N/A call(RuntimeAddress(CAST_FROM_FN_PTR(address, _print_CPU_state)));
304N/A addptr(rsp, wordSize); // discard argument
0N/A pop_CPU_state();
0N/A}
0N/A
0N/A
0N/Astatic bool _verify_FPU(int stack_depth, char* s, CPU_State* state) {
0N/A static int counter = 0;
0N/A FPU_State* fs = &state->_fpu_state;
0N/A counter++;
0N/A // For leaf calls, only verify that the top few elements remain empty.
0N/A // We only need 1 empty at the top for C2 code.
0N/A if( stack_depth < 0 ) {
0N/A if( fs->tag_for_st(7) != 3 ) {
0N/A printf("FPR7 not empty\n");
0N/A state->print();
0N/A assert(false, "error");
0N/A return false;
0N/A }
0N/A return true; // All other stack states do not matter
0N/A }
0N/A
0N/A assert((fs->_control_word._value & 0xffff) == StubRoutines::_fpu_cntrl_wrd_std,
0N/A "bad FPU control word");
0N/A
0N/A // compute stack depth
0N/A int i = 0;
0N/A while (i < FPU_State::number_of_registers && fs->tag_for_st(i) < 3) i++;
0N/A int d = i;
0N/A while (i < FPU_State::number_of_registers && fs->tag_for_st(i) == 3) i++;
0N/A // verify findings
0N/A if (i != FPU_State::number_of_registers) {
0N/A // stack not contiguous
0N/A printf("%s: stack not contiguous at ST%d\n", s, i);
0N/A state->print();
0N/A assert(false, "error");
0N/A return false;
0N/A }
0N/A // check if computed stack depth corresponds to expected stack depth
0N/A if (stack_depth < 0) {
0N/A // expected stack depth is -stack_depth or less
0N/A if (d > -stack_depth) {
0N/A // too many elements on the stack
0N/A printf("%s: <= %d stack elements expected but found %d\n", s, -stack_depth, d);
0N/A state->print();
0N/A assert(false, "error");
0N/A return false;
0N/A }
0N/A } else {
0N/A // expected stack depth is stack_depth
0N/A if (d != stack_depth) {
0N/A // wrong stack depth
0N/A printf("%s: %d stack elements expected but found %d\n", s, stack_depth, d);
0N/A state->print();
0N/A assert(false, "error");
0N/A return false;
0N/A }
0N/A }
0N/A // everything is cool
0N/A return true;
0N/A}
0N/A
0N/A
0N/Avoid MacroAssembler::verify_FPU(int stack_depth, const char* s) {
0N/A if (!VerifyFPU) return;
0N/A push_CPU_state();
304N/A push(rsp); // pass CPU state
0N/A ExternalAddress msg((address) s);
0N/A // pass message string s
0N/A pushptr(msg.addr());
304N/A push(stack_depth); // pass stack depth
0N/A call(RuntimeAddress(CAST_FROM_FN_PTR(address, _verify_FPU)));
304N/A addptr(rsp, 3 * wordSize); // discard arguments
0N/A // check for error
0N/A { Label L;
0N/A testl(rax, rax);
0N/A jcc(Assembler::notZero, L);
0N/A int3(); // break if error condition
0N/A bind(L);
0N/A }
0N/A pop_CPU_state();
0N/A}
0N/A
304N/Avoid MacroAssembler::load_klass(Register dst, Register src) {
304N/A#ifdef _LP64
304N/A if (UseCompressedOops) {
304N/A movl(dst, Address(src, oopDesc::klass_offset_in_bytes()));
304N/A decode_heap_oop_not_null(dst);
304N/A } else
304N/A#endif
304N/A movptr(dst, Address(src, oopDesc::klass_offset_in_bytes()));
304N/A}
304N/A
304N/Avoid MacroAssembler::load_prototype_header(Register dst, Register src) {
304N/A#ifdef _LP64
304N/A if (UseCompressedOops) {
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
304N/A movl(dst, Address(src, oopDesc::klass_offset_in_bytes()));
642N/A if (Universe::narrow_oop_shift() != 0) {
642N/A assert(Address::times_8 == LogMinObjAlignmentInBytes &&
642N/A Address::times_8 == Universe::narrow_oop_shift(), "decode alg wrong");
642N/A movq(dst, Address(r12_heapbase, dst, Address::times_8, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
642N/A } else {
642N/A movq(dst, Address(dst, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
642N/A }
304N/A } else
304N/A#endif
642N/A {
642N/A movptr(dst, Address(src, oopDesc::klass_offset_in_bytes()));
642N/A movptr(dst, Address(dst, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
642N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::store_klass(Register dst, Register src) {
304N/A#ifdef _LP64
304N/A if (UseCompressedOops) {
304N/A encode_heap_oop_not_null(src);
304N/A movl(Address(dst, oopDesc::klass_offset_in_bytes()), src);
304N/A } else
304N/A#endif
304N/A movptr(Address(dst, oopDesc::klass_offset_in_bytes()), src);
304N/A}
304N/A
304N/A#ifdef _LP64
304N/Avoid MacroAssembler::store_klass_gap(Register dst, Register src) {
304N/A if (UseCompressedOops) {
304N/A // Store to klass gap in destination
304N/A movl(Address(dst, oopDesc::klass_gap_offset_in_bytes()), src);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::load_heap_oop(Register dst, Address src) {
304N/A if (UseCompressedOops) {
304N/A movl(dst, src);
304N/A decode_heap_oop(dst);
304N/A } else {
304N/A movq(dst, src);
304N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::store_heap_oop(Address dst, Register src) {
304N/A if (UseCompressedOops) {
304N/A assert(!dst.uses(src), "not enough registers");
304N/A encode_heap_oop(src);
304N/A movl(dst, src);
304N/A } else {
304N/A movq(dst, src);
304N/A }
304N/A}
304N/A
1047N/A// Used for storing NULLs.
1047N/Avoid MacroAssembler::store_heap_oop_null(Address dst) {
1047N/A if (UseCompressedOops) {
1047N/A movl(dst, (int32_t)NULL_WORD);
1047N/A } else {
1047N/A movslq(dst, (int32_t)NULL_WORD);
1047N/A }
1047N/A}
1047N/A
304N/A// Algorithm must match oop.inline.hpp encode_heap_oop.
304N/Avoid MacroAssembler::encode_heap_oop(Register r) {
304N/A assert (UseCompressedOops, "should be compressed");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
642N/A if (Universe::narrow_oop_base() == NULL) {
642N/A verify_oop(r, "broken oop in encode_heap_oop");
642N/A if (Universe::narrow_oop_shift() != 0) {
642N/A assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong");
642N/A shrq(r, LogMinObjAlignmentInBytes);
642N/A }
642N/A return;
642N/A }
0N/A#ifdef ASSERT
304N/A if (CheckCompressedOops) {
304N/A Label ok;
304N/A push(rscratch1); // cmpptr trashes rscratch1
642N/A cmpptr(r12_heapbase, ExternalAddress((address)Universe::narrow_oop_base_addr()));
304N/A jcc(Assembler::equal, ok);
304N/A stop("MacroAssembler::encode_heap_oop: heap base corrupted?");
0N/A bind(ok);
304N/A pop(rscratch1);
0N/A }
0N/A#endif
304N/A verify_oop(r, "broken oop in encode_heap_oop");
304N/A testq(r, r);
304N/A cmovq(Assembler::equal, r, r12_heapbase);
304N/A subq(r, r12_heapbase);
304N/A shrq(r, LogMinObjAlignmentInBytes);
304N/A}
304N/A
304N/Avoid MacroAssembler::encode_heap_oop_not_null(Register r) {
304N/A assert (UseCompressedOops, "should be compressed");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
0N/A#ifdef ASSERT
304N/A if (CheckCompressedOops) {
0N/A Label ok;
304N/A testq(r, r);
304N/A jcc(Assembler::notEqual, ok);
304N/A stop("null oop passed to encode_heap_oop_not_null");
0N/A bind(ok);
304N/A }
304N/A#endif
304N/A verify_oop(r, "broken oop in encode_heap_oop_not_null");
642N/A if (Universe::narrow_oop_base() != NULL) {
642N/A subq(r, r12_heapbase);
642N/A }
642N/A if (Universe::narrow_oop_shift() != 0) {
642N/A assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong");
642N/A shrq(r, LogMinObjAlignmentInBytes);
642N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::encode_heap_oop_not_null(Register dst, Register src) {
304N/A assert (UseCompressedOops, "should be compressed");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
304N/A#ifdef ASSERT
304N/A if (CheckCompressedOops) {
304N/A Label ok;
304N/A testq(src, src);
304N/A jcc(Assembler::notEqual, ok);
304N/A stop("null oop passed to encode_heap_oop_not_null2");
304N/A bind(ok);
0N/A }
0N/A#endif
304N/A verify_oop(src, "broken oop in encode_heap_oop_not_null2");
304N/A if (dst != src) {
304N/A movq(dst, src);
304N/A }
642N/A if (Universe::narrow_oop_base() != NULL) {
642N/A subq(dst, r12_heapbase);
642N/A }
642N/A if (Universe::narrow_oop_shift() != 0) {
642N/A assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong");
642N/A shrq(dst, LogMinObjAlignmentInBytes);
642N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::decode_heap_oop(Register r) {
304N/A assert (UseCompressedOops, "should be compressed");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
642N/A if (Universe::narrow_oop_base() == NULL) {
642N/A if (Universe::narrow_oop_shift() != 0) {
642N/A assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong");
642N/A shlq(r, LogMinObjAlignmentInBytes);
642N/A }
642N/A verify_oop(r, "broken oop in decode_heap_oop");
642N/A return;
642N/A }
304N/A#ifdef ASSERT
304N/A if (CheckCompressedOops) {
304N/A Label ok;
304N/A push(rscratch1);
304N/A cmpptr(r12_heapbase,
642N/A ExternalAddress((address)Universe::narrow_oop_base_addr()));
304N/A jcc(Assembler::equal, ok);
304N/A stop("MacroAssembler::decode_heap_oop: heap base corrupted?");
304N/A bind(ok);
304N/A pop(rscratch1);
304N/A }
304N/A#endif
304N/A
304N/A Label done;
304N/A shlq(r, LogMinObjAlignmentInBytes);
304N/A jccb(Assembler::equal, done);
304N/A addq(r, r12_heapbase);
304N/A#if 0
304N/A // alternate decoding probably a wash.
304N/A testq(r, r);
304N/A jccb(Assembler::equal, done);
304N/A leaq(r, Address(r12_heapbase, r, Address::times_8, 0));
304N/A#endif
304N/A bind(done);
304N/A verify_oop(r, "broken oop in decode_heap_oop");
304N/A}
304N/A
304N/Avoid MacroAssembler::decode_heap_oop_not_null(Register r) {
304N/A assert (UseCompressedOops, "should only be used for compressed headers");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
304N/A // Cannot assert, unverified entry point counts instructions (see .ad file)
304N/A // vtableStubs also counts instructions in pd_code_size_limit.
304N/A // Also do not verify_oop as this is called by verify_oop.
898N/A if (Universe::narrow_oop_shift() != 0) {
898N/A assert (Address::times_8 == LogMinObjAlignmentInBytes &&
898N/A Address::times_8 == Universe::narrow_oop_shift(), "decode alg wrong");
898N/A // Don't use Shift since it modifies flags.
898N/A leaq(r, Address(r12_heapbase, r, Address::times_8, 0));
642N/A } else {
898N/A assert (Universe::narrow_oop_base() == NULL, "sanity");
642N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::decode_heap_oop_not_null(Register dst, Register src) {
304N/A assert (UseCompressedOops, "should only be used for compressed headers");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
304N/A // Cannot assert, unverified entry point counts instructions (see .ad file)
304N/A // vtableStubs also counts instructions in pd_code_size_limit.
304N/A // Also do not verify_oop as this is called by verify_oop.
642N/A if (Universe::narrow_oop_shift() != 0) {
642N/A assert (Address::times_8 == LogMinObjAlignmentInBytes &&
642N/A Address::times_8 == Universe::narrow_oop_shift(), "decode alg wrong");
642N/A leaq(dst, Address(r12_heapbase, src, Address::times_8, 0));
642N/A } else if (dst != src) {
898N/A assert (Universe::narrow_oop_base() == NULL, "sanity");
642N/A movq(dst, src);
642N/A }
304N/A}
304N/A
304N/Avoid MacroAssembler::set_narrow_oop(Register dst, jobject obj) {
642N/A assert (UseCompressedOops, "should only be used for compressed headers");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
642N/A assert (oop_recorder() != NULL, "this assembler needs an OopRecorder");
642N/A int oop_index = oop_recorder()->find_index(obj);
642N/A RelocationHolder rspec = oop_Relocation::spec(oop_index);
642N/A mov_narrow_oop(dst, oop_index, rspec);
642N/A}
642N/A
642N/Avoid MacroAssembler::set_narrow_oop(Address dst, jobject obj) {
642N/A assert (UseCompressedOops, "should only be used for compressed headers");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
642N/A assert (oop_recorder() != NULL, "this assembler needs an OopRecorder");
304N/A int oop_index = oop_recorder()->find_index(obj);
304N/A RelocationHolder rspec = oop_Relocation::spec(oop_index);
642N/A mov_narrow_oop(dst, oop_index, rspec);
642N/A}
642N/A
642N/Avoid MacroAssembler::cmp_narrow_oop(Register dst, jobject obj) {
642N/A assert (UseCompressedOops, "should only be used for compressed headers");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
642N/A assert (oop_recorder() != NULL, "this assembler needs an OopRecorder");
642N/A int oop_index = oop_recorder()->find_index(obj);
642N/A RelocationHolder rspec = oop_Relocation::spec(oop_index);
642N/A Assembler::cmp_narrow_oop(dst, oop_index, rspec);
642N/A}
642N/A
642N/Avoid MacroAssembler::cmp_narrow_oop(Address dst, jobject obj) {
642N/A assert (UseCompressedOops, "should only be used for compressed headers");
642N/A assert (Universe::heap() != NULL, "java heap should be initialized");
642N/A assert (oop_recorder() != NULL, "this assembler needs an OopRecorder");
642N/A int oop_index = oop_recorder()->find_index(obj);
642N/A RelocationHolder rspec = oop_Relocation::spec(oop_index);
642N/A Assembler::cmp_narrow_oop(dst, oop_index, rspec);
304N/A}
304N/A
304N/Avoid MacroAssembler::reinit_heapbase() {
304N/A if (UseCompressedOops) {
642N/A movptr(r12_heapbase, ExternalAddress((address)Universe::narrow_oop_base_addr()));
304N/A }
304N/A}
304N/A#endif // _LP64
0N/A
986N/A// IndexOf substring.
986N/Avoid MacroAssembler::string_indexof(Register str1, Register str2,
986N/A Register cnt1, Register cnt2, Register result,
986N/A XMMRegister vec, Register tmp) {
986N/A assert(UseSSE42Intrinsics, "SSE4.2 is required");
986N/A
986N/A Label RELOAD_SUBSTR, PREP_FOR_SCAN, SCAN_TO_SUBSTR,
986N/A SCAN_SUBSTR, RET_NOT_FOUND, CLEANUP;
986N/A
986N/A push(str1); // string addr
986N/A push(str2); // substr addr
986N/A push(cnt2); // substr count
986N/A jmpb(PREP_FOR_SCAN);
986N/A
986N/A // Substr count saved at sp
986N/A // Substr saved at sp+1*wordSize
986N/A // String saved at sp+2*wordSize
986N/A
986N/A // Reload substr for rescan
986N/A bind(RELOAD_SUBSTR);
986N/A movl(cnt2, Address(rsp, 0));
986N/A movptr(str2, Address(rsp, wordSize));
986N/A // We came here after the beginninig of the substring was
986N/A // matched but the rest of it was not so we need to search
986N/A // again. Start from the next element after the previous match.
986N/A subptr(str1, result); // Restore counter
986N/A shrl(str1, 1);
986N/A addl(cnt1, str1);
986N/A lea(str1, Address(result, 2)); // Reload string
986N/A
986N/A // Load substr
986N/A bind(PREP_FOR_SCAN);
986N/A movdqu(vec, Address(str2, 0));
986N/A addl(cnt1, 8); // prime the loop
986N/A subptr(str1, 16);
986N/A
986N/A // Scan string for substr in 16-byte vectors
986N/A bind(SCAN_TO_SUBSTR);
986N/A subl(cnt1, 8);
986N/A addptr(str1, 16);
986N/A
986N/A // pcmpestri
986N/A // inputs:
986N/A // xmm - substring
986N/A // rax - substring length (elements count)
986N/A // mem - scaned string
986N/A // rdx - string length (elements count)
986N/A // 0xd - mode: 1100 (substring search) + 01 (unsigned shorts)
986N/A // outputs:
986N/A // rcx - matched index in string
986N/A assert(cnt1 == rdx && cnt2 == rax && tmp == rcx, "pcmpestri");
986N/A
986N/A pcmpestri(vec, Address(str1, 0), 0x0d);
986N/A jcc(Assembler::above, SCAN_TO_SUBSTR); // CF == 0 && ZF == 0
986N/A jccb(Assembler::aboveEqual, RET_NOT_FOUND); // CF == 0
986N/A
986N/A // Fallthrough: found a potential substr
986N/A
986N/A // Make sure string is still long enough
986N/A subl(cnt1, tmp);
986N/A cmpl(cnt1, cnt2);
986N/A jccb(Assembler::negative, RET_NOT_FOUND);
986N/A // Compute start addr of substr
986N/A lea(str1, Address(str1, tmp, Address::times_2));
986N/A movptr(result, str1); // save
986N/A
986N/A // Compare potential substr
986N/A addl(cnt1, 8); // prime the loop
986N/A addl(cnt2, 8);
986N/A subptr(str1, 16);
986N/A subptr(str2, 16);
986N/A
986N/A // Scan 16-byte vectors of string and substr
986N/A bind(SCAN_SUBSTR);
986N/A subl(cnt1, 8);
986N/A subl(cnt2, 8);
986N/A addptr(str1, 16);
986N/A addptr(str2, 16);
986N/A movdqu(vec, Address(str2, 0));
986N/A pcmpestri(vec, Address(str1, 0), 0x0d);
986N/A jcc(Assembler::noOverflow, RELOAD_SUBSTR); // OF == 0
986N/A jcc(Assembler::positive, SCAN_SUBSTR); // SF == 0
986N/A
986N/A // Compute substr offset
986N/A subptr(result, Address(rsp, 2*wordSize));
986N/A shrl(result, 1); // index
986N/A jmpb(CLEANUP);
986N/A
986N/A bind(RET_NOT_FOUND);
986N/A movl(result, -1);
986N/A
986N/A bind(CLEANUP);
986N/A addptr(rsp, 3*wordSize);
986N/A}
986N/A
986N/A// Compare strings.
986N/Avoid MacroAssembler::string_compare(Register str1, Register str2,
986N/A Register cnt1, Register cnt2, Register result,
986N/A XMMRegister vec1, XMMRegister vec2) {
986N/A Label LENGTH_DIFF_LABEL, POP_LABEL, DONE_LABEL, WHILE_HEAD_LABEL;
986N/A
986N/A // Compute the minimum of the string lengths and the
986N/A // difference of the string lengths (stack).
986N/A // Do the conditional move stuff
986N/A movl(result, cnt1);
986N/A subl(cnt1, cnt2);
986N/A push(cnt1);
986N/A if (VM_Version::supports_cmov()) {
986N/A cmovl(Assembler::lessEqual, cnt2, result);
986N/A } else {
986N/A Label GT_LABEL;
986N/A jccb(Assembler::greater, GT_LABEL);
986N/A movl(cnt2, result);
986N/A bind(GT_LABEL);
986N/A }
986N/A
986N/A // Is the minimum length zero?
986N/A testl(cnt2, cnt2);
986N/A jcc(Assembler::zero, LENGTH_DIFF_LABEL);
986N/A
986N/A // Load first characters
986N/A load_unsigned_short(result, Address(str1, 0));
986N/A load_unsigned_short(cnt1, Address(str2, 0));
986N/A
986N/A // Compare first characters
986N/A subl(result, cnt1);
986N/A jcc(Assembler::notZero, POP_LABEL);
986N/A decrementl(cnt2);
986N/A jcc(Assembler::zero, LENGTH_DIFF_LABEL);
986N/A
986N/A {
986N/A // Check after comparing first character to see if strings are equivalent
986N/A Label LSkip2;
986N/A // Check if the strings start at same location
986N/A cmpptr(str1, str2);
986N/A jccb(Assembler::notEqual, LSkip2);
986N/A
986N/A // Check if the length difference is zero (from stack)
986N/A cmpl(Address(rsp, 0), 0x0);
986N/A jcc(Assembler::equal, LENGTH_DIFF_LABEL);
986N/A
986N/A // Strings might not be equivalent
986N/A bind(LSkip2);
986N/A }
986N/A
986N/A // Advance to next character
986N/A addptr(str1, 2);
986N/A addptr(str2, 2);
986N/A
986N/A if (UseSSE42Intrinsics) {
986N/A // With SSE4.2, use double quad vector compare
986N/A Label COMPARE_VECTORS, VECTOR_NOT_EQUAL, COMPARE_TAIL;
986N/A // Setup to compare 16-byte vectors
986N/A movl(cnt1, cnt2);
986N/A andl(cnt2, 0xfffffff8); // cnt2 holds the vector count
986N/A andl(cnt1, 0x00000007); // cnt1 holds the tail count
986N/A testl(cnt2, cnt2);
986N/A jccb(Assembler::zero, COMPARE_TAIL);
986N/A
986N/A lea(str2, Address(str2, cnt2, Address::times_2));
986N/A lea(str1, Address(str1, cnt2, Address::times_2));
986N/A negptr(cnt2);
986N/A
986N/A bind(COMPARE_VECTORS);
986N/A movdqu(vec1, Address(str1, cnt2, Address::times_2));
986N/A movdqu(vec2, Address(str2, cnt2, Address::times_2));
986N/A pxor(vec1, vec2);
986N/A ptest(vec1, vec1);
986N/A jccb(Assembler::notZero, VECTOR_NOT_EQUAL);
986N/A addptr(cnt2, 8);
986N/A jcc(Assembler::notZero, COMPARE_VECTORS);
986N/A jmpb(COMPARE_TAIL);
986N/A
986N/A // Mismatched characters in the vectors
986N/A bind(VECTOR_NOT_EQUAL);
986N/A lea(str1, Address(str1, cnt2, Address::times_2));
986N/A lea(str2, Address(str2, cnt2, Address::times_2));
986N/A movl(cnt1, 8);
986N/A
986N/A // Compare tail (< 8 chars), or rescan last vectors to
986N/A // find 1st mismatched characters
986N/A bind(COMPARE_TAIL);
986N/A testl(cnt1, cnt1);
986N/A jccb(Assembler::zero, LENGTH_DIFF_LABEL);
986N/A movl(cnt2, cnt1);
986N/A // Fallthru to tail compare
986N/A }
986N/A
986N/A // Shift str2 and str1 to the end of the arrays, negate min
986N/A lea(str1, Address(str1, cnt2, Address::times_2, 0));
986N/A lea(str2, Address(str2, cnt2, Address::times_2, 0));
986N/A negptr(cnt2);
986N/A
986N/A // Compare the rest of the characters
986N/A bind(WHILE_HEAD_LABEL);
986N/A load_unsigned_short(result, Address(str1, cnt2, Address::times_2, 0));
986N/A load_unsigned_short(cnt1, Address(str2, cnt2, Address::times_2, 0));
986N/A subl(result, cnt1);
986N/A jccb(Assembler::notZero, POP_LABEL);
986N/A increment(cnt2);
986N/A jcc(Assembler::notZero, WHILE_HEAD_LABEL);
986N/A
986N/A // Strings are equal up to min length. Return the length difference.
986N/A bind(LENGTH_DIFF_LABEL);
986N/A pop(result);
986N/A jmpb(DONE_LABEL);
986N/A
986N/A // Discard the stored length difference
986N/A bind(POP_LABEL);
986N/A addptr(rsp, wordSize);
986N/A
986N/A // That's it
986N/A bind(DONE_LABEL);
986N/A}
986N/A
986N/A// Compare char[] arrays aligned to 4 bytes or substrings.
986N/Avoid MacroAssembler::char_arrays_equals(bool is_array_equ, Register ary1, Register ary2,
986N/A Register limit, Register result, Register chr,
986N/A XMMRegister vec1, XMMRegister vec2) {
986N/A Label TRUE_LABEL, FALSE_LABEL, DONE, COMPARE_VECTORS, COMPARE_CHAR;
986N/A
986N/A int length_offset = arrayOopDesc::length_offset_in_bytes();
986N/A int base_offset = arrayOopDesc::base_offset_in_bytes(T_CHAR);
986N/A
986N/A // Check the input args
986N/A cmpptr(ary1, ary2);
986N/A jcc(Assembler::equal, TRUE_LABEL);
986N/A
986N/A if (is_array_equ) {
986N/A // Need additional checks for arrays_equals.
1016N/A testptr(ary1, ary1);
1016N/A jcc(Assembler::zero, FALSE_LABEL);
1016N/A testptr(ary2, ary2);
1016N/A jcc(Assembler::zero, FALSE_LABEL);
986N/A
986N/A // Check the lengths
986N/A movl(limit, Address(ary1, length_offset));
986N/A cmpl(limit, Address(ary2, length_offset));
986N/A jcc(Assembler::notEqual, FALSE_LABEL);
986N/A }
986N/A
986N/A // count == 0
986N/A testl(limit, limit);
986N/A jcc(Assembler::zero, TRUE_LABEL);
986N/A
986N/A if (is_array_equ) {
986N/A // Load array address
986N/A lea(ary1, Address(ary1, base_offset));
986N/A lea(ary2, Address(ary2, base_offset));
986N/A }
986N/A
986N/A shll(limit, 1); // byte count != 0
986N/A movl(result, limit); // copy
986N/A
986N/A if (UseSSE42Intrinsics) {
986N/A // With SSE4.2, use double quad vector compare
986N/A Label COMPARE_WIDE_VECTORS, COMPARE_TAIL;
986N/A // Compare 16-byte vectors
986N/A andl(result, 0x0000000e); // tail count (in bytes)
986N/A andl(limit, 0xfffffff0); // vector count (in bytes)
986N/A jccb(Assembler::zero, COMPARE_TAIL);
986N/A
986N/A lea(ary1, Address(ary1, limit, Address::times_1));
986N/A lea(ary2, Address(ary2, limit, Address::times_1));
986N/A negptr(limit);
986N/A
986N/A bind(COMPARE_WIDE_VECTORS);
986N/A movdqu(vec1, Address(ary1, limit, Address::times_1));
986N/A movdqu(vec2, Address(ary2, limit, Address::times_1));
986N/A pxor(vec1, vec2);
986N/A ptest(vec1, vec1);
986N/A jccb(Assembler::notZero, FALSE_LABEL);
986N/A addptr(limit, 16);
986N/A jcc(Assembler::notZero, COMPARE_WIDE_VECTORS);
986N/A
986N/A bind(COMPARE_TAIL); // limit is zero
986N/A movl(limit, result);
986N/A // Fallthru to tail compare
986N/A }
986N/A
986N/A // Compare 4-byte vectors
986N/A andl(limit, 0xfffffffc); // vector count (in bytes)
986N/A jccb(Assembler::zero, COMPARE_CHAR);
986N/A
986N/A lea(ary1, Address(ary1, limit, Address::times_1));
986N/A lea(ary2, Address(ary2, limit, Address::times_1));
986N/A negptr(limit);
986N/A
986N/A bind(COMPARE_VECTORS);
986N/A movl(chr, Address(ary1, limit, Address::times_1));
986N/A cmpl(chr, Address(ary2, limit, Address::times_1));
986N/A jccb(Assembler::notEqual, FALSE_LABEL);
986N/A addptr(limit, 4);
986N/A jcc(Assembler::notZero, COMPARE_VECTORS);
986N/A
986N/A // Compare trailing char (final 2 bytes), if any
986N/A bind(COMPARE_CHAR);
986N/A testl(result, 0x2); // tail char
986N/A jccb(Assembler::zero, TRUE_LABEL);
986N/A load_unsigned_short(chr, Address(ary1, 0));
986N/A load_unsigned_short(limit, Address(ary2, 0));
986N/A cmpl(chr, limit);
986N/A jccb(Assembler::notEqual, FALSE_LABEL);
986N/A
986N/A bind(TRUE_LABEL);
986N/A movl(result, 1); // return true
986N/A jmpb(DONE);
986N/A
986N/A bind(FALSE_LABEL);
986N/A xorl(result, result); // return false
986N/A
986N/A // That's it
986N/A bind(DONE);
986N/A}
986N/A
0N/AAssembler::Condition MacroAssembler::negate_condition(Assembler::Condition cond) {
0N/A switch (cond) {
0N/A // Note some conditions are synonyms for others
0N/A case Assembler::zero: return Assembler::notZero;
0N/A case Assembler::notZero: return Assembler::zero;
0N/A case Assembler::less: return Assembler::greaterEqual;
0N/A case Assembler::lessEqual: return Assembler::greater;
0N/A case Assembler::greater: return Assembler::lessEqual;
0N/A case Assembler::greaterEqual: return Assembler::less;
0N/A case Assembler::below: return Assembler::aboveEqual;
0N/A case Assembler::belowEqual: return Assembler::above;
0N/A case Assembler::above: return Assembler::belowEqual;
0N/A case Assembler::aboveEqual: return Assembler::below;
0N/A case Assembler::overflow: return Assembler::noOverflow;
0N/A case Assembler::noOverflow: return Assembler::overflow;
0N/A case Assembler::negative: return Assembler::positive;
0N/A case Assembler::positive: return Assembler::negative;
0N/A case Assembler::parity: return Assembler::noParity;
0N/A case Assembler::noParity: return Assembler::parity;
0N/A }
0N/A ShouldNotReachHere(); return Assembler::overflow;
0N/A}
0N/A
0N/ASkipIfEqual::SkipIfEqual(
0N/A MacroAssembler* masm, const bool* flag_addr, bool value) {
0N/A _masm = masm;
0N/A _masm->cmp8(ExternalAddress((address)flag_addr), value);
0N/A _masm->jcc(Assembler::equal, _label);
0N/A}
0N/A
0N/ASkipIfEqual::~SkipIfEqual() {
0N/A _masm->bind(_label);
0N/A}