blob: 0d24a751c0fbdadd1d1369c77ec2cc0ac0028676 [file] [log] [blame]
Dmitry Petrochenkofca82202014-03-21 11:21:37 +07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_UTILS_X86_64_ASSEMBLER_X86_64_H_
18#define ART_COMPILER_UTILS_X86_64_ASSEMBLER_X86_64_H_
19
20#include <vector>
Vladimir Marko80afd022015-05-19 18:08:00 +010021
Vladimir Marko93205e32016-04-13 11:59:46 +010022#include "base/arena_containers.h"
David Brazdild9c90372016-09-14 16:53:55 +010023#include "base/array_ref.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010024#include "base/bit_utils.h"
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070025#include "base/macros.h"
26#include "constants_x86_64.h"
27#include "globals.h"
Andreas Gampe09659c22017-09-18 18:23:32 -070028#include "heap_poisoning.h"
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070029#include "managed_register_x86_64.h"
30#include "offsets.h"
31#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070032#include "utils/jni_macro_assembler.h"
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070033
34namespace art {
35namespace x86_64 {
36
avignate5408b6b2014-06-04 17:59:44 +070037// Encodes an immediate value for operands.
38//
39// Note: Immediates can be 64b on x86-64 for certain instructions, but are often restricted
40// to 32b.
41//
42// Note: As we support cross-compilation, the value type must be int64_t. Please be aware of
43// conversion rules in expressions regarding negation, especially size_t on 32b.
Ian Rogerscf7f1912014-10-22 22:06:39 -070044class Immediate : public ValueObject {
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070045 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -080046 explicit Immediate(int64_t value_in) : value_(value_in) {}
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070047
Andreas Gampe5a4fa822014-03-31 16:50:12 -070048 int64_t value() const { return value_; }
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070049
Andreas Gampeab1eb0d2015-02-13 19:23:55 -080050 bool is_int8() const { return IsInt<8>(value_); }
51 bool is_uint8() const { return IsUint<8>(value_); }
52 bool is_int16() const { return IsInt<16>(value_); }
53 bool is_uint16() const { return IsUint<16>(value_); }
54 bool is_int32() const { return IsInt<32>(value_); }
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070055
56 private:
Andreas Gampe5a4fa822014-03-31 16:50:12 -070057 const int64_t value_;
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070058};
59
60
Ian Rogerscf7f1912014-10-22 22:06:39 -070061class Operand : public ValueObject {
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070062 public:
63 uint8_t mod() const {
64 return (encoding_at(0) >> 6) & 3;
65 }
66
67 Register rm() const {
68 return static_cast<Register>(encoding_at(0) & 7);
69 }
70
71 ScaleFactor scale() const {
72 return static_cast<ScaleFactor>((encoding_at(1) >> 6) & 3);
73 }
74
75 Register index() const {
76 return static_cast<Register>((encoding_at(1) >> 3) & 7);
77 }
78
79 Register base() const {
80 return static_cast<Register>(encoding_at(1) & 7);
81 }
82
Aart Bikf7754e82017-09-20 10:33:06 -070083 CpuRegister cpu_rm() const {
84 int ext = (rex_ & 1) != 0 ? x86_64::R8 : x86_64::RAX;
85 return static_cast<CpuRegister>(rm() + ext);
86 }
87
88 CpuRegister cpu_index() const {
89 int ext = (rex_ & 2) != 0 ? x86_64::R8 : x86_64::RAX;
90 return static_cast<CpuRegister>(index() + ext);
91 }
92
93 CpuRegister cpu_base() const {
94 int ext = (rex_ & 1) != 0 ? x86_64::R8 : x86_64::RAX;
95 return static_cast<CpuRegister>(base() + ext);
96 }
97
Ian Rogers790a6b72014-04-01 10:36:00 -070098 uint8_t rex() const {
99 return rex_;
100 }
101
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700102 int8_t disp8() const {
103 CHECK_GE(length_, 2);
104 return static_cast<int8_t>(encoding_[length_ - 1]);
105 }
106
107 int32_t disp32() const {
108 CHECK_GE(length_, 5);
109 int32_t value;
110 memcpy(&value, &encoding_[length_ - 4], sizeof(value));
111 return value;
112 }
113
Ian Rogersdd7624d2014-03-14 17:43:00 -0700114 bool IsRegister(CpuRegister reg) const {
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700115 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only.
Ian Rogers790a6b72014-04-01 10:36:00 -0700116 && ((encoding_[0] & 0x07) == reg.LowBits()) // Register codes match.
117 && (reg.NeedsRex() == ((rex_ & 1) != 0)); // REX.000B bits match.
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700118 }
119
Mark Mendellf55c3e02015-03-26 21:07:46 -0400120 AssemblerFixup* GetFixup() const {
121 return fixup_;
122 }
123
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700124 protected:
125 // Operand can be sub classed (e.g: Address).
Mark Mendellf55c3e02015-03-26 21:07:46 -0400126 Operand() : rex_(0), length_(0), fixup_(nullptr) { }
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700127
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800128 void SetModRM(uint8_t mod_in, CpuRegister rm_in) {
129 CHECK_EQ(mod_in & ~3, 0);
130 if (rm_in.NeedsRex()) {
Ian Rogers790a6b72014-04-01 10:36:00 -0700131 rex_ |= 0x41; // REX.000B
132 }
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800133 encoding_[0] = (mod_in << 6) | rm_in.LowBits();
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700134 length_ = 1;
135 }
136
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800137 void SetSIB(ScaleFactor scale_in, CpuRegister index_in, CpuRegister base_in) {
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700138 CHECK_EQ(length_, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800139 CHECK_EQ(scale_in & ~3, 0);
140 if (base_in.NeedsRex()) {
Ian Rogers790a6b72014-04-01 10:36:00 -0700141 rex_ |= 0x41; // REX.000B
142 }
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800143 if (index_in.NeedsRex()) {
Ian Rogers790a6b72014-04-01 10:36:00 -0700144 rex_ |= 0x42; // REX.00X0
145 }
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800146 encoding_[1] = (scale_in << 6) | (static_cast<uint8_t>(index_in.LowBits()) << 3) |
147 static_cast<uint8_t>(base_in.LowBits());
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700148 length_ = 2;
149 }
150
151 void SetDisp8(int8_t disp) {
152 CHECK(length_ == 1 || length_ == 2);
153 encoding_[length_++] = static_cast<uint8_t>(disp);
154 }
155
156 void SetDisp32(int32_t disp) {
157 CHECK(length_ == 1 || length_ == 2);
158 int disp_size = sizeof(disp);
159 memmove(&encoding_[length_], &disp, disp_size);
160 length_ += disp_size;
161 }
162
Mark Mendellf55c3e02015-03-26 21:07:46 -0400163 void SetFixup(AssemblerFixup* fixup) {
164 fixup_ = fixup;
165 }
166
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700167 private:
Ian Rogers790a6b72014-04-01 10:36:00 -0700168 uint8_t rex_;
169 uint8_t length_;
170 uint8_t encoding_[6];
Mark Mendellf55c3e02015-03-26 21:07:46 -0400171 AssemblerFixup* fixup_;
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700172
Mark Mendellf55c3e02015-03-26 21:07:46 -0400173 explicit Operand(CpuRegister reg) : rex_(0), length_(0), fixup_(nullptr) { SetModRM(3, reg); }
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700174
175 // Get the operand encoding byte at the given index.
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800176 uint8_t encoding_at(int index_in) const {
177 CHECK_GE(index_in, 0);
178 CHECK_LT(index_in, length_);
179 return encoding_[index_in];
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700180 }
181
182 friend class X86_64Assembler;
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700183};
184
185
186class Address : public Operand {
187 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800188 Address(CpuRegister base_in, int32_t disp) {
189 Init(base_in, disp);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700190 }
191
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800192 Address(CpuRegister base_in, Offset disp) {
193 Init(base_in, disp.Int32Value());
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700194 }
195
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800196 Address(CpuRegister base_in, FrameOffset disp) {
197 CHECK_EQ(base_in.AsRegister(), RSP);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700198 Init(CpuRegister(RSP), disp.Int32Value());
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700199 }
200
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800201 Address(CpuRegister base_in, MemberOffset disp) {
202 Init(base_in, disp.Int32Value());
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700203 }
204
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800205 void Init(CpuRegister base_in, int32_t disp) {
Nicolas Geoffray784cc5c2014-12-18 20:25:18 +0000206 if (disp == 0 && base_in.LowBits() != RBP) {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800207 SetModRM(0, base_in);
Nicolas Geoffray98893962015-01-21 12:32:32 +0000208 if (base_in.LowBits() == RSP) {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800209 SetSIB(TIMES_1, CpuRegister(RSP), base_in);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700210 }
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700211 } else if (disp >= -128 && disp <= 127) {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800212 SetModRM(1, base_in);
Nicolas Geoffray98893962015-01-21 12:32:32 +0000213 if (base_in.LowBits() == RSP) {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800214 SetSIB(TIMES_1, CpuRegister(RSP), base_in);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700215 }
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700216 SetDisp8(disp);
217 } else {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800218 SetModRM(2, base_in);
Nicolas Geoffray98893962015-01-21 12:32:32 +0000219 if (base_in.LowBits() == RSP) {
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800220 SetSIB(TIMES_1, CpuRegister(RSP), base_in);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700221 }
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700222 SetDisp32(disp);
223 }
224 }
225
226
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800227 Address(CpuRegister index_in, ScaleFactor scale_in, int32_t disp) {
228 CHECK_NE(index_in.AsRegister(), RSP); // Illegal addressing mode.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700229 SetModRM(0, CpuRegister(RSP));
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800230 SetSIB(scale_in, index_in, CpuRegister(RBP));
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700231 SetDisp32(disp);
232 }
233
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800234 Address(CpuRegister base_in, CpuRegister index_in, ScaleFactor scale_in, int32_t disp) {
235 CHECK_NE(index_in.AsRegister(), RSP); // Illegal addressing mode.
Nicolas Geoffray784cc5c2014-12-18 20:25:18 +0000236 if (disp == 0 && base_in.LowBits() != RBP) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700237 SetModRM(0, CpuRegister(RSP));
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800238 SetSIB(scale_in, index_in, base_in);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700239 } else if (disp >= -128 && disp <= 127) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700240 SetModRM(1, CpuRegister(RSP));
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800241 SetSIB(scale_in, index_in, base_in);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700242 SetDisp8(disp);
243 } else {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700244 SetModRM(2, CpuRegister(RSP));
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800245 SetSIB(scale_in, index_in, base_in);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700246 SetDisp32(disp);
247 }
248 }
249
Ian Rogersdd7624d2014-03-14 17:43:00 -0700250 // If no_rip is true then the Absolute address isn't RIP relative.
Ian Rogers13735952014-10-08 12:43:28 -0700251 static Address Absolute(uintptr_t addr, bool no_rip = false) {
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700252 Address result;
Ian Rogersdd7624d2014-03-14 17:43:00 -0700253 if (no_rip) {
254 result.SetModRM(0, CpuRegister(RSP));
255 result.SetSIB(TIMES_1, CpuRegister(RSP), CpuRegister(RBP));
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700256 result.SetDisp32(addr);
257 } else {
Mark Mendell39dcf552015-04-09 20:42:42 -0400258 // RIP addressing is done using RBP as the base register.
259 // The value in RBP isn't used. Instead the offset is added to RIP.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700260 result.SetModRM(0, CpuRegister(RBP));
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700261 result.SetDisp32(addr);
262 }
263 return result;
264 }
265
Mark Mendellf55c3e02015-03-26 21:07:46 -0400266 // An RIP relative address that will be fixed up later.
267 static Address RIP(AssemblerFixup* fixup) {
268 Address result;
Mark Mendell39dcf552015-04-09 20:42:42 -0400269 // RIP addressing is done using RBP as the base register.
270 // The value in RBP isn't used. Instead the offset is added to RIP.
Mark Mendellf55c3e02015-03-26 21:07:46 -0400271 result.SetModRM(0, CpuRegister(RBP));
272 result.SetDisp32(0);
273 result.SetFixup(fixup);
274 return result;
275 }
276
Ian Rogersdd7624d2014-03-14 17:43:00 -0700277 // If no_rip is true then the Absolute address isn't RIP relative.
Andreas Gampe542451c2016-07-26 09:02:02 -0700278 static Address Absolute(ThreadOffset64 addr, bool no_rip = false) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700279 return Absolute(addr.Int32Value(), no_rip);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700280 }
281
282 private:
283 Address() {}
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700284};
285
Aart Bikf7754e82017-09-20 10:33:06 -0700286std::ostream& operator<<(std::ostream& os, const Address& addr);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700287
Mark Mendellf55c3e02015-03-26 21:07:46 -0400288/**
289 * Class to handle constant area values.
290 */
291class ConstantArea {
Mark Mendell9c86b482015-09-18 13:36:07 -0400292 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100293 explicit ConstantArea(ArenaAllocator* allocator)
294 : buffer_(allocator->Adapter(kArenaAllocAssembler)) {}
Mark Mendellf55c3e02015-03-26 21:07:46 -0400295
Mark Mendell9c86b482015-09-18 13:36:07 -0400296 // Add a double to the constant area, returning the offset into
297 // the constant area where the literal resides.
298 size_t AddDouble(double v);
Mark Mendellf55c3e02015-03-26 21:07:46 -0400299
Mark Mendell9c86b482015-09-18 13:36:07 -0400300 // Add a float to the constant area, returning the offset into
301 // the constant area where the literal resides.
302 size_t AddFloat(float v);
Mark Mendellf55c3e02015-03-26 21:07:46 -0400303
Mark Mendell9c86b482015-09-18 13:36:07 -0400304 // Add an int32_t to the constant area, returning the offset into
305 // the constant area where the literal resides.
306 size_t AddInt32(int32_t v);
Mark Mendellf55c3e02015-03-26 21:07:46 -0400307
Mark Mendell9c86b482015-09-18 13:36:07 -0400308 // Add an int32_t to the end of the constant area, returning the offset into
309 // the constant area where the literal resides.
310 size_t AppendInt32(int32_t v);
Mark Mendellf55c3e02015-03-26 21:07:46 -0400311
Mark Mendell9c86b482015-09-18 13:36:07 -0400312 // Add an int64_t to the constant area, returning the offset into
313 // the constant area where the literal resides.
314 size_t AddInt64(int64_t v);
Mark Mendellf55c3e02015-03-26 21:07:46 -0400315
Mark Mendell9c86b482015-09-18 13:36:07 -0400316 size_t GetSize() const {
317 return buffer_.size() * elem_size_;
318 }
Mark Mendellf55c3e02015-03-26 21:07:46 -0400319
Vladimir Marko93205e32016-04-13 11:59:46 +0100320 ArrayRef<const int32_t> GetBuffer() const {
321 return ArrayRef<const int32_t>(buffer_);
Mark Mendell9c86b482015-09-18 13:36:07 -0400322 }
323
324 private:
325 static constexpr size_t elem_size_ = sizeof(int32_t);
Vladimir Marko93205e32016-04-13 11:59:46 +0100326 ArenaVector<int32_t> buffer_;
Mark Mendellf55c3e02015-03-26 21:07:46 -0400327};
328
329
Mark Mendell73f455e2015-08-21 09:30:05 -0400330// This is equivalent to the Label class, used in a slightly different context. We
331// inherit the functionality of the Label class, but prevent unintended
332// derived-to-base conversions by making the base class private.
333class NearLabel : private Label {
334 public:
335 NearLabel() : Label() {}
336
337 // Expose the Label routines that we need.
338 using Label::Position;
339 using Label::LinkPosition;
340 using Label::IsBound;
341 using Label::IsUnused;
342 using Label::IsLinked;
343
344 private:
345 using Label::BindTo;
346 using Label::LinkTo;
347
348 friend class x86_64::X86_64Assembler;
349
350 DISALLOW_COPY_AND_ASSIGN(NearLabel);
351};
352
353
Andreas Gampe1ace16b2016-08-05 09:01:50 -0700354class X86_64Assembler FINAL : public Assembler {
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700355 public:
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100356 explicit X86_64Assembler(ArenaAllocator* allocator)
357 : Assembler(allocator), constant_area_(allocator) {}
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700358 virtual ~X86_64Assembler() {}
359
360 /*
361 * Emit Machine Instructions.
362 */
Ian Rogersdd7624d2014-03-14 17:43:00 -0700363 void call(CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700364 void call(const Address& address);
365 void call(Label* label);
366
Ian Rogersdd7624d2014-03-14 17:43:00 -0700367 void pushq(CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700368 void pushq(const Address& address);
369 void pushq(const Immediate& imm);
370
Ian Rogersdd7624d2014-03-14 17:43:00 -0700371 void popq(CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700372 void popq(const Address& address);
373
Ian Rogersdd7624d2014-03-14 17:43:00 -0700374 void movq(CpuRegister dst, const Immediate& src);
375 void movl(CpuRegister dst, const Immediate& src);
376 void movq(CpuRegister dst, CpuRegister src);
377 void movl(CpuRegister dst, CpuRegister src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700378
Mark Mendell7a08fb52015-07-15 14:09:35 -0400379 void movntl(const Address& dst, CpuRegister src);
380 void movntq(const Address& dst, CpuRegister src);
381
Ian Rogersdd7624d2014-03-14 17:43:00 -0700382 void movq(CpuRegister dst, const Address& src);
383 void movl(CpuRegister dst, const Address& src);
384 void movq(const Address& dst, CpuRegister src);
Mark Mendellcfa410b2015-05-25 16:02:44 -0400385 void movq(const Address& dst, const Immediate& imm);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700386 void movl(const Address& dst, CpuRegister src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700387 void movl(const Address& dst, const Immediate& imm);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700388
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800389 void cmov(Condition c, CpuRegister dst, CpuRegister src); // This is the 64b version.
390 void cmov(Condition c, CpuRegister dst, CpuRegister src, bool is64bit);
Mark Mendellabdac472016-02-12 13:49:03 -0500391 void cmov(Condition c, CpuRegister dst, const Address& src, bool is64bit);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800392
Ian Rogersdd7624d2014-03-14 17:43:00 -0700393 void movzxb(CpuRegister dst, CpuRegister src);
394 void movzxb(CpuRegister dst, const Address& src);
395 void movsxb(CpuRegister dst, CpuRegister src);
396 void movsxb(CpuRegister dst, const Address& src);
397 void movb(CpuRegister dst, const Address& src);
398 void movb(const Address& dst, CpuRegister src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700399 void movb(const Address& dst, const Immediate& imm);
400
Ian Rogersdd7624d2014-03-14 17:43:00 -0700401 void movzxw(CpuRegister dst, CpuRegister src);
402 void movzxw(CpuRegister dst, const Address& src);
403 void movsxw(CpuRegister dst, CpuRegister src);
404 void movsxw(CpuRegister dst, const Address& src);
405 void movw(CpuRegister dst, const Address& src);
406 void movw(const Address& dst, CpuRegister src);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100407 void movw(const Address& dst, const Immediate& imm);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700408
Ian Rogersdd7624d2014-03-14 17:43:00 -0700409 void leaq(CpuRegister dst, const Address& src);
Nicolas Geoffray748f1402015-01-27 08:17:54 +0000410 void leal(CpuRegister dst, const Address& src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700411
Aart Bikc7782262017-01-13 16:20:08 -0800412 void movaps(XmmRegister dst, XmmRegister src); // move
413 void movaps(XmmRegister dst, const Address& src); // load aligned
414 void movups(XmmRegister dst, const Address& src); // load unaligned
415 void movaps(const Address& dst, XmmRegister src); // store aligned
416 void movups(const Address& dst, XmmRegister src); // store unaligned
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100417
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700418 void movss(XmmRegister dst, const Address& src);
419 void movss(const Address& dst, XmmRegister src);
420 void movss(XmmRegister dst, XmmRegister src);
421
Roland Levillaindff1f282014-11-05 14:15:05 +0000422 void movsxd(CpuRegister dst, CpuRegister src);
423 void movsxd(CpuRegister dst, const Address& src);
424
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800425 void movd(XmmRegister dst, CpuRegister src); // Note: this is the r64 version, formally movq.
426 void movd(CpuRegister dst, XmmRegister src); // Note: this is the r64 version, formally movq.
427 void movd(XmmRegister dst, CpuRegister src, bool is64bit);
428 void movd(CpuRegister dst, XmmRegister src, bool is64bit);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700429
430 void addss(XmmRegister dst, XmmRegister src);
431 void addss(XmmRegister dst, const Address& src);
432 void subss(XmmRegister dst, XmmRegister src);
433 void subss(XmmRegister dst, const Address& src);
434 void mulss(XmmRegister dst, XmmRegister src);
435 void mulss(XmmRegister dst, const Address& src);
436 void divss(XmmRegister dst, XmmRegister src);
437 void divss(XmmRegister dst, const Address& src);
438
Aart Bikc7782262017-01-13 16:20:08 -0800439 void addps(XmmRegister dst, XmmRegister src); // no addr variant (for now)
440 void subps(XmmRegister dst, XmmRegister src);
441 void mulps(XmmRegister dst, XmmRegister src);
442 void divps(XmmRegister dst, XmmRegister src);
443
444 void movapd(XmmRegister dst, XmmRegister src); // move
445 void movapd(XmmRegister dst, const Address& src); // load aligned
446 void movupd(XmmRegister dst, const Address& src); // load unaligned
447 void movapd(const Address& dst, XmmRegister src); // store aligned
448 void movupd(const Address& dst, XmmRegister src); // store unaligned
449
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700450 void movsd(XmmRegister dst, const Address& src);
451 void movsd(const Address& dst, XmmRegister src);
452 void movsd(XmmRegister dst, XmmRegister src);
453
454 void addsd(XmmRegister dst, XmmRegister src);
455 void addsd(XmmRegister dst, const Address& src);
456 void subsd(XmmRegister dst, XmmRegister src);
457 void subsd(XmmRegister dst, const Address& src);
458 void mulsd(XmmRegister dst, XmmRegister src);
459 void mulsd(XmmRegister dst, const Address& src);
460 void divsd(XmmRegister dst, XmmRegister src);
461 void divsd(XmmRegister dst, const Address& src);
462
Aart Bikc7782262017-01-13 16:20:08 -0800463 void addpd(XmmRegister dst, XmmRegister src); // no addr variant (for now)
464 void subpd(XmmRegister dst, XmmRegister src);
465 void mulpd(XmmRegister dst, XmmRegister src);
466 void divpd(XmmRegister dst, XmmRegister src);
467
Aart Bik68555e92017-02-13 14:28:45 -0800468 void movdqa(XmmRegister dst, XmmRegister src); // move
469 void movdqa(XmmRegister dst, const Address& src); // load aligned
470 void movdqu(XmmRegister dst, const Address& src); // load unaligned
471 void movdqa(const Address& dst, XmmRegister src); // store aligned
472 void movdqu(const Address& dst, XmmRegister src); // store unaligned
473
Aart Bike69d7a92017-02-17 11:48:23 -0800474 void paddb(XmmRegister dst, XmmRegister src); // no addr variant (for now)
475 void psubb(XmmRegister dst, XmmRegister src);
476
477 void paddw(XmmRegister dst, XmmRegister src);
478 void psubw(XmmRegister dst, XmmRegister src);
479 void pmullw(XmmRegister dst, XmmRegister src);
480
481 void paddd(XmmRegister dst, XmmRegister src);
Aart Bik68555e92017-02-13 14:28:45 -0800482 void psubd(XmmRegister dst, XmmRegister src);
483 void pmulld(XmmRegister dst, XmmRegister src);
484
Aart Bike69d7a92017-02-17 11:48:23 -0800485 void paddq(XmmRegister dst, XmmRegister src);
486 void psubq(XmmRegister dst, XmmRegister src);
487
Andreas Gampe851df202014-11-12 14:05:46 -0800488 void cvtsi2ss(XmmRegister dst, CpuRegister src); // Note: this is the r/m32 version.
Roland Levillain6d0e4832014-11-27 18:31:21 +0000489 void cvtsi2ss(XmmRegister dst, CpuRegister src, bool is64bit);
Mark Mendell40741f32015-04-20 22:10:34 -0400490 void cvtsi2ss(XmmRegister dst, const Address& src, bool is64bit);
Andreas Gampe851df202014-11-12 14:05:46 -0800491 void cvtsi2sd(XmmRegister dst, CpuRegister src); // Note: this is the r/m32 version.
Roland Levillain647b9ed2014-11-27 12:06:00 +0000492 void cvtsi2sd(XmmRegister dst, CpuRegister src, bool is64bit);
Mark Mendell40741f32015-04-20 22:10:34 -0400493 void cvtsi2sd(XmmRegister dst, const Address& src, bool is64bit);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700494
Andreas Gampe851df202014-11-12 14:05:46 -0800495 void cvtss2si(CpuRegister dst, XmmRegister src); // Note: this is the r32 version.
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700496 void cvtss2sd(XmmRegister dst, XmmRegister src);
Mark Mendell40741f32015-04-20 22:10:34 -0400497 void cvtss2sd(XmmRegister dst, const Address& src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700498
Andreas Gampe851df202014-11-12 14:05:46 -0800499 void cvtsd2si(CpuRegister dst, XmmRegister src); // Note: this is the r32 version.
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700500 void cvtsd2ss(XmmRegister dst, XmmRegister src);
Mark Mendell40741f32015-04-20 22:10:34 -0400501 void cvtsd2ss(XmmRegister dst, const Address& src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700502
Andreas Gampe851df202014-11-12 14:05:46 -0800503 void cvttss2si(CpuRegister dst, XmmRegister src); // Note: this is the r32 version.
Roland Levillain624279f2014-12-04 11:54:28 +0000504 void cvttss2si(CpuRegister dst, XmmRegister src, bool is64bit);
Andreas Gampe851df202014-11-12 14:05:46 -0800505 void cvttsd2si(CpuRegister dst, XmmRegister src); // Note: this is the r32 version.
Roland Levillain4c0b61f2014-12-05 12:06:01 +0000506 void cvttsd2si(CpuRegister dst, XmmRegister src, bool is64bit);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700507
Aart Bik3ae3b592017-02-24 14:09:15 -0800508 void cvtdq2ps(XmmRegister dst, XmmRegister src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700509 void cvtdq2pd(XmmRegister dst, XmmRegister src);
510
511 void comiss(XmmRegister a, XmmRegister b);
Mark Mendell40741f32015-04-20 22:10:34 -0400512 void comiss(XmmRegister a, const Address& b);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700513 void comisd(XmmRegister a, XmmRegister b);
Mark Mendell40741f32015-04-20 22:10:34 -0400514 void comisd(XmmRegister a, const Address& b);
Calin Juravleddb7df22014-11-25 20:56:51 +0000515 void ucomiss(XmmRegister a, XmmRegister b);
Mark Mendell40741f32015-04-20 22:10:34 -0400516 void ucomiss(XmmRegister a, const Address& b);
Calin Juravleddb7df22014-11-25 20:56:51 +0000517 void ucomisd(XmmRegister a, XmmRegister b);
Mark Mendell40741f32015-04-20 22:10:34 -0400518 void ucomisd(XmmRegister a, const Address& b);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700519
Mark Mendellfb8d2792015-03-31 22:16:59 -0400520 void roundsd(XmmRegister dst, XmmRegister src, const Immediate& imm);
521 void roundss(XmmRegister dst, XmmRegister src, const Immediate& imm);
522
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700523 void sqrtsd(XmmRegister dst, XmmRegister src);
524 void sqrtss(XmmRegister dst, XmmRegister src);
525
526 void xorpd(XmmRegister dst, const Address& src);
527 void xorpd(XmmRegister dst, XmmRegister src);
528 void xorps(XmmRegister dst, const Address& src);
529 void xorps(XmmRegister dst, XmmRegister src);
Aart Bik68555e92017-02-13 14:28:45 -0800530 void pxor(XmmRegister dst, XmmRegister src); // no addr variant (for now)
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700531
532 void andpd(XmmRegister dst, const Address& src);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800533 void andpd(XmmRegister dst, XmmRegister src);
Aart Bik68555e92017-02-13 14:28:45 -0800534 void andps(XmmRegister dst, XmmRegister src); // no addr variant (for now)
535 void pand(XmmRegister dst, XmmRegister src);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800536
Aart Bik21c580b2017-03-13 11:52:07 -0700537 void andnpd(XmmRegister dst, XmmRegister src); // no addr variant (for now)
538 void andnps(XmmRegister dst, XmmRegister src);
539 void pandn(XmmRegister dst, XmmRegister src);
540
Aart Bik68555e92017-02-13 14:28:45 -0800541 void orpd(XmmRegister dst, XmmRegister src); // no addr variant (for now)
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800542 void orps(XmmRegister dst, XmmRegister src);
Aart Bik68555e92017-02-13 14:28:45 -0800543 void por(XmmRegister dst, XmmRegister src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700544
Aart Bik67d3fd72017-03-31 15:11:53 -0700545 void pavgb(XmmRegister dst, XmmRegister src); // no addr variant (for now)
546 void pavgw(XmmRegister dst, XmmRegister src);
Aart Bik6005a872017-07-24 13:33:39 -0700547 void psadbw(XmmRegister dst, XmmRegister src);
548 void pmaddwd(XmmRegister dst, XmmRegister src);
549 void phaddw(XmmRegister dst, XmmRegister src);
550 void phaddd(XmmRegister dst, XmmRegister src);
551 void haddps(XmmRegister dst, XmmRegister src);
552 void haddpd(XmmRegister dst, XmmRegister src);
553 void phsubw(XmmRegister dst, XmmRegister src);
554 void phsubd(XmmRegister dst, XmmRegister src);
555 void hsubps(XmmRegister dst, XmmRegister src);
556 void hsubpd(XmmRegister dst, XmmRegister src);
Aart Bik67d3fd72017-03-31 15:11:53 -0700557
Aart Bikc8e93c72017-05-10 10:49:22 -0700558 void pminsb(XmmRegister dst, XmmRegister src); // no addr variant (for now)
559 void pmaxsb(XmmRegister dst, XmmRegister src);
560 void pminsw(XmmRegister dst, XmmRegister src);
561 void pmaxsw(XmmRegister dst, XmmRegister src);
562 void pminsd(XmmRegister dst, XmmRegister src);
563 void pmaxsd(XmmRegister dst, XmmRegister src);
564
565 void pminub(XmmRegister dst, XmmRegister src); // no addr variant (for now)
566 void pmaxub(XmmRegister dst, XmmRegister src);
567 void pminuw(XmmRegister dst, XmmRegister src);
568 void pmaxuw(XmmRegister dst, XmmRegister src);
569 void pminud(XmmRegister dst, XmmRegister src);
570 void pmaxud(XmmRegister dst, XmmRegister src);
571
572 void minps(XmmRegister dst, XmmRegister src); // no addr variant (for now)
573 void maxps(XmmRegister dst, XmmRegister src);
574 void minpd(XmmRegister dst, XmmRegister src);
575 void maxpd(XmmRegister dst, XmmRegister src);
576
Aart Bik4b455332017-03-15 11:19:35 -0700577 void pcmpeqb(XmmRegister dst, XmmRegister src);
578 void pcmpeqw(XmmRegister dst, XmmRegister src);
579 void pcmpeqd(XmmRegister dst, XmmRegister src);
580 void pcmpeqq(XmmRegister dst, XmmRegister src);
581
Aart Bik8939c642017-04-03 14:09:01 -0700582 void pcmpgtb(XmmRegister dst, XmmRegister src);
583 void pcmpgtw(XmmRegister dst, XmmRegister src);
584 void pcmpgtd(XmmRegister dst, XmmRegister src);
585 void pcmpgtq(XmmRegister dst, XmmRegister src); // SSE4.2
586
Aart Bik12e06ed2017-01-31 16:11:24 -0800587 void shufpd(XmmRegister dst, XmmRegister src, const Immediate& imm);
588 void shufps(XmmRegister dst, XmmRegister src, const Immediate& imm);
Aart Bik68555e92017-02-13 14:28:45 -0800589 void pshufd(XmmRegister dst, XmmRegister src, const Immediate& imm);
Aart Bik12e06ed2017-01-31 16:11:24 -0800590
Aart Bike69d7a92017-02-17 11:48:23 -0800591 void punpcklbw(XmmRegister dst, XmmRegister src);
592 void punpcklwd(XmmRegister dst, XmmRegister src);
593 void punpckldq(XmmRegister dst, XmmRegister src);
594 void punpcklqdq(XmmRegister dst, XmmRegister src);
595
Aart Bik3332db82017-08-11 15:10:30 -0700596 void punpckhbw(XmmRegister dst, XmmRegister src);
597 void punpckhwd(XmmRegister dst, XmmRegister src);
598 void punpckhdq(XmmRegister dst, XmmRegister src);
599 void punpckhqdq(XmmRegister dst, XmmRegister src);
600
Aart Bike69d7a92017-02-17 11:48:23 -0800601 void psllw(XmmRegister reg, const Immediate& shift_count);
602 void pslld(XmmRegister reg, const Immediate& shift_count);
603 void psllq(XmmRegister reg, const Immediate& shift_count);
604
605 void psraw(XmmRegister reg, const Immediate& shift_count);
606 void psrad(XmmRegister reg, const Immediate& shift_count);
607 // no psraq
608
609 void psrlw(XmmRegister reg, const Immediate& shift_count);
610 void psrld(XmmRegister reg, const Immediate& shift_count);
611 void psrlq(XmmRegister reg, const Immediate& shift_count);
Aart Bik3332db82017-08-11 15:10:30 -0700612 void psrldq(XmmRegister reg, const Immediate& shift_count);
Aart Bike69d7a92017-02-17 11:48:23 -0800613
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700614 void flds(const Address& src);
615 void fstps(const Address& dst);
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500616 void fsts(const Address& dst);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700617
618 void fldl(const Address& src);
619 void fstpl(const Address& dst);
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500620 void fstl(const Address& dst);
621
622 void fstsw();
623
624 void fucompp();
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700625
626 void fnstcw(const Address& dst);
627 void fldcw(const Address& src);
628
629 void fistpl(const Address& dst);
630 void fistps(const Address& dst);
631 void fildl(const Address& src);
Roland Levillain0a186012015-04-13 17:00:20 +0100632 void filds(const Address& src);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700633
634 void fincstp();
635 void ffree(const Immediate& index);
636
637 void fsin();
638 void fcos();
639 void fptan();
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500640 void fprem();
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700641
Ian Rogersdd7624d2014-03-14 17:43:00 -0700642 void xchgl(CpuRegister dst, CpuRegister src);
Nicolas Geoffrayecb2f9b2014-06-13 08:59:59 +0000643 void xchgq(CpuRegister dst, CpuRegister src);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700644 void xchgl(CpuRegister reg, const Address& address);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700645
Serguei Katkov3b625932016-05-06 10:24:17 +0600646 void cmpb(const Address& address, const Immediate& imm);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100647 void cmpw(const Address& address, const Immediate& imm);
648
Ian Rogersdd7624d2014-03-14 17:43:00 -0700649 void cmpl(CpuRegister reg, const Immediate& imm);
650 void cmpl(CpuRegister reg0, CpuRegister reg1);
651 void cmpl(CpuRegister reg, const Address& address);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700652 void cmpl(const Address& address, CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700653 void cmpl(const Address& address, const Immediate& imm);
654
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700655 void cmpq(CpuRegister reg0, CpuRegister reg1);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100656 void cmpq(CpuRegister reg0, const Immediate& imm);
657 void cmpq(CpuRegister reg0, const Address& address);
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000658 void cmpq(const Address& address, const Immediate& imm);
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700659
Ian Rogersdd7624d2014-03-14 17:43:00 -0700660 void testl(CpuRegister reg1, CpuRegister reg2);
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000661 void testl(CpuRegister reg, const Address& address);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700662 void testl(CpuRegister reg, const Immediate& imm);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700663
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000664 void testq(CpuRegister reg1, CpuRegister reg2);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100665 void testq(CpuRegister reg, const Address& address);
666
Vladimir Marko953437b2016-08-24 08:30:46 +0000667 void testb(const Address& address, const Immediate& imm);
668 void testl(const Address& address, const Immediate& imm);
669
Ian Rogersdd7624d2014-03-14 17:43:00 -0700670 void andl(CpuRegister dst, const Immediate& imm);
671 void andl(CpuRegister dst, CpuRegister src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000672 void andl(CpuRegister reg, const Address& address);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100673 void andq(CpuRegister dst, const Immediate& imm);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000674 void andq(CpuRegister dst, CpuRegister src);
Mark Mendell40741f32015-04-20 22:10:34 -0400675 void andq(CpuRegister reg, const Address& address);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700676
Ian Rogersdd7624d2014-03-14 17:43:00 -0700677 void orl(CpuRegister dst, const Immediate& imm);
678 void orl(CpuRegister dst, CpuRegister src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000679 void orl(CpuRegister reg, const Address& address);
680 void orq(CpuRegister dst, CpuRegister src);
Mark Mendell3f6c7f62015-03-13 13:47:53 -0400681 void orq(CpuRegister dst, const Immediate& imm);
Mark Mendell40741f32015-04-20 22:10:34 -0400682 void orq(CpuRegister reg, const Address& address);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700683
Ian Rogersdd7624d2014-03-14 17:43:00 -0700684 void xorl(CpuRegister dst, CpuRegister src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000685 void xorl(CpuRegister dst, const Immediate& imm);
686 void xorl(CpuRegister reg, const Address& address);
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700687 void xorq(CpuRegister dst, const Immediate& imm);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +0100688 void xorq(CpuRegister dst, CpuRegister src);
Mark Mendell40741f32015-04-20 22:10:34 -0400689 void xorq(CpuRegister reg, const Address& address);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700690
Ian Rogersdd7624d2014-03-14 17:43:00 -0700691 void addl(CpuRegister dst, CpuRegister src);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700692 void addl(CpuRegister reg, const Immediate& imm);
693 void addl(CpuRegister reg, const Address& address);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700694 void addl(const Address& address, CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700695 void addl(const Address& address, const Immediate& imm);
696
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700697 void addq(CpuRegister reg, const Immediate& imm);
698 void addq(CpuRegister dst, CpuRegister src);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100699 void addq(CpuRegister dst, const Address& address);
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700700
Ian Rogersdd7624d2014-03-14 17:43:00 -0700701 void subl(CpuRegister dst, CpuRegister src);
702 void subl(CpuRegister reg, const Immediate& imm);
703 void subl(CpuRegister reg, const Address& address);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700704
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700705 void subq(CpuRegister reg, const Immediate& imm);
706 void subq(CpuRegister dst, CpuRegister src);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100707 void subq(CpuRegister dst, const Address& address);
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700708
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700709 void cdq();
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000710 void cqo();
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700711
Ian Rogersdd7624d2014-03-14 17:43:00 -0700712 void idivl(CpuRegister reg);
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000713 void idivq(CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700714
Ian Rogersdd7624d2014-03-14 17:43:00 -0700715 void imull(CpuRegister dst, CpuRegister src);
716 void imull(CpuRegister reg, const Immediate& imm);
Mark Mendell4a2aa4a2015-07-27 16:13:10 -0400717 void imull(CpuRegister dst, CpuRegister src, const Immediate& imm);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700718 void imull(CpuRegister reg, const Address& address);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700719
Guillaume Sanchez0f88e872015-03-30 17:55:45 +0100720 void imulq(CpuRegister src);
Calin Juravle34bacdf2014-10-07 20:23:36 +0100721 void imulq(CpuRegister dst, CpuRegister src);
722 void imulq(CpuRegister reg, const Immediate& imm);
723 void imulq(CpuRegister reg, const Address& address);
Mark Mendell3f6c7f62015-03-13 13:47:53 -0400724 void imulq(CpuRegister dst, CpuRegister reg, const Immediate& imm);
Calin Juravle34bacdf2014-10-07 20:23:36 +0100725
Ian Rogersdd7624d2014-03-14 17:43:00 -0700726 void imull(CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700727 void imull(const Address& address);
728
Ian Rogersdd7624d2014-03-14 17:43:00 -0700729 void mull(CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700730 void mull(const Address& address);
731
Ian Rogersdd7624d2014-03-14 17:43:00 -0700732 void shll(CpuRegister reg, const Immediate& imm);
733 void shll(CpuRegister operand, CpuRegister shifter);
734 void shrl(CpuRegister reg, const Immediate& imm);
735 void shrl(CpuRegister operand, CpuRegister shifter);
736 void sarl(CpuRegister reg, const Immediate& imm);
737 void sarl(CpuRegister operand, CpuRegister shifter);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700738
Calin Juravle9aec02f2014-11-18 23:06:35 +0000739 void shlq(CpuRegister reg, const Immediate& imm);
740 void shlq(CpuRegister operand, CpuRegister shifter);
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +0100741 void shrq(CpuRegister reg, const Immediate& imm);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000742 void shrq(CpuRegister operand, CpuRegister shifter);
743 void sarq(CpuRegister reg, const Immediate& imm);
744 void sarq(CpuRegister operand, CpuRegister shifter);
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +0100745
Ian Rogersdd7624d2014-03-14 17:43:00 -0700746 void negl(CpuRegister reg);
Roland Levillain2e07b4f2014-10-23 18:12:09 +0100747 void negq(CpuRegister reg);
Roland Levillain70566432014-10-24 16:20:17 +0100748
Ian Rogersdd7624d2014-03-14 17:43:00 -0700749 void notl(CpuRegister reg);
Roland Levillain70566432014-10-24 16:20:17 +0100750 void notq(CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700751
752 void enter(const Immediate& imm);
753 void leave();
754
755 void ret();
756 void ret(const Immediate& imm);
757
758 void nop();
759 void int3();
760 void hlt();
761
762 void j(Condition condition, Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400763 void j(Condition condition, NearLabel* label);
764 void jrcxz(NearLabel* label);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700765
Ian Rogersdd7624d2014-03-14 17:43:00 -0700766 void jmp(CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700767 void jmp(const Address& address);
768 void jmp(Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400769 void jmp(NearLabel* label);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700770
771 X86_64Assembler* lock();
Ian Rogersdd7624d2014-03-14 17:43:00 -0700772 void cmpxchgl(const Address& address, CpuRegister reg);
Mark Mendell58d25fd2015-04-03 14:52:31 -0400773 void cmpxchgq(const Address& address, CpuRegister reg);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700774
775 void mfence();
776
777 X86_64Assembler* gs();
778
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700779 void setcc(Condition condition, CpuRegister dst);
780
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800781 void bswapl(CpuRegister dst);
782 void bswapq(CpuRegister dst);
783
Mark Mendellbcee0922015-09-15 21:45:01 -0400784 void bsfl(CpuRegister dst, CpuRegister src);
785 void bsfl(CpuRegister dst, const Address& src);
786 void bsfq(CpuRegister dst, CpuRegister src);
787 void bsfq(CpuRegister dst, const Address& src);
788
Mark Mendell8ae3ffb2015-08-12 21:16:41 -0400789 void bsrl(CpuRegister dst, CpuRegister src);
790 void bsrl(CpuRegister dst, const Address& src);
791 void bsrq(CpuRegister dst, CpuRegister src);
792 void bsrq(CpuRegister dst, const Address& src);
793
Aart Bik3f67e692016-01-15 14:35:12 -0800794 void popcntl(CpuRegister dst, CpuRegister src);
795 void popcntl(CpuRegister dst, const Address& src);
796 void popcntq(CpuRegister dst, CpuRegister src);
797 void popcntq(CpuRegister dst, const Address& src);
798
Mark Mendellbcee0922015-09-15 21:45:01 -0400799 void rorl(CpuRegister reg, const Immediate& imm);
800 void rorl(CpuRegister operand, CpuRegister shifter);
801 void roll(CpuRegister reg, const Immediate& imm);
802 void roll(CpuRegister operand, CpuRegister shifter);
803
804 void rorq(CpuRegister reg, const Immediate& imm);
805 void rorq(CpuRegister operand, CpuRegister shifter);
806 void rolq(CpuRegister reg, const Immediate& imm);
807 void rolq(CpuRegister operand, CpuRegister shifter);
808
jessicahandojob03d6402016-09-07 12:16:53 -0700809 void repne_scasb();
Andreas Gampe21030dd2015-05-07 14:46:15 -0700810 void repne_scasw();
agicsaki71311f82015-07-27 11:34:13 -0700811 void repe_cmpsw();
agicsaki970abfb2015-07-31 10:31:14 -0700812 void repe_cmpsl();
agicsaki3fd0e6a2015-08-03 20:14:29 -0700813 void repe_cmpsq();
Mark Mendellb9c4bbe2015-07-01 14:26:52 -0400814 void rep_movsw();
Andreas Gampe21030dd2015-05-07 14:46:15 -0700815
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700816 //
817 // Macros for High-level operations.
818 //
819
Ian Rogersdd7624d2014-03-14 17:43:00 -0700820 void AddImmediate(CpuRegister reg, const Immediate& imm);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700821
822 void LoadDoubleConstant(XmmRegister dst, double value);
823
Ian Rogersdd7624d2014-03-14 17:43:00 -0700824 void LockCmpxchgl(const Address& address, CpuRegister reg) {
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700825 lock()->cmpxchgl(address, reg);
826 }
827
Mark Mendell58d25fd2015-04-03 14:52:31 -0400828 void LockCmpxchgq(const Address& address, CpuRegister reg) {
829 lock()->cmpxchgq(address, reg);
830 }
831
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700832 //
833 // Misc. functionality
834 //
835 int PreferredLoopAlignment() { return 16; }
836 void Align(int alignment, int offset);
Andreas Gampe85b62f22015-09-09 13:15:38 -0700837 void Bind(Label* label) OVERRIDE;
838 void Jump(Label* label) OVERRIDE {
839 jmp(label);
840 }
Mark Mendell73f455e2015-08-21 09:30:05 -0400841 void Bind(NearLabel* label);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700842
Mark Mendell39dcf552015-04-09 20:42:42 -0400843 // Add a double to the constant area, returning the offset into
844 // the constant area where the literal resides.
Mark Mendell9c86b482015-09-18 13:36:07 -0400845 size_t AddDouble(double v) { return constant_area_.AddDouble(v); }
Mark Mendellf55c3e02015-03-26 21:07:46 -0400846
Mark Mendell39dcf552015-04-09 20:42:42 -0400847 // Add a float to the constant area, returning the offset into
848 // the constant area where the literal resides.
Mark Mendell9c86b482015-09-18 13:36:07 -0400849 size_t AddFloat(float v) { return constant_area_.AddFloat(v); }
Mark Mendellf55c3e02015-03-26 21:07:46 -0400850
Mark Mendell39dcf552015-04-09 20:42:42 -0400851 // Add an int32_t to the constant area, returning the offset into
852 // the constant area where the literal resides.
Mark Mendell9c86b482015-09-18 13:36:07 -0400853 size_t AddInt32(int32_t v) {
854 return constant_area_.AddInt32(v);
855 }
856
857 // Add an int32_t to the end of the constant area, returning the offset into
858 // the constant area where the literal resides.
859 size_t AppendInt32(int32_t v) {
860 return constant_area_.AppendInt32(v);
861 }
Mark Mendellf55c3e02015-03-26 21:07:46 -0400862
Mark Mendell39dcf552015-04-09 20:42:42 -0400863 // Add an int64_t to the constant area, returning the offset into
864 // the constant area where the literal resides.
Mark Mendell9c86b482015-09-18 13:36:07 -0400865 size_t AddInt64(int64_t v) { return constant_area_.AddInt64(v); }
Mark Mendellf55c3e02015-03-26 21:07:46 -0400866
Mark Mendell39dcf552015-04-09 20:42:42 -0400867 // Add the contents of the constant area to the assembler buffer.
Mark Mendellf55c3e02015-03-26 21:07:46 -0400868 void AddConstantArea();
869
Mark Mendell39dcf552015-04-09 20:42:42 -0400870 // Is the constant area empty? Return true if there are no literals in the constant area.
Mark Mendellf55c3e02015-03-26 21:07:46 -0400871 bool IsConstantAreaEmpty() const { return constant_area_.GetSize() == 0; }
872
Mark Mendell9c86b482015-09-18 13:36:07 -0400873 // Return the current size of the constant area.
874 size_t ConstantAreaSize() const { return constant_area_.GetSize(); }
875
Roland Levillain4d027112015-07-01 15:41:14 +0100876 //
877 // Heap poisoning.
878 //
879
880 // Poison a heap reference contained in `reg`.
881 void PoisonHeapReference(CpuRegister reg) { negl(reg); }
882 // Unpoison a heap reference contained in `reg`.
883 void UnpoisonHeapReference(CpuRegister reg) { negl(reg); }
Roland Levillain0b671c02016-08-19 12:02:34 +0100884 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
885 void MaybePoisonHeapReference(CpuRegister reg) {
886 if (kPoisonHeapReferences) {
887 PoisonHeapReference(reg);
888 }
889 }
Roland Levillain4d027112015-07-01 15:41:14 +0100890 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
891 void MaybeUnpoisonHeapReference(CpuRegister reg) {
892 if (kPoisonHeapReferences) {
893 UnpoisonHeapReference(reg);
894 }
895 }
896
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700897 private:
Ian Rogersdd7624d2014-03-14 17:43:00 -0700898 void EmitUint8(uint8_t value);
899 void EmitInt32(int32_t value);
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700900 void EmitInt64(int64_t value);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700901 void EmitRegisterOperand(uint8_t rm, uint8_t reg);
902 void EmitXmmRegisterOperand(uint8_t rm, XmmRegister reg);
903 void EmitFixup(AssemblerFixup* fixup);
904 void EmitOperandSizeOverride();
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700905
Ian Rogersdd7624d2014-03-14 17:43:00 -0700906 void EmitOperand(uint8_t rm, const Operand& operand);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700907 void EmitImmediate(const Immediate& imm);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700908 void EmitComplex(uint8_t rm, const Operand& operand, const Immediate& immediate);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700909 void EmitLabel(Label* label, int instruction_size);
910 void EmitLabelLink(Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400911 void EmitLabelLink(NearLabel* label);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700912
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +0100913 void EmitGenericShift(bool wide, int rm, CpuRegister reg, const Immediate& imm);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000914 void EmitGenericShift(bool wide, int rm, CpuRegister operand, CpuRegister shifter);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700915
916 // If any input is not false, output the necessary rex prefix.
917 void EmitOptionalRex(bool force, bool w, bool r, bool x, bool b);
918
919 // Emit a rex prefix byte if necessary for reg. ie if reg is a register in the range R8 to R15.
920 void EmitOptionalRex32(CpuRegister reg);
921 void EmitOptionalRex32(CpuRegister dst, CpuRegister src);
922 void EmitOptionalRex32(XmmRegister dst, XmmRegister src);
923 void EmitOptionalRex32(CpuRegister dst, XmmRegister src);
924 void EmitOptionalRex32(XmmRegister dst, CpuRegister src);
925 void EmitOptionalRex32(const Operand& operand);
926 void EmitOptionalRex32(CpuRegister dst, const Operand& operand);
927 void EmitOptionalRex32(XmmRegister dst, const Operand& operand);
928
929 // Emit a REX.W prefix plus necessary register bit encodings.
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000930 void EmitRex64();
Ian Rogersdd7624d2014-03-14 17:43:00 -0700931 void EmitRex64(CpuRegister reg);
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000932 void EmitRex64(const Operand& operand);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700933 void EmitRex64(CpuRegister dst, CpuRegister src);
934 void EmitRex64(CpuRegister dst, const Operand& operand);
Mark Mendell40741f32015-04-20 22:10:34 -0400935 void EmitRex64(XmmRegister dst, const Operand& operand);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100936 void EmitRex64(XmmRegister dst, CpuRegister src);
Roland Levillain624279f2014-12-04 11:54:28 +0000937 void EmitRex64(CpuRegister dst, XmmRegister src);
Ian Rogersdd7624d2014-03-14 17:43:00 -0700938
939 // Emit a REX prefix to normalize byte registers plus necessary register bit encodings.
940 void EmitOptionalByteRegNormalizingRex32(CpuRegister dst, CpuRegister src);
941 void EmitOptionalByteRegNormalizingRex32(CpuRegister dst, const Operand& operand);
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700942
Mark Mendellf55c3e02015-03-26 21:07:46 -0400943 ConstantArea constant_area_;
944
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700945 DISALLOW_COPY_AND_ASSIGN(X86_64Assembler);
946};
947
948inline void X86_64Assembler::EmitUint8(uint8_t value) {
949 buffer_.Emit<uint8_t>(value);
950}
951
952inline void X86_64Assembler::EmitInt32(int32_t value) {
953 buffer_.Emit<int32_t>(value);
954}
955
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700956inline void X86_64Assembler::EmitInt64(int64_t value) {
Roland Levillain55dcfb52014-10-24 18:09:09 +0100957 // Write this 64-bit value as two 32-bit words for alignment reasons
958 // (this is essentially when running on ARM, which does not allow
959 // 64-bit unaligned accesses). We assume little-endianness here.
960 EmitInt32(Low32Bits(value));
961 EmitInt32(High32Bits(value));
Andreas Gampe5a4fa822014-03-31 16:50:12 -0700962}
963
Ian Rogersdd7624d2014-03-14 17:43:00 -0700964inline void X86_64Assembler::EmitRegisterOperand(uint8_t rm, uint8_t reg) {
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700965 CHECK_GE(rm, 0);
966 CHECK_LT(rm, 8);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100967 buffer_.Emit<uint8_t>((0xC0 | (reg & 7)) + (rm << 3));
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700968}
969
Ian Rogersdd7624d2014-03-14 17:43:00 -0700970inline void X86_64Assembler::EmitXmmRegisterOperand(uint8_t rm, XmmRegister reg) {
971 EmitRegisterOperand(rm, static_cast<uint8_t>(reg.AsFloatRegister()));
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700972}
973
974inline void X86_64Assembler::EmitFixup(AssemblerFixup* fixup) {
975 buffer_.EmitFixup(fixup);
976}
977
978inline void X86_64Assembler::EmitOperandSizeOverride() {
979 EmitUint8(0x66);
980}
981
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700982} // namespace x86_64
983} // namespace art
984
985#endif // ART_COMPILER_UTILS_X86_64_ASSEMBLER_X86_64_H_