blob: 3e1f98e5e27abbf1f824b1e922360affa89a6c9a [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005#include "src/base/adapters.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006#include "src/base/bits.h"
7#include "src/compiler/instruction-selector-impl.h"
8#include "src/compiler/node-matchers.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009#include "src/compiler/node-properties.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15#define TRACE_UNIMPL() \
16 PrintF("UNIMPLEMENTED instr_sel: %s at line %d\n", __FUNCTION__, __LINE__)
17
18#define TRACE() PrintF("instr_sel: %s at line %d\n", __FUNCTION__, __LINE__)
19
20
21// Adds Mips-specific methods for generating InstructionOperands.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000022class Mips64OperandGenerator final : public OperandGenerator {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040023 public:
24 explicit Mips64OperandGenerator(InstructionSelector* selector)
25 : OperandGenerator(selector) {}
26
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000027 InstructionOperand UseOperand(Node* node, InstructionCode opcode) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040028 if (CanBeImmediate(node, opcode)) {
29 return UseImmediate(node);
30 }
31 return UseRegister(node);
32 }
33
34 bool CanBeImmediate(Node* node, InstructionCode opcode) {
35 int64_t value;
36 if (node->opcode() == IrOpcode::kInt32Constant)
37 value = OpParameter<int32_t>(node);
38 else if (node->opcode() == IrOpcode::kInt64Constant)
39 value = OpParameter<int64_t>(node);
40 else
41 return false;
42 switch (ArchOpcodeField::decode(opcode)) {
43 case kMips64Shl:
44 case kMips64Sar:
45 case kMips64Shr:
46 return is_uint5(value);
47 case kMips64Dshl:
48 case kMips64Dsar:
49 case kMips64Dshr:
50 return is_uint6(value);
51 case kMips64Xor:
52 return is_uint16(value);
53 case kMips64Ldc1:
54 case kMips64Sdc1:
55 return is_int16(value + kIntSize);
56 default:
57 return is_int16(value);
58 }
59 }
60
Emily Bernierd0a1eb72015-03-24 16:35:39 -040061 private:
62 bool ImmediateFitsAddrMode1Instruction(int32_t imm) const {
63 TRACE_UNIMPL();
64 return false;
65 }
66};
67
68
69static void VisitRR(InstructionSelector* selector, ArchOpcode opcode,
70 Node* node) {
71 Mips64OperandGenerator g(selector);
72 selector->Emit(opcode, g.DefineAsRegister(node),
73 g.UseRegister(node->InputAt(0)));
74}
75
76
77static void VisitRRR(InstructionSelector* selector, ArchOpcode opcode,
78 Node* node) {
79 Mips64OperandGenerator g(selector);
80 selector->Emit(opcode, g.DefineAsRegister(node),
81 g.UseRegister(node->InputAt(0)),
82 g.UseRegister(node->InputAt(1)));
83}
84
85
86static void VisitRRO(InstructionSelector* selector, ArchOpcode opcode,
87 Node* node) {
88 Mips64OperandGenerator g(selector);
89 selector->Emit(opcode, g.DefineAsRegister(node),
90 g.UseRegister(node->InputAt(0)),
91 g.UseOperand(node->InputAt(1), opcode));
92}
93
94
95static void VisitBinop(InstructionSelector* selector, Node* node,
96 InstructionCode opcode, FlagsContinuation* cont) {
97 Mips64OperandGenerator g(selector);
98 Int32BinopMatcher m(node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000099 InstructionOperand inputs[4];
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400100 size_t input_count = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101 InstructionOperand outputs[2];
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400102 size_t output_count = 0;
103
104 inputs[input_count++] = g.UseRegister(m.left().node());
105 inputs[input_count++] = g.UseOperand(m.right().node(), opcode);
106
107 if (cont->IsBranch()) {
108 inputs[input_count++] = g.Label(cont->true_block());
109 inputs[input_count++] = g.Label(cont->false_block());
110 }
111
112 outputs[output_count++] = g.DefineAsRegister(node);
113 if (cont->IsSet()) {
114 outputs[output_count++] = g.DefineAsRegister(cont->result());
115 }
116
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117 DCHECK_NE(0u, input_count);
118 DCHECK_NE(0u, output_count);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400119 DCHECK_GE(arraysize(inputs), input_count);
120 DCHECK_GE(arraysize(outputs), output_count);
121
Ben Murdochda12d292016-06-02 14:46:10 +0100122 opcode = cont->Encode(opcode);
123 if (cont->IsDeoptimize()) {
124 selector->EmitDeoptimize(opcode, output_count, outputs, input_count, inputs,
125 cont->frame_state());
126 } else {
127 selector->Emit(opcode, output_count, outputs, input_count, inputs);
128 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400129}
130
131
132static void VisitBinop(InstructionSelector* selector, Node* node,
133 InstructionCode opcode) {
134 FlagsContinuation cont;
135 VisitBinop(selector, node, opcode, &cont);
136}
137
138
139void InstructionSelector::VisitLoad(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000140 LoadRepresentation load_rep = LoadRepresentationOf(node->op());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400141 Mips64OperandGenerator g(this);
142 Node* base = node->InputAt(0);
143 Node* index = node->InputAt(1);
144
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000145 ArchOpcode opcode = kArchNop;
146 switch (load_rep.representation()) {
147 case MachineRepresentation::kFloat32:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400148 opcode = kMips64Lwc1;
149 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000150 case MachineRepresentation::kFloat64:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400151 opcode = kMips64Ldc1;
152 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000153 case MachineRepresentation::kBit: // Fall through.
154 case MachineRepresentation::kWord8:
155 opcode = load_rep.IsUnsigned() ? kMips64Lbu : kMips64Lb;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400156 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000157 case MachineRepresentation::kWord16:
158 opcode = load_rep.IsUnsigned() ? kMips64Lhu : kMips64Lh;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400159 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000160 case MachineRepresentation::kWord32:
Ben Murdochc5610432016-08-08 18:44:38 +0100161 opcode = load_rep.IsUnsigned() ? kMips64Lwu : kMips64Lw;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400162 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000163 case MachineRepresentation::kTagged: // Fall through.
164 case MachineRepresentation::kWord64:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400165 opcode = kMips64Ld;
166 break;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100167 case MachineRepresentation::kSimd128: // Fall through.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000168 case MachineRepresentation::kNone:
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400169 UNREACHABLE();
170 return;
171 }
172
173 if (g.CanBeImmediate(index, opcode)) {
174 Emit(opcode | AddressingModeField::encode(kMode_MRI),
175 g.DefineAsRegister(node), g.UseRegister(base), g.UseImmediate(index));
176 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000177 InstructionOperand addr_reg = g.TempRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400178 Emit(kMips64Dadd | AddressingModeField::encode(kMode_None), addr_reg,
179 g.UseRegister(index), g.UseRegister(base));
180 // Emit desired load opcode, using temp addr_reg.
181 Emit(opcode | AddressingModeField::encode(kMode_MRI),
182 g.DefineAsRegister(node), addr_reg, g.TempImmediate(0));
183 }
184}
185
186
187void InstructionSelector::VisitStore(Node* node) {
188 Mips64OperandGenerator g(this);
189 Node* base = node->InputAt(0);
190 Node* index = node->InputAt(1);
191 Node* value = node->InputAt(2);
192
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000193 StoreRepresentation store_rep = StoreRepresentationOf(node->op());
194 WriteBarrierKind write_barrier_kind = store_rep.write_barrier_kind();
195 MachineRepresentation rep = store_rep.representation();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400196
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000197 // TODO(mips): I guess this could be done in a better way.
198 if (write_barrier_kind != kNoWriteBarrier) {
199 DCHECK_EQ(MachineRepresentation::kTagged, rep);
200 InstructionOperand inputs[3];
201 size_t input_count = 0;
202 inputs[input_count++] = g.UseUniqueRegister(base);
203 inputs[input_count++] = g.UseUniqueRegister(index);
Ben Murdochda12d292016-06-02 14:46:10 +0100204 inputs[input_count++] = g.UseUniqueRegister(value);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000205 RecordWriteMode record_write_mode = RecordWriteMode::kValueIsAny;
206 switch (write_barrier_kind) {
207 case kNoWriteBarrier:
208 UNREACHABLE();
209 break;
210 case kMapWriteBarrier:
211 record_write_mode = RecordWriteMode::kValueIsMap;
212 break;
213 case kPointerWriteBarrier:
214 record_write_mode = RecordWriteMode::kValueIsPointer;
215 break;
216 case kFullWriteBarrier:
217 record_write_mode = RecordWriteMode::kValueIsAny;
218 break;
219 }
220 InstructionOperand temps[] = {g.TempRegister(), g.TempRegister()};
221 size_t const temp_count = arraysize(temps);
222 InstructionCode code = kArchStoreWithWriteBarrier;
223 code |= MiscField::encode(static_cast<int>(record_write_mode));
224 Emit(code, 0, nullptr, input_count, inputs, temp_count, temps);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400225 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000226 ArchOpcode opcode = kArchNop;
227 switch (rep) {
228 case MachineRepresentation::kFloat32:
229 opcode = kMips64Swc1;
230 break;
231 case MachineRepresentation::kFloat64:
232 opcode = kMips64Sdc1;
233 break;
234 case MachineRepresentation::kBit: // Fall through.
235 case MachineRepresentation::kWord8:
236 opcode = kMips64Sb;
237 break;
238 case MachineRepresentation::kWord16:
239 opcode = kMips64Sh;
240 break;
241 case MachineRepresentation::kWord32:
242 opcode = kMips64Sw;
243 break;
244 case MachineRepresentation::kTagged: // Fall through.
245 case MachineRepresentation::kWord64:
246 opcode = kMips64Sd;
247 break;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100248 case MachineRepresentation::kSimd128: // Fall through.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000249 case MachineRepresentation::kNone:
250 UNREACHABLE();
251 return;
252 }
253
254 if (g.CanBeImmediate(index, opcode)) {
255 Emit(opcode | AddressingModeField::encode(kMode_MRI), g.NoOutput(),
256 g.UseRegister(base), g.UseImmediate(index), g.UseRegister(value));
257 } else {
258 InstructionOperand addr_reg = g.TempRegister();
259 Emit(kMips64Dadd | AddressingModeField::encode(kMode_None), addr_reg,
260 g.UseRegister(index), g.UseRegister(base));
261 // Emit desired store opcode, using temp addr_reg.
262 Emit(opcode | AddressingModeField::encode(kMode_MRI), g.NoOutput(),
263 addr_reg, g.TempImmediate(0), g.UseRegister(value));
264 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400265 }
266}
267
268
269void InstructionSelector::VisitWord32And(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000270 Mips64OperandGenerator g(this);
271 Int32BinopMatcher m(node);
272 if (m.left().IsWord32Shr() && CanCover(node, m.left().node()) &&
273 m.right().HasValue()) {
274 uint32_t mask = m.right().Value();
275 uint32_t mask_width = base::bits::CountPopulation32(mask);
276 uint32_t mask_msb = base::bits::CountLeadingZeros32(mask);
277 if ((mask_width != 0) && (mask_msb + mask_width == 32)) {
278 // The mask must be contiguous, and occupy the least-significant bits.
279 DCHECK_EQ(0u, base::bits::CountTrailingZeros32(mask));
280
281 // Select Ext for And(Shr(x, imm), mask) where the mask is in the least
282 // significant bits.
283 Int32BinopMatcher mleft(m.left().node());
284 if (mleft.right().HasValue()) {
285 // Any shift value can match; int32 shifts use `value % 32`.
286 uint32_t lsb = mleft.right().Value() & 0x1f;
287
288 // Ext cannot extract bits past the register size, however since
289 // shifting the original value would have introduced some zeros we can
290 // still use Ext with a smaller mask and the remaining bits will be
291 // zeros.
292 if (lsb + mask_width > 32) mask_width = 32 - lsb;
293
294 Emit(kMips64Ext, g.DefineAsRegister(node),
295 g.UseRegister(mleft.left().node()), g.TempImmediate(lsb),
296 g.TempImmediate(mask_width));
297 return;
298 }
299 // Other cases fall through to the normal And operation.
300 }
301 }
302 if (m.right().HasValue()) {
303 uint32_t mask = m.right().Value();
304 uint32_t shift = base::bits::CountPopulation32(~mask);
305 uint32_t msb = base::bits::CountLeadingZeros32(~mask);
306 if (shift != 0 && shift != 32 && msb + shift == 32) {
307 // Insert zeros for (x >> K) << K => x & ~(2^K - 1) expression reduction
308 // and remove constant loading of inverted mask.
309 Emit(kMips64Ins, g.DefineSameAsFirst(node),
310 g.UseRegister(m.left().node()), g.TempImmediate(0),
311 g.TempImmediate(shift));
312 return;
313 }
314 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400315 VisitBinop(this, node, kMips64And);
316}
317
318
319void InstructionSelector::VisitWord64And(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000320 Mips64OperandGenerator g(this);
321 Int64BinopMatcher m(node);
322 if (m.left().IsWord64Shr() && CanCover(node, m.left().node()) &&
323 m.right().HasValue()) {
324 uint64_t mask = m.right().Value();
325 uint32_t mask_width = base::bits::CountPopulation64(mask);
326 uint32_t mask_msb = base::bits::CountLeadingZeros64(mask);
327 if ((mask_width != 0) && (mask_msb + mask_width == 64)) {
328 // The mask must be contiguous, and occupy the least-significant bits.
329 DCHECK_EQ(0u, base::bits::CountTrailingZeros64(mask));
330
331 // Select Dext for And(Shr(x, imm), mask) where the mask is in the least
332 // significant bits.
333 Int64BinopMatcher mleft(m.left().node());
334 if (mleft.right().HasValue()) {
335 // Any shift value can match; int64 shifts use `value % 64`.
336 uint32_t lsb = static_cast<uint32_t>(mleft.right().Value() & 0x3f);
337
338 // Dext cannot extract bits past the register size, however since
339 // shifting the original value would have introduced some zeros we can
340 // still use Dext with a smaller mask and the remaining bits will be
341 // zeros.
342 if (lsb + mask_width > 64) mask_width = 64 - lsb;
343
344 Emit(kMips64Dext, g.DefineAsRegister(node),
345 g.UseRegister(mleft.left().node()), g.TempImmediate(lsb),
346 g.TempImmediate(static_cast<int32_t>(mask_width)));
347 return;
348 }
349 // Other cases fall through to the normal And operation.
350 }
351 }
352 if (m.right().HasValue()) {
353 uint64_t mask = m.right().Value();
354 uint32_t shift = base::bits::CountPopulation64(~mask);
355 uint32_t msb = base::bits::CountLeadingZeros64(~mask);
356 if (shift != 0 && shift < 32 && msb + shift == 64) {
357 // Insert zeros for (x >> K) << K => x & ~(2^K - 1) expression reduction
358 // and remove constant loading of inverted mask. Dins cannot insert bits
359 // past word size, so shifts smaller than 32 are covered.
360 Emit(kMips64Dins, g.DefineSameAsFirst(node),
361 g.UseRegister(m.left().node()), g.TempImmediate(0),
362 g.TempImmediate(shift));
363 return;
364 }
365 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400366 VisitBinop(this, node, kMips64And);
367}
368
369
370void InstructionSelector::VisitWord32Or(Node* node) {
371 VisitBinop(this, node, kMips64Or);
372}
373
374
375void InstructionSelector::VisitWord64Or(Node* node) {
376 VisitBinop(this, node, kMips64Or);
377}
378
379
380void InstructionSelector::VisitWord32Xor(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000381 Int32BinopMatcher m(node);
382 if (m.left().IsWord32Or() && CanCover(node, m.left().node()) &&
383 m.right().Is(-1)) {
384 Int32BinopMatcher mleft(m.left().node());
385 if (!mleft.right().HasValue()) {
386 Mips64OperandGenerator g(this);
387 Emit(kMips64Nor, g.DefineAsRegister(node),
388 g.UseRegister(mleft.left().node()),
389 g.UseRegister(mleft.right().node()));
390 return;
391 }
392 }
393 if (m.right().Is(-1)) {
394 // Use Nor for bit negation and eliminate constant loading for xori.
395 Mips64OperandGenerator g(this);
396 Emit(kMips64Nor, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
397 g.TempImmediate(0));
398 return;
399 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400400 VisitBinop(this, node, kMips64Xor);
401}
402
403
404void InstructionSelector::VisitWord64Xor(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000405 Int64BinopMatcher m(node);
406 if (m.left().IsWord64Or() && CanCover(node, m.left().node()) &&
407 m.right().Is(-1)) {
408 Int64BinopMatcher mleft(m.left().node());
409 if (!mleft.right().HasValue()) {
410 Mips64OperandGenerator g(this);
411 Emit(kMips64Nor, g.DefineAsRegister(node),
412 g.UseRegister(mleft.left().node()),
413 g.UseRegister(mleft.right().node()));
414 return;
415 }
416 }
417 if (m.right().Is(-1)) {
418 // Use Nor for bit negation and eliminate constant loading for xori.
419 Mips64OperandGenerator g(this);
420 Emit(kMips64Nor, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
421 g.TempImmediate(0));
422 return;
423 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400424 VisitBinop(this, node, kMips64Xor);
425}
426
427
428void InstructionSelector::VisitWord32Shl(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000429 Int32BinopMatcher m(node);
430 if (m.left().IsWord32And() && CanCover(node, m.left().node()) &&
431 m.right().IsInRange(1, 31)) {
432 Mips64OperandGenerator g(this);
433 Int32BinopMatcher mleft(m.left().node());
434 // Match Word32Shl(Word32And(x, mask), imm) to Shl where the mask is
435 // contiguous, and the shift immediate non-zero.
436 if (mleft.right().HasValue()) {
437 uint32_t mask = mleft.right().Value();
438 uint32_t mask_width = base::bits::CountPopulation32(mask);
439 uint32_t mask_msb = base::bits::CountLeadingZeros32(mask);
440 if ((mask_width != 0) && (mask_msb + mask_width == 32)) {
441 uint32_t shift = m.right().Value();
442 DCHECK_EQ(0u, base::bits::CountTrailingZeros32(mask));
443 DCHECK_NE(0u, shift);
444 if ((shift + mask_width) >= 32) {
445 // If the mask is contiguous and reaches or extends beyond the top
446 // bit, only the shift is needed.
447 Emit(kMips64Shl, g.DefineAsRegister(node),
448 g.UseRegister(mleft.left().node()),
449 g.UseImmediate(m.right().node()));
450 return;
451 }
452 }
453 }
454 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400455 VisitRRO(this, kMips64Shl, node);
456}
457
458
459void InstructionSelector::VisitWord32Shr(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000460 Int32BinopMatcher m(node);
461 if (m.left().IsWord32And() && m.right().HasValue()) {
462 uint32_t lsb = m.right().Value() & 0x1f;
463 Int32BinopMatcher mleft(m.left().node());
464 if (mleft.right().HasValue()) {
465 // Select Ext for Shr(And(x, mask), imm) where the result of the mask is
466 // shifted into the least-significant bits.
467 uint32_t mask = (mleft.right().Value() >> lsb) << lsb;
468 unsigned mask_width = base::bits::CountPopulation32(mask);
469 unsigned mask_msb = base::bits::CountLeadingZeros32(mask);
470 if ((mask_msb + mask_width + lsb) == 32) {
471 Mips64OperandGenerator g(this);
472 DCHECK_EQ(lsb, base::bits::CountTrailingZeros32(mask));
473 Emit(kMips64Ext, g.DefineAsRegister(node),
474 g.UseRegister(mleft.left().node()), g.TempImmediate(lsb),
475 g.TempImmediate(mask_width));
476 return;
477 }
478 }
479 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400480 VisitRRO(this, kMips64Shr, node);
481}
482
483
484void InstructionSelector::VisitWord32Sar(Node* node) {
485 VisitRRO(this, kMips64Sar, node);
486}
487
488
489void InstructionSelector::VisitWord64Shl(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000490 Mips64OperandGenerator g(this);
491 Int64BinopMatcher m(node);
492 if ((m.left().IsChangeInt32ToInt64() || m.left().IsChangeUint32ToUint64()) &&
493 m.right().IsInRange(32, 63)) {
494 // There's no need to sign/zero-extend to 64-bit if we shift out the upper
495 // 32 bits anyway.
496 Emit(kMips64Dshl, g.DefineSameAsFirst(node),
497 g.UseRegister(m.left().node()->InputAt(0)),
498 g.UseImmediate(m.right().node()));
499 return;
500 }
501 if (m.left().IsWord64And() && CanCover(node, m.left().node()) &&
502 m.right().IsInRange(1, 63)) {
503 // Match Word64Shl(Word64And(x, mask), imm) to Dshl where the mask is
504 // contiguous, and the shift immediate non-zero.
505 Int64BinopMatcher mleft(m.left().node());
506 if (mleft.right().HasValue()) {
507 uint64_t mask = mleft.right().Value();
508 uint32_t mask_width = base::bits::CountPopulation64(mask);
509 uint32_t mask_msb = base::bits::CountLeadingZeros64(mask);
510 if ((mask_width != 0) && (mask_msb + mask_width == 64)) {
511 uint64_t shift = m.right().Value();
512 DCHECK_EQ(0u, base::bits::CountTrailingZeros64(mask));
513 DCHECK_NE(0u, shift);
514
515 if ((shift + mask_width) >= 64) {
516 // If the mask is contiguous and reaches or extends beyond the top
517 // bit, only the shift is needed.
518 Emit(kMips64Dshl, g.DefineAsRegister(node),
519 g.UseRegister(mleft.left().node()),
520 g.UseImmediate(m.right().node()));
521 return;
522 }
523 }
524 }
525 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400526 VisitRRO(this, kMips64Dshl, node);
527}
528
529
530void InstructionSelector::VisitWord64Shr(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000531 Int64BinopMatcher m(node);
532 if (m.left().IsWord64And() && m.right().HasValue()) {
533 uint32_t lsb = m.right().Value() & 0x3f;
534 Int64BinopMatcher mleft(m.left().node());
535 if (mleft.right().HasValue()) {
536 // Select Dext for Shr(And(x, mask), imm) where the result of the mask is
537 // shifted into the least-significant bits.
538 uint64_t mask = (mleft.right().Value() >> lsb) << lsb;
539 unsigned mask_width = base::bits::CountPopulation64(mask);
540 unsigned mask_msb = base::bits::CountLeadingZeros64(mask);
541 if ((mask_msb + mask_width + lsb) == 64) {
542 Mips64OperandGenerator g(this);
543 DCHECK_EQ(lsb, base::bits::CountTrailingZeros64(mask));
544 Emit(kMips64Dext, g.DefineAsRegister(node),
545 g.UseRegister(mleft.left().node()), g.TempImmediate(lsb),
546 g.TempImmediate(mask_width));
547 return;
548 }
549 }
550 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400551 VisitRRO(this, kMips64Dshr, node);
552}
553
554
555void InstructionSelector::VisitWord64Sar(Node* node) {
556 VisitRRO(this, kMips64Dsar, node);
557}
558
559
560void InstructionSelector::VisitWord32Ror(Node* node) {
561 VisitRRO(this, kMips64Ror, node);
562}
563
564
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000565void InstructionSelector::VisitWord32Clz(Node* node) {
566 VisitRR(this, kMips64Clz, node);
567}
568
569
Ben Murdoch097c5b22016-05-18 11:27:45 +0100570void InstructionSelector::VisitWord32ReverseBits(Node* node) { UNREACHABLE(); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000571
572
Ben Murdoch097c5b22016-05-18 11:27:45 +0100573void InstructionSelector::VisitWord64ReverseBits(Node* node) { UNREACHABLE(); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000574
575
Ben Murdoch097c5b22016-05-18 11:27:45 +0100576void InstructionSelector::VisitWord32Ctz(Node* node) {
577 Mips64OperandGenerator g(this);
578 Emit(kMips64Ctz, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0)));
579}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000580
581
Ben Murdoch097c5b22016-05-18 11:27:45 +0100582void InstructionSelector::VisitWord64Ctz(Node* node) {
583 Mips64OperandGenerator g(this);
584 Emit(kMips64Dctz, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0)));
585}
586
587
588void InstructionSelector::VisitWord32Popcnt(Node* node) {
589 Mips64OperandGenerator g(this);
590 Emit(kMips64Popcnt, g.DefineAsRegister(node),
591 g.UseRegister(node->InputAt(0)));
592}
593
594
595void InstructionSelector::VisitWord64Popcnt(Node* node) {
596 Mips64OperandGenerator g(this);
597 Emit(kMips64Dpopcnt, g.DefineAsRegister(node),
598 g.UseRegister(node->InputAt(0)));
599}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000600
601
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400602void InstructionSelector::VisitWord64Ror(Node* node) {
603 VisitRRO(this, kMips64Dror, node);
604}
605
606
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000607void InstructionSelector::VisitWord64Clz(Node* node) {
608 VisitRR(this, kMips64Dclz, node);
609}
610
611
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400612void InstructionSelector::VisitInt32Add(Node* node) {
613 Mips64OperandGenerator g(this);
Ben Murdochc5610432016-08-08 18:44:38 +0100614 Int32BinopMatcher m(node);
615
616 // Select Lsa for (left + (left_of_right << imm)).
617 if (m.right().opcode() == IrOpcode::kWord32Shl &&
618 CanCover(node, m.left().node()) && CanCover(node, m.right().node())) {
619 Int32BinopMatcher mright(m.right().node());
620 if (mright.right().HasValue()) {
621 int32_t shift_value = static_cast<int32_t>(mright.right().Value());
622 Emit(kMips64Lsa, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
623 g.UseRegister(mright.left().node()), g.TempImmediate(shift_value));
624 return;
625 }
626 }
627
628 // Select Lsa for ((left_of_left << imm) + right).
629 if (m.left().opcode() == IrOpcode::kWord32Shl &&
630 CanCover(node, m.right().node()) && CanCover(node, m.left().node())) {
631 Int32BinopMatcher mleft(m.left().node());
632 if (mleft.right().HasValue()) {
633 int32_t shift_value = static_cast<int32_t>(mleft.right().Value());
634 Emit(kMips64Lsa, g.DefineAsRegister(node),
635 g.UseRegister(m.right().node()), g.UseRegister(mleft.left().node()),
636 g.TempImmediate(shift_value));
637 return;
638 }
639 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400640 VisitBinop(this, node, kMips64Add);
641}
642
643
644void InstructionSelector::VisitInt64Add(Node* node) {
645 Mips64OperandGenerator g(this);
Ben Murdochc5610432016-08-08 18:44:38 +0100646 Int64BinopMatcher m(node);
647
648 // Select Dlsa for (left + (left_of_right << imm)).
649 if (m.right().opcode() == IrOpcode::kWord64Shl &&
650 CanCover(node, m.left().node()) && CanCover(node, m.right().node())) {
651 Int64BinopMatcher mright(m.right().node());
652 if (mright.right().HasValue()) {
653 int32_t shift_value = static_cast<int32_t>(mright.right().Value());
654 Emit(kMips64Dlsa, g.DefineAsRegister(node),
655 g.UseRegister(m.left().node()), g.UseRegister(mright.left().node()),
656 g.TempImmediate(shift_value));
657 return;
658 }
659 }
660
661 // Select Dlsa for ((left_of_left << imm) + right).
662 if (m.left().opcode() == IrOpcode::kWord64Shl &&
663 CanCover(node, m.right().node()) && CanCover(node, m.left().node())) {
664 Int64BinopMatcher mleft(m.left().node());
665 if (mleft.right().HasValue()) {
666 int32_t shift_value = static_cast<int32_t>(mleft.right().Value());
667 Emit(kMips64Dlsa, g.DefineAsRegister(node),
668 g.UseRegister(m.right().node()), g.UseRegister(mleft.left().node()),
669 g.TempImmediate(shift_value));
670 return;
671 }
672 }
673
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400674 VisitBinop(this, node, kMips64Dadd);
675}
676
677
678void InstructionSelector::VisitInt32Sub(Node* node) {
679 VisitBinop(this, node, kMips64Sub);
680}
681
682
683void InstructionSelector::VisitInt64Sub(Node* node) {
684 VisitBinop(this, node, kMips64Dsub);
685}
686
687
688void InstructionSelector::VisitInt32Mul(Node* node) {
689 Mips64OperandGenerator g(this);
690 Int32BinopMatcher m(node);
691 if (m.right().HasValue() && m.right().Value() > 0) {
692 int32_t value = m.right().Value();
693 if (base::bits::IsPowerOfTwo32(value)) {
694 Emit(kMips64Shl | AddressingModeField::encode(kMode_None),
695 g.DefineAsRegister(node), g.UseRegister(m.left().node()),
696 g.TempImmediate(WhichPowerOf2(value)));
697 return;
698 }
699 if (base::bits::IsPowerOfTwo32(value - 1)) {
Ben Murdochc5610432016-08-08 18:44:38 +0100700 Emit(kMips64Lsa, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400701 g.UseRegister(m.left().node()),
702 g.TempImmediate(WhichPowerOf2(value - 1)));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400703 return;
704 }
705 if (base::bits::IsPowerOfTwo32(value + 1)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000706 InstructionOperand temp = g.TempRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400707 Emit(kMips64Shl | AddressingModeField::encode(kMode_None), temp,
708 g.UseRegister(m.left().node()),
709 g.TempImmediate(WhichPowerOf2(value + 1)));
710 Emit(kMips64Sub | AddressingModeField::encode(kMode_None),
711 g.DefineAsRegister(node), temp, g.UseRegister(m.left().node()));
712 return;
713 }
714 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000715 Node* left = node->InputAt(0);
716 Node* right = node->InputAt(1);
717 if (CanCover(node, left) && CanCover(node, right)) {
718 if (left->opcode() == IrOpcode::kWord64Sar &&
719 right->opcode() == IrOpcode::kWord64Sar) {
720 Int64BinopMatcher leftInput(left), rightInput(right);
721 if (leftInput.right().Is(32) && rightInput.right().Is(32)) {
722 // Combine untagging shifts with Dmul high.
723 Emit(kMips64DMulHigh, g.DefineSameAsFirst(node),
724 g.UseRegister(leftInput.left().node()),
725 g.UseRegister(rightInput.left().node()));
726 return;
727 }
728 }
729 }
730 VisitRRR(this, kMips64Mul, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400731}
732
733
734void InstructionSelector::VisitInt32MulHigh(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000735 VisitRRR(this, kMips64MulHigh, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400736}
737
738
739void InstructionSelector::VisitUint32MulHigh(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000740 VisitRRR(this, kMips64MulHighU, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400741}
742
743
744void InstructionSelector::VisitInt64Mul(Node* node) {
745 Mips64OperandGenerator g(this);
746 Int64BinopMatcher m(node);
747 // TODO(dusmil): Add optimization for shifts larger than 32.
748 if (m.right().HasValue() && m.right().Value() > 0) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000749 int32_t value = static_cast<int32_t>(m.right().Value());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400750 if (base::bits::IsPowerOfTwo32(value)) {
751 Emit(kMips64Dshl | AddressingModeField::encode(kMode_None),
752 g.DefineAsRegister(node), g.UseRegister(m.left().node()),
753 g.TempImmediate(WhichPowerOf2(value)));
754 return;
755 }
756 if (base::bits::IsPowerOfTwo32(value - 1)) {
Ben Murdochc5610432016-08-08 18:44:38 +0100757 // Dlsa macro will handle the shifting value out of bound cases.
758 Emit(kMips64Dlsa, g.DefineAsRegister(node),
759 g.UseRegister(m.left().node()), g.UseRegister(m.left().node()),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400760 g.TempImmediate(WhichPowerOf2(value - 1)));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400761 return;
762 }
763 if (base::bits::IsPowerOfTwo32(value + 1)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000764 InstructionOperand temp = g.TempRegister();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400765 Emit(kMips64Dshl | AddressingModeField::encode(kMode_None), temp,
766 g.UseRegister(m.left().node()),
767 g.TempImmediate(WhichPowerOf2(value + 1)));
768 Emit(kMips64Dsub | AddressingModeField::encode(kMode_None),
769 g.DefineAsRegister(node), temp, g.UseRegister(m.left().node()));
770 return;
771 }
772 }
773 Emit(kMips64Dmul, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
774 g.UseRegister(m.right().node()));
775}
776
777
778void InstructionSelector::VisitInt32Div(Node* node) {
779 Mips64OperandGenerator g(this);
780 Int32BinopMatcher m(node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000781 Node* left = node->InputAt(0);
782 Node* right = node->InputAt(1);
783 if (CanCover(node, left) && CanCover(node, right)) {
784 if (left->opcode() == IrOpcode::kWord64Sar &&
785 right->opcode() == IrOpcode::kWord64Sar) {
786 Int64BinopMatcher rightInput(right), leftInput(left);
787 if (rightInput.right().Is(32) && leftInput.right().Is(32)) {
788 // Combine both shifted operands with Ddiv.
789 Emit(kMips64Ddiv, g.DefineSameAsFirst(node),
790 g.UseRegister(leftInput.left().node()),
791 g.UseRegister(rightInput.left().node()));
792 return;
793 }
794 }
795 }
796 Emit(kMips64Div, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400797 g.UseRegister(m.right().node()));
798}
799
800
801void InstructionSelector::VisitUint32Div(Node* node) {
802 Mips64OperandGenerator g(this);
803 Int32BinopMatcher m(node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000804 Emit(kMips64DivU, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400805 g.UseRegister(m.right().node()));
806}
807
808
809void InstructionSelector::VisitInt32Mod(Node* node) {
810 Mips64OperandGenerator g(this);
811 Int32BinopMatcher m(node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000812 Node* left = node->InputAt(0);
813 Node* right = node->InputAt(1);
814 if (CanCover(node, left) && CanCover(node, right)) {
815 if (left->opcode() == IrOpcode::kWord64Sar &&
816 right->opcode() == IrOpcode::kWord64Sar) {
817 Int64BinopMatcher rightInput(right), leftInput(left);
818 if (rightInput.right().Is(32) && leftInput.right().Is(32)) {
819 // Combine both shifted operands with Dmod.
820 Emit(kMips64Dmod, g.DefineSameAsFirst(node),
821 g.UseRegister(leftInput.left().node()),
822 g.UseRegister(rightInput.left().node()));
823 return;
824 }
825 }
826 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400827 Emit(kMips64Mod, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
828 g.UseRegister(m.right().node()));
829}
830
831
832void InstructionSelector::VisitUint32Mod(Node* node) {
833 Mips64OperandGenerator g(this);
834 Int32BinopMatcher m(node);
835 Emit(kMips64ModU, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
836 g.UseRegister(m.right().node()));
837}
838
839
840void InstructionSelector::VisitInt64Div(Node* node) {
841 Mips64OperandGenerator g(this);
842 Int64BinopMatcher m(node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000843 Emit(kMips64Ddiv, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400844 g.UseRegister(m.right().node()));
845}
846
847
848void InstructionSelector::VisitUint64Div(Node* node) {
849 Mips64OperandGenerator g(this);
850 Int64BinopMatcher m(node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000851 Emit(kMips64DdivU, g.DefineSameAsFirst(node), g.UseRegister(m.left().node()),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400852 g.UseRegister(m.right().node()));
853}
854
855
856void InstructionSelector::VisitInt64Mod(Node* node) {
857 Mips64OperandGenerator g(this);
858 Int64BinopMatcher m(node);
859 Emit(kMips64Dmod, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
860 g.UseRegister(m.right().node()));
861}
862
863
864void InstructionSelector::VisitUint64Mod(Node* node) {
865 Mips64OperandGenerator g(this);
866 Int64BinopMatcher m(node);
867 Emit(kMips64DmodU, g.DefineAsRegister(node), g.UseRegister(m.left().node()),
868 g.UseRegister(m.right().node()));
869}
870
871
872void InstructionSelector::VisitChangeFloat32ToFloat64(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000873 VisitRR(this, kMips64CvtDS, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400874}
875
876
Ben Murdoch097c5b22016-05-18 11:27:45 +0100877void InstructionSelector::VisitRoundInt32ToFloat32(Node* node) {
878 VisitRR(this, kMips64CvtSW, node);
879}
880
881
882void InstructionSelector::VisitRoundUint32ToFloat32(Node* node) {
883 VisitRR(this, kMips64CvtSUw, node);
884}
885
886
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400887void InstructionSelector::VisitChangeInt32ToFloat64(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000888 VisitRR(this, kMips64CvtDW, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400889}
890
891
892void InstructionSelector::VisitChangeUint32ToFloat64(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000893 VisitRR(this, kMips64CvtDUw, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400894}
895
896
Ben Murdoch097c5b22016-05-18 11:27:45 +0100897void InstructionSelector::VisitTruncateFloat32ToInt32(Node* node) {
898 VisitRR(this, kMips64TruncWS, node);
899}
900
901
902void InstructionSelector::VisitTruncateFloat32ToUint32(Node* node) {
903 VisitRR(this, kMips64TruncUwS, node);
904}
905
906
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400907void InstructionSelector::VisitChangeFloat64ToInt32(Node* node) {
908 Mips64OperandGenerator g(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000909 Node* value = node->InputAt(0);
910 // Match ChangeFloat64ToInt32(Float64Round##OP) to corresponding instruction
911 // which does rounding and conversion to integer format.
912 if (CanCover(node, value)) {
913 switch (value->opcode()) {
914 case IrOpcode::kFloat64RoundDown:
915 Emit(kMips64FloorWD, g.DefineAsRegister(node),
916 g.UseRegister(value->InputAt(0)));
917 return;
918 case IrOpcode::kFloat64RoundUp:
919 Emit(kMips64CeilWD, g.DefineAsRegister(node),
920 g.UseRegister(value->InputAt(0)));
921 return;
922 case IrOpcode::kFloat64RoundTiesEven:
923 Emit(kMips64RoundWD, g.DefineAsRegister(node),
924 g.UseRegister(value->InputAt(0)));
925 return;
926 case IrOpcode::kFloat64RoundTruncate:
927 Emit(kMips64TruncWD, g.DefineAsRegister(node),
928 g.UseRegister(value->InputAt(0)));
929 return;
930 default:
931 break;
932 }
933 if (value->opcode() == IrOpcode::kChangeFloat32ToFloat64) {
934 Node* next = value->InputAt(0);
935 if (CanCover(value, next)) {
936 // Match ChangeFloat64ToInt32(ChangeFloat32ToFloat64(Float64Round##OP))
937 switch (next->opcode()) {
938 case IrOpcode::kFloat32RoundDown:
939 Emit(kMips64FloorWS, g.DefineAsRegister(node),
940 g.UseRegister(next->InputAt(0)));
941 return;
942 case IrOpcode::kFloat32RoundUp:
943 Emit(kMips64CeilWS, g.DefineAsRegister(node),
944 g.UseRegister(next->InputAt(0)));
945 return;
946 case IrOpcode::kFloat32RoundTiesEven:
947 Emit(kMips64RoundWS, g.DefineAsRegister(node),
948 g.UseRegister(next->InputAt(0)));
949 return;
950 case IrOpcode::kFloat32RoundTruncate:
951 Emit(kMips64TruncWS, g.DefineAsRegister(node),
952 g.UseRegister(next->InputAt(0)));
953 return;
954 default:
955 Emit(kMips64TruncWS, g.DefineAsRegister(node),
956 g.UseRegister(value->InputAt(0)));
957 return;
958 }
959 } else {
960 // Match float32 -> float64 -> int32 representation change path.
961 Emit(kMips64TruncWS, g.DefineAsRegister(node),
962 g.UseRegister(value->InputAt(0)));
963 return;
964 }
965 }
966 }
967 VisitRR(this, kMips64TruncWD, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400968}
969
970
971void InstructionSelector::VisitChangeFloat64ToUint32(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000972 VisitRR(this, kMips64TruncUwD, node);
973}
974
Ben Murdochda12d292016-06-02 14:46:10 +0100975void InstructionSelector::VisitTruncateFloat64ToUint32(Node* node) {
976 VisitRR(this, kMips64TruncUwD, node);
977}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000978
979void InstructionSelector::VisitTryTruncateFloat32ToInt64(Node* node) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400980 Mips64OperandGenerator g(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000981 InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
982 InstructionOperand outputs[2];
983 size_t output_count = 0;
984 outputs[output_count++] = g.DefineAsRegister(node);
985
986 Node* success_output = NodeProperties::FindProjection(node, 1);
987 if (success_output) {
988 outputs[output_count++] = g.DefineAsRegister(success_output);
989 }
990
991 this->Emit(kMips64TruncLS, output_count, outputs, 1, inputs);
992}
993
994
995void InstructionSelector::VisitTryTruncateFloat64ToInt64(Node* node) {
996 Mips64OperandGenerator g(this);
997 InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
998 InstructionOperand outputs[2];
999 size_t output_count = 0;
1000 outputs[output_count++] = g.DefineAsRegister(node);
1001
1002 Node* success_output = NodeProperties::FindProjection(node, 1);
1003 if (success_output) {
1004 outputs[output_count++] = g.DefineAsRegister(success_output);
1005 }
1006
1007 Emit(kMips64TruncLD, output_count, outputs, 1, inputs);
1008}
1009
1010
1011void InstructionSelector::VisitTryTruncateFloat32ToUint64(Node* node) {
1012 Mips64OperandGenerator g(this);
1013 InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
1014 InstructionOperand outputs[2];
1015 size_t output_count = 0;
1016 outputs[output_count++] = g.DefineAsRegister(node);
1017
1018 Node* success_output = NodeProperties::FindProjection(node, 1);
1019 if (success_output) {
1020 outputs[output_count++] = g.DefineAsRegister(success_output);
1021 }
1022
1023 Emit(kMips64TruncUlS, output_count, outputs, 1, inputs);
1024}
1025
1026
1027void InstructionSelector::VisitTryTruncateFloat64ToUint64(Node* node) {
1028 Mips64OperandGenerator g(this);
1029
1030 InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
1031 InstructionOperand outputs[2];
1032 size_t output_count = 0;
1033 outputs[output_count++] = g.DefineAsRegister(node);
1034
1035 Node* success_output = NodeProperties::FindProjection(node, 1);
1036 if (success_output) {
1037 outputs[output_count++] = g.DefineAsRegister(success_output);
1038 }
1039
1040 Emit(kMips64TruncUlD, output_count, outputs, 1, inputs);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001041}
1042
1043
1044void InstructionSelector::VisitChangeInt32ToInt64(Node* node) {
1045 Mips64OperandGenerator g(this);
1046 Emit(kMips64Shl, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0)),
1047 g.TempImmediate(0));
1048}
1049
1050
1051void InstructionSelector::VisitChangeUint32ToUint64(Node* node) {
1052 Mips64OperandGenerator g(this);
1053 Emit(kMips64Dext, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0)),
1054 g.TempImmediate(0), g.TempImmediate(32));
1055}
1056
1057
1058void InstructionSelector::VisitTruncateInt64ToInt32(Node* node) {
1059 Mips64OperandGenerator g(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001060 Node* value = node->InputAt(0);
1061 if (CanCover(node, value)) {
1062 switch (value->opcode()) {
1063 case IrOpcode::kWord64Sar: {
1064 Int64BinopMatcher m(value);
1065 if (m.right().IsInRange(32, 63)) {
1066 // After smi untagging no need for truncate. Combine sequence.
1067 Emit(kMips64Dsar, g.DefineSameAsFirst(node),
1068 g.UseRegister(m.left().node()),
1069 g.UseImmediate(m.right().node()));
1070 return;
1071 }
1072 break;
1073 }
1074 default:
1075 break;
1076 }
1077 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001078 Emit(kMips64Ext, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0)),
1079 g.TempImmediate(0), g.TempImmediate(32));
1080}
1081
1082
1083void InstructionSelector::VisitTruncateFloat64ToFloat32(Node* node) {
1084 Mips64OperandGenerator g(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001085 Node* value = node->InputAt(0);
1086 // Match TruncateFloat64ToFloat32(ChangeInt32ToFloat64) to corresponding
1087 // instruction.
1088 if (CanCover(node, value) &&
1089 value->opcode() == IrOpcode::kChangeInt32ToFloat64) {
1090 Emit(kMips64CvtSW, g.DefineAsRegister(node),
1091 g.UseRegister(value->InputAt(0)));
1092 return;
1093 }
1094 VisitRR(this, kMips64CvtSD, node);
1095}
1096
Ben Murdochc5610432016-08-08 18:44:38 +01001097void InstructionSelector::VisitTruncateFloat64ToWord32(Node* node) {
1098 VisitRR(this, kArchTruncateDoubleToI, node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001099}
1100
Ben Murdochc5610432016-08-08 18:44:38 +01001101void InstructionSelector::VisitRoundFloat64ToInt32(Node* node) {
1102 VisitRR(this, kMips64TruncWD, node);
1103}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001104
1105void InstructionSelector::VisitRoundInt64ToFloat32(Node* node) {
1106 VisitRR(this, kMips64CvtSL, node);
1107}
1108
1109
1110void InstructionSelector::VisitRoundInt64ToFloat64(Node* node) {
1111 VisitRR(this, kMips64CvtDL, node);
1112}
1113
1114
1115void InstructionSelector::VisitRoundUint64ToFloat32(Node* node) {
1116 VisitRR(this, kMips64CvtSUl, node);
1117}
1118
1119
1120void InstructionSelector::VisitRoundUint64ToFloat64(Node* node) {
1121 VisitRR(this, kMips64CvtDUl, node);
1122}
1123
1124
1125void InstructionSelector::VisitBitcastFloat32ToInt32(Node* node) {
1126 VisitRR(this, kMips64Float64ExtractLowWord32, node);
1127}
1128
1129
1130void InstructionSelector::VisitBitcastFloat64ToInt64(Node* node) {
1131 VisitRR(this, kMips64BitcastDL, node);
1132}
1133
1134
1135void InstructionSelector::VisitBitcastInt32ToFloat32(Node* node) {
1136 Mips64OperandGenerator g(this);
1137 Emit(kMips64Float64InsertLowWord32, g.DefineAsRegister(node),
1138 ImmediateOperand(ImmediateOperand::INLINE, 0),
1139 g.UseRegister(node->InputAt(0)));
1140}
1141
1142
1143void InstructionSelector::VisitBitcastInt64ToFloat64(Node* node) {
1144 VisitRR(this, kMips64BitcastLD, node);
1145}
1146
1147
1148void InstructionSelector::VisitFloat32Add(Node* node) {
1149 VisitRRR(this, kMips64AddS, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001150}
1151
1152
1153void InstructionSelector::VisitFloat64Add(Node* node) {
1154 VisitRRR(this, kMips64AddD, node);
1155}
1156
1157
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001158void InstructionSelector::VisitFloat32Sub(Node* node) {
1159 VisitRRR(this, kMips64SubS, node);
1160}
1161
Ben Murdochc5610432016-08-08 18:44:38 +01001162void InstructionSelector::VisitFloat32SubPreserveNan(Node* node) {
Ben Murdoch61f157c2016-09-16 13:49:30 +01001163 VisitRRR(this, kMips64SubPreserveNanS, node);
Ben Murdochc5610432016-08-08 18:44:38 +01001164}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001165
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001166void InstructionSelector::VisitFloat64Sub(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001167 Mips64OperandGenerator g(this);
1168 Float64BinopMatcher m(node);
1169 if (m.left().IsMinusZero() && m.right().IsFloat64RoundDown() &&
1170 CanCover(m.node(), m.right().node())) {
1171 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub &&
1172 CanCover(m.right().node(), m.right().InputAt(0))) {
1173 Float64BinopMatcher mright0(m.right().InputAt(0));
1174 if (mright0.left().IsMinusZero()) {
1175 Emit(kMips64Float64RoundUp, g.DefineAsRegister(node),
1176 g.UseRegister(mright0.right().node()));
1177 return;
1178 }
1179 }
1180 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001181 VisitRRR(this, kMips64SubD, node);
1182}
1183
Ben Murdochc5610432016-08-08 18:44:38 +01001184void InstructionSelector::VisitFloat64SubPreserveNan(Node* node) {
Ben Murdoch61f157c2016-09-16 13:49:30 +01001185 VisitRRR(this, kMips64SubPreserveNanD, node);
Ben Murdochc5610432016-08-08 18:44:38 +01001186}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001187
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001188void InstructionSelector::VisitFloat32Mul(Node* node) {
1189 VisitRRR(this, kMips64MulS, node);
1190}
1191
1192
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001193void InstructionSelector::VisitFloat64Mul(Node* node) {
1194 VisitRRR(this, kMips64MulD, node);
1195}
1196
1197
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001198void InstructionSelector::VisitFloat32Div(Node* node) {
1199 VisitRRR(this, kMips64DivS, node);
1200}
1201
1202
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001203void InstructionSelector::VisitFloat64Div(Node* node) {
1204 VisitRRR(this, kMips64DivD, node);
1205}
1206
1207
1208void InstructionSelector::VisitFloat64Mod(Node* node) {
1209 Mips64OperandGenerator g(this);
1210 Emit(kMips64ModD, g.DefineAsFixed(node, f0),
1211 g.UseFixed(node->InputAt(0), f12),
1212 g.UseFixed(node->InputAt(1), f14))->MarkAsCall();
1213}
1214
1215
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001216void InstructionSelector::VisitFloat32Max(Node* node) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001217 Mips64OperandGenerator g(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001218 if (kArchVariant == kMips64r6) {
1219 Emit(kMips64Float32Max, g.DefineAsRegister(node),
1220 g.UseUniqueRegister(node->InputAt(0)),
1221 g.UseUniqueRegister(node->InputAt(1)));
1222
1223 } else {
1224 // Reverse operands, and use same reg. for result and right operand.
1225 Emit(kMips64Float32Max, g.DefineSameAsFirst(node),
1226 g.UseRegister(node->InputAt(1)), g.UseRegister(node->InputAt(0)));
1227 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001228}
1229
1230
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001231void InstructionSelector::VisitFloat64Max(Node* node) {
1232 Mips64OperandGenerator g(this);
1233 if (kArchVariant == kMips64r6) {
1234 Emit(kMips64Float64Max, g.DefineAsRegister(node),
1235 g.UseUniqueRegister(node->InputAt(0)),
1236 g.UseUniqueRegister(node->InputAt(1)));
1237
1238 } else {
1239 // Reverse operands, and use same reg. for result and right operand.
1240 Emit(kMips64Float64Max, g.DefineSameAsFirst(node),
1241 g.UseRegister(node->InputAt(1)), g.UseRegister(node->InputAt(0)));
1242 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001243}
1244
1245
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001246void InstructionSelector::VisitFloat32Min(Node* node) {
1247 Mips64OperandGenerator g(this);
1248 if (kArchVariant == kMips64r6) {
1249 Emit(kMips64Float32Min, g.DefineAsRegister(node),
1250 g.UseUniqueRegister(node->InputAt(0)),
1251 g.UseUniqueRegister(node->InputAt(1)));
1252
1253 } else {
1254 // Reverse operands, and use same reg. for result and right operand.
1255 Emit(kMips64Float32Min, g.DefineSameAsFirst(node),
1256 g.UseRegister(node->InputAt(1)), g.UseRegister(node->InputAt(0)));
1257 }
1258}
1259
1260
1261void InstructionSelector::VisitFloat64Min(Node* node) {
1262 Mips64OperandGenerator g(this);
1263 if (kArchVariant == kMips64r6) {
1264 Emit(kMips64Float64Min, g.DefineAsRegister(node),
1265 g.UseUniqueRegister(node->InputAt(0)),
1266 g.UseUniqueRegister(node->InputAt(1)));
1267
1268 } else {
1269 // Reverse operands, and use same reg. for result and right operand.
1270 Emit(kMips64Float64Min, g.DefineSameAsFirst(node),
1271 g.UseRegister(node->InputAt(1)), g.UseRegister(node->InputAt(0)));
1272 }
1273}
1274
1275
1276void InstructionSelector::VisitFloat32Abs(Node* node) {
1277 VisitRR(this, kMips64AbsS, node);
1278}
1279
1280
1281void InstructionSelector::VisitFloat64Abs(Node* node) {
1282 VisitRR(this, kMips64AbsD, node);
1283}
1284
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001285void InstructionSelector::VisitFloat32Sqrt(Node* node) {
1286 VisitRR(this, kMips64SqrtS, node);
1287}
1288
1289
1290void InstructionSelector::VisitFloat64Sqrt(Node* node) {
1291 VisitRR(this, kMips64SqrtD, node);
1292}
1293
1294
1295void InstructionSelector::VisitFloat32RoundDown(Node* node) {
1296 VisitRR(this, kMips64Float32RoundDown, node);
1297}
1298
1299
1300void InstructionSelector::VisitFloat64RoundDown(Node* node) {
1301 VisitRR(this, kMips64Float64RoundDown, node);
1302}
1303
1304
1305void InstructionSelector::VisitFloat32RoundUp(Node* node) {
1306 VisitRR(this, kMips64Float32RoundUp, node);
1307}
1308
1309
1310void InstructionSelector::VisitFloat64RoundUp(Node* node) {
1311 VisitRR(this, kMips64Float64RoundUp, node);
1312}
1313
1314
1315void InstructionSelector::VisitFloat32RoundTruncate(Node* node) {
1316 VisitRR(this, kMips64Float32RoundTruncate, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001317}
1318
1319
1320void InstructionSelector::VisitFloat64RoundTruncate(Node* node) {
1321 VisitRR(this, kMips64Float64RoundTruncate, node);
1322}
1323
1324
1325void InstructionSelector::VisitFloat64RoundTiesAway(Node* node) {
1326 UNREACHABLE();
1327}
1328
1329
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001330void InstructionSelector::VisitFloat32RoundTiesEven(Node* node) {
1331 VisitRR(this, kMips64Float32RoundTiesEven, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001332}
1333
1334
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001335void InstructionSelector::VisitFloat64RoundTiesEven(Node* node) {
1336 VisitRR(this, kMips64Float64RoundTiesEven, node);
1337}
1338
Ben Murdoch61f157c2016-09-16 13:49:30 +01001339void InstructionSelector::VisitFloat32Neg(Node* node) { UNREACHABLE(); }
1340
1341void InstructionSelector::VisitFloat64Neg(Node* node) { UNREACHABLE(); }
1342
1343void InstructionSelector::VisitFloat64Ieee754Binop(Node* node,
1344 InstructionCode opcode) {
1345 Mips64OperandGenerator g(this);
1346 Emit(opcode, g.DefineAsFixed(node, f0), g.UseFixed(node->InputAt(0), f12),
1347 g.UseFixed(node->InputAt(1), f14))
1348 ->MarkAsCall();
1349}
1350
1351void InstructionSelector::VisitFloat64Ieee754Unop(Node* node,
1352 InstructionCode opcode) {
1353 Mips64OperandGenerator g(this);
1354 Emit(opcode, g.DefineAsFixed(node, f0), g.UseFixed(node->InputAt(0), f12))
1355 ->MarkAsCall();
1356}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001357
1358void InstructionSelector::EmitPrepareArguments(
1359 ZoneVector<PushParameter>* arguments, const CallDescriptor* descriptor,
1360 Node* node) {
1361 Mips64OperandGenerator g(this);
1362
1363 // Prepare for C function call.
1364 if (descriptor->IsCFunctionCall()) {
1365 Emit(kArchPrepareCallCFunction |
1366 MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
1367 0, nullptr, 0, nullptr);
1368
1369 // Poke any stack arguments.
1370 int slot = kCArgSlotCount;
1371 for (PushParameter input : (*arguments)) {
1372 Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(input.node()),
1373 g.TempImmediate(slot << kPointerSizeLog2));
1374 ++slot;
1375 }
1376 } else {
1377 int push_count = static_cast<int>(descriptor->StackParameterCount());
1378 if (push_count > 0) {
1379 Emit(kMips64StackClaim, g.NoOutput(),
1380 g.TempImmediate(push_count << kPointerSizeLog2));
1381 }
1382 for (size_t n = 0; n < arguments->size(); ++n) {
1383 PushParameter input = (*arguments)[n];
1384 if (input.node()) {
1385 Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(input.node()),
1386 g.TempImmediate(static_cast<int>(n << kPointerSizeLog2)));
1387 }
1388 }
1389 }
1390}
1391
1392
1393bool InstructionSelector::IsTailCallAddressImmediate() { return false; }
1394
Ben Murdochda12d292016-06-02 14:46:10 +01001395int InstructionSelector::GetTempsCountForTailCallFromJSFunction() { return 3; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001396
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001397void InstructionSelector::VisitCheckedLoad(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001398 CheckedLoadRepresentation load_rep = CheckedLoadRepresentationOf(node->op());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001399 Mips64OperandGenerator g(this);
1400 Node* const buffer = node->InputAt(0);
1401 Node* const offset = node->InputAt(1);
1402 Node* const length = node->InputAt(2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001403 ArchOpcode opcode = kArchNop;
1404 switch (load_rep.representation()) {
1405 case MachineRepresentation::kWord8:
1406 opcode = load_rep.IsSigned() ? kCheckedLoadInt8 : kCheckedLoadUint8;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001407 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001408 case MachineRepresentation::kWord16:
1409 opcode = load_rep.IsSigned() ? kCheckedLoadInt16 : kCheckedLoadUint16;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001410 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001411 case MachineRepresentation::kWord32:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001412 opcode = kCheckedLoadWord32;
1413 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001414 case MachineRepresentation::kWord64:
1415 opcode = kCheckedLoadWord64;
1416 break;
1417 case MachineRepresentation::kFloat32:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001418 opcode = kCheckedLoadFloat32;
1419 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001420 case MachineRepresentation::kFloat64:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001421 opcode = kCheckedLoadFloat64;
1422 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001423 case MachineRepresentation::kBit:
1424 case MachineRepresentation::kTagged:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001425 case MachineRepresentation::kSimd128:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001426 case MachineRepresentation::kNone:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001427 UNREACHABLE();
1428 return;
1429 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001430 InstructionOperand offset_operand = g.CanBeImmediate(offset, opcode)
1431 ? g.UseImmediate(offset)
1432 : g.UseRegister(offset);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001433
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001434 InstructionOperand length_operand = (!g.CanBeImmediate(offset, opcode))
1435 ? g.CanBeImmediate(length, opcode)
1436 ? g.UseImmediate(length)
1437 : g.UseRegister(length)
1438 : g.UseRegister(length);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001439
1440 Emit(opcode | AddressingModeField::encode(kMode_MRI),
1441 g.DefineAsRegister(node), offset_operand, length_operand,
1442 g.UseRegister(buffer));
1443}
1444
1445
1446void InstructionSelector::VisitCheckedStore(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001447 MachineRepresentation rep = CheckedStoreRepresentationOf(node->op());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001448 Mips64OperandGenerator g(this);
1449 Node* const buffer = node->InputAt(0);
1450 Node* const offset = node->InputAt(1);
1451 Node* const length = node->InputAt(2);
1452 Node* const value = node->InputAt(3);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001453 ArchOpcode opcode = kArchNop;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001454 switch (rep) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001455 case MachineRepresentation::kWord8:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001456 opcode = kCheckedStoreWord8;
1457 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001458 case MachineRepresentation::kWord16:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001459 opcode = kCheckedStoreWord16;
1460 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001461 case MachineRepresentation::kWord32:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001462 opcode = kCheckedStoreWord32;
1463 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001464 case MachineRepresentation::kWord64:
1465 opcode = kCheckedStoreWord64;
1466 break;
1467 case MachineRepresentation::kFloat32:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001468 opcode = kCheckedStoreFloat32;
1469 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001470 case MachineRepresentation::kFloat64:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001471 opcode = kCheckedStoreFloat64;
1472 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001473 case MachineRepresentation::kBit:
1474 case MachineRepresentation::kTagged:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001475 case MachineRepresentation::kSimd128:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001476 case MachineRepresentation::kNone:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001477 UNREACHABLE();
1478 return;
1479 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001480 InstructionOperand offset_operand = g.CanBeImmediate(offset, opcode)
1481 ? g.UseImmediate(offset)
1482 : g.UseRegister(offset);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001483
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001484 InstructionOperand length_operand = (!g.CanBeImmediate(offset, opcode))
1485 ? g.CanBeImmediate(length, opcode)
1486 ? g.UseImmediate(length)
1487 : g.UseRegister(length)
1488 : g.UseRegister(length);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001489
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001490 Emit(opcode | AddressingModeField::encode(kMode_MRI), g.NoOutput(),
1491 offset_operand, length_operand, g.UseRegister(value),
1492 g.UseRegister(buffer));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001493}
1494
1495
1496namespace {
1497
1498// Shared routine for multiple compare operations.
1499static void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001500 InstructionOperand left, InstructionOperand right,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001501 FlagsContinuation* cont) {
1502 Mips64OperandGenerator g(selector);
1503 opcode = cont->Encode(opcode);
1504 if (cont->IsBranch()) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001505 selector->Emit(opcode, g.NoOutput(), left, right,
1506 g.Label(cont->true_block()), g.Label(cont->false_block()));
Ben Murdochda12d292016-06-02 14:46:10 +01001507 } else if (cont->IsDeoptimize()) {
1508 selector->EmitDeoptimize(opcode, g.NoOutput(), left, right,
1509 cont->frame_state());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001510 } else {
1511 DCHECK(cont->IsSet());
1512 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right);
1513 }
1514}
1515
1516
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001517// Shared routine for multiple float32 compare operations.
1518void VisitFloat32Compare(InstructionSelector* selector, Node* node,
1519 FlagsContinuation* cont) {
1520 Mips64OperandGenerator g(selector);
1521 Float32BinopMatcher m(node);
1522 InstructionOperand lhs, rhs;
1523
1524 lhs = m.left().IsZero() ? g.UseImmediate(m.left().node())
1525 : g.UseRegister(m.left().node());
1526 rhs = m.right().IsZero() ? g.UseImmediate(m.right().node())
1527 : g.UseRegister(m.right().node());
1528 VisitCompare(selector, kMips64CmpS, lhs, rhs, cont);
1529}
1530
1531
1532// Shared routine for multiple float64 compare operations.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001533void VisitFloat64Compare(InstructionSelector* selector, Node* node,
1534 FlagsContinuation* cont) {
1535 Mips64OperandGenerator g(selector);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001536 Float64BinopMatcher m(node);
1537 InstructionOperand lhs, rhs;
1538
1539 lhs = m.left().IsZero() ? g.UseImmediate(m.left().node())
1540 : g.UseRegister(m.left().node());
1541 rhs = m.right().IsZero() ? g.UseImmediate(m.right().node())
1542 : g.UseRegister(m.right().node());
1543 VisitCompare(selector, kMips64CmpD, lhs, rhs, cont);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001544}
1545
1546
1547// Shared routine for multiple word compare operations.
1548void VisitWordCompare(InstructionSelector* selector, Node* node,
1549 InstructionCode opcode, FlagsContinuation* cont,
1550 bool commutative) {
1551 Mips64OperandGenerator g(selector);
1552 Node* left = node->InputAt(0);
1553 Node* right = node->InputAt(1);
1554
1555 // Match immediates on left or right side of comparison.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001556 if (g.CanBeImmediate(right, opcode)) {
1557 switch (cont->condition()) {
1558 case kEqual:
1559 case kNotEqual:
1560 if (cont->IsSet()) {
1561 VisitCompare(selector, opcode, g.UseRegister(left),
1562 g.UseImmediate(right), cont);
1563 } else {
1564 VisitCompare(selector, opcode, g.UseRegister(left),
1565 g.UseRegister(right), cont);
1566 }
1567 break;
1568 case kSignedLessThan:
1569 case kSignedGreaterThanOrEqual:
1570 case kUnsignedLessThan:
1571 case kUnsignedGreaterThanOrEqual:
1572 VisitCompare(selector, opcode, g.UseRegister(left),
1573 g.UseImmediate(right), cont);
1574 break;
1575 default:
1576 VisitCompare(selector, opcode, g.UseRegister(left),
1577 g.UseRegister(right), cont);
1578 }
1579 } else if (g.CanBeImmediate(left, opcode)) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001580 if (!commutative) cont->Commute();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001581 switch (cont->condition()) {
1582 case kEqual:
1583 case kNotEqual:
1584 if (cont->IsSet()) {
1585 VisitCompare(selector, opcode, g.UseRegister(right),
1586 g.UseImmediate(left), cont);
1587 } else {
1588 VisitCompare(selector, opcode, g.UseRegister(right),
1589 g.UseRegister(left), cont);
1590 }
1591 break;
1592 case kSignedLessThan:
1593 case kSignedGreaterThanOrEqual:
1594 case kUnsignedLessThan:
1595 case kUnsignedGreaterThanOrEqual:
1596 VisitCompare(selector, opcode, g.UseRegister(right),
1597 g.UseImmediate(left), cont);
1598 break;
1599 default:
1600 VisitCompare(selector, opcode, g.UseRegister(right),
1601 g.UseRegister(left), cont);
1602 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001603 } else {
1604 VisitCompare(selector, opcode, g.UseRegister(left), g.UseRegister(right),
1605 cont);
1606 }
1607}
1608
1609
1610void VisitWord32Compare(InstructionSelector* selector, Node* node,
1611 FlagsContinuation* cont) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001612 VisitWordCompare(selector, node, kMips64Cmp, cont, false);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001613}
1614
1615
1616void VisitWord64Compare(InstructionSelector* selector, Node* node,
1617 FlagsContinuation* cont) {
1618 VisitWordCompare(selector, node, kMips64Cmp, cont, false);
1619}
1620
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001621
1622
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001623void EmitWordCompareZero(InstructionSelector* selector, Node* value,
1624 FlagsContinuation* cont) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001625 Mips64OperandGenerator g(selector);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001626 InstructionCode opcode = cont->Encode(kMips64Cmp);
1627 InstructionOperand const value_operand = g.UseRegister(value);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001628 if (cont->IsBranch()) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001629 selector->Emit(opcode, g.NoOutput(), value_operand, g.TempImmediate(0),
1630 g.Label(cont->true_block()), g.Label(cont->false_block()));
Ben Murdochda12d292016-06-02 14:46:10 +01001631 } else if (cont->IsDeoptimize()) {
1632 selector->EmitDeoptimize(opcode, g.NoOutput(), value_operand,
1633 g.TempImmediate(0), cont->frame_state());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001634 } else {
1635 selector->Emit(opcode, g.DefineAsRegister(cont->result()), value_operand,
1636 g.TempImmediate(0));
1637 }
1638}
1639
1640
1641// Shared routine for word comparisons against zero.
1642void VisitWordCompareZero(InstructionSelector* selector, Node* user,
1643 Node* value, FlagsContinuation* cont) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001644 while (selector->CanCover(user, value)) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001645 switch (value->opcode()) {
1646 case IrOpcode::kWord32Equal: {
1647 // Combine with comparisons against 0 by simply inverting the
1648 // continuation.
1649 Int32BinopMatcher m(value);
1650 if (m.right().Is(0)) {
1651 user = value;
1652 value = m.left().node();
1653 cont->Negate();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001654 continue;
1655 }
1656 cont->OverwriteAndNegateIfEqual(kEqual);
1657 return VisitWord32Compare(selector, value, cont);
1658 }
1659 case IrOpcode::kInt32LessThan:
1660 cont->OverwriteAndNegateIfEqual(kSignedLessThan);
1661 return VisitWord32Compare(selector, value, cont);
1662 case IrOpcode::kInt32LessThanOrEqual:
1663 cont->OverwriteAndNegateIfEqual(kSignedLessThanOrEqual);
1664 return VisitWord32Compare(selector, value, cont);
1665 case IrOpcode::kUint32LessThan:
1666 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan);
1667 return VisitWord32Compare(selector, value, cont);
1668 case IrOpcode::kUint32LessThanOrEqual:
1669 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual);
1670 return VisitWord32Compare(selector, value, cont);
1671 case IrOpcode::kWord64Equal: {
1672 // Combine with comparisons against 0 by simply inverting the
1673 // continuation.
1674 Int64BinopMatcher m(value);
1675 if (m.right().Is(0)) {
1676 user = value;
1677 value = m.left().node();
1678 cont->Negate();
1679 continue;
1680 }
1681 cont->OverwriteAndNegateIfEqual(kEqual);
1682 return VisitWord64Compare(selector, value, cont);
1683 }
1684 case IrOpcode::kInt64LessThan:
1685 cont->OverwriteAndNegateIfEqual(kSignedLessThan);
1686 return VisitWord64Compare(selector, value, cont);
1687 case IrOpcode::kInt64LessThanOrEqual:
1688 cont->OverwriteAndNegateIfEqual(kSignedLessThanOrEqual);
1689 return VisitWord64Compare(selector, value, cont);
1690 case IrOpcode::kUint64LessThan:
1691 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan);
1692 return VisitWord64Compare(selector, value, cont);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001693 case IrOpcode::kUint64LessThanOrEqual:
1694 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual);
1695 return VisitWord64Compare(selector, value, cont);
1696 case IrOpcode::kFloat32Equal:
1697 cont->OverwriteAndNegateIfEqual(kEqual);
1698 return VisitFloat32Compare(selector, value, cont);
1699 case IrOpcode::kFloat32LessThan:
1700 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan);
1701 return VisitFloat32Compare(selector, value, cont);
1702 case IrOpcode::kFloat32LessThanOrEqual:
1703 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual);
1704 return VisitFloat32Compare(selector, value, cont);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001705 case IrOpcode::kFloat64Equal:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001706 cont->OverwriteAndNegateIfEqual(kEqual);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001707 return VisitFloat64Compare(selector, value, cont);
1708 case IrOpcode::kFloat64LessThan:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001709 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001710 return VisitFloat64Compare(selector, value, cont);
1711 case IrOpcode::kFloat64LessThanOrEqual:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001712 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001713 return VisitFloat64Compare(selector, value, cont);
1714 case IrOpcode::kProjection:
1715 // Check if this is the overflow output projection of an
1716 // <Operation>WithOverflow node.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001717 if (ProjectionIndexOf(value->op()) == 1u) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001718 // We cannot combine the <Operation>WithOverflow with this branch
1719 // unless the 0th projection (the use of the actual value of the
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001720 // <Operation> is either nullptr, which means there's no use of the
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001721 // actual value, or was already defined, which means it is scheduled
1722 // *AFTER* this branch).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001723 Node* const node = value->InputAt(0);
1724 Node* const result = NodeProperties::FindProjection(node, 0);
1725 if (result == nullptr || selector->IsDefined(result)) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001726 switch (node->opcode()) {
1727 case IrOpcode::kInt32AddWithOverflow:
1728 cont->OverwriteAndNegateIfEqual(kOverflow);
1729 return VisitBinop(selector, node, kMips64Dadd, cont);
1730 case IrOpcode::kInt32SubWithOverflow:
1731 cont->OverwriteAndNegateIfEqual(kOverflow);
1732 return VisitBinop(selector, node, kMips64Dsub, cont);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001733 case IrOpcode::kInt64AddWithOverflow:
1734 cont->OverwriteAndNegateIfEqual(kOverflow);
1735 return VisitBinop(selector, node, kMips64DaddOvf, cont);
1736 case IrOpcode::kInt64SubWithOverflow:
1737 cont->OverwriteAndNegateIfEqual(kOverflow);
1738 return VisitBinop(selector, node, kMips64DsubOvf, cont);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001739 default:
1740 break;
1741 }
1742 }
1743 }
1744 break;
1745 case IrOpcode::kWord32And:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001746 case IrOpcode::kWord64And:
1747 return VisitWordCompare(selector, value, kMips64Tst, cont, true);
1748 default:
1749 break;
1750 }
1751 break;
1752 }
1753
1754 // Continuation could not be combined with a compare, emit compare against 0.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001755 EmitWordCompareZero(selector, value, cont);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001756}
1757
Ben Murdochda12d292016-06-02 14:46:10 +01001758} // namespace
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001759
1760void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
1761 BasicBlock* fbranch) {
1762 FlagsContinuation cont(kNotEqual, tbranch, fbranch);
1763 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont);
1764}
1765
Ben Murdochda12d292016-06-02 14:46:10 +01001766void InstructionSelector::VisitDeoptimizeIf(Node* node) {
1767 FlagsContinuation cont =
1768 FlagsContinuation::ForDeoptimize(kNotEqual, node->InputAt(1));
1769 VisitWordCompareZero(this, node, node->InputAt(0), &cont);
1770}
1771
1772void InstructionSelector::VisitDeoptimizeUnless(Node* node) {
1773 FlagsContinuation cont =
1774 FlagsContinuation::ForDeoptimize(kEqual, node->InputAt(1));
1775 VisitWordCompareZero(this, node, node->InputAt(0), &cont);
1776}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001777
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001778void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) {
1779 Mips64OperandGenerator g(this);
1780 InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
1781
1782 // Emit either ArchTableSwitch or ArchLookupSwitch.
1783 size_t table_space_cost = 10 + 2 * sw.value_range;
1784 size_t table_time_cost = 3;
1785 size_t lookup_space_cost = 2 + 2 * sw.case_count;
1786 size_t lookup_time_cost = sw.case_count;
1787 if (sw.case_count > 0 &&
1788 table_space_cost + 3 * table_time_cost <=
1789 lookup_space_cost + 3 * lookup_time_cost &&
1790 sw.min_value > std::numeric_limits<int32_t>::min()) {
1791 InstructionOperand index_operand = value_operand;
1792 if (sw.min_value) {
1793 index_operand = g.TempRegister();
1794 Emit(kMips64Sub, index_operand, value_operand,
1795 g.TempImmediate(sw.min_value));
1796 }
1797 // Generate a table lookup.
1798 return EmitTableSwitch(sw, index_operand);
1799 }
1800
1801 // Generate a sequence of conditional jumps.
1802 return EmitLookupSwitch(sw, value_operand);
1803}
1804
1805
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001806void InstructionSelector::VisitWord32Equal(Node* const node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001807 FlagsContinuation cont = FlagsContinuation::ForSet(kEqual, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001808 Int32BinopMatcher m(node);
1809 if (m.right().Is(0)) {
1810 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont);
1811 }
1812
1813 VisitWord32Compare(this, node, &cont);
1814}
1815
1816
1817void InstructionSelector::VisitInt32LessThan(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001818 FlagsContinuation cont = FlagsContinuation::ForSet(kSignedLessThan, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001819 VisitWord32Compare(this, node, &cont);
1820}
1821
1822
1823void InstructionSelector::VisitInt32LessThanOrEqual(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001824 FlagsContinuation cont =
1825 FlagsContinuation::ForSet(kSignedLessThanOrEqual, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001826 VisitWord32Compare(this, node, &cont);
1827}
1828
1829
1830void InstructionSelector::VisitUint32LessThan(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001831 FlagsContinuation cont = FlagsContinuation::ForSet(kUnsignedLessThan, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001832 VisitWord32Compare(this, node, &cont);
1833}
1834
1835
1836void InstructionSelector::VisitUint32LessThanOrEqual(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001837 FlagsContinuation cont =
1838 FlagsContinuation::ForSet(kUnsignedLessThanOrEqual, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001839 VisitWord32Compare(this, node, &cont);
1840}
1841
1842
1843void InstructionSelector::VisitInt32AddWithOverflow(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001844 if (Node* ovf = NodeProperties::FindProjection(node, 1)) {
Ben Murdochda12d292016-06-02 14:46:10 +01001845 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001846 return VisitBinop(this, node, kMips64Dadd, &cont);
1847 }
1848 FlagsContinuation cont;
1849 VisitBinop(this, node, kMips64Dadd, &cont);
1850}
1851
1852
1853void InstructionSelector::VisitInt32SubWithOverflow(Node* node) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001854 if (Node* ovf = NodeProperties::FindProjection(node, 1)) {
Ben Murdochda12d292016-06-02 14:46:10 +01001855 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001856 return VisitBinop(this, node, kMips64Dsub, &cont);
1857 }
1858 FlagsContinuation cont;
1859 VisitBinop(this, node, kMips64Dsub, &cont);
1860}
1861
1862
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001863void InstructionSelector::VisitInt64AddWithOverflow(Node* node) {
1864 if (Node* ovf = NodeProperties::FindProjection(node, 1)) {
Ben Murdochda12d292016-06-02 14:46:10 +01001865 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001866 return VisitBinop(this, node, kMips64DaddOvf, &cont);
1867 }
1868 FlagsContinuation cont;
1869 VisitBinop(this, node, kMips64DaddOvf, &cont);
1870}
1871
1872
1873void InstructionSelector::VisitInt64SubWithOverflow(Node* node) {
1874 if (Node* ovf = NodeProperties::FindProjection(node, 1)) {
Ben Murdochda12d292016-06-02 14:46:10 +01001875 FlagsContinuation cont = FlagsContinuation::ForSet(kOverflow, ovf);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001876 return VisitBinop(this, node, kMips64DsubOvf, &cont);
1877 }
1878 FlagsContinuation cont;
1879 VisitBinop(this, node, kMips64DsubOvf, &cont);
1880}
1881
1882
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001883void InstructionSelector::VisitWord64Equal(Node* const node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001884 FlagsContinuation cont = FlagsContinuation::ForSet(kEqual, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001885 Int64BinopMatcher m(node);
1886 if (m.right().Is(0)) {
1887 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont);
1888 }
1889
1890 VisitWord64Compare(this, node, &cont);
1891}
1892
1893
1894void InstructionSelector::VisitInt64LessThan(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001895 FlagsContinuation cont = FlagsContinuation::ForSet(kSignedLessThan, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001896 VisitWord64Compare(this, node, &cont);
1897}
1898
1899
1900void InstructionSelector::VisitInt64LessThanOrEqual(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001901 FlagsContinuation cont =
1902 FlagsContinuation::ForSet(kSignedLessThanOrEqual, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001903 VisitWord64Compare(this, node, &cont);
1904}
1905
1906
1907void InstructionSelector::VisitUint64LessThan(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001908 FlagsContinuation cont = FlagsContinuation::ForSet(kUnsignedLessThan, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001909 VisitWord64Compare(this, node, &cont);
1910}
1911
1912
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001913void InstructionSelector::VisitUint64LessThanOrEqual(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001914 FlagsContinuation cont =
1915 FlagsContinuation::ForSet(kUnsignedLessThanOrEqual, node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001916 VisitWord64Compare(this, node, &cont);
1917}
1918
1919
1920void InstructionSelector::VisitFloat32Equal(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001921 FlagsContinuation cont = FlagsContinuation::ForSet(kEqual, node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001922 VisitFloat32Compare(this, node, &cont);
1923}
1924
1925
1926void InstructionSelector::VisitFloat32LessThan(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001927 FlagsContinuation cont = FlagsContinuation::ForSet(kUnsignedLessThan, node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001928 VisitFloat32Compare(this, node, &cont);
1929}
1930
1931
1932void InstructionSelector::VisitFloat32LessThanOrEqual(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001933 FlagsContinuation cont =
1934 FlagsContinuation::ForSet(kUnsignedLessThanOrEqual, node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001935 VisitFloat32Compare(this, node, &cont);
1936}
1937
1938
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001939void InstructionSelector::VisitFloat64Equal(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001940 FlagsContinuation cont = FlagsContinuation::ForSet(kEqual, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001941 VisitFloat64Compare(this, node, &cont);
1942}
1943
1944
1945void InstructionSelector::VisitFloat64LessThan(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001946 FlagsContinuation cont = FlagsContinuation::ForSet(kUnsignedLessThan, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001947 VisitFloat64Compare(this, node, &cont);
1948}
1949
1950
1951void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) {
Ben Murdochda12d292016-06-02 14:46:10 +01001952 FlagsContinuation cont =
1953 FlagsContinuation::ForSet(kUnsignedLessThanOrEqual, node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001954 VisitFloat64Compare(this, node, &cont);
1955}
1956
1957
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001958void InstructionSelector::VisitFloat64ExtractLowWord32(Node* node) {
1959 VisitRR(this, kMips64Float64ExtractLowWord32, node);
1960}
1961
1962
1963void InstructionSelector::VisitFloat64ExtractHighWord32(Node* node) {
1964 VisitRR(this, kMips64Float64ExtractHighWord32, node);
1965}
1966
Ben Murdoch61f157c2016-09-16 13:49:30 +01001967void InstructionSelector::VisitFloat64SilenceNaN(Node* node) {
1968 VisitRR(this, kMips64Float64SilenceNaN, node);
1969}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001970
1971void InstructionSelector::VisitFloat64InsertLowWord32(Node* node) {
1972 Mips64OperandGenerator g(this);
1973 Node* left = node->InputAt(0);
1974 Node* right = node->InputAt(1);
1975 Emit(kMips64Float64InsertLowWord32, g.DefineSameAsFirst(node),
1976 g.UseRegister(left), g.UseRegister(right));
1977}
1978
1979
1980void InstructionSelector::VisitFloat64InsertHighWord32(Node* node) {
1981 Mips64OperandGenerator g(this);
1982 Node* left = node->InputAt(0);
1983 Node* right = node->InputAt(1);
1984 Emit(kMips64Float64InsertHighWord32, g.DefineSameAsFirst(node),
1985 g.UseRegister(left), g.UseRegister(right));
1986}
1987
Ben Murdochc5610432016-08-08 18:44:38 +01001988void InstructionSelector::VisitAtomicLoad(Node* node) {
1989 LoadRepresentation load_rep = LoadRepresentationOf(node->op());
1990 Mips64OperandGenerator g(this);
1991 Node* base = node->InputAt(0);
1992 Node* index = node->InputAt(1);
1993 ArchOpcode opcode = kArchNop;
1994 switch (load_rep.representation()) {
1995 case MachineRepresentation::kWord8:
1996 opcode = load_rep.IsSigned() ? kAtomicLoadInt8 : kAtomicLoadUint8;
1997 break;
1998 case MachineRepresentation::kWord16:
1999 opcode = load_rep.IsSigned() ? kAtomicLoadInt16 : kAtomicLoadUint16;
2000 break;
2001 case MachineRepresentation::kWord32:
2002 opcode = kAtomicLoadWord32;
2003 break;
2004 default:
2005 UNREACHABLE();
2006 return;
2007 }
2008 if (g.CanBeImmediate(index, opcode)) {
2009 Emit(opcode | AddressingModeField::encode(kMode_MRI),
2010 g.DefineAsRegister(node), g.UseRegister(base), g.UseImmediate(index));
2011 } else {
2012 InstructionOperand addr_reg = g.TempRegister();
2013 Emit(kMips64Dadd | AddressingModeField::encode(kMode_None), addr_reg,
2014 g.UseRegister(index), g.UseRegister(base));
2015 // Emit desired load opcode, using temp addr_reg.
2016 Emit(opcode | AddressingModeField::encode(kMode_MRI),
2017 g.DefineAsRegister(node), addr_reg, g.TempImmediate(0));
2018 }
2019}
2020
2021void InstructionSelector::VisitAtomicStore(Node* node) {
2022 MachineRepresentation rep = AtomicStoreRepresentationOf(node->op());
2023 Mips64OperandGenerator g(this);
2024 Node* base = node->InputAt(0);
2025 Node* index = node->InputAt(1);
2026 Node* value = node->InputAt(2);
2027 ArchOpcode opcode = kArchNop;
2028 switch (rep) {
2029 case MachineRepresentation::kWord8:
2030 opcode = kAtomicStoreWord8;
2031 break;
2032 case MachineRepresentation::kWord16:
2033 opcode = kAtomicStoreWord16;
2034 break;
2035 case MachineRepresentation::kWord32:
2036 opcode = kAtomicStoreWord32;
2037 break;
2038 default:
2039 UNREACHABLE();
2040 return;
2041 }
2042
2043 if (g.CanBeImmediate(index, opcode)) {
2044 Emit(opcode | AddressingModeField::encode(kMode_MRI), g.NoOutput(),
2045 g.UseRegister(base), g.UseImmediate(index), g.UseRegister(value));
2046 } else {
2047 InstructionOperand addr_reg = g.TempRegister();
2048 Emit(kMips64Dadd | AddressingModeField::encode(kMode_None), addr_reg,
2049 g.UseRegister(index), g.UseRegister(base));
2050 // Emit desired store opcode, using temp addr_reg.
2051 Emit(opcode | AddressingModeField::encode(kMode_MRI), g.NoOutput(),
2052 addr_reg, g.TempImmediate(0), g.UseRegister(value));
2053 }
2054}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002055
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002056// static
2057MachineOperatorBuilder::Flags
2058InstructionSelector::SupportedMachineOperatorFlags() {
Ben Murdoch097c5b22016-05-18 11:27:45 +01002059 return MachineOperatorBuilder::kWord32Ctz |
2060 MachineOperatorBuilder::kWord64Ctz |
2061 MachineOperatorBuilder::kWord32Popcnt |
2062 MachineOperatorBuilder::kWord64Popcnt |
2063 MachineOperatorBuilder::kWord32ShiftIsSafe |
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002064 MachineOperatorBuilder::kInt32DivIsSafe |
2065 MachineOperatorBuilder::kUint32DivIsSafe |
2066 MachineOperatorBuilder::kFloat64Min |
2067 MachineOperatorBuilder::kFloat64Max |
2068 MachineOperatorBuilder::kFloat32Min |
2069 MachineOperatorBuilder::kFloat32Max |
2070 MachineOperatorBuilder::kFloat64RoundDown |
2071 MachineOperatorBuilder::kFloat32RoundDown |
2072 MachineOperatorBuilder::kFloat64RoundUp |
2073 MachineOperatorBuilder::kFloat32RoundUp |
2074 MachineOperatorBuilder::kFloat64RoundTruncate |
2075 MachineOperatorBuilder::kFloat32RoundTruncate |
2076 MachineOperatorBuilder::kFloat64RoundTiesEven |
2077 MachineOperatorBuilder::kFloat32RoundTiesEven;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002078}
2079
Ben Murdoch61f157c2016-09-16 13:49:30 +01002080// static
2081MachineOperatorBuilder::AlignmentRequirements
2082InstructionSelector::AlignmentRequirements() {
2083 if (kArchVariant == kMips64r6) {
2084 return MachineOperatorBuilder::AlignmentRequirements::
2085 FullUnalignedAccessSupport();
2086 } else {
2087 DCHECK(kArchVariant == kMips64r2);
2088 return MachineOperatorBuilder::AlignmentRequirements::
2089 NoUnalignedAccessSupport();
2090 }
2091}
2092
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002093} // namespace compiler
2094} // namespace internal
2095} // namespace v8