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