hotspot/src/cpu/x86/vm/assembler_x86_32.cpp
author kvn
Wed, 19 Mar 2008 15:33:25 -0700
changeset 244 c8ad6f221400
parent 1 489c9b5090e2
child 364 0d803d2ebd6b
permissions -rw-r--r--
6662967: Optimize I2D conversion on new x86 Summary: Use CVTDQ2PS and CVTDQ2PD for integer values conversions to float and double values on new AMD cpu. Reviewed-by: sgoldman, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_assembler_x86_32.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Implementation of AddressLiteral
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
AddressLiteral::AddressLiteral(address target, relocInfo::relocType rtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  _is_lval = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  _target = target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  switch (rtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  case relocInfo::oop_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    // Oops are a special case. Normally they would be their own section
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    // but in cases like icBuffer they are literals in the code stream that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    // we don't have a section for. We use none so that we get a literal address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    // which is always patchable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  case relocInfo::external_word_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    _rspec = external_word_Relocation::spec(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  case relocInfo::internal_word_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    _rspec = internal_word_Relocation::spec(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  case relocInfo::opt_virtual_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    _rspec = opt_virtual_call_Relocation::spec();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  case relocInfo::static_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    _rspec = static_call_Relocation::spec();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  case relocInfo::runtime_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    _rspec = runtime_call_Relocation::spec();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  case relocInfo::poll_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  case relocInfo::poll_return_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    _rspec = Relocation::spec_simple(rtype);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  case relocInfo::none:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// Implementation of Address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
Address Address::make_array(ArrayAddress adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // Not implementable on 64bit machines
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Should have been handled higher up the call chain.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  AddressLiteral base = adr.base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  Address index = adr.index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  assert(index._disp == 0, "must not have disp"); // maybe it can?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  Address array(index._base, index._index, index._scale, (intptr_t) base.target());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  array._rspec = base._rspec;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  return array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// exceedingly dangerous constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
Address::Address(address loc, RelocationHolder spec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  _base  = noreg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  _index = noreg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  _scale = no_scale;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  _disp  = (intptr_t) loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _rspec = spec;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// Convert the raw encoding form into the form expected by the constructor for
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
// Address.  An index of 4 (rsp) corresponds to having no index, so convert
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// that to noreg for the Address constructor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
Address Address::make_raw(int base, int index, int scale, int disp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  bool valid_index = index != rsp->encoding();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  if (valid_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    Address madr(as_Register(base), as_Register(index), (Address::ScaleFactor)scale, in_ByteSize(disp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return madr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    Address madr(as_Register(base), noreg, Address::no_scale, in_ByteSize(disp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    return madr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
// Implementation of Assembler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
int AbstractAssembler::code_fill_byte() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  return (u_char)'\xF4'; // hlt
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// make this go away someday
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
void Assembler::emit_data(jint data, relocInfo::relocType rtype, int format) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  if (rtype == relocInfo::none)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        emit_long(data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  else  emit_data(data, Relocation::spec_simple(rtype), format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
void Assembler::emit_data(jint data, RelocationHolder const& rspec, int format) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  assert(imm32_operand == 0, "default format must be imm32 in this file");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  assert(inst_mark() != NULL, "must be inside InstructionMark");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  if (rspec.type() !=  relocInfo::none) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      check_relocation(rspec, format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    // Do not use AbstractAssembler::relocate, which is not intended for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // embedded words.  Instead, relocate to the enclosing instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    // hack. call32 is too wide for mask so use disp32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    if (format == call32_operand)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      code_section()->relocate(inst_mark(), rspec, disp32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      code_section()->relocate(inst_mark(), rspec, format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  emit_long(data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  assert(dst->has_byte_register(), "must have byte register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  assert(isByte(op1) && isByte(op2), "wrong opcode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  assert(isByte(imm8), "not a byte");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  assert((op1 & 0x01) == 0, "should be 8bit operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  emit_byte(op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  emit_byte(op2 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  emit_byte(imm8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
void Assembler::emit_arith(int op1, int op2, Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  assert(isByte(op1) && isByte(op2), "wrong opcode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  assert((op1 & 0x01) == 1, "should be 32bit operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if (is8bit(imm32)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    emit_byte(op1 | 0x02); // set sign bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    emit_byte(op2 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    emit_byte(imm32 & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    emit_byte(op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    emit_byte(op2 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// immediate-to-memory forms
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
void Assembler::emit_arith_operand(int op1, Register rm, Address adr, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  assert((op1 & 0x01) == 1, "should be 32bit operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  if (is8bit(imm32)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    emit_byte(op1 | 0x02); // set sign bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    emit_operand(rm,adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    emit_byte(imm32 & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    emit_byte(op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    emit_operand(rm,adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
void Assembler::emit_arith(int op1, int op2, Register dst, jobject obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  assert(isByte(op1) && isByte(op2), "wrong opcode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  assert((op1 & 0x01) == 1, "should be 32bit operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  emit_byte(op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  emit_byte(op2 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  emit_data((int)obj, relocInfo::oop_type, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
void Assembler::emit_arith(int op1, int op2, Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(isByte(op1) && isByte(op2), "wrong opcode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  emit_byte(op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  emit_byte(op2 | dst->encoding() << 3 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
void Assembler::emit_operand(Register reg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                             Register base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                             Register index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                             Address::ScaleFactor scale,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
                             int disp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
                             RelocationHolder const& rspec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  relocInfo::relocType rtype = (relocInfo::relocType) rspec.type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  if (base->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    if (index->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      assert(scale != Address::no_scale, "inconsistent address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      // [base + index*scale + disp]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      if (disp == 0 && rtype == relocInfo::none && base != rbp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        // [base + index*scale]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        // [00 reg 100][ss index base]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        assert(index != rsp, "illegal addressing mode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
        emit_byte(0x04 | reg->encoding() << 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        emit_byte(scale << 6 | index->encoding() << 3 | base->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      } else if (is8bit(disp) && rtype == relocInfo::none) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
        // [base + index*scale + imm8]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        // [01 reg 100][ss index base] imm8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        assert(index != rsp, "illegal addressing mode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        emit_byte(0x44 | reg->encoding() << 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        emit_byte(scale << 6 | index->encoding() << 3 | base->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        emit_byte(disp & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        // [base + index*scale + imm32]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        // [10 reg 100][ss index base] imm32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        assert(index != rsp, "illegal addressing mode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        emit_byte(0x84 | reg->encoding() << 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        emit_byte(scale << 6 | index->encoding() << 3 | base->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
        emit_data(disp, rspec, disp32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    } else if (base == rsp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      // [esp + disp]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      if (disp == 0 && rtype == relocInfo::none) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        // [esp]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        // [00 reg 100][00 100 100]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
        emit_byte(0x04 | reg->encoding() << 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
        emit_byte(0x24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      } else if (is8bit(disp) && rtype == relocInfo::none) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        // [esp + imm8]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
        // [01 reg 100][00 100 100] imm8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        emit_byte(0x44 | reg->encoding() << 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
        emit_byte(0x24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        emit_byte(disp & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        // [esp + imm32]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        // [10 reg 100][00 100 100] imm32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
        emit_byte(0x84 | reg->encoding() << 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
        emit_byte(0x24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        emit_data(disp, rspec, disp32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      // [base + disp]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      assert(base != rsp, "illegal addressing mode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      if (disp == 0 && rtype == relocInfo::none && base != rbp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        // [base]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        // [00 reg base]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        assert(base != rbp, "illegal addressing mode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        emit_byte(0x00 | reg->encoding() << 3 | base->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      } else if (is8bit(disp) && rtype == relocInfo::none) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
        // [base + imm8]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
        // [01 reg base] imm8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
        emit_byte(0x40 | reg->encoding() << 3 | base->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
        emit_byte(disp & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
        // [base + imm32]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
        // [10 reg base] imm32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
        emit_byte(0x80 | reg->encoding() << 3 | base->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
        emit_data(disp, rspec, disp32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    if (index->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      assert(scale != Address::no_scale, "inconsistent address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      // [index*scale + disp]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      // [00 reg 100][ss index 101] imm32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      assert(index != rsp, "illegal addressing mode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      emit_byte(0x04 | reg->encoding() << 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      emit_byte(scale << 6 | index->encoding() << 3 | 0x05);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
      emit_data(disp, rspec, disp32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      // [disp]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      // [00 reg 101] imm32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      emit_byte(0x05 | reg->encoding() << 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      emit_data(disp, rspec, disp32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
// Secret local extension to Assembler::WhichOperand:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
#define end_pc_operand (_WhichOperand_limit)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
address Assembler::locate_operand(address inst, WhichOperand which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // Decode the given instruction, and return the address of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // an embedded 32-bit operand word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // If "which" is disp32_operand, selects the displacement portion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  // of an effective address specifier.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  // If "which" is imm32_operand, selects the trailing immediate constant.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // If "which" is call32_operand, selects the displacement of a call or jump.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  // Caller is responsible for ensuring that there is such an operand,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // and that it is 32 bits wide.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // If "which" is end_pc_operand, find the end of the instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  address ip = inst;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  debug_only(bool has_imm32 = false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  int tail_size = 0;    // other random bytes (#32, #16, etc.) at end of insn
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
 again_after_prefix:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  switch (0xFF & *ip++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  // These convenience macros generate groups of "case" labels for the switch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  #define REP4(x) (x)+0: case (x)+1: case (x)+2: case (x)+3
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  #define REP8(x) (x)+0: case (x)+1: case (x)+2: case (x)+3: \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
             case (x)+4: case (x)+5: case (x)+6: case (x)+7
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  #define REP16(x) REP8((x)+0): \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
              case REP8((x)+8)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  case CS_segment:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  case SS_segment:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  case DS_segment:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  case ES_segment:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  case FS_segment:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  case GS_segment:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    assert(ip == inst+1, "only one prefix allowed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    goto again_after_prefix;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  case 0xFF: // pushl a; decl a; incl a; call a; jmp a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  case 0x88: // movb a, r
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  case 0x89: // movl a, r
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  case 0x8A: // movb r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  case 0x8B: // movl r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  case 0x8F: // popl a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  case 0x68: // pushl #32(oop?)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    if (which == end_pc_operand)  return ip + 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    assert(which == imm32_operand, "pushl has no disp32");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    return ip;                  // not produced by emit_operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  case 0x66: // movw ... (size prefix)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    switch (0xFF & *ip++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    case 0x8B: // movw r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    case 0x89: // movw a, r
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    case 0xC7: // movw a, #16
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
      tail_size = 2;  // the imm16
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    case 0x0F: // several SSE/SSE2 variants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      ip--;    // reparse the 0x0F
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      goto again_after_prefix;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  case REP8(0xB8): // movl r, #32(oop?)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    if (which == end_pc_operand)  return ip + 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    assert(which == imm32_operand || which == disp32_operand, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    return ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  case 0x69: // imul r, a, #32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  case 0xC7: // movl a, #32(oop?)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    tail_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    debug_only(has_imm32 = true); // has both kinds of operands!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  case 0x0F: // movx..., etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    switch (0xFF & *ip++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    case 0x12: // movlps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    case 0x28: // movaps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    case 0x2E: // ucomiss
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    case 0x2F: // comiss
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    case 0x54: // andps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    case 0x55: // andnps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    case 0x56: // orps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    case 0x57: // xorps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    case 0x6E: // movd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    case 0x7E: // movd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    case 0xAE: // ldmxcsr   a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
      // amd side says it these have both operands but that doesn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
      // appear to be true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      // debug_only(has_imm32 = true); // has both kinds of operands!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    case 0xAD: // shrd r, a, %cl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    case 0xAF: // imul r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    case 0xBE: // movsxb r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    case 0xBF: // movsxw r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    case 0xB6: // movzxb r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    case 0xB7: // movzxw r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    case REP16(0x40): // cmovl cc, r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    case 0xB0: // cmpxchgb
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    case 0xB1: // cmpxchg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    case 0xC1: // xaddl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    case 0xC7: // cmpxchg8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    case REP16(0x90): // setcc a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      // fall out of the switch to decode the address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    case 0xAC: // shrd r, a, #8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
      tail_size = 1;  // the imm8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    case REP16(0x80): // jcc rdisp32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      if (which == end_pc_operand)  return ip + 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      assert(which == call32_operand, "jcc has no disp32 or imm32");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      return ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  case 0x81: // addl a, #32; addl r, #32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    // also: orl, adcl, sbbl, andl, subl, xorl, cmpl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    // in the case of cmpl, the imm32 might be an oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    tail_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    debug_only(has_imm32 = true); // has both kinds of operands!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  case 0x85: // test r/m, r
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  case 0x83: // addl a, #8; addl r, #8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    // also: orl, adcl, sbbl, andl, subl, xorl, cmpl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    tail_size = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  case 0x9B:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    switch (0xFF & *ip++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    case 0xD9: // fnstcw a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  case REP4(0x00): // addb a, r; addl a, r; addb r, a; addl r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  case REP4(0x10): // adc...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  case REP4(0x20): // and...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  case REP4(0x30): // xor...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  case REP4(0x08): // or...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  case REP4(0x18): // sbb...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  case REP4(0x28): // sub...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  case REP4(0x38): // cmp...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  case 0xF7: // mull a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  case 0x8D: // leal r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  case 0x87: // xchg r, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  case 0xC1: // sal a, #8; sar a, #8; shl a, #8; shr a, #8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  case 0xC6: // movb a, #8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  case 0x80: // cmpb a, #8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  case 0x6B: // imul r, a, #8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    tail_size = 1; // the imm8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  case 0xE8: // call rdisp32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  case 0xE9: // jmp  rdisp32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    if (which == end_pc_operand)  return ip + 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    assert(which == call32_operand, "call has no disp32 or imm32");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    return ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  case 0xD1: // sal a, 1; sar a, 1; shl a, 1; shr a, 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  case 0xD3: // sal a, %cl; sar a, %cl; shl a, %cl; shr a, %cl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  case 0xD9: // fld_s a; fst_s a; fstp_s a; fldcw a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  case 0xDD: // fld_d a; fst_d a; fstp_d a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  case 0xDB: // fild_s a; fistp_s a; fld_x a; fstp_x a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  case 0xDF: // fild_d a; fistp_d a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  case 0xD8: // fadd_s a; fsubr_s a; fmul_s a; fdivr_s a; fcomp_s a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  case 0xDC: // fadd_d a; fsubr_d a; fmul_d a; fdivr_d a; fcomp_d a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  case 0xDE: // faddp_d a; fsubrp_d a; fmulp_d a; fdivrp_d a; fcompp_d a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  case 0xF3:                    // For SSE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  case 0xF2:                    // For SSE2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    ip++; ip++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  #undef REP8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  #undef REP16
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  assert(which != call32_operand, "instruction is not a call, jmp, or jcc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  assert(which != imm32_operand || has_imm32, "instruction has no imm32 field");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  // parse the output of emit_operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  int op2 = 0xFF & *ip++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  int base = op2 & 0x07;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  int op3 = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  const int b100 = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  const int b101 = 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  if (base == b100 && (op2 >> 6) != 3) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    op3 = 0xFF & *ip++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    base = op3 & 0x07;   // refetch the base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  // now ip points at the disp (if any)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  switch (op2 >> 6) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  case 0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    // [00 reg  100][ss index base]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    // [00 reg  100][00   100  rsp]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    // [00 reg base]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    // [00 reg  100][ss index  101][disp32]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    // [00 reg  101]               [disp32]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    if (base == b101) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
      if (which == disp32_operand)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
        return ip;              // caller wants the disp32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
      ip += 4;                  // skip the disp32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  case 1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    // [01 reg  100][ss index base][disp8]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    // [01 reg  100][00   100  rsp][disp8]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    // [01 reg base]               [disp8]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    ip += 1;                    // skip the disp8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  case 2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    // [10 reg  100][ss index base][disp32]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    // [10 reg  100][00   100  rsp][disp32]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    // [10 reg base]               [disp32]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    if (which == disp32_operand)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      return ip;                // caller wants the disp32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    ip += 4;                    // skip the disp32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  case 3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    // [11 reg base]  (not a memory addressing mode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  if (which == end_pc_operand) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    return ip + tail_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  assert(which == imm32_operand, "instruction has only an imm32 field");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  return ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
address Assembler::locate_next_instruction(address inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  // Secretly share code with locate_operand:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  return locate_operand(inst, end_pc_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
void Assembler::check_relocation(RelocationHolder const& rspec, int format) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  address inst = inst_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  assert(inst != NULL && inst < pc(), "must point to beginning of instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  address opnd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  Relocation* r = rspec.reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  if (r->type() == relocInfo::none) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  } else if (r->is_call() || format == call32_operand) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    // assert(format == imm32_operand, "cannot specify a nonzero format");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    opnd = locate_operand(inst, call32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  } else if (r->is_data()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
    assert(format == imm32_operand || format == disp32_operand, "format ok");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    opnd = locate_operand(inst, (WhichOperand)format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    assert(format == imm32_operand, "cannot specify a format");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  assert(opnd == pc(), "must put operand where relocs can find it");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
void Assembler::emit_operand(Register reg, Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  emit_operand(reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
void Assembler::emit_farith(int b1, int b2, int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  assert(isByte(b1) && isByte(b2), "wrong opcode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  assert(0 <= i &&  i < 8, "illegal stack offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  emit_byte(b1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  emit_byte(b2 + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
void Assembler::pushad() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  emit_byte(0x60);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
void Assembler::popad() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  emit_byte(0x61);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
void Assembler::pushfd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  emit_byte(0x9C);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
void Assembler::popfd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  emit_byte(0x9D);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
void Assembler::pushl(int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  emit_byte(0x68);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
void Assembler::push_literal32(int32_t imm32, RelocationHolder const& rspec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  emit_byte(0x68);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  emit_data(imm32, rspec, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
void Assembler::pushl(Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  emit_byte(0x50 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
void Assembler::pushl(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  emit_byte(0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  emit_operand(rsi, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
void Assembler::popl(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  emit_byte(0x58 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
void Assembler::popl(Address dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  emit_byte(0x8F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  emit_operand(rax, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
void Assembler::prefix(Prefix p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  a_byte(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
void Assembler::movb(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  assert(dst->has_byte_register(), "must have byte register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  emit_byte(0x8A);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
void Assembler::movb(Address dst, int imm8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  emit_byte(0xC6);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  emit_operand(rax, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  emit_byte(imm8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
void Assembler::movb(Address dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  assert(src->has_byte_register(), "must have byte register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  emit_byte(0x88);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  emit_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
void Assembler::movw(Address dst, int imm16) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  emit_byte(0x66); // switch to 16-bit mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  emit_byte(0xC7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  emit_operand(rax, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  emit_word(imm16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
void Assembler::movw(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  emit_byte(0x8B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
void Assembler::movw(Address dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  emit_byte(0x89);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  emit_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
void Assembler::movl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  emit_byte(0xB8 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
void Assembler::mov_literal32(Register dst, int32_t imm32, RelocationHolder const& rspec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  emit_byte(0xB8 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  emit_data((int)imm32, rspec, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
void Assembler::movl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  emit_byte(0x8B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
void Assembler::movl(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  emit_byte(0x8B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
void Assembler::movl(Address dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  emit_byte(0xC7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  emit_operand(rax, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
void Assembler::mov_literal32(Address dst, int32_t imm32,  RelocationHolder const& rspec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  emit_byte(0xC7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  emit_operand(rax, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  emit_data((int)imm32, rspec, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
void Assembler::movl(Address dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  emit_byte(0x89);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  emit_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
void Assembler::movsxb(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  emit_byte(0xBE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
void Assembler::movsxb(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  assert(src->has_byte_register(), "must have byte register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  emit_byte(0xBE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
void Assembler::movsxw(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  emit_byte(0xBF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
void Assembler::movsxw(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  emit_byte(0xBF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
void Assembler::movzxb(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  emit_byte(0xB6);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
void Assembler::movzxb(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  assert(src->has_byte_register(), "must have byte register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  emit_byte(0xB6);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
void Assembler::movzxw(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  emit_byte(0xB7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
void Assembler::movzxw(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  emit_byte(0xB7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
void Assembler::cmovl(Condition cc, Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  guarantee(VM_Version::supports_cmov(), "illegal instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  emit_byte(0x40 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
void Assembler::cmovl(Condition cc, Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  guarantee(VM_Version::supports_cmov(), "illegal instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  // The code below seems to be wrong - however the manual is inconclusive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  // do not use for now (remember to enable all callers when fixing this)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  Unimplemented();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  // wrong bytes?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  emit_byte(0x40 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
void Assembler::prefetcht0(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  assert(VM_Version::supports_sse(), "must support");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  emit_byte(0x18);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
  emit_operand(rcx, src); // 1, src
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
void Assembler::prefetcht1(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  assert(VM_Version::supports_sse(), "must support");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  emit_byte(0x18);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  emit_operand(rdx, src); // 2, src
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
void Assembler::prefetcht2(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  assert(VM_Version::supports_sse(), "must support");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  emit_byte(0x18);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  emit_operand(rbx, src); // 3, src
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
void Assembler::prefetchnta(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  assert(VM_Version::supports_sse2(), "must support");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  emit_byte(0x18);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  emit_operand(rax, src); // 0, src
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
void Assembler::prefetchw(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  assert(VM_Version::supports_3dnow(), "must support");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  emit_byte(0x0D);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  emit_operand(rcx, src); // 1, src
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
void Assembler::prefetchr(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  assert(VM_Version::supports_3dnow(), "must support");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  emit_byte(0x0D);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  emit_operand(rax, src); // 0, src
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
void Assembler::adcl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  emit_arith(0x81, 0xD0, dst, imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
void Assembler::adcl(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  emit_byte(0x13);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
void Assembler::adcl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  emit_arith(0x13, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
void Assembler::addl(Address dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  emit_arith_operand(0x81,rax,dst,imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
void Assembler::addl(Address dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  emit_byte(0x01);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  emit_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
void Assembler::addl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  emit_arith(0x81, 0xC0, dst, imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
void Assembler::addl(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  emit_byte(0x03);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
void Assembler::addl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  emit_arith(0x03, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
void Assembler::andl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  emit_arith(0x81, 0xE0, dst, imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
void Assembler::andl(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
  emit_byte(0x23);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
void Assembler::andl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  emit_arith(0x23, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
void Assembler::cmpb(Address dst, int imm8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  emit_byte(0x80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  emit_operand(rdi, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  emit_byte(imm8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
void Assembler::cmpw(Address dst, int imm16) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  emit_byte(0x81);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  emit_operand(rdi, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  emit_word(imm16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
void Assembler::cmpl(Address dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  emit_byte(0x81);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  emit_operand(rdi, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
void Assembler::cmp_literal32(Register src1, int32_t imm32, RelocationHolder const& rspec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  emit_byte(0x81);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  emit_byte(0xF8 | src1->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  emit_data(imm32, rspec, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
void Assembler::cmp_literal32(Address src1, int32_t imm32, RelocationHolder const& rspec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  emit_byte(0x81);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  emit_operand(rdi, src1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  emit_data(imm32, rspec, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
void Assembler::cmpl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  emit_arith(0x81, 0xF8, dst, imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
void Assembler::cmpl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  emit_arith(0x3B, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
void Assembler::cmpl(Register dst, Address  src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  emit_byte(0x3B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
void Assembler::decl(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
  // Don't use it directly. Use MacroAssembler::decrement() instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
  emit_byte(0x48 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
void Assembler::decl(Address dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  // Don't use it directly. Use MacroAssembler::decrement() instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  emit_byte(0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  emit_operand(rcx, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
void Assembler::idivl(Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  emit_byte(0xF7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  emit_byte(0xF8 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
void Assembler::cdql() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  emit_byte(0x99);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
void Assembler::imull(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  emit_byte(0xAF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
void Assembler::imull(Register dst, Register src, int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  if (is8bit(value)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    emit_byte(0x6B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    emit_byte(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    emit_byte(0x69);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    emit_long(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
void Assembler::incl(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
  // Don't use it directly. Use MacroAssembler::increment() instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  emit_byte(0x40 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
void Assembler::incl(Address dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  // Don't use it directly. Use MacroAssembler::increment() instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  emit_byte(0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  emit_operand(rax, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
void Assembler::leal(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  emit_byte(0x8D);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
void Assembler::mull(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  emit_byte(0xF7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  emit_operand(rsp, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
void Assembler::mull(Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  emit_byte(0xF7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  emit_byte(0xE0 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
void Assembler::negl(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  emit_byte(0xF7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  emit_byte(0xD8 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
void Assembler::notl(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
  emit_byte(0xF7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  emit_byte(0xD0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
void Assembler::orl(Address dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  emit_byte(0x81);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
  emit_operand(rcx, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
  emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
void Assembler::orl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  emit_arith(0x81, 0xC8, dst, imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
void Assembler::orl(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
  emit_byte(0x0B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
void Assembler::orl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
  emit_arith(0x0B, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
void Assembler::rcll(Register dst, int imm8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
  assert(isShiftCount(imm8), "illegal shift count");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
  if (imm8 == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
    emit_byte(0xD1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
    emit_byte(0xD0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    emit_byte(0xC1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
    emit_byte(0xD0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
    emit_byte(imm8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
void Assembler::sarl(Register dst, int imm8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
  assert(isShiftCount(imm8), "illegal shift count");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
  if (imm8 == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    emit_byte(0xD1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
    emit_byte(0xF8 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
    emit_byte(0xC1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
    emit_byte(0xF8 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
    emit_byte(imm8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
void Assembler::sarl(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  emit_byte(0xD3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
  emit_byte(0xF8 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
void Assembler::sbbl(Address dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
  emit_arith_operand(0x81,rbx,dst,imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
void Assembler::sbbl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  emit_arith(0x81, 0xD8, dst, imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
void Assembler::sbbl(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  emit_byte(0x1B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
void Assembler::sbbl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
  emit_arith(0x1B, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
void Assembler::shldl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
  emit_byte(0xA5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
  emit_byte(0xC0 | src->encoding() << 3 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
void Assembler::shll(Register dst, int imm8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  assert(isShiftCount(imm8), "illegal shift count");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  if (imm8 == 1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
    emit_byte(0xD1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
    emit_byte(0xE0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
    emit_byte(0xC1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
    emit_byte(0xE0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
    emit_byte(imm8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
void Assembler::shll(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  emit_byte(0xD3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  emit_byte(0xE0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
void Assembler::shrdl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  emit_byte(0xAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
  emit_byte(0xC0 | src->encoding() << 3 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
void Assembler::shrl(Register dst, int imm8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
  assert(isShiftCount(imm8), "illegal shift count");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
  emit_byte(0xC1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
  emit_byte(0xE8 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
  emit_byte(imm8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
void Assembler::shrl(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
  emit_byte(0xD3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
  emit_byte(0xE8 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
void Assembler::subl(Address dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
  if (is8bit(imm32)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    emit_byte(0x83);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
    emit_operand(rbp, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    emit_byte(imm32 & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
    InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
    emit_byte(0x81);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
    emit_operand(rbp, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
    emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
void Assembler::subl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  emit_arith(0x81, 0xE8, dst, imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
void Assembler::subl(Address dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
  emit_byte(0x29);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
  emit_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
void Assembler::subl(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
  emit_byte(0x2B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
void Assembler::subl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
  emit_arith(0x2B, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
void Assembler::testb(Register dst, int imm8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  assert(dst->has_byte_register(), "must have byte register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
  emit_arith_b(0xF6, 0xC0, dst, imm8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
void Assembler::testl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  // not using emit_arith because test
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
  // doesn't support sign-extension of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
  // 8bit operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
  if (dst->encoding() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    emit_byte(0xA9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    emit_byte(0xF7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    emit_byte(0xC0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
  emit_long(imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
void Assembler::testl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
  emit_arith(0x85, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
void Assembler::testl(Register dst, Address  src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
  emit_byte(0x85);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
void Assembler::xaddl(Address dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
  emit_byte(0xC1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  emit_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
void Assembler::xorl(Register dst, int imm32) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  emit_arith(0x81, 0xF0, dst, imm32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
void Assembler::xorl(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  emit_byte(0x33);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  emit_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
void Assembler::xorl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
  emit_arith(0x33, 0xC0, dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
void Assembler::bswap(Register reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
  emit_byte(0xC8 | reg->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
void Assembler::lock() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
  if (Atomics & 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
     // Emit either nothing, a NOP, or a NOP: prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
     emit_byte(0x90) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
     emit_byte(0xF0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
void Assembler::xchg(Register reg, Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
  emit_byte(0x87);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
  emit_operand(reg, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
void Assembler::xchgl(Register dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
  emit_byte(0x87);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
  emit_byte(0xc0 | dst->encoding() << 3 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
// The 32-bit cmpxchg compares the value at adr with the contents of rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
// and stores reg into adr if so; otherwise, the value at adr is loaded into rax,.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
// The ZF is set if the compared values were equal, and cleared otherwise.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
void Assembler::cmpxchg(Register reg, Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
  if (Atomics & 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
     // caveat: no instructionmark, so this isn't relocatable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
     // Emit a synthetic, non-atomic, CAS equivalent.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
     // Beware.  The synthetic form sets all ICCs, not just ZF.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
     // cmpxchg r,[m] is equivalent to rax, = CAS (m, rax, r)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
     cmpl (rax, adr) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
     movl (rax, adr) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
     if (reg != rax) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
        Label L ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
        jcc (Assembler::notEqual, L) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
        movl (adr, reg) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
        bind (L) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
     InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
     emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
     emit_byte(0xB1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
     emit_operand(reg, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
// The 64-bit cmpxchg compares the value at adr with the contents of rdx:rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
// and stores rcx:rbx into adr if so; otherwise, the value at adr is loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
// into rdx:rax.  The ZF is set if the compared values were equal, and cleared otherwise.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
void Assembler::cmpxchg8(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
  emit_byte(0xc7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
  emit_operand(rcx, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
void Assembler::hlt() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
  emit_byte(0xF4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
void Assembler::addr_nop_4() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
  // 4 bytes: NOP DWORD PTR [EAX+0]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
  emit_byte(0x1F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
  emit_byte(0x40); // emit_rm(cbuf, 0x1, EAX_enc, EAX_enc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
  emit_byte(0);    // 8-bits offset (1 byte)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
void Assembler::addr_nop_5() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
  // 5 bytes: NOP DWORD PTR [EAX+EAX*0+0] 8-bits offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
  emit_byte(0x1F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
  emit_byte(0x44); // emit_rm(cbuf, 0x1, EAX_enc, 0x4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  emit_byte(0x00); // emit_rm(cbuf, 0x0, EAX_enc, EAX_enc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  emit_byte(0);    // 8-bits offset (1 byte)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
void Assembler::addr_nop_7() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
  // 7 bytes: NOP DWORD PTR [EAX+0] 32-bits offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
  emit_byte(0x1F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
  emit_byte(0x80); // emit_rm(cbuf, 0x2, EAX_enc, EAX_enc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
  emit_long(0);    // 32-bits offset (4 bytes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
void Assembler::addr_nop_8() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
  // 8 bytes: NOP DWORD PTR [EAX+EAX*0+0] 32-bits offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
  emit_byte(0x1F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
  emit_byte(0x84); // emit_rm(cbuf, 0x2, EAX_enc, 0x4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
  emit_byte(0x00); // emit_rm(cbuf, 0x0, EAX_enc, EAX_enc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
  emit_long(0);    // 32-bits offset (4 bytes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
void Assembler::nop(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
  assert(i > 0, " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
  if (UseAddressNop && VM_Version::is_intel()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
    // Using multi-bytes nops "0x0F 0x1F [address]" for Intel
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
    //  1: 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
    //  2: 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
    //  3: 0x66 0x66 0x90 (don't use "0x0F 0x1F 0x00" - need patching safe padding)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
    //  4: 0x0F 0x1F 0x40 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
    //  5: 0x0F 0x1F 0x44 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
    //  6: 0x66 0x0F 0x1F 0x44 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
    //  7: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
    //  8: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
    //  9: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
    // 10: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
    // 11: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
    // The rest coding is Intel specific - don't use consecutive address nops
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
    // 12: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
    // 13: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
    // 14: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
    // 15: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
    while(i >= 15) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
      // For Intel don't generate consecutive addess nops (mix with regular nops)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
      i -= 15;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
      emit_byte(0x66);   // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
      emit_byte(0x66);   // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
      emit_byte(0x66);   // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
      addr_nop_8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
      emit_byte(0x66);   // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
      emit_byte(0x66);   // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
      emit_byte(0x66);   // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
      emit_byte(0x90);   // nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
    switch (i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
      case 14:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
      case 13:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
      case 12:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
        addr_nop_8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
        emit_byte(0x90); // nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
      case 11:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
      case 10:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
      case 9:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
      case 8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
        addr_nop_8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
      case 7:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
        addr_nop_7();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
      case 6:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
      case 5:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
        addr_nop_5();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
      case 4:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
        addr_nop_4();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
      case 3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
        // Don't use "0x0F 0x1F 0x00" - need patching safe padding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
      case 2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
      case 1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
        emit_byte(0x90); // nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
        assert(i == 0, " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
  if (UseAddressNop && VM_Version::is_amd()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
    // Using multi-bytes nops "0x0F 0x1F [address]" for AMD.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
    //  1: 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
    //  2: 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
    //  3: 0x66 0x66 0x90 (don't use "0x0F 0x1F 0x00" - need patching safe padding)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
    //  4: 0x0F 0x1F 0x40 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
    //  5: 0x0F 0x1F 0x44 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
    //  6: 0x66 0x0F 0x1F 0x44 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
    //  7: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
    //  8: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
    //  9: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
    // 10: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
    // 11: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
    // The rest coding is AMD specific - use consecutive address nops
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
    // 12: 0x66 0x0F 0x1F 0x44 0x00 0x00 0x66 0x0F 0x1F 0x44 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
    // 13: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00 0x66 0x0F 0x1F 0x44 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
    // 14: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
    // 15: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
    // 16: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
    //     Size prefixes (0x66) are added for larger sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
    while(i >= 22) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
      i -= 11;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
      emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
      emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
      emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
      addr_nop_8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
    // Generate first nop for size between 21-12
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
    switch (i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
      case 21:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
        i -= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
      case 20:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
      case 19:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
        i -= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
      case 18:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
      case 17:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
        i -= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
      case 16:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
      case 15:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
        i -= 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
        addr_nop_8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
      case 14:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
      case 13:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
        i -= 7;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
        addr_nop_7();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
      case 12:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
        i -= 6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
        addr_nop_5();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
        assert(i < 12, " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
    // Generate second nop for size between 11-1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
    switch (i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
      case 11:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
      case 10:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
      case 9:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
      case 8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
        addr_nop_8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
      case 7:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
        addr_nop_7();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
      case 6:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
      case 5:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
        addr_nop_5();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
      case 4:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
        addr_nop_4();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
      case 3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
        // Don't use "0x0F 0x1F 0x00" - need patching safe padding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
      case 2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
        emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
      case 1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
        emit_byte(0x90); // nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
        assert(i == 0, " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
  // Using nops with size prefixes "0x66 0x90".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
  // From AMD Optimization Guide:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  //  1: 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
  //  2: 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
  //  3: 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
  //  4: 0x66 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  //  5: 0x66 0x66 0x90 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
  //  6: 0x66 0x66 0x90 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
  //  7: 0x66 0x66 0x66 0x90 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
  //  8: 0x66 0x66 0x66 0x90 0x66 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
  //  9: 0x66 0x66 0x90 0x66 0x66 0x90 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
  // 10: 0x66 0x66 0x66 0x90 0x66 0x66 0x90 0x66 0x66 0x90
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
  while(i > 12) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
    i -= 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
    emit_byte(0x66); // size prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
    emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
    emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
    emit_byte(0x90); // nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
  // 1 - 12 nops
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
  if(i > 8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
    if(i > 9) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
      i -= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
      emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
    i -= 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
    emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
    emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
    emit_byte(0x90);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
  // 1 - 8 nops
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
  if(i > 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
    if(i > 6) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
      i -= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
      emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
    i -= 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
    emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
    emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
    emit_byte(0x90);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
  switch (i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
    case 4:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
      emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
    case 3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
      emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
    case 2:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
      emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
    case 1:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
      emit_byte(0x90);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
      assert(i == 0, " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
void Assembler::ret(int imm16) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
  if (imm16 == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
    emit_byte(0xC3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
    emit_byte(0xC2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
    emit_word(imm16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
void Assembler::set_byte_if_not_zero(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
  emit_byte(0x95);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
  emit_byte(0xE0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
// copies a single word from [esi] to [edi]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
void Assembler::smovl() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
  emit_byte(0xA5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
// copies data from [esi] to [edi] using rcx double words (m32)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
void Assembler::rep_movl() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
  emit_byte(0xF3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
  emit_byte(0xA5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
// sets rcx double words (m32) with rax, value at [edi]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
void Assembler::rep_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
  emit_byte(0xF3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
  emit_byte(0xAB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
// scans rcx double words (m32) at [edi] for occurance of rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
void Assembler::repne_scan() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
  emit_byte(0xF2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
  emit_byte(0xAF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
void Assembler::setb(Condition cc, Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
  assert(0 <= cc && cc < 16, "illegal cc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
  emit_byte(0x90 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
  emit_byte(0xC0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
void Assembler::cld() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
  emit_byte(0xfc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
void Assembler::std() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
  emit_byte(0xfd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
void Assembler::emit_raw (unsigned char b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
  emit_byte (b) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
// Serializes memory.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
void Assembler::membar() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
    // Memory barriers are only needed on multiprocessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
  if (os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
    if( VM_Version::supports_sse2() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
      emit_byte( 0x0F );                // MFENCE; faster blows no regs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
      emit_byte( 0xAE );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
      emit_byte( 0xF0 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
      // All usable chips support "locked" instructions which suffice
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
      // as barriers, and are much faster than the alternative of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
      // using cpuid instruction. We use here a locked add [esp],0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
      // This is conveniently otherwise a no-op except for blowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
      // flags (which we save and restore.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
      pushfd();                // Save eflags register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
      lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
      addl(Address(rsp, 0), 0);// Assert the lock# signal here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
      popfd();                 // Restore eflags register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
// Identify processor type and features
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
void Assembler::cpuid() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
  // Note: we can't assert VM_Version::supports_cpuid() here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
  //       because this instruction is used in the processor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
  //       identification code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
  emit_byte( 0x0F );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
  emit_byte( 0xA2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
void Assembler::call(Label& L, relocInfo::relocType rtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
  if (L.is_bound()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
    const int long_size = 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
    int offs = target(L) - pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
    assert(offs <= 0, "assembler error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
    InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
    // 1110 1000 #32-bit disp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
    emit_byte(0xE8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
    emit_data(offs - long_size, rtype, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
    InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
    // 1110 1000 #32-bit disp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
    L.add_patch_at(code(), locator());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
    emit_byte(0xE8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
    emit_data(int(0), rtype, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
void Assembler::call(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
  emit_byte(0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
  emit_byte(0xD0 | dst->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
void Assembler::call(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
  relocInfo::relocType rtype = adr.reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
  if (rtype !=  relocInfo::runtime_call_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
    emit_byte(0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
    emit_operand(rdx, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
    assert(false, "ack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
void Assembler::call_literal(address dest, RelocationHolder const& rspec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
  emit_byte(0xE8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
  intptr_t disp = dest - (_code_pos + sizeof(int32_t));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
  assert(dest != NULL, "must have a target");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
  emit_data(disp, rspec, call32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
void Assembler::jmp(Register entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
  emit_byte(0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
  emit_byte(0xE0 | entry->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
void Assembler::jmp(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
  emit_byte(0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
  emit_operand(rsp, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
void Assembler::jmp_literal(address dest, RelocationHolder const& rspec) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
  emit_byte(0xE9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
  assert(dest != NULL, "must have a target");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
  intptr_t disp = dest - (_code_pos + sizeof(int32_t));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
  emit_data(disp, rspec.reloc(), call32_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
void Assembler::jmp(Label& L, relocInfo::relocType rtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  if (L.is_bound()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
    address entry = target(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
    assert(entry != NULL, "jmp most probably wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
    InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
    const int short_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
    const int long_size = 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
    intptr_t offs = entry - _code_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
    if (rtype == relocInfo::none && is8bit(offs - short_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
      emit_byte(0xEB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
      emit_byte((offs - short_size) & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
      emit_byte(0xE9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
      emit_long(offs - long_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
    // By default, forward jumps are always 32-bit displacements, since
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
    // we can't yet know where the label will be bound.  If you're sure that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
    // the forward jump will not run beyond 256 bytes, use jmpb to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
    // force an 8-bit displacement.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
    InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
    relocate(rtype);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
    L.add_patch_at(code(), locator());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
    emit_byte(0xE9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
    emit_long(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
void Assembler::jmpb(Label& L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
  if (L.is_bound()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
    const int short_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
    address entry = target(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
    assert(is8bit((entry - _code_pos) + short_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
           "Dispacement too large for a short jmp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
    assert(entry != NULL, "jmp most probably wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
    intptr_t offs = entry - _code_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
    emit_byte(0xEB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
    emit_byte((offs - short_size) & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
    InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
    L.add_patch_at(code(), locator());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
    emit_byte(0xEB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
    emit_byte(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
void Assembler::jcc(Condition cc, Label& L, relocInfo::relocType rtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
  relocate(rtype);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
  assert((0 <= cc) && (cc < 16), "illegal cc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
  if (L.is_bound()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
    address dst = target(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
    assert(dst != NULL, "jcc most probably wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
    const int short_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
    const int long_size = 6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
    int offs = (int)dst - ((int)_code_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
    if (rtype == relocInfo::none && is8bit(offs - short_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
      // 0111 tttn #8-bit disp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
      emit_byte(0x70 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
      emit_byte((offs - short_size) & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
      // 0000 1111 1000 tttn #32-bit disp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
      emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
      emit_byte(0x80 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
      emit_long(offs - long_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
    // Note: could eliminate cond. jumps to this jump if condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
    //       is the same however, seems to be rather unlikely case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
    // Note: use jccb() if label to be bound is very close to get
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
    //       an 8-bit displacement
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
    L.add_patch_at(code(), locator());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
    emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
    emit_byte(0x80 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
    emit_long(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
void Assembler::jccb(Condition cc, Label& L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
  if (L.is_bound()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
    const int short_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
    address entry = target(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
    assert(is8bit((intptr_t)entry - ((intptr_t)_code_pos + short_size)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
           "Dispacement too large for a short jmp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
    intptr_t offs = (intptr_t)entry - (intptr_t)_code_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
    // 0111 tttn #8-bit disp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
    emit_byte(0x70 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
    emit_byte((offs - short_size) & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
    jcc(cc, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
    InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
    L.add_patch_at(code(), locator());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
    emit_byte(0x70 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
    emit_byte(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
// FPU instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
void Assembler::fld1() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
  emit_byte(0xE8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
void Assembler::fldz() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
  emit_byte(0xEE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
void Assembler::fld_s(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
  emit_operand(rax, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
void Assembler::fld_s (int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
  emit_farith(0xD9, 0xC0, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
void Assembler::fld_d(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
  emit_byte(0xDD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
  emit_operand(rax, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
void Assembler::fld_x(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
  emit_byte(0xDB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
  emit_operand(rbp, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
void Assembler::fst_s(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
  emit_operand(rdx, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
void Assembler::fst_d(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
  emit_byte(0xDD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
  emit_operand(rdx, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
void Assembler::fstp_s(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
  emit_operand(rbx, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
void Assembler::fstp_d(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
  emit_byte(0xDD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
  emit_operand(rbx, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
void Assembler::fstp_x(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
  emit_byte(0xDB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
  emit_operand(rdi, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
void Assembler::fstp_d(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
  emit_farith(0xDD, 0xD8, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
void Assembler::fild_s(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
  emit_byte(0xDB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
  emit_operand(rax, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
void Assembler::fild_d(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
  emit_byte(0xDF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
  emit_operand(rbp, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
void Assembler::fistp_s(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
  emit_byte(0xDB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
  emit_operand(rbx, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
void Assembler::fistp_d(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
  emit_byte(0xDF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
  emit_operand(rdi, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
void Assembler::fist_s(Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
  emit_byte(0xDB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
  emit_operand(rdx, adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
void Assembler::fabs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
  emit_byte(0xE1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
void Assembler::fldln2() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
  emit_byte(0xED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
void Assembler::fyl2x() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
  emit_byte(0xF1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
void Assembler::fldlg2() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
  emit_byte(0xEC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
void Assembler::flog() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
  fldln2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
  fxch();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
  fyl2x();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
void Assembler::flog10() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
  fldlg2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
  fxch();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
  fyl2x();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
void Assembler::fsin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
  emit_byte(0xFE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
void Assembler::fcos() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
  emit_byte(0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
void Assembler::ftan() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2075
  emit_byte(0xF2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
  emit_byte(0xDD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
  emit_byte(0xD8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
void Assembler::fsqrt() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
  emit_byte(0xFA);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
void Assembler::fchs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
  emit_byte(0xE0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
void Assembler::fadd_s(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
  emit_byte(0xD8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
  emit_operand(rax, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
void Assembler::fadd_d(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
  emit_byte(0xDC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
  emit_operand(rax, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
void Assembler::fadd(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
  emit_farith(0xD8, 0xC0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
void Assembler::fadda(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
  emit_farith(0xDC, 0xC0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
void Assembler::fsub_d(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
  emit_byte(0xDC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
  emit_operand(rsp, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
void Assembler::fsub_s(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
  emit_byte(0xD8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
  emit_operand(rsp, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
void Assembler::fsubr_s(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
  emit_byte(0xD8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
  emit_operand(rbp, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
void Assembler::fsubr_d(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
  emit_byte(0xDC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
  emit_operand(rbp, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
void Assembler::fmul_s(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
  emit_byte(0xD8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
  emit_operand(rcx, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
void Assembler::fmul_d(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
  emit_byte(0xDC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
  emit_operand(rcx, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
void Assembler::fmul(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
  emit_farith(0xD8, 0xC8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
void Assembler::fmula(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
  emit_farith(0xDC, 0xC8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
void Assembler::fdiv_s(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
  emit_byte(0xD8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
  emit_operand(rsi, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
void Assembler::fdiv_d(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
  emit_byte(0xDC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
  emit_operand(rsi, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
void Assembler::fdivr_s(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
  emit_byte(0xD8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
  emit_operand(rdi, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2188
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2189
void Assembler::fdivr_d(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2190
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2191
  emit_byte(0xDC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2192
  emit_operand(rdi, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2194
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2195
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2196
void Assembler::fsub(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2197
  emit_farith(0xD8, 0xE0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2199
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2200
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2201
void Assembler::fsuba(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2202
  emit_farith(0xDC, 0xE8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2203
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2204
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
void Assembler::fsubr(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
  emit_farith(0xD8, 0xE8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
void Assembler::fsubra(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
  emit_farith(0xDC, 0xE0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2215
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
void Assembler::fdiv(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2217
  emit_farith(0xD8, 0xF0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2220
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
void Assembler::fdiva(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
  emit_farith(0xDC, 0xF8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
void Assembler::fdivr(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
  emit_farith(0xD8, 0xF8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
void Assembler::fdivra(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
  emit_farith(0xDC, 0xF0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
// Note: The Intel manual (Pentium Processor User's Manual, Vol.3, 1994)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
//       is erroneous for some of the floating-point instructions below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
void Assembler::fdivp(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
  emit_farith(0xDE, 0xF8, i);                    // ST(0) <- ST(0) / ST(1) and pop (Intel manual wrong)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
void Assembler::fdivrp(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
  emit_farith(0xDE, 0xF0, i);                    // ST(0) <- ST(1) / ST(0) and pop (Intel manual wrong)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
void Assembler::fsubp(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
  emit_farith(0xDE, 0xE8, i);                    // ST(0) <- ST(0) - ST(1) and pop (Intel manual wrong)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
void Assembler::fsubrp(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
  emit_farith(0xDE, 0xE0, i);                    // ST(0) <- ST(1) - ST(0) and pop (Intel manual wrong)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2258
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2259
void Assembler::faddp(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2260
  emit_farith(0xDE, 0xC0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2261
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2262
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2263
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2264
void Assembler::fmulp(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2265
  emit_farith(0xDE, 0xC8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2267
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2268
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2269
void Assembler::fprem() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2270
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2271
  emit_byte(0xF8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2272
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2273
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2274
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2275
void Assembler::fprem1() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2276
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2277
  emit_byte(0xF5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2280
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2281
void Assembler::fxch(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2282
  emit_farith(0xD9, 0xC8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2283
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2285
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2286
void Assembler::fincstp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2287
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2288
  emit_byte(0xF7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2291
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2292
void Assembler::fdecstp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2293
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2294
  emit_byte(0xF6);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2295
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2296
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2298
void Assembler::ffree(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
  emit_farith(0xDD, 0xC0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2303
void Assembler::fcomp_s(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
  emit_byte(0xD8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2306
  emit_operand(rbx, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2310
void Assembler::fcomp_d(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
  emit_byte(0xDC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
  emit_operand(rbx, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
void Assembler::fcom(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
  emit_farith(0xD8, 0xD0, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
void Assembler::fcomp(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
  emit_farith(0xD8, 0xD8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2327
void Assembler::fcompp() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2328
  emit_byte(0xDE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2329
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2331
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2332
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2333
void Assembler::fucomi(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2334
  // make sure the instruction is supported (introduced for P6, together with cmov)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2335
  guarantee(VM_Version::supports_cmov(), "illegal instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2336
  emit_farith(0xDB, 0xE8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2338
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2339
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2340
void Assembler::fucomip(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2341
  // make sure the instruction is supported (introduced for P6, together with cmov)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2342
  guarantee(VM_Version::supports_cmov(), "illegal instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2343
  emit_farith(0xDF, 0xE8, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2344
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2345
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2346
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2347
void Assembler::ftst() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2348
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2349
  emit_byte(0xE4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2350
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2351
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2353
void Assembler::fnstsw_ax() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2354
  emit_byte(0xdF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2355
  emit_byte(0xE0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2356
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2357
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2358
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2359
void Assembler::fwait() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2360
  emit_byte(0x9B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2361
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2362
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2363
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2364
void Assembler::finit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2365
  emit_byte(0x9B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2366
  emit_byte(0xDB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2367
  emit_byte(0xE3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2368
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2369
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2370
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2371
void Assembler::fldcw(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2372
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2373
  emit_byte(0xd9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2374
  emit_operand(rbp, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2375
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2376
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2377
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2378
void Assembler::fnstcw(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2379
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2380
  emit_byte(0x9B);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2381
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2382
  emit_operand(rdi, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2383
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2384
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2385
void Assembler::fnsave(Address dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2386
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2387
  emit_byte(0xDD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2388
  emit_operand(rsi, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2389
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2390
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2391
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2392
void Assembler::frstor(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2393
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2394
  emit_byte(0xDD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2395
  emit_operand(rsp, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2396
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2397
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2398
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2399
void Assembler::fldenv(Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2400
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2401
  emit_byte(0xD9);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2402
  emit_operand(rsp, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2403
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2404
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2405
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2406
void Assembler::sahf() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2407
  emit_byte(0x9E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2408
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2409
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2410
// MMX operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2411
void Assembler::emit_operand(MMXRegister reg, Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2412
  emit_operand((Register)reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2413
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2414
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2415
void Assembler::movq( MMXRegister dst, Address src ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2416
  assert( VM_Version::supports_mmx(), "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2417
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2418
  emit_byte(0x6F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2419
  emit_operand(dst,src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2420
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2421
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2422
void Assembler::movq( Address dst, MMXRegister src ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2423
  assert( VM_Version::supports_mmx(), "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2424
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2425
  emit_byte(0x7F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2426
  emit_operand(src,dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2427
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2428
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2429
void Assembler::emms() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2430
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2431
  emit_byte(0x77);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2432
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2433
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2434
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2435
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2436
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2437
// SSE and SSE2 instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2438
inline void Assembler::emit_sse_operand(XMMRegister reg, Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2439
  assert(((Register)reg)->encoding() == reg->encoding(), "otherwise typecast is invalid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2440
  emit_operand((Register)reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2441
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2442
inline void Assembler::emit_sse_operand(Register reg, Address adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2443
  emit_operand(reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2444
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2445
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2446
inline void Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2447
  emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2448
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2449
inline void Assembler::emit_sse_operand(XMMRegister dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2450
  emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2451
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2452
inline void Assembler::emit_sse_operand(Register dst, XMMRegister src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2453
  emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2454
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2455
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2456
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2457
// Macro for creation of SSE2 instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2458
// The SSE2 instricution set is highly regular, so this macro saves
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2459
// a lot of cut&paste
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2460
// Each macro expansion creates two methods (same name with different
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2461
// parameter list)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2462
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2463
// Macro parameters:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2464
//  * name: name of the created methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2465
//  * sse_version: either sse or sse2 for the assertion if instruction supported by processor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2466
//  * prefix: first opcode byte of the instruction (or 0 if no prefix byte)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2467
//  * opcode: last opcode byte of the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2468
//  * conversion instruction have parameters of type Register instead of XMMRegister,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2469
//    so this can also configured with macro parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2470
#define emit_sse_instruction(name, sse_version, prefix, opcode, dst_register_type, src_register_type)      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2471
                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2472
  void Assembler:: name (dst_register_type dst, Address src) {           \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2473
    assert(VM_Version::supports_##sse_version(), "");                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2474
                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2475
    InstructionMark im(this);                                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2476
    if (prefix != 0) emit_byte(prefix);                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2477
    emit_byte(0x0F);                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2478
    emit_byte(opcode);                                                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2479
    emit_sse_operand(dst, src);                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2480
  }                                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2481
                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2482
  void Assembler:: name (dst_register_type dst, src_register_type src) { \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2483
    assert(VM_Version::supports_##sse_version(), "");                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2484
                                                                         \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2485
    if (prefix != 0) emit_byte(prefix);                                  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2486
    emit_byte(0x0F);                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2487
    emit_byte(opcode);                                                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2488
    emit_sse_operand(dst, src);                                          \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2489
  }                                                                      \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2490
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2491
emit_sse_instruction(addss,  sse,  0xF3, 0x58, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2492
emit_sse_instruction(addsd,  sse2, 0xF2, 0x58, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2493
emit_sse_instruction(subss,  sse,  0xF3, 0x5C, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2494
emit_sse_instruction(subsd,  sse2, 0xF2, 0x5C, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2495
emit_sse_instruction(mulss,  sse,  0xF3, 0x59, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2496
emit_sse_instruction(mulsd,  sse2, 0xF2, 0x59, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2497
emit_sse_instruction(divss,  sse,  0xF3, 0x5E, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2498
emit_sse_instruction(divsd,  sse2, 0xF2, 0x5E, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2499
emit_sse_instruction(sqrtss, sse,  0xF3, 0x51, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2500
emit_sse_instruction(sqrtsd, sse2, 0xF2, 0x51, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2501
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2502
emit_sse_instruction(pxor,  sse2,  0x66, 0xEF, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2503
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2504
emit_sse_instruction(comiss,  sse,  0,    0x2F, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2505
emit_sse_instruction(comisd,  sse2, 0x66, 0x2F, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2506
emit_sse_instruction(ucomiss, sse,  0,    0x2E, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2507
emit_sse_instruction(ucomisd, sse2, 0x66, 0x2E, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2508
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2509
emit_sse_instruction(cvtss2sd,  sse2, 0xF3, 0x5A, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2510
emit_sse_instruction(cvtsd2ss,  sse2, 0xF2, 0x5A, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2511
emit_sse_instruction(cvtsi2ss,  sse,  0xF3, 0x2A, XMMRegister, Register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2512
emit_sse_instruction(cvtsi2sd,  sse2, 0xF2, 0x2A, XMMRegister, Register)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2513
emit_sse_instruction(cvtss2si,  sse,  0xF3, 0x2D, Register, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2514
emit_sse_instruction(cvtsd2si,  sse2, 0xF2, 0x2D, Register, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2515
emit_sse_instruction(cvttss2si, sse,  0xF3, 0x2C, Register, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2516
emit_sse_instruction(cvttsd2si, sse2, 0xF2, 0x2C, Register, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2517
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2518
emit_sse_instruction(movss, sse,  0xF3, 0x10, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2519
emit_sse_instruction(movsd, sse2, 0xF2, 0x10, XMMRegister, XMMRegister)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2520
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2521
emit_sse_instruction(movq,  sse2, 0xF3, 0x7E, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2522
emit_sse_instruction(movd,  sse2, 0x66, 0x6E, XMMRegister, Register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2523
emit_sse_instruction(movdqa, sse2, 0x66, 0x6F, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2525
emit_sse_instruction(punpcklbw,  sse2, 0x66, 0x60, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2526
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2527
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2528
// Instruction not covered by macro
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2529
void Assembler::movq(Address dst, XMMRegister src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2530
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2531
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2532
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2533
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2534
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2535
  emit_byte(0xD6);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2536
  emit_sse_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2537
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2538
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2539
void Assembler::movd(Address dst, XMMRegister src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2540
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2541
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2542
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2543
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2544
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2545
  emit_byte(0x7E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2546
  emit_sse_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2547
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2548
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2549
void Assembler::movd(Register dst, XMMRegister src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2550
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2551
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2552
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2553
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2554
  emit_byte(0x7E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2555
  emit_sse_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2556
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2557
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2558
void Assembler::movdqa(Address dst, XMMRegister src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2559
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2560
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2561
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2562
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2563
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2564
  emit_byte(0x7F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2565
  emit_sse_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2566
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2567
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2568
void Assembler::pshufd(XMMRegister dst, XMMRegister src, int mode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2569
  assert(isByte(mode), "invalid value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2570
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2571
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2572
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2573
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2574
  emit_byte(0x70);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2575
  emit_sse_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2576
  emit_byte(mode & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2577
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2578
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2579
void Assembler::pshufd(XMMRegister dst, Address src, int mode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2580
  assert(isByte(mode), "invalid value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2581
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2582
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2583
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2584
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2585
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2586
  emit_byte(0x70);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2587
  emit_sse_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2588
  emit_byte(mode & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2589
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2590
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2591
void Assembler::pshuflw(XMMRegister dst, XMMRegister src, int mode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2592
  assert(isByte(mode), "invalid value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2593
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2594
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2595
  emit_byte(0xF2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2596
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2597
  emit_byte(0x70);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2598
  emit_sse_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2599
  emit_byte(mode & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2600
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2601
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2602
void Assembler::pshuflw(XMMRegister dst, Address src, int mode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2603
  assert(isByte(mode), "invalid value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2604
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2605
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2606
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2607
  emit_byte(0xF2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2608
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2609
  emit_byte(0x70);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2610
  emit_sse_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2611
  emit_byte(mode & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2612
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2613
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2614
void Assembler::psrlq(XMMRegister dst, int shift) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2615
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2616
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2617
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2618
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2619
  emit_byte(0x73);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2620
  emit_sse_operand(xmm2, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2621
  emit_byte(shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2622
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2623
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2624
void Assembler::movss( Address dst, XMMRegister src ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2625
  assert(VM_Version::supports_sse(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2626
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2627
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2628
  emit_byte(0xF3); // single
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2629
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2630
  emit_byte(0x11); // store
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2631
  emit_sse_operand(src, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2632
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2633
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2634
void Assembler::movsd( Address dst, XMMRegister src ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2635
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2636
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2637
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2638
  emit_byte(0xF2); // double
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2639
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2640
  emit_byte(0x11); // store
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2641
  emit_sse_operand(src,dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2642
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2643
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2644
// New cpus require to use movaps and movapd to avoid partial register stall
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2645
// when moving between registers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2646
void Assembler::movaps(XMMRegister dst, XMMRegister src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2647
  assert(VM_Version::supports_sse(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2648
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2649
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2650
  emit_byte(0x28);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2651
  emit_sse_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2652
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2653
void Assembler::movapd(XMMRegister dst, XMMRegister src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2654
  assert(VM_Version::supports_sse2(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2655
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2656
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2657
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2658
  emit_byte(0x28);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2659
  emit_sse_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2660
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2661
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2662
// New cpus require to use movsd and movss to avoid partial register stall
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2663
// when loading from memory. But for old Opteron use movlpd instead of movsd.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2664
// The selection is done in MacroAssembler::movdbl() and movflt().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2665
void Assembler::movlpd(XMMRegister dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2666
  assert(VM_Version::supports_sse(), "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2667
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2668
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2669
  emit_byte(0x66);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2670
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2671
  emit_byte(0x12);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2672
  emit_sse_operand(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2673
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2674
244
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2675
void Assembler::cvtdq2pd(XMMRegister dst, XMMRegister src) {
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2676
  assert(VM_Version::supports_sse2(), "");
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2677
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2678
  emit_byte(0xF3);
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2679
  emit_byte(0x0F);
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2680
  emit_byte(0xE6);
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2681
  emit_sse_operand(dst, src);
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2682
}
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2683
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2684
void Assembler::cvtdq2ps(XMMRegister dst, XMMRegister src) {
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2685
  assert(VM_Version::supports_sse2(), "");
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2686
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2687
  emit_byte(0x0F);
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2688
  emit_byte(0x5B);
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2689
  emit_sse_operand(dst, src);
c8ad6f221400 6662967: Optimize I2D conversion on new x86
kvn
parents: 1
diff changeset
  2690
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2691
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2692
emit_sse_instruction(andps,  sse,  0,    0x54, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2693
emit_sse_instruction(andpd,  sse2, 0x66, 0x54, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2694
emit_sse_instruction(andnps, sse,  0,    0x55, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2695
emit_sse_instruction(andnpd, sse2, 0x66, 0x55, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2696
emit_sse_instruction(orps,   sse,  0,    0x56, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2697
emit_sse_instruction(orpd,   sse2, 0x66, 0x56, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2698
emit_sse_instruction(xorps,  sse,  0,    0x57, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2699
emit_sse_instruction(xorpd,  sse2, 0x66, 0x57, XMMRegister, XMMRegister);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2700
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2701
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2702
void Assembler::ldmxcsr( Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2703
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2704
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2705
  emit_byte(0xAE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2706
  emit_operand(rdx /* 2 */, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2707
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2708
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2709
void Assembler::stmxcsr( Address dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2710
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2711
  emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2712
  emit_byte(0xAE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2713
  emit_operand(rbx /* 3 */, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2714
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2715
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2716
// Implementation of MacroAssembler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2717
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2718
Address MacroAssembler::as_Address(AddressLiteral adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2719
  // amd64 always does this as a pc-rel
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2720
  // we can be absolute or disp based on the instruction type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2721
  // jmp/call are displacements others are absolute
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2722
  assert(!adr.is_lval(), "must be rval");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2723
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2724
  return Address(adr.target(), adr.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2725
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2726
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2727
Address MacroAssembler::as_Address(ArrayAddress adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2728
  return Address::make_array(adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2729
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2730
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2731
void MacroAssembler::fat_nop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2732
  // A 5 byte nop that is safe for patching (see patch_verified_entry)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2733
  emit_byte(0x26); // es:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2734
  emit_byte(0x2e); // cs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2735
  emit_byte(0x64); // fs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2736
  emit_byte(0x65); // gs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2737
  emit_byte(0x90);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2738
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2739
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2740
// 32bit can do a case table jump in one instruction but we no longer allow the base
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2741
// to be installed in the Address class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2742
void MacroAssembler::jump(ArrayAddress entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2743
  jmp(as_Address(entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2744
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2746
void MacroAssembler::jump(AddressLiteral dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2747
  jmp_literal(dst.target(), dst.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2748
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2749
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2750
void MacroAssembler::jump_cc(Condition cc, AddressLiteral dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2751
  assert((0 <= cc) && (cc < 16), "illegal cc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2752
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2753
  InstructionMark im(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2754
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2755
  relocInfo::relocType rtype = dst.reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2756
  relocate(rtype);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2757
  const int short_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2758
  const int long_size = 6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2759
  int offs = (int)dst.target() - ((int)_code_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2760
  if (rtype == relocInfo::none && is8bit(offs - short_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2761
    // 0111 tttn #8-bit disp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2762
    emit_byte(0x70 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2763
    emit_byte((offs - short_size) & 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2764
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2765
    // 0000 1111 1000 tttn #32-bit disp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2766
    emit_byte(0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2767
    emit_byte(0x80 | cc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2768
    emit_long(offs - long_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2769
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2770
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2771
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2772
// Calls
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2773
void MacroAssembler::call(Label& L, relocInfo::relocType rtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2774
  Assembler::call(L, rtype);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2775
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2776
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2777
void MacroAssembler::call(Register entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2778
  Assembler::call(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2779
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2780
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2781
void MacroAssembler::call(AddressLiteral entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2782
  Assembler::call_literal(entry.target(), entry.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2783
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2784
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2785
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2786
void MacroAssembler::cmp8(AddressLiteral src1, int8_t imm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2787
  Assembler::cmpb(as_Address(src1), imm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2788
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2789
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2790
void MacroAssembler::cmp32(AddressLiteral src1, int32_t imm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2791
  Assembler::cmpl(as_Address(src1), imm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2792
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2793
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2794
void MacroAssembler::cmp32(Register src1, AddressLiteral src2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2795
  if (src2.is_lval()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2796
    cmp_literal32(src1, (int32_t) src2.target(), src2.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2797
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2798
    Assembler::cmpl(src1, as_Address(src2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2799
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2800
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2801
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2802
void MacroAssembler::cmp32(Register src1, int32_t imm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2803
  Assembler::cmpl(src1, imm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2804
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2805
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2806
void MacroAssembler::cmp32(Register src1, Address src2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2807
  Assembler::cmpl(src1, src2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2808
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2809
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2810
void MacroAssembler::cmpoop(Address src1, jobject obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2811
  cmp_literal32(src1, (int32_t)obj, oop_Relocation::spec_for_immediate());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2812
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2813
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2814
void MacroAssembler::cmpoop(Register src1, jobject obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2815
  cmp_literal32(src1, (int32_t)obj, oop_Relocation::spec_for_immediate());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2817
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2818
void MacroAssembler::cmpptr(Register src1, AddressLiteral src2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2819
  if (src2.is_lval()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2820
    // compare the effect address of src2 to src1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2821
    cmp_literal32(src1, (int32_t)src2.target(), src2.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2822
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2823
    Assembler::cmpl(src1, as_Address(src2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2824
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2825
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2826
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2827
void MacroAssembler::cmpptr(Address src1, AddressLiteral src2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2828
  assert(src2.is_lval(), "not a mem-mem compare");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2829
  cmp_literal32(src1, (int32_t) src2.target(), src2.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2830
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2831
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2832
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2833
void MacroAssembler::cmpxchgptr(Register reg, AddressLiteral adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2834
  cmpxchg(reg, as_Address(adr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2835
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2836
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2837
void MacroAssembler::increment(AddressLiteral dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2838
  increment(as_Address(dst));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2839
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2840
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2841
void MacroAssembler::increment(ArrayAddress dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2842
  increment(as_Address(dst));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2843
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2844
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2845
void MacroAssembler::lea(Register dst, AddressLiteral adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2846
  // leal(dst, as_Address(adr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2847
  // see note in movl as to why we musr use a move
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2848
  mov_literal32(dst, (int32_t) adr.target(), adr.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2849
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2850
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2851
void MacroAssembler::lea(Address dst, AddressLiteral adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2852
  // leal(dst, as_Address(adr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2853
  // see note in movl as to why we musr use a move
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2854
  mov_literal32(dst, (int32_t) adr.target(), adr.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2855
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2856
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2857
void MacroAssembler::mov32(AddressLiteral dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2858
  Assembler::movl(as_Address(dst), src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2859
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2860
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2861
void MacroAssembler::mov32(Register dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2862
  Assembler::movl(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2863
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2864
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2865
void MacroAssembler::movbyte(ArrayAddress dst, int src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2866
  movb(as_Address(dst), src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2867
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2868
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2869
void MacroAssembler::movoop(Address dst, jobject obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2870
  mov_literal32(dst, (int32_t)obj, oop_Relocation::spec_for_immediate());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2871
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2872
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2873
void MacroAssembler::movoop(Register dst, jobject obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2874
  mov_literal32(dst, (int32_t)obj, oop_Relocation::spec_for_immediate());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2875
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2876
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2877
void MacroAssembler::movptr(Register dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2878
  if (src.is_lval()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2879
    // essentially an lea
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2880
    mov_literal32(dst, (int32_t) src.target(), src.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2881
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2882
    // mov 32bits from an absolute address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2883
    movl(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2884
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2885
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2886
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2887
void MacroAssembler::movptr(ArrayAddress dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2888
  movl(as_Address(dst), src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2889
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2890
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2891
void MacroAssembler::movptr(Register dst, ArrayAddress src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2892
  movl(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2893
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2894
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2895
void MacroAssembler::movflt(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2896
  movss(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2897
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2898
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2899
void MacroAssembler::movdbl(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2900
  if (UseXmmLoadAndClearUpper) { movsd (dst, as_Address(src)); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2901
  else                         { movlpd(dst, as_Address(src)); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2902
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2903
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2904
void Assembler::pushoop(jobject obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2905
  push_literal32((int32_t)obj, oop_Relocation::spec_for_immediate());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2906
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2907
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2908
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2909
void MacroAssembler::pushptr(AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2910
  if (src.is_lval()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2911
    push_literal32((int32_t)src.target(), src.rspec());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2912
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2913
    pushl(as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2914
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2915
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2916
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2917
void MacroAssembler::test32(Register src1, AddressLiteral src2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2918
  // src2 must be rval
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2919
  testl(src1, as_Address(src2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2920
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2921
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2922
// FPU
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2923
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2924
void MacroAssembler::fld_x(AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2925
  Assembler::fld_x(as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2926
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2927
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2928
void MacroAssembler::fld_d(AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2929
  fld_d(as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2930
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2931
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2932
void MacroAssembler::fld_s(AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2933
  fld_s(as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2934
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2935
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2936
void MacroAssembler::fldcw(AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2937
  Assembler::fldcw(as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2938
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2939
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2940
void MacroAssembler::ldmxcsr(AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2941
  Assembler::ldmxcsr(as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2942
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2943
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2944
// SSE
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2945
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2946
void MacroAssembler::andpd(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2947
  andpd(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2948
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2949
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2950
void MacroAssembler::comisd(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2951
  comisd(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2952
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2953
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2954
void MacroAssembler::comiss(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2955
  comiss(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2956
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2957
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2958
void MacroAssembler::movsd(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2959
  movsd(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2960
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2961
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2962
void MacroAssembler::movss(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2963
  movss(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2964
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2965
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2966
void MacroAssembler::xorpd(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2967
  xorpd(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2968
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2969
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2970
void MacroAssembler::xorps(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2971
  xorps(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2972
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2973
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2974
void MacroAssembler::ucomisd(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2975
  ucomisd(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2976
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2977
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2978
void MacroAssembler::ucomiss(XMMRegister dst, AddressLiteral src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2979
  ucomiss(dst, as_Address(src));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2980
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2981
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2982
void MacroAssembler::null_check(Register reg, int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2983
  if (needs_explicit_null_check(offset)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2984
    // provoke OS NULL exception if reg = NULL by
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2985
    // accessing M[reg] w/o changing any (non-CC) registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2986
    cmpl(rax, Address(reg, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2987
    // Note: should probably use testl(rax, Address(reg, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2988
    //       may be shorter code (however, this version of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2989
    //       testl needs to be implemented first)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2990
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2991
    // nothing to do, (later) access of M[reg + offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2992
    // will provoke OS NULL exception if reg = NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2993
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2994
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2995
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2996
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2997
int MacroAssembler::load_unsigned_byte(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2998
  // According to Intel Doc. AP-526, "Zero-Extension of Short", p.16,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2999
  // and "3.9 Partial Register Penalties", p. 22).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3000
  int off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3001
  if (VM_Version::is_P6() || src.uses(dst)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3002
    off = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3003
    movzxb(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3004
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3005
    xorl(dst, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3006
    off = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3007
    movb(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3008
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3009
  return off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3010
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3011
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3012
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3013
int MacroAssembler::load_unsigned_word(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3014
  // According to Intel Doc. AP-526, "Zero-Extension of Short", p.16,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3015
  // and "3.9 Partial Register Penalties", p. 22).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3016
  int off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3017
  if (VM_Version::is_P6() || src.uses(dst)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3018
    off = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3019
    movzxw(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3020
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3021
    xorl(dst, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3022
    off = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3023
    movw(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3024
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3025
  return off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3026
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3027
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3028
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3029
int MacroAssembler::load_signed_byte(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3030
  int off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3031
  if (VM_Version::is_P6()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3032
    off = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3033
    movsxb(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3034
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3035
    off = load_unsigned_byte(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3036
    shll(dst, 24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3037
    sarl(dst, 24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3038
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3039
  return off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3040
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3042
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3043
int MacroAssembler::load_signed_word(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3044
  int off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3045
  if (VM_Version::is_P6()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3046
    off = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3047
    movsxw(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3048
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3049
    off = load_unsigned_word(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3050
    shll(dst, 16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3051
    sarl(dst, 16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3052
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3053
  return off;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3054
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3056
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3057
void MacroAssembler::extend_sign(Register hi, Register lo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3058
  // According to Intel Doc. AP-526, "Integer Divide", p.18.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3059
  if (VM_Version::is_P6() && hi == rdx && lo == rax) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3060
    cdql();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3061
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3062
    movl(hi, lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3063
    sarl(hi, 31);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3064
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3065
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3066
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3067
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3068
void MacroAssembler::increment(Register reg, int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3069
  if (value == min_jint) {addl(reg, value); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3070
  if (value <  0) { decrement(reg, -value); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3071
  if (value == 0) {                       ; return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3072
  if (value == 1 && UseIncDec) { incl(reg); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3073
  /* else */      { addl(reg, value)      ; return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3074
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3075
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3076
void MacroAssembler::increment(Address dst, int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3077
  if (value == min_jint) {addl(dst, value); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3078
  if (value <  0) { decrement(dst, -value); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3079
  if (value == 0) {                       ; return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3080
  if (value == 1 && UseIncDec) { incl(dst); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3081
  /* else */      { addl(dst, value)      ; return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3082
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3084
void MacroAssembler::decrement(Register reg, int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3085
  if (value == min_jint) {subl(reg, value); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3086
  if (value <  0) { increment(reg, -value); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3087
  if (value == 0) {                       ; return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3088
  if (value == 1 && UseIncDec) { decl(reg); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3089
  /* else */      { subl(reg, value)      ; return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3090
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3091
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3092
void MacroAssembler::decrement(Address dst, int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3093
  if (value == min_jint) {subl(dst, value); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3094
  if (value <  0) { increment(dst, -value); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3095
  if (value == 0) {                       ; return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3096
  if (value == 1 && UseIncDec) { decl(dst); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3097
  /* else */      { subl(dst, value)      ; return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3098
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3099
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3100
void MacroAssembler::align(int modulus) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3101
  if (offset() % modulus != 0) nop(modulus - (offset() % modulus));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3103
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3104
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3105
void MacroAssembler::enter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3106
  pushl(rbp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3107
  movl(rbp, rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3109
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3111
void MacroAssembler::leave() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3112
  movl(rsp, rbp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3113
  popl(rbp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3115
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3116
void MacroAssembler::set_last_Java_frame(Register java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3117
                                         Register last_java_sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3118
                                         Register last_java_fp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3119
                                         address  last_java_pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3120
  // determine java_thread register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3121
  if (!java_thread->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3122
    java_thread = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3123
    get_thread(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3125
  // determine last_java_sp register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3126
  if (!last_java_sp->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3127
    last_java_sp = rsp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3129
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3130
  // last_java_fp is optional
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3131
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3132
  if (last_java_fp->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3133
    movl(Address(java_thread, JavaThread::last_Java_fp_offset()), last_java_fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3135
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3136
  // last_java_pc is optional
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3137
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3138
  if (last_java_pc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3139
    lea(Address(java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3140
                 JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3141
        InternalAddress(last_java_pc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3142
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3144
  movl(Address(java_thread, JavaThread::last_Java_sp_offset()), last_java_sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3145
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3146
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3147
void MacroAssembler::reset_last_Java_frame(Register java_thread, bool clear_fp, bool clear_pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3148
  // determine java_thread register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3149
  if (!java_thread->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3150
    java_thread = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3151
    get_thread(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3153
  // we must set sp to zero to clear frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3154
  movl(Address(java_thread, JavaThread::last_Java_sp_offset()), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3155
  if (clear_fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3156
    movl(Address(java_thread, JavaThread::last_Java_fp_offset()), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3158
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3159
  if (clear_pc)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3160
    movl(Address(java_thread, JavaThread::last_Java_pc_offset()), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3161
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3163
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3164
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3165
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3166
// Implementation of call_VM versions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3167
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3168
void MacroAssembler::call_VM_leaf_base(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3169
  address entry_point,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3170
  int     number_of_arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3171
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3172
  call(RuntimeAddress(entry_point));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3173
  increment(rsp, number_of_arguments * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3175
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3176
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3177
void MacroAssembler::call_VM_base(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3178
  Register oop_result,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3179
  Register java_thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3180
  Register last_java_sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3181
  address  entry_point,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3182
  int      number_of_arguments,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3183
  bool     check_exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3184
) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3185
  // determine java_thread register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3186
  if (!java_thread->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3187
    java_thread = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3188
    get_thread(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3190
  // determine last_java_sp register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3191
  if (!last_java_sp->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3192
    last_java_sp = rsp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3194
  // debugging support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3195
  assert(number_of_arguments >= 0   , "cannot have negative number of arguments");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3196
  assert(java_thread != oop_result  , "cannot use the same register for java_thread & oop_result");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3197
  assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3198
  // push java thread (becomes first argument of C function)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3199
  pushl(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3200
  // set last Java frame before call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3201
  assert(last_java_sp != rbp, "this code doesn't work for last_java_sp == rbp, which currently can't portably work anyway since C2 doesn't save rbp,");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3202
  // Only interpreter should have to set fp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3203
  set_last_Java_frame(java_thread, last_java_sp, rbp, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3204
  // do the call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3205
  call(RuntimeAddress(entry_point));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3206
  // restore the thread (cannot use the pushed argument since arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3207
  // may be overwritten by C code generated by an optimizing compiler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3208
  // however can use the register value directly if it is callee saved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3209
  if (java_thread == rdi || java_thread == rsi) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3210
    // rdi & rsi are callee saved -> nothing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3211
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3212
    guarantee(java_thread != rax, "change this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3213
    pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3214
    { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3215
      get_thread(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3216
      cmpl(java_thread, rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3217
      jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3218
      stop("MacroAssembler::call_VM_base: rdi not callee saved?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3219
      bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3220
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3221
    popl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3222
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3223
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3224
    get_thread(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3226
  // reset last Java frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3227
  // Only interpreter should have to clear fp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3228
  reset_last_Java_frame(java_thread, true, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3229
  // discard thread and arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3230
  addl(rsp, (1 + number_of_arguments)*wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3231
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3232
#ifndef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3233
   // C++ interp handles this in the interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3234
  check_and_handle_popframe(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3235
  check_and_handle_earlyret(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3236
#endif /* CC_INTERP */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3237
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3238
  if (check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3239
    // check for pending exceptions (java_thread is set upon return)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3240
    cmpl(Address(java_thread, Thread::pending_exception_offset()), NULL_WORD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3241
    jump_cc(Assembler::notEqual,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3242
            RuntimeAddress(StubRoutines::forward_exception_entry()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3244
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3245
  // get oop result if there is one and reset the value in the thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3246
  if (oop_result->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3247
    movl(oop_result, Address(java_thread, JavaThread::vm_result_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3248
    movl(Address(java_thread, JavaThread::vm_result_offset()), NULL_WORD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3249
    verify_oop(oop_result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3250
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3252
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3253
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3254
void MacroAssembler::check_and_handle_popframe(Register java_thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3256
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3257
void MacroAssembler::check_and_handle_earlyret(Register java_thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3259
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3260
void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3261
  leal(rax, Address(rsp, (1 + number_of_arguments) * wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3262
  call_VM_base(oop_result, noreg, rax, entry_point, number_of_arguments, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3263
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3264
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3265
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3266
void MacroAssembler::call_VM(Register oop_result, address entry_point, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3267
  Label C, E;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3268
  call(C, relocInfo::none);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3269
  jmp(E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3270
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3271
  bind(C);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3272
  call_VM_helper(oop_result, entry_point, 0, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3273
  ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3274
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3275
  bind(E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3276
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3277
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3278
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3279
void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3280
  Label C, E;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3281
  call(C, relocInfo::none);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3282
  jmp(E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3283
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3284
  bind(C);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3285
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3286
  call_VM_helper(oop_result, entry_point, 1, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3287
  ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3288
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3289
  bind(E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3290
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3291
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3292
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3293
void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3294
  Label C, E;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3295
  call(C, relocInfo::none);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3296
  jmp(E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3298
  bind(C);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3299
  pushl(arg_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3300
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3301
  call_VM_helper(oop_result, entry_point, 2, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3302
  ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3303
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3304
  bind(E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3305
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3306
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3307
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3308
void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3309
  Label C, E;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3310
  call(C, relocInfo::none);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3311
  jmp(E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3312
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3313
  bind(C);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3314
  pushl(arg_3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3315
  pushl(arg_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3316
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3317
  call_VM_helper(oop_result, entry_point, 3, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3318
  ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3320
  bind(E);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3321
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3322
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3323
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3324
void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, int number_of_arguments, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3325
  call_VM_base(oop_result, noreg, last_java_sp, entry_point, number_of_arguments, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3326
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3327
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3328
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3329
void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3330
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3331
  call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3332
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3333
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3334
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3335
void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3336
  pushl(arg_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3337
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3338
  call_VM(oop_result, last_java_sp, entry_point, 2, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3339
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3340
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3341
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3342
void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3343
  pushl(arg_3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3344
  pushl(arg_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3345
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3346
  call_VM(oop_result, last_java_sp, entry_point, 3, check_exceptions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3347
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3348
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3349
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3350
void MacroAssembler::call_VM_leaf(address entry_point, int number_of_arguments) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3351
  call_VM_leaf_base(entry_point, number_of_arguments);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3352
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3353
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3354
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3355
void MacroAssembler::call_VM_leaf(address entry_point, Register arg_1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3356
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3357
  call_VM_leaf(entry_point, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3358
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3359
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3360
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3361
void MacroAssembler::call_VM_leaf(address entry_point, Register arg_1, Register arg_2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3362
  pushl(arg_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3363
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3364
  call_VM_leaf(entry_point, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3365
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3366
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3367
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3368
void MacroAssembler::call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3369
  pushl(arg_3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3370
  pushl(arg_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3371
  pushl(arg_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3372
  call_VM_leaf(entry_point, 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3373
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3374
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3375
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3376
// Calls to C land
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3377
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3378
// When entering C land, the rbp, & rsp of the last Java frame have to be recorded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3379
// in the (thread-local) JavaThread object. When leaving C land, the last Java fp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3380
// has to be reset to 0. This is required to allow proper stack traversal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3381
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3382
void MacroAssembler::store_check(Register obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3383
  // Does a store check for the oop in register obj. The content of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3384
  // register obj is destroyed afterwards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3385
  store_check_part_1(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3386
  store_check_part_2(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3387
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3388
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3389
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3390
void MacroAssembler::store_check(Register obj, Address dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3391
  store_check(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3392
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3393
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3394
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3395
// split the store check operation so that other instructions can be scheduled inbetween
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3396
void MacroAssembler::store_check_part_1(Register obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3397
  BarrierSet* bs = Universe::heap()->barrier_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3398
  assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3399
  shrl(obj, CardTableModRefBS::card_shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3400
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3401
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3402
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3403
void MacroAssembler::store_check_part_2(Register obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3404
  BarrierSet* bs = Universe::heap()->barrier_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3405
  assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3406
  CardTableModRefBS* ct = (CardTableModRefBS*)bs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3407
  assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3408
  ExternalAddress cardtable((address)ct->byte_map_base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3409
  Address index(noreg, obj, Address::times_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3410
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3411
  movb(as_Address(ArrayAddress(cardtable, index)), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3412
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3413
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3414
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3415
void MacroAssembler::c2bool(Register x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3416
  // implements x == 0 ? 0 : 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3417
  // note: must only look at least-significant byte of x
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3418
  //       since C-style booleans are stored in one byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3419
  //       only! (was bug)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3420
  andl(x, 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3421
  setb(Assembler::notZero, x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3422
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3423
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3424
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3425
int MacroAssembler::corrected_idivl(Register reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3426
  // Full implementation of Java idiv and irem; checks for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3427
  // special case as described in JVM spec., p.243 & p.271.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3428
  // The function returns the (pc) offset of the idivl
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3429
  // instruction - may be needed for implicit exceptions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3430
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3431
  //         normal case                           special case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3432
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3433
  // input : rax,: dividend                         min_int
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3434
  //         reg: divisor   (may not be rax,/rdx)   -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3435
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3436
  // output: rax,: quotient  (= rax, idiv reg)       min_int
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3437
  //         rdx: remainder (= rax, irem reg)       0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3438
  assert(reg != rax && reg != rdx, "reg cannot be rax, or rdx register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3439
  const int min_int = 0x80000000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3440
  Label normal_case, special_case;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3441
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3442
  // check for special case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3443
  cmpl(rax, min_int);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3444
  jcc(Assembler::notEqual, normal_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3445
  xorl(rdx, rdx); // prepare rdx for possible special case (where remainder = 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3446
  cmpl(reg, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3447
  jcc(Assembler::equal, special_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3448
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3449
  // handle normal case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3450
  bind(normal_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3451
  cdql();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3452
  int idivl_offset = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3453
  idivl(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3454
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3455
  // normal and special case exit
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3456
  bind(special_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3457
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3458
  return idivl_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3459
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3460
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3461
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3462
void MacroAssembler::lneg(Register hi, Register lo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3463
  negl(lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3464
  adcl(hi, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3465
  negl(hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3466
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3467
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3468
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3469
void MacroAssembler::lmul(int x_rsp_offset, int y_rsp_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3470
  // Multiplication of two Java long values stored on the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3471
  // as illustrated below. Result is in rdx:rax.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3472
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3473
  // rsp ---> [  ??  ] \               \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3474
  //            ....    | y_rsp_offset  |
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3475
  //          [ y_lo ] /  (in bytes)    | x_rsp_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3476
  //          [ y_hi ]                  | (in bytes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3477
  //            ....                    |
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3478
  //          [ x_lo ]                 /
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3479
  //          [ x_hi ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3480
  //            ....
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3481
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3482
  // Basic idea: lo(result) = lo(x_lo * y_lo)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3483
  //             hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3484
  Address x_hi(rsp, x_rsp_offset + wordSize); Address x_lo(rsp, x_rsp_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3485
  Address y_hi(rsp, y_rsp_offset + wordSize); Address y_lo(rsp, y_rsp_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3486
  Label quick;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3487
  // load x_hi, y_hi and check if quick
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3488
  // multiplication is possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3489
  movl(rbx, x_hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3490
  movl(rcx, y_hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3491
  movl(rax, rbx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3492
  orl(rbx, rcx);                                 // rbx, = 0 <=> x_hi = 0 and y_hi = 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3493
  jcc(Assembler::zero, quick);                   // if rbx, = 0 do quick multiply
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3494
  // do full multiplication
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3495
  // 1st step
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3496
  mull(y_lo);                                    // x_hi * y_lo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3497
  movl(rbx, rax);                                // save lo(x_hi * y_lo) in rbx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3498
  // 2nd step
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3499
  movl(rax, x_lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3500
  mull(rcx);                                     // x_lo * y_hi
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3501
  addl(rbx, rax);                                // add lo(x_lo * y_hi) to rbx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3502
  // 3rd step
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3503
  bind(quick);                                   // note: rbx, = 0 if quick multiply!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3504
  movl(rax, x_lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3505
  mull(y_lo);                                    // x_lo * y_lo
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3506
  addl(rdx, rbx);                                // correct hi(x_lo * y_lo)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3507
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3508
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3509
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3510
void MacroAssembler::lshl(Register hi, Register lo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3511
  // Java shift left long support (semantics as described in JVM spec., p.305)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3512
  // (basic idea for shift counts s >= n: x << s == (x << n) << (s - n))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3513
  // shift value is in rcx !
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3514
  assert(hi != rcx, "must not use rcx");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3515
  assert(lo != rcx, "must not use rcx");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3516
  const Register s = rcx;                        // shift count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3517
  const int      n = BitsPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3518
  Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3519
  andl(s, 0x3f);                                 // s := s & 0x3f (s < 0x40)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3520
  cmpl(s, n);                                    // if (s < n)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3521
  jcc(Assembler::less, L);                       // else (s >= n)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3522
  movl(hi, lo);                                  // x := x << n
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3523
  xorl(lo, lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3524
  // Note: subl(s, n) is not needed since the Intel shift instructions work rcx mod n!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3525
  bind(L);                                       // s (mod n) < n
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3526
  shldl(hi, lo);                                 // x := x << s
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3527
  shll(lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3528
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3529
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3530
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3531
void MacroAssembler::lshr(Register hi, Register lo, bool sign_extension) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3532
  // Java shift right long support (semantics as described in JVM spec., p.306 & p.310)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3533
  // (basic idea for shift counts s >= n: x >> s == (x >> n) >> (s - n))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3534
  assert(hi != rcx, "must not use rcx");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3535
  assert(lo != rcx, "must not use rcx");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3536
  const Register s = rcx;                        // shift count
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3537
  const int      n = BitsPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3538
  Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3539
  andl(s, 0x3f);                                 // s := s & 0x3f (s < 0x40)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3540
  cmpl(s, n);                                    // if (s < n)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3541
  jcc(Assembler::less, L);                       // else (s >= n)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3542
  movl(lo, hi);                                  // x := x >> n
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3543
  if (sign_extension) sarl(hi, 31);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3544
  else                xorl(hi, hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3545
  // Note: subl(s, n) is not needed since the Intel shift instructions work rcx mod n!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3546
  bind(L);                                       // s (mod n) < n
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3547
  shrdl(lo, hi);                                 // x := x >> s
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3548
  if (sign_extension) sarl(hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3549
  else                shrl(hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3550
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3551
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3552
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3553
// Note: y_lo will be destroyed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3554
void MacroAssembler::lcmp2int(Register x_hi, Register x_lo, Register y_hi, Register y_lo) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3555
  // Long compare for Java (semantics as described in JVM spec.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3556
  Label high, low, done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3557
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3558
  cmpl(x_hi, y_hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3559
  jcc(Assembler::less, low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3560
  jcc(Assembler::greater, high);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3561
  // x_hi is the return register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3562
  xorl(x_hi, x_hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3563
  cmpl(x_lo, y_lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3564
  jcc(Assembler::below, low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3565
  jcc(Assembler::equal, done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3566
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3567
  bind(high);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3568
  xorl(x_hi, x_hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3569
  increment(x_hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3570
  jmp(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3571
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3572
  bind(low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3573
  xorl(x_hi, x_hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3574
  decrement(x_hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3575
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3576
  bind(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3577
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3578
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3579
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3580
void MacroAssembler::save_rax(Register tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3581
  if (tmp == noreg) pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3582
  else if (tmp != rax) movl(tmp, rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3583
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3584
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3585
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3586
void MacroAssembler::restore_rax(Register tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3587
  if (tmp == noreg) popl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3588
  else if (tmp != rax) movl(rax, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3589
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3590
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3591
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3592
void MacroAssembler::fremr(Register tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3593
  save_rax(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3594
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3595
    bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3596
    fprem();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3597
    fwait(); fnstsw_ax();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3598
    sahf();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3599
    jcc(Assembler::parity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3601
  restore_rax(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3602
  // Result is in ST0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3603
  // Note: fxch & fpop to get rid of ST1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3604
  // (otherwise FPU stack could overflow eventually)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3605
  fxch(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3606
  fpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3607
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3608
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3609
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3610
static const double     pi_4 =  0.7853981633974483;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3611
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3612
void MacroAssembler::trigfunc(char trig, int num_fpu_regs_in_use) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3613
  // A hand-coded argument reduction for values in fabs(pi/4, pi/2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3614
  // was attempted in this code; unfortunately it appears that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3615
  // switch to 80-bit precision and back causes this to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3616
  // unprofitable compared with simply performing a runtime call if
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3617
  // the argument is out of the (-pi/4, pi/4) range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3618
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3619
  Register tmp = noreg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3620
  if (!VM_Version::supports_cmov()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3621
    // fcmp needs a temporary so preserve rbx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3622
    tmp = rbx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3623
    pushl(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3624
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3625
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3626
  Label slow_case, done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3627
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3628
  // x ?<= pi/4
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3629
  fld_d(ExternalAddress((address)&pi_4));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3630
  fld_s(1);                // Stack:  X  PI/4  X
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3631
  fabs();                  // Stack: |X| PI/4  X
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3632
  fcmp(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3633
  jcc(Assembler::above, slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3634
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3635
  // fastest case: -pi/4 <= x <= pi/4
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3636
  switch(trig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3637
  case 's':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3638
    fsin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3639
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3640
  case 'c':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3641
    fcos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3642
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3643
  case 't':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3644
    ftan();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3645
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3646
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3647
    assert(false, "bad intrinsic");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3648
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3649
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3650
  jmp(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3651
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3652
  // slow case: runtime call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3653
  bind(slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3654
  // Preserve registers across runtime call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3655
  pushad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3656
  int incoming_argument_and_return_value_offset = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3657
  if (num_fpu_regs_in_use > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3658
    // Must preserve all other FPU regs (could alternatively convert
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3659
    // SharedRuntime::dsin and dcos into assembly routines known not to trash
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3660
    // FPU state, but can not trust C compiler)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3661
    NEEDS_CLEANUP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3662
    // NOTE that in this case we also push the incoming argument to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3663
    // the stack and restore it later; we also use this stack slot to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3664
    // hold the return value from dsin or dcos.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3665
    for (int i = 0; i < num_fpu_regs_in_use; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3666
      subl(rsp, wordSize*2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3667
      fstp_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3668
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3669
    incoming_argument_and_return_value_offset = 2*wordSize*(num_fpu_regs_in_use-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3670
    fld_d(Address(rsp, incoming_argument_and_return_value_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3671
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3672
  subl(rsp, wordSize*2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3673
  fstp_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3674
  // NOTE: we must not use call_VM_leaf here because that requires a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3675
  // complete interpreter frame in debug mode -- same bug as 4387334
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3676
  NEEDS_CLEANUP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3677
  // Need to add stack banging before this runtime call if it needs to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3678
  // be taken; however, there is no generic stack banging routine at
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3679
  // the MacroAssembler level
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3680
  switch(trig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3681
  case 's':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3682
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3683
      call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dsin)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3684
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3685
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3686
  case 'c':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3687
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3688
      call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dcos)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3689
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3690
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3691
  case 't':
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3692
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3693
      call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dtan)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3694
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3695
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3696
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3697
    assert(false, "bad intrinsic");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3698
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3699
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3700
  addl(rsp, wordSize * 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3701
  if (num_fpu_regs_in_use > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3702
    // Must save return value to stack and then restore entire FPU stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3703
    fstp_d(Address(rsp, incoming_argument_and_return_value_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3704
    for (int i = 0; i < num_fpu_regs_in_use; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3705
      fld_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3706
      addl(rsp, wordSize*2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3707
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3708
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3709
  popad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3710
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3711
  // Come here with result in F-TOS
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3712
  bind(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3713
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3714
  if (tmp != noreg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3715
    popl(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3716
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3717
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3718
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3719
void MacroAssembler::jC2(Register tmp, Label& L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3720
  // set parity bit if FPU flag C2 is set (via rax)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3721
  save_rax(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3722
  fwait(); fnstsw_ax();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3723
  sahf();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3724
  restore_rax(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3725
  // branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3726
  jcc(Assembler::parity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3727
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3728
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3729
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3730
void MacroAssembler::jnC2(Register tmp, Label& L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3731
  // set parity bit if FPU flag C2 is set (via rax)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3732
  save_rax(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3733
  fwait(); fnstsw_ax();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3734
  sahf();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3735
  restore_rax(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3736
  // branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3737
  jcc(Assembler::noParity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3738
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3739
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3740
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3741
void MacroAssembler::fcmp(Register tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3742
  fcmp(tmp, 1, true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3743
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3744
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3746
void MacroAssembler::fcmp(Register tmp, int index, bool pop_left, bool pop_right) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3747
  assert(!pop_right || pop_left, "usage error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3748
  if (VM_Version::supports_cmov()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3749
    assert(tmp == noreg, "unneeded temp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3750
    if (pop_left) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3751
      fucomip(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3752
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3753
      fucomi(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3754
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3755
    if (pop_right) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3756
      fpop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3757
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3758
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3759
    assert(tmp != noreg, "need temp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3760
    if (pop_left) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3761
      if (pop_right) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3762
        fcompp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3763
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3764
        fcomp(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3765
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3766
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3767
      fcom(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3768
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3769
    // convert FPU condition into eflags condition via rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3770
    save_rax(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3771
    fwait(); fnstsw_ax();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3772
    sahf();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3773
    restore_rax(tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3774
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3775
  // condition codes set as follows:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3776
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3777
  // CF (corresponds to C0) if x < y
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3778
  // PF (corresponds to C2) if unordered
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3779
  // ZF (corresponds to C3) if x = y
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3780
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3781
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3782
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3783
void MacroAssembler::fcmp2int(Register dst, bool unordered_is_less) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3784
  fcmp2int(dst, unordered_is_less, 1, true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3785
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3786
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3787
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3788
void MacroAssembler::fcmp2int(Register dst, bool unordered_is_less, int index, bool pop_left, bool pop_right) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3789
  fcmp(VM_Version::supports_cmov() ? noreg : dst, index, pop_left, pop_right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3790
  Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3791
  if (unordered_is_less) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3792
    movl(dst, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3793
    jcc(Assembler::parity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3794
    jcc(Assembler::below , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3795
    movl(dst, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3796
    jcc(Assembler::equal , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3797
    increment(dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3798
  } else { // unordered is greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3799
    movl(dst, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3800
    jcc(Assembler::parity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3801
    jcc(Assembler::above , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3802
    movl(dst, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3803
    jcc(Assembler::equal , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3804
    decrement(dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3805
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3806
  bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3807
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3808
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3809
void MacroAssembler::cmpss2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3810
  ucomiss(opr1, opr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3811
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3812
  Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3813
  if (unordered_is_less) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3814
    movl(dst, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3815
    jcc(Assembler::parity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3816
    jcc(Assembler::below , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3817
    movl(dst, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3818
    jcc(Assembler::equal , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3819
    increment(dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3820
  } else { // unordered is greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3821
    movl(dst, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3822
    jcc(Assembler::parity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3823
    jcc(Assembler::above , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3824
    movl(dst, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3825
    jcc(Assembler::equal , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3826
    decrement(dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3827
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3828
  bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3829
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3830
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3831
void MacroAssembler::cmpsd2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3832
  ucomisd(opr1, opr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3833
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3834
  Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3835
  if (unordered_is_less) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3836
    movl(dst, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3837
    jcc(Assembler::parity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3838
    jcc(Assembler::below , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3839
    movl(dst, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3840
    jcc(Assembler::equal , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3841
    increment(dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3842
  } else { // unordered is greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3843
    movl(dst, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3844
    jcc(Assembler::parity, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3845
    jcc(Assembler::above , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3846
    movl(dst, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3847
    jcc(Assembler::equal , L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3848
    decrement(dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3849
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3850
  bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3851
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3852
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3853
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3854
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3855
void MacroAssembler::fpop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3856
  ffree();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3857
  fincstp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3858
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3859
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3860
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3861
void MacroAssembler::sign_extend_short(Register reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3862
  if (VM_Version::is_P6()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3863
    movsxw(reg, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3864
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3865
    shll(reg, 16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3866
    sarl(reg, 16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3867
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3868
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3869
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3870
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3871
void MacroAssembler::sign_extend_byte(Register reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3872
  if (VM_Version::is_P6() && reg->has_byte_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3873
    movsxb(reg, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3874
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3875
    shll(reg, 24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3876
    sarl(reg, 24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3877
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3878
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3879
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3880
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3881
void MacroAssembler::division_with_shift (Register reg, int shift_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3882
  assert (shift_value > 0, "illegal shift value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3883
  Label _is_positive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3884
  testl (reg, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3885
  jcc (Assembler::positive, _is_positive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3886
  int offset = (1 << shift_value) - 1 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3887
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3888
  increment(reg, offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3889
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3890
  bind (_is_positive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3891
  sarl(reg, shift_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3892
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3893
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3894
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3895
void MacroAssembler::round_to(Register reg, int modulus) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3896
  addl(reg, modulus - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3897
  andl(reg, -modulus);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3898
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3899
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3900
// C++ bool manipulation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3901
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3902
void MacroAssembler::movbool(Register dst, Address src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3903
  if(sizeof(bool) == 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3904
    movb(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3905
  else if(sizeof(bool) == 2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3906
    movw(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3907
  else if(sizeof(bool) == 4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3908
    movl(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3909
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3910
    // unsupported
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3911
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3912
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3913
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3914
void MacroAssembler::movbool(Address dst, bool boolconst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3915
  if(sizeof(bool) == 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3916
    movb(dst, (int) boolconst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3917
  else if(sizeof(bool) == 2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3918
    movw(dst, (int) boolconst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3919
  else if(sizeof(bool) == 4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3920
    movl(dst, (int) boolconst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3921
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3922
    // unsupported
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3923
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3924
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3925
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3926
void MacroAssembler::movbool(Address dst, Register src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3927
  if(sizeof(bool) == 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3928
    movb(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3929
  else if(sizeof(bool) == 2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3930
    movw(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3931
  else if(sizeof(bool) == 4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3932
    movl(dst, src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3933
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3934
    // unsupported
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3935
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3936
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3937
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3938
void MacroAssembler::testbool(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3939
  if(sizeof(bool) == 1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3940
    testb(dst, (int) 0xff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3941
  else if(sizeof(bool) == 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3942
    // testw implementation needed for two byte bools
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3943
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3944
  } else if(sizeof(bool) == 4)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3945
    testl(dst, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3946
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3947
    // unsupported
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3948
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3949
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3950
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3951
void MacroAssembler::verify_oop(Register reg, const char* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3952
  if (!VerifyOops) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3953
  // Pass register number to verify_oop_subroutine
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3954
  char* b = new char[strlen(s) + 50];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3955
  sprintf(b, "verify_oop: %s: %s", reg->name(), s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3956
  pushl(rax);                          // save rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3957
  pushl(reg);                          // pass register argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3958
  ExternalAddress buffer((address) b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3959
  pushptr(buffer.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3960
  // call indirectly to solve generation ordering problem
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3961
  movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3962
  call(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3963
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3964
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3965
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3966
void MacroAssembler::verify_oop_addr(Address addr, const char* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3967
  if (!VerifyOops) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3968
  // QQQ fix this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3969
  // Address adjust(addr.base(), addr.index(), addr.scale(), addr.disp() + BytesPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3970
  // Pass register number to verify_oop_subroutine
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3971
  char* b = new char[strlen(s) + 50];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3972
  sprintf(b, "verify_oop_addr: %s", s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3973
  pushl(rax);                          // save rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3974
  // addr may contain rsp so we will have to adjust it based on the push
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3975
  // we just did
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3976
  if (addr.uses(rsp)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3977
    leal(rax, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3978
    pushl(Address(rax, BytesPerWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3979
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3980
    pushl(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3981
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3982
  ExternalAddress buffer((address) b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3983
  // pass msg argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3984
  pushptr(buffer.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3985
  // call indirectly to solve generation ordering problem
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3986
  movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3987
  call(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3988
  // Caller pops the arguments and restores rax, from the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3989
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3990
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3991
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3992
void MacroAssembler::stop(const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3993
  ExternalAddress message((address)msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3994
  // push address of message
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3995
  pushptr(message.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3996
  { Label L; call(L, relocInfo::none); bind(L); }     // push eip
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3997
  pushad();                                           // push registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3998
  call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3999
  hlt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4000
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4001
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4003
void MacroAssembler::warn(const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4004
  push_CPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4005
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4006
  ExternalAddress message((address) msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4007
  // push address of message
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4008
  pushptr(message.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4009
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4010
  call(RuntimeAddress(CAST_FROM_FN_PTR(address, warning)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4011
  addl(rsp, wordSize);       // discard argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4012
  pop_CPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4013
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4014
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4015
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4016
void MacroAssembler::debug(int rdi, int rsi, int rbp, int rsp, int rbx, int rdx, int rcx, int rax, int eip, char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4017
  // In order to get locks to work, we need to fake a in_VM state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4018
  JavaThread* thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4019
  JavaThreadState saved_state = thread->thread_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4020
  thread->set_thread_state(_thread_in_vm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4021
  if (ShowMessageBoxOnError) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4022
    JavaThread* thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4023
    JavaThreadState saved_state = thread->thread_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4024
    thread->set_thread_state(_thread_in_vm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4025
    ttyLocker ttyl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4026
    if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4027
      BytecodeCounter::print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4028
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4029
    // To see where a verify_oop failed, get $ebx+40/X for this frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4030
    // This is the value of eip which points to where verify_oop will return.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4031
    if (os::message_box(msg, "Execution stopped, print registers?")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4032
      tty->print_cr("eip = 0x%08x", eip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4033
      tty->print_cr("rax, = 0x%08x", rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4034
      tty->print_cr("rbx, = 0x%08x", rbx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4035
      tty->print_cr("rcx = 0x%08x", rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4036
      tty->print_cr("rdx = 0x%08x", rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4037
      tty->print_cr("rdi = 0x%08x", rdi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4038
      tty->print_cr("rsi = 0x%08x", rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4039
      tty->print_cr("rbp, = 0x%08x", rbp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4040
      tty->print_cr("rsp = 0x%08x", rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4041
      BREAKPOINT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4042
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4043
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4044
    ::tty->print_cr("=============== DEBUG MESSAGE: %s ================\n", msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4045
    assert(false, "DEBUG MESSAGE");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4046
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4047
  ThreadStateTransition::transition(thread, _thread_in_vm, saved_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4048
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4049
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4050
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4051
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4052
void MacroAssembler::os_breakpoint() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4053
  // instead of directly emitting a breakpoint, call os:breakpoint for better debugability
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4054
  // (e.g., MSVC can't call ps() otherwise)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4055
  call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4056
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4057
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4058
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4059
void MacroAssembler::push_fTOS() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4060
  subl(rsp, 2 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4061
  fstp_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4062
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4063
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4065
void MacroAssembler::pop_fTOS() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4066
  fld_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4067
  addl(rsp, 2 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4068
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4069
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4070
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4071
void MacroAssembler::empty_FPU_stack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4072
  if (VM_Version::supports_mmx()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4073
    emms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4074
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4075
    for (int i = 8; i-- > 0; ) ffree(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4076
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4077
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4078
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4080
class ControlWord {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4081
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4082
  int32_t _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4084
  int  rounding_control() const        { return  (_value >> 10) & 3      ; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4085
  int  precision_control() const       { return  (_value >>  8) & 3      ; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4086
  bool precision() const               { return ((_value >>  5) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4087
  bool underflow() const               { return ((_value >>  4) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4088
  bool overflow() const                { return ((_value >>  3) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4089
  bool zero_divide() const             { return ((_value >>  2) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4090
  bool denormalized() const            { return ((_value >>  1) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4091
  bool invalid() const                 { return ((_value >>  0) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4092
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4093
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4094
    // rounding control
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4095
    const char* rc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4096
    switch (rounding_control()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4097
      case 0: rc = "round near"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4098
      case 1: rc = "round down"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4099
      case 2: rc = "round up  "; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4100
      case 3: rc = "chop      "; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4101
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4102
    // precision control
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4103
    const char* pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4104
    switch (precision_control()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4105
      case 0: pc = "24 bits "; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4106
      case 1: pc = "reserved"; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4107
      case 2: pc = "53 bits "; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4108
      case 3: pc = "64 bits "; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4109
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4110
    // flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4111
    char f[9];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4112
    f[0] = ' ';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4113
    f[1] = ' ';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4114
    f[2] = (precision   ()) ? 'P' : 'p';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4115
    f[3] = (underflow   ()) ? 'U' : 'u';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4116
    f[4] = (overflow    ()) ? 'O' : 'o';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4117
    f[5] = (zero_divide ()) ? 'Z' : 'z';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4118
    f[6] = (denormalized()) ? 'D' : 'd';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4119
    f[7] = (invalid     ()) ? 'I' : 'i';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4120
    f[8] = '\x0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4121
    // output
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4122
    printf("%04x  masks = %s, %s, %s", _value & 0xFFFF, f, rc, pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4124
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4125
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4126
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4128
class StatusWord {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4129
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4130
  int32_t _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4131
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4132
  bool busy() const                    { return ((_value >> 15) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4133
  bool C3() const                      { return ((_value >> 14) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4134
  bool C2() const                      { return ((_value >> 10) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4135
  bool C1() const                      { return ((_value >>  9) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4136
  bool C0() const                      { return ((_value >>  8) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4137
  int  top() const                     { return  (_value >> 11) & 7      ; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4138
  bool error_status() const            { return ((_value >>  7) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4139
  bool stack_fault() const             { return ((_value >>  6) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4140
  bool precision() const               { return ((_value >>  5) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4141
  bool underflow() const               { return ((_value >>  4) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4142
  bool overflow() const                { return ((_value >>  3) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4143
  bool zero_divide() const             { return ((_value >>  2) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4144
  bool denormalized() const            { return ((_value >>  1) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4145
  bool invalid() const                 { return ((_value >>  0) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4146
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4147
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4148
    // condition codes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4149
    char c[5];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4150
    c[0] = (C3()) ? '3' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4151
    c[1] = (C2()) ? '2' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4152
    c[2] = (C1()) ? '1' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4153
    c[3] = (C0()) ? '0' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4154
    c[4] = '\x0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4155
    // flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4156
    char f[9];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4157
    f[0] = (error_status()) ? 'E' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4158
    f[1] = (stack_fault ()) ? 'S' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4159
    f[2] = (precision   ()) ? 'P' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4160
    f[3] = (underflow   ()) ? 'U' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4161
    f[4] = (overflow    ()) ? 'O' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4162
    f[5] = (zero_divide ()) ? 'Z' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4163
    f[6] = (denormalized()) ? 'D' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4164
    f[7] = (invalid     ()) ? 'I' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4165
    f[8] = '\x0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4166
    // output
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4167
    printf("%04x  flags = %s, cc =  %s, top = %d", _value & 0xFFFF, f, c, top());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4169
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4170
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4172
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4173
class TagWord {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4174
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4175
  int32_t _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4176
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4177
  int tag_at(int i) const              { return (_value >> (i*2)) & 3; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4178
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4179
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4180
    printf("%04x", _value & 0xFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4182
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4183
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4184
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4185
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4186
class FPU_Register {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4187
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4188
  int32_t _m0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4189
  int32_t _m1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4190
  int16_t _ex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4191
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4192
  bool is_indefinite() const           {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4193
    return _ex == -1 && _m1 == (int32_t)0xC0000000 && _m0 == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4195
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4196
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4197
    char  sign = (_ex < 0) ? '-' : '+';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4198
    const char* kind = (_ex == 0x7FFF || _ex == (int16_t)-1) ? "NaN" : "   ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4199
    printf("%c%04hx.%08x%08x  %s", sign, _ex, _m1, _m0, kind);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4200
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4201
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4202
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4203
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4204
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4205
class FPU_State {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4206
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4207
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4208
    register_size       = 10,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4209
    number_of_registers =  8,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4210
    register_mask       =  7
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4211
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4212
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4213
  ControlWord  _control_word;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4214
  StatusWord   _status_word;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4215
  TagWord      _tag_word;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4216
  int32_t      _error_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4217
  int32_t      _error_selector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4218
  int32_t      _data_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4219
  int32_t      _data_selector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4220
  int8_t       _register[register_size * number_of_registers];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4222
  int tag_for_st(int i) const          { return _tag_word.tag_at((_status_word.top() + i) & register_mask); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4223
  FPU_Register* st(int i) const        { return (FPU_Register*)&_register[register_size * i]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4224
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4225
  const char* tag_as_string(int tag) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4226
    switch (tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4227
      case 0: return "valid";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4228
      case 1: return "zero";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4229
      case 2: return "special";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4230
      case 3: return "empty";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4232
    ShouldNotReachHere()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4233
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4234
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4236
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4237
    // print computation registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4238
    { int t = _status_word.top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4239
      for (int i = 0; i < number_of_registers; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4240
        int j = (i - t) & register_mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4241
        printf("%c r%d = ST%d = ", (j == 0 ? '*' : ' '), i, j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4242
        st(j)->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4243
        printf(" %s\n", tag_as_string(_tag_word.tag_at(i)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4244
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4246
    printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4247
    // print control registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4248
    printf("ctrl = "); _control_word.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4249
    printf("stat = "); _status_word .print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4250
    printf("tags = "); _tag_word    .print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4251
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4252
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4253
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4254
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4255
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4256
class Flag_Register {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4257
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4258
  int32_t _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4259
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4260
  bool overflow() const                { return ((_value >> 11) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4261
  bool direction() const               { return ((_value >> 10) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4262
  bool sign() const                    { return ((_value >>  7) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4263
  bool zero() const                    { return ((_value >>  6) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4264
  bool auxiliary_carry() const         { return ((_value >>  4) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4265
  bool parity() const                  { return ((_value >>  2) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4266
  bool carry() const                   { return ((_value >>  0) & 1) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4267
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4268
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4269
    // flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4270
    char f[8];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4271
    f[0] = (overflow       ()) ? 'O' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4272
    f[1] = (direction      ()) ? 'D' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4273
    f[2] = (sign           ()) ? 'S' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4274
    f[3] = (zero           ()) ? 'Z' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4275
    f[4] = (auxiliary_carry()) ? 'A' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4276
    f[5] = (parity         ()) ? 'P' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4277
    f[6] = (carry          ()) ? 'C' : '-';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4278
    f[7] = '\x0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4279
    // output
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4280
    printf("%08x  flags = %s", _value, f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4281
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4282
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4283
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4285
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4286
class IU_Register {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4287
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4288
  int32_t _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4289
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4290
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4291
    printf("%08x  %11d", _value, _value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4292
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4293
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4294
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4296
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4297
class IU_State {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4298
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4299
  Flag_Register _eflags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4300
  IU_Register   _rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4301
  IU_Register   _rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4302
  IU_Register   _rbp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4303
  IU_Register   _rsp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4304
  IU_Register   _rbx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4305
  IU_Register   _rdx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4306
  IU_Register   _rcx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4307
  IU_Register   _rax;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4308
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4309
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4310
    // computation registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4311
    printf("rax,  = "); _rax.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4312
    printf("rbx,  = "); _rbx.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4313
    printf("rcx  = "); _rcx.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4314
    printf("rdx  = "); _rdx.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4315
    printf("rdi  = "); _rdi.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4316
    printf("rsi  = "); _rsi.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4317
    printf("rbp,  = "); _rbp.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4318
    printf("rsp  = "); _rsp.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4319
    printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4320
    // control registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4321
    printf("flgs = "); _eflags.print(); printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4323
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4324
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4325
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4326
class CPU_State {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4327
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4328
  FPU_State _fpu_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4329
  IU_State  _iu_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4330
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4331
  void print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4332
    printf("--------------------------------------------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4333
    _iu_state .print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4334
    printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4335
    _fpu_state.print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4336
    printf("--------------------------------------------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4337
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4338
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4339
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4340
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4341
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4342
static void _print_CPU_state(CPU_State* state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4343
  state->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4344
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4345
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4346
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4347
void MacroAssembler::print_CPU_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4348
  push_CPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4349
  pushl(rsp);                // pass CPU state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4350
  call(RuntimeAddress(CAST_FROM_FN_PTR(address, _print_CPU_state)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4351
  addl(rsp, wordSize);       // discard argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4352
  pop_CPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4353
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4354
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4355
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4356
static bool _verify_FPU(int stack_depth, char* s, CPU_State* state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4357
  static int counter = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4358
  FPU_State* fs = &state->_fpu_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4359
  counter++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4360
  // For leaf calls, only verify that the top few elements remain empty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4361
  // We only need 1 empty at the top for C2 code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4362
  if( stack_depth < 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4363
    if( fs->tag_for_st(7) != 3 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4364
      printf("FPR7 not empty\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4365
      state->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4366
      assert(false, "error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4367
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4368
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4369
    return true;                // All other stack states do not matter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4370
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4371
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4372
  assert((fs->_control_word._value & 0xffff) == StubRoutines::_fpu_cntrl_wrd_std,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4373
         "bad FPU control word");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4374
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4375
  // compute stack depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4376
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4377
  while (i < FPU_State::number_of_registers && fs->tag_for_st(i)  < 3) i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4378
  int d = i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4379
  while (i < FPU_State::number_of_registers && fs->tag_for_st(i) == 3) i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4380
  // verify findings
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4381
  if (i != FPU_State::number_of_registers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4382
    // stack not contiguous
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4383
    printf("%s: stack not contiguous at ST%d\n", s, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4384
    state->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4385
    assert(false, "error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4386
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4387
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4388
  // check if computed stack depth corresponds to expected stack depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4389
  if (stack_depth < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4390
    // expected stack depth is -stack_depth or less
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4391
    if (d > -stack_depth) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4392
      // too many elements on the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4393
      printf("%s: <= %d stack elements expected but found %d\n", s, -stack_depth, d);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4394
      state->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4395
      assert(false, "error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4396
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4397
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4398
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4399
    // expected stack depth is stack_depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4400
    if (d != stack_depth) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4401
      // wrong stack depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4402
      printf("%s: %d stack elements expected but found %d\n", s, stack_depth, d);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4403
      state->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4404
      assert(false, "error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4405
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4406
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4407
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4408
  // everything is cool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4409
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4410
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4411
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4412
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4413
void MacroAssembler::verify_FPU(int stack_depth, const char* s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4414
  if (!VerifyFPU) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4415
  push_CPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4416
  pushl(rsp);                // pass CPU state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4417
  ExternalAddress msg((address) s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4418
  // pass message string s
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4419
  pushptr(msg.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4420
  pushl(stack_depth);        // pass stack depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4421
  call(RuntimeAddress(CAST_FROM_FN_PTR(address, _verify_FPU)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4422
  addl(rsp, 3 * wordSize);   // discard arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4423
  // check for error
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4424
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4425
    testl(rax, rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4426
    jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4427
    int3();                  // break if error condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4428
    bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4429
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4430
  pop_CPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4431
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4432
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4433
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4434
void MacroAssembler::push_IU_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4435
  pushad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4436
  pushfd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4437
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4438
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4439
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4440
void MacroAssembler::pop_IU_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4441
  popfd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4442
  popad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4443
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4444
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4445
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4446
void MacroAssembler::push_FPU_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4447
  subl(rsp, FPUStateSizeInWords * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4448
  fnsave(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4449
  fwait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4450
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4451
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4452
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4453
void MacroAssembler::pop_FPU_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4454
  frstor(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4455
  addl(rsp, FPUStateSizeInWords * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4456
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4457
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4458
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4459
void MacroAssembler::push_CPU_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4460
  push_IU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4461
  push_FPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4462
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4463
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4464
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4465
void MacroAssembler::pop_CPU_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4466
  pop_FPU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4467
  pop_IU_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4468
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4469
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4470
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4471
void MacroAssembler::push_callee_saved_registers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4472
  pushl(rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4473
  pushl(rdi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4474
  pushl(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4475
  pushl(rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4476
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4477
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4478
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4479
void MacroAssembler::pop_callee_saved_registers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4480
  popl(rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4481
  popl(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4482
  popl(rdi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4483
  popl(rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4484
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4485
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4486
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4487
void MacroAssembler::set_word_if_not_zero(Register dst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4488
  xorl(dst, dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4489
  set_byte_if_not_zero(dst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4490
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4491
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4492
// Write serialization page so VM thread can do a pseudo remote membar.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4493
// We use the current thread pointer to calculate a thread specific
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4494
// offset to write to within the page. This minimizes bus traffic
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4495
// due to cache line collision.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4496
void MacroAssembler::serialize_memory(Register thread, Register tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4497
  movl(tmp, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4498
  shrl(tmp, os::get_serialize_page_shift_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4499
  andl(tmp, (os::vm_page_size() - sizeof(int)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4500
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4501
  Address index(noreg, tmp, Address::times_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4502
  ExternalAddress page(os::get_memory_serialize_page());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4503
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4504
  movptr(ArrayAddress(page, index), tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4505
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4506
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4507
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4508
void MacroAssembler::verify_tlab() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4509
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4510
  if (UseTLAB && VerifyOops) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4511
    Label next, ok;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4512
    Register t1 = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4513
    Register thread_reg = rbx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4514
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4515
    pushl(t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4516
    pushl(thread_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4517
    get_thread(thread_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4518
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4519
    movl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4520
    cmpl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_start_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4521
    jcc(Assembler::aboveEqual, next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4522
    stop("assert(top >= start)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4523
    should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4525
    bind(next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4526
    movl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4527
    cmpl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4528
    jcc(Assembler::aboveEqual, ok);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4529
    stop("assert(top <= end)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4530
    should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4531
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4532
    bind(ok);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4533
    popl(thread_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4534
    popl(t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4535
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4536
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4537
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4538
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4539
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4540
// Defines obj, preserves var_size_in_bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4541
void MacroAssembler::eden_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4542
                                   Register t1, Label& slow_case) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4543
  assert(obj == rax, "obj must be in rax, for cmpxchg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4544
  assert_different_registers(obj, var_size_in_bytes, t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4545
  Register end = t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4546
  Label retry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4547
  bind(retry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4548
  ExternalAddress heap_top((address) Universe::heap()->top_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4549
  movptr(obj, heap_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4550
  if (var_size_in_bytes == noreg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4551
    leal(end, Address(obj, con_size_in_bytes));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4552
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4553
    leal(end, Address(obj, var_size_in_bytes, Address::times_1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4554
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4555
  // if end < obj then we wrapped around => object too long => slow case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4556
  cmpl(end, obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4557
  jcc(Assembler::below, slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4558
  cmpptr(end, ExternalAddress((address) Universe::heap()->end_addr()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4559
  jcc(Assembler::above, slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4560
  // Compare obj with the top addr, and if still equal, store the new top addr in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4561
  // end at the address of the top addr pointer. Sets ZF if was equal, and clears
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4562
  // it otherwise. Use lock prefix for atomicity on MPs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4563
  if (os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4564
    lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4565
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4566
  cmpxchgptr(end, heap_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4567
  jcc(Assembler::notEqual, retry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4568
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4569
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4570
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4571
// Defines obj, preserves var_size_in_bytes, okay for t2 == var_size_in_bytes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4572
void MacroAssembler::tlab_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4573
                                   Register t1, Register t2, Label& slow_case) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4574
  assert_different_registers(obj, t1, t2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4575
  assert_different_registers(obj, var_size_in_bytes, t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4576
  Register end = t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4577
  Register thread = t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4578
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4579
  verify_tlab();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4580
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4581
  get_thread(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4582
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4583
  movl(obj, Address(thread, JavaThread::tlab_top_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4584
  if (var_size_in_bytes == noreg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4585
    leal(end, Address(obj, con_size_in_bytes));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4586
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4587
    leal(end, Address(obj, var_size_in_bytes, Address::times_1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4588
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4589
  cmpl(end, Address(thread, JavaThread::tlab_end_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4590
  jcc(Assembler::above, slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4591
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4592
  // update the tlab top pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4593
  movl(Address(thread, JavaThread::tlab_top_offset()), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4594
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4595
  // recover var_size_in_bytes if necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4596
  if (var_size_in_bytes == end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4597
    subl(var_size_in_bytes, obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4598
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4599
  verify_tlab();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4600
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4601
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4602
// Preserves rbx, and rdx.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4603
void MacroAssembler::tlab_refill(Label& retry, Label& try_eden, Label& slow_case) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4604
  Register top = rax;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4605
  Register t1  = rcx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4606
  Register t2  = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4607
  Register thread_reg = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4608
  assert_different_registers(top, thread_reg, t1, t2, /* preserve: */ rbx, rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4609
  Label do_refill, discard_tlab;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4610
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4611
  if (CMSIncrementalMode || !Universe::heap()->supports_inline_contig_alloc()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4612
    // No allocation in the shared eden.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4613
    jmp(slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4614
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4615
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4616
  get_thread(thread_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4617
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4618
  movl(top, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4619
  movl(t1,  Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4620
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4621
  // calculate amount of free space
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4622
  subl(t1, top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4623
  shrl(t1, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4624
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4625
  // Retain tlab and allocate object in shared space if
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4626
  // the amount free in the tlab is too large to discard.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4627
  cmpl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_refill_waste_limit_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4628
  jcc(Assembler::lessEqual, discard_tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4629
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4630
  // Retain
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4631
  movl(t2, ThreadLocalAllocBuffer::refill_waste_limit_increment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4632
  addl(Address(thread_reg, in_bytes(JavaThread::tlab_refill_waste_limit_offset())), t2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4633
  if (TLABStats) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4634
    // increment number of slow_allocations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4635
    addl(Address(thread_reg, in_bytes(JavaThread::tlab_slow_allocations_offset())), 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4636
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4637
  jmp(try_eden);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4638
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4639
  bind(discard_tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4640
  if (TLABStats) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4641
    // increment number of refills
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4642
    addl(Address(thread_reg, in_bytes(JavaThread::tlab_number_of_refills_offset())), 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4643
    // accumulate wastage -- t1 is amount free in tlab
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4644
    addl(Address(thread_reg, in_bytes(JavaThread::tlab_fast_refill_waste_offset())), t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4645
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4646
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4647
  // if tlab is currently allocated (top or end != null) then
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4648
  // fill [top, end + alignment_reserve) with array object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4649
  testl (top, top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4650
  jcc(Assembler::zero, do_refill);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4651
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4652
  // set up the mark word
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4653
  movl(Address(top, oopDesc::mark_offset_in_bytes()), (int)markOopDesc::prototype()->copy_set_hash(0x2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4654
  // set the length to the remaining space
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4655
  subl(t1, typeArrayOopDesc::header_size(T_INT));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4656
  addl(t1, ThreadLocalAllocBuffer::alignment_reserve());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4657
  shll(t1, log2_intptr(HeapWordSize/sizeof(jint)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4658
  movl(Address(top, arrayOopDesc::length_offset_in_bytes()), t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4659
  // set klass to intArrayKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4660
  // dubious reloc why not an oop reloc?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4661
  movptr(t1, ExternalAddress((address) Universe::intArrayKlassObj_addr()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4662
  movl(Address(top, oopDesc::klass_offset_in_bytes()), t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4663
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4664
  // refill the tlab with an eden allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4665
  bind(do_refill);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4666
  movl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_size_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4667
  shll(t1, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4668
  // add object_size ??
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4669
  eden_allocate(top, t1, 0, t2, slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4670
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4671
  // Check that t1 was preserved in eden_allocate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4672
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4673
  if (UseTLAB) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4674
    Label ok;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4675
    Register tsize = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4676
    assert_different_registers(tsize, thread_reg, t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4677
    pushl(tsize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4678
    movl(tsize, Address(thread_reg, in_bytes(JavaThread::tlab_size_offset())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4679
    shll(tsize, LogHeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4680
    cmpl(t1, tsize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4681
    jcc(Assembler::equal, ok);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4682
    stop("assert(t1 != tlab size)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4683
    should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4684
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4685
    bind(ok);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4686
    popl(tsize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4687
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4688
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4689
  movl(Address(thread_reg, in_bytes(JavaThread::tlab_start_offset())), top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4690
  movl(Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())), top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4691
  addl(top, t1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4692
  subl(top, ThreadLocalAllocBuffer::alignment_reserve_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4693
  movl(Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())), top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4694
  verify_tlab();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4695
  jmp(retry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4696
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4697
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4698
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4699
int MacroAssembler::biased_locking_enter(Register lock_reg, Register obj_reg, Register swap_reg, Register tmp_reg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4700
                                         bool swap_reg_contains_mark,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4701
                                         Label& done, Label* slow_case,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4702
                                         BiasedLockingCounters* counters) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4703
  assert(UseBiasedLocking, "why call this otherwise?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4704
  assert(swap_reg == rax, "swap_reg must be rax, for cmpxchg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4705
  assert_different_registers(lock_reg, obj_reg, swap_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4706
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4707
  if (PrintBiasedLockingStatistics && counters == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4708
    counters = BiasedLocking::counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4709
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4710
  bool need_tmp_reg = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4711
  if (tmp_reg == noreg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4712
    need_tmp_reg = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4713
    tmp_reg = lock_reg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4714
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4715
    assert_different_registers(lock_reg, obj_reg, swap_reg, tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4716
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4717
  assert(markOopDesc::age_shift == markOopDesc::lock_bits + markOopDesc::biased_lock_bits, "biased locking makes assumptions about bit layout");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4718
  Address mark_addr      (obj_reg, oopDesc::mark_offset_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4719
  Address klass_addr     (obj_reg, oopDesc::klass_offset_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4720
  Address saved_mark_addr(lock_reg, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4721
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4722
  // Biased locking
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4723
  // See whether the lock is currently biased toward our thread and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4724
  // whether the epoch is still valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4725
  // Note that the runtime guarantees sufficient alignment of JavaThread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4726
  // pointers to allow age to be placed into low bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4727
  // First check to see whether biasing is even enabled for this object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4728
  Label cas_label;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4729
  int null_check_offset = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4730
  if (!swap_reg_contains_mark) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4731
    null_check_offset = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4732
    movl(swap_reg, mark_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4733
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4734
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4735
    pushl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4736
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4737
  movl(tmp_reg, swap_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4738
  andl(tmp_reg, markOopDesc::biased_lock_mask_in_place);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4739
  cmpl(tmp_reg, markOopDesc::biased_lock_pattern);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4740
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4741
    popl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4742
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4743
  jcc(Assembler::notEqual, cas_label);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4744
  // The bias pattern is present in the object's header. Need to check
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4745
  // whether the bias owner and the epoch are both still current.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4746
  // Note that because there is no current thread register on x86 we
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4747
  // need to store off the mark word we read out of the object to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4748
  // avoid reloading it and needing to recheck invariants below. This
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4749
  // store is unfortunate but it makes the overall code shorter and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4750
  // simpler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4751
  movl(saved_mark_addr, swap_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4752
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4753
    pushl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4754
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4755
  get_thread(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4756
  xorl(swap_reg, tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4757
  if (swap_reg_contains_mark) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4758
    null_check_offset = offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4759
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4760
  movl(tmp_reg, klass_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4761
  xorl(swap_reg, Address(tmp_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4762
  andl(swap_reg, ~((int) markOopDesc::age_mask_in_place));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4763
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4764
    popl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4765
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4766
  if (counters != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4767
    cond_inc32(Assembler::zero,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4768
               ExternalAddress((address)counters->biased_lock_entry_count_addr()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4769
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4770
  jcc(Assembler::equal, done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4771
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4772
  Label try_revoke_bias;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4773
  Label try_rebias;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4774
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4775
  // At this point we know that the header has the bias pattern and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4776
  // that we are not the bias owner in the current epoch. We need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4777
  // figure out more details about the state of the header in order to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4778
  // know what operations can be legally performed on the object's
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4779
  // header.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4780
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4781
  // If the low three bits in the xor result aren't clear, that means
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4782
  // the prototype header is no longer biased and we have to revoke
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4783
  // the bias on this object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4784
  testl(swap_reg, markOopDesc::biased_lock_mask_in_place);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4785
  jcc(Assembler::notZero, try_revoke_bias);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4786
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4787
  // Biasing is still enabled for this data type. See whether the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4788
  // epoch of the current bias is still valid, meaning that the epoch
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4789
  // bits of the mark word are equal to the epoch bits of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4790
  // prototype header. (Note that the prototype header's epoch bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4791
  // only change at a safepoint.) If not, attempt to rebias the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4792
  // toward the current thread. Note that we must be absolutely sure
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4793
  // that the current epoch is invalid in order to do this because
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4794
  // otherwise the manipulations it performs on the mark word are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4795
  // illegal.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4796
  testl(swap_reg, markOopDesc::epoch_mask_in_place);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4797
  jcc(Assembler::notZero, try_rebias);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4798
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4799
  // The epoch of the current bias is still valid but we know nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4800
  // about the owner; it might be set or it might be clear. Try to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4801
  // acquire the bias of the object using an atomic operation. If this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4802
  // fails we will go in to the runtime to revoke the object's bias.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4803
  // Note that we first construct the presumed unbiased header so we
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4804
  // don't accidentally blow away another thread's valid bias.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4805
  movl(swap_reg, saved_mark_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4806
  andl(swap_reg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4807
       markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | markOopDesc::epoch_mask_in_place);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4808
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4809
    pushl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4810
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4811
  get_thread(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4812
  orl(tmp_reg, swap_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4813
  if (os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4814
    lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4816
  cmpxchg(tmp_reg, Address(obj_reg, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4817
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4818
    popl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4819
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4820
  // If the biasing toward our thread failed, this means that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4821
  // another thread succeeded in biasing it toward itself and we
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4822
  // need to revoke that bias. The revocation will occur in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4823
  // interpreter runtime in the slow case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4824
  if (counters != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4825
    cond_inc32(Assembler::zero,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4826
               ExternalAddress((address)counters->anonymously_biased_lock_entry_count_addr()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4827
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4828
  if (slow_case != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4829
    jcc(Assembler::notZero, *slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4830
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4831
  jmp(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4832
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4833
  bind(try_rebias);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4834
  // At this point we know the epoch has expired, meaning that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4835
  // current "bias owner", if any, is actually invalid. Under these
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4836
  // circumstances _only_, we are allowed to use the current header's
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4837
  // value as the comparison value when doing the cas to acquire the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4838
  // bias in the current epoch. In other words, we allow transfer of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4839
  // the bias from one thread to another directly in this situation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4840
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4841
  // FIXME: due to a lack of registers we currently blow away the age
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4842
  // bits in this situation. Should attempt to preserve them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4843
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4844
    pushl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4845
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4846
  get_thread(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4847
  movl(swap_reg, klass_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4848
  orl(tmp_reg, Address(swap_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4849
  movl(swap_reg, saved_mark_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4850
  if (os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4851
    lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4853
  cmpxchg(tmp_reg, Address(obj_reg, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4854
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4855
    popl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4856
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4857
  // If the biasing toward our thread failed, then another thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4858
  // succeeded in biasing it toward itself and we need to revoke that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4859
  // bias. The revocation will occur in the runtime in the slow case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4860
  if (counters != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4861
    cond_inc32(Assembler::zero,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4862
               ExternalAddress((address)counters->rebiased_lock_entry_count_addr()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4863
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4864
  if (slow_case != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4865
    jcc(Assembler::notZero, *slow_case);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4866
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4867
  jmp(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4868
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4869
  bind(try_revoke_bias);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4870
  // The prototype mark in the klass doesn't have the bias bit set any
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4871
  // more, indicating that objects of this data type are not supposed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4872
  // to be biased any more. We are going to try to reset the mark of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4873
  // this object to the prototype value and fall through to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4874
  // CAS-based locking scheme. Note that if our CAS fails, it means
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4875
  // that another thread raced us for the privilege of revoking the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4876
  // bias of this particular object, so it's okay to continue in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4877
  // normal locking code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4878
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4879
  // FIXME: due to a lack of registers we currently blow away the age
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4880
  // bits in this situation. Should attempt to preserve them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4881
  movl(swap_reg, saved_mark_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4882
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4883
    pushl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4884
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4885
  movl(tmp_reg, klass_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4886
  movl(tmp_reg, Address(tmp_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4887
  if (os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4888
    lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4889
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4890
  cmpxchg(tmp_reg, Address(obj_reg, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4891
  if (need_tmp_reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4892
    popl(tmp_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4893
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4894
  // Fall through to the normal CAS-based lock, because no matter what
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4895
  // the result of the above CAS, some thread must have succeeded in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4896
  // removing the bias bit from the object's header.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4897
  if (counters != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4898
    cond_inc32(Assembler::zero,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4899
               ExternalAddress((address)counters->revoked_lock_entry_count_addr()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4900
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4901
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4902
  bind(cas_label);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4903
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4904
  return null_check_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4905
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4906
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4907
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4908
void MacroAssembler::biased_locking_exit(Register obj_reg, Register temp_reg, Label& done) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4909
  assert(UseBiasedLocking, "why call this otherwise?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4910
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4911
  // Check for biased locking unlock case, which is a no-op
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4912
  // Note: we do not have to check the thread ID for two reasons.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4913
  // First, the interpreter checks for IllegalMonitorStateException at
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4914
  // a higher level. Second, if the bias was revoked while we held the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4915
  // lock, the object could not be rebiased toward another thread, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4916
  // the bias bit would be clear.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4917
  movl(temp_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4918
  andl(temp_reg, markOopDesc::biased_lock_mask_in_place);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4919
  cmpl(temp_reg, markOopDesc::biased_lock_pattern);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4920
  jcc(Assembler::equal, done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4921
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4922
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4923
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4924
Assembler::Condition MacroAssembler::negate_condition(Assembler::Condition cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4925
  switch (cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4926
    // Note some conditions are synonyms for others
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4927
    case Assembler::zero:         return Assembler::notZero;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4928
    case Assembler::notZero:      return Assembler::zero;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4929
    case Assembler::less:         return Assembler::greaterEqual;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4930
    case Assembler::lessEqual:    return Assembler::greater;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4931
    case Assembler::greater:      return Assembler::lessEqual;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4932
    case Assembler::greaterEqual: return Assembler::less;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4933
    case Assembler::below:        return Assembler::aboveEqual;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4934
    case Assembler::belowEqual:   return Assembler::above;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4935
    case Assembler::above:        return Assembler::belowEqual;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4936
    case Assembler::aboveEqual:   return Assembler::below;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4937
    case Assembler::overflow:     return Assembler::noOverflow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4938
    case Assembler::noOverflow:   return Assembler::overflow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4939
    case Assembler::negative:     return Assembler::positive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4940
    case Assembler::positive:     return Assembler::negative;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4941
    case Assembler::parity:       return Assembler::noParity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4942
    case Assembler::noParity:     return Assembler::parity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4943
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4944
  ShouldNotReachHere(); return Assembler::overflow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4945
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4946
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4947
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4948
void MacroAssembler::cond_inc32(Condition cond, AddressLiteral counter_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4949
  Condition negated_cond = negate_condition(cond);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4950
  Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4951
  jcc(negated_cond, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4952
  atomic_incl(counter_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4953
  bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4954
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4955
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4956
void MacroAssembler::atomic_incl(AddressLiteral counter_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4957
  pushfd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4958
  if (os::is_MP())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4959
    lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4960
  increment(counter_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4961
  popfd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4962
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4963
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4964
SkipIfEqual::SkipIfEqual(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4965
    MacroAssembler* masm, const bool* flag_addr, bool value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4966
  _masm = masm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4967
  _masm->cmp8(ExternalAddress((address)flag_addr), value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4968
  _masm->jcc(Assembler::equal, _label);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4969
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4970
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4971
SkipIfEqual::~SkipIfEqual() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4972
  _masm->bind(_label);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4973
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4974
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4975
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4976
// Writes to stack successive pages until offset reached to check for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4977
// stack overflow + shadow pages.  This clobbers tmp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4978
void MacroAssembler::bang_stack_size(Register size, Register tmp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4979
  movl(tmp, rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4980
  // Bang stack for total size given plus shadow page size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4981
  // Bang one page at a time because large size can bang beyond yellow and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4982
  // red zones.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4983
  Label loop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4984
  bind(loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4985
  movl(Address(tmp, (-os::vm_page_size())), size );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4986
  subl(tmp, os::vm_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4987
  subl(size, os::vm_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4988
  jcc(Assembler::greater, loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4989
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4990
  // Bang down shadow pages too.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4991
  // The -1 because we already subtracted 1 page.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4992
  for (int i = 0; i< StackShadowPages-1; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4993
    movl(Address(tmp, (-i*os::vm_page_size())), size );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4994
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4995
}