1958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Copyright 2014 the V8 project authors. All rights reserved.
2958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Use of this source code is governed by a BSD-style license that can be
3958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// found in the LICENSE file
4958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
5958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier#include "test/unittests/compiler/instruction-selector-unittest.h"
6958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
7958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniernamespace v8 {
8958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniernamespace internal {
9958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniernamespace compiler {
10958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
11958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniernamespace {
12958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertemplate <typename T>
13958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstruct MachInst {
14958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  T constructor;
15958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const char* constructor_name;
16958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ArchOpcode arch_opcode;
17958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  MachineType machine_type;
18958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier};
19958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
20958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertemplate <typename T>
21958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstd::ostream& operator<<(std::ostream& os, const MachInst<T>& mi) {
22958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  return os << mi.constructor_name;
23958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
24958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
25958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef MachInst<Node* (RawMachineAssembler::*)(Node*)> MachInst1;
26958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef MachInst<Node* (RawMachineAssembler::*)(Node*, Node*)> MachInst2;
27958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
28958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
29958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// To avoid duplicated code IntCmp helper structure
30958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// is created. It contains MachInst2 with two nodes and expected_size
31958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// because different cmp instructions have different size.
32958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstruct IntCmp {
33958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  MachInst2 mi;
34958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  uint32_t expected_size;
35958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier};
36958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
37958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstruct FPCmp {
38958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  MachInst2 mi;
39958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  FlagsCondition cond;
40958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier};
41958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
42958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst FPCmp kFPCmpInstructions[] = {
43958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::Float64Equal, "Float64Equal", kMips64CmpD,
44014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Float64()},
45014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     kEqual},
46958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::Float64LessThan, "Float64LessThan", kMips64CmpD,
47014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Float64()},
48014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     kUnsignedLessThan},
49958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::Float64LessThanOrEqual, "Float64LessThanOrEqual",
50014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64CmpD, MachineType::Float64()},
51014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     kUnsignedLessThanOrEqual},
52958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::Float64GreaterThan, "Float64GreaterThan",
53014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64CmpD, MachineType::Float64()},
54014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     kUnsignedLessThan},
55958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::Float64GreaterThanOrEqual,
56014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      "Float64GreaterThanOrEqual", kMips64CmpD, MachineType::Float64()},
57014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     kUnsignedLessThanOrEqual}};
58958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
59958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstruct Conversion {
60958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  // The machine_type field in MachInst1 represents the destination type.
61958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  MachInst1 mi;
62958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  MachineType src_machine_type;
63958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier};
64958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
65958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
66958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
67958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Logical instructions.
68958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
69958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
70958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
71958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MachInst2 kLogicalInstructions[] = {
72014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word32And, "Word32And", kMips64And,
73014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
74014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word64And, "Word64And", kMips64And,
75014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()},
76014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word32Or, "Word32Or", kMips64Or,
77014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
78014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word64Or, "Word64Or", kMips64Or,
79014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()},
80014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word32Xor, "Word32Xor", kMips64Xor,
81014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
82014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word64Xor, "Word64Xor", kMips64Xor,
83014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()}};
84958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
85958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
86958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
87958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Shift instructions.
88958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
89958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
90958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
91958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MachInst2 kShiftInstructions[] = {
92014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word32Shl, "Word32Shl", kMips64Shl,
93014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
94014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word64Shl, "Word64Shl", kMips64Dshl,
95014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()},
96014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word32Shr, "Word32Shr", kMips64Shr,
97014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
98014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word64Shr, "Word64Shr", kMips64Dshr,
99014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()},
100014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word32Sar, "Word32Sar", kMips64Sar,
101014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
102014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word64Sar, "Word64Sar", kMips64Dsar,
103014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()},
104014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word32Ror, "Word32Ror", kMips64Ror,
105014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
106014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Word64Ror, "Word64Ror", kMips64Dror,
107014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()}};
108958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
109958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
110958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
111958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// MUL/DIV instructions.
112958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
113958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
114958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
115958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MachInst2 kMulDivInstructions[] = {
116014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int32Mul, "Int32Mul", kMips64Mul,
117014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
118014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int32Div, "Int32Div", kMips64Div,
119014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
120014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Uint32Div, "Uint32Div", kMips64DivU,
121014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Uint32()},
122014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int64Mul, "Int64Mul", kMips64Dmul,
123014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()},
124014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int64Div, "Int64Div", kMips64Ddiv,
125014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()},
126014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Uint64Div, "Uint64Div", kMips64DdivU,
127014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Uint64()},
128014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Float64Mul, "Float64Mul", kMips64MulD,
129014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()},
130958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {&RawMachineAssembler::Float64Div, "Float64Div", kMips64DivD,
131014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()}};
132958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
133958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
134958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
135958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// MOD instructions.
136958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
137958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
138958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
139958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MachInst2 kModInstructions[] = {
140014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int32Mod, "Int32Mod", kMips64Mod,
141014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
142014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Uint32Mod, "Uint32Mod", kMips64ModU,
143014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
144958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {&RawMachineAssembler::Float64Mod, "Float64Mod", kMips64ModD,
145014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()}};
146958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
147958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
148958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
149958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Arithmetic FPU instructions.
150958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
151958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
152958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
153958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MachInst2 kFPArithInstructions[] = {
154014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Float64Add, "Float64Add", kMips64AddD,
155014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()},
156958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {&RawMachineAssembler::Float64Sub, "Float64Sub", kMips64SubD,
157014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()}};
158958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
159958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
160958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
161958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// IntArithTest instructions, two nodes.
162958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
163958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
164958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
165958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MachInst2 kAddSubInstructions[] = {
166014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int32Add, "Int32Add", kMips64Add,
167014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
168014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int64Add, "Int64Add", kMips64Dadd,
169014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()},
170014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int32Sub, "Int32Sub", kMips64Sub,
171014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
172014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int64Sub, "Int64Sub", kMips64Dsub,
173014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()}};
174958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
175958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
176958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
177958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// IntArithTest instructions, one node.
178958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
179958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
180958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
181958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MachInst1 kAddSubOneInstructions[] = {
182014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int32Neg, "Int32Neg", kMips64Sub,
183014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
184014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {&RawMachineAssembler::Int64Neg, "Int64Neg", kMips64Dsub,
185014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int64()}};
186958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
187958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
188958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
189958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Arithmetic compare instructions.
190958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
191958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
192958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
193958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst IntCmp kCmpInstructions[] = {
194014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::WordEqual, "WordEqual", kMips64Cmp,
195014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Int64()},
196958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
197958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::WordNotEqual, "WordNotEqual", kMips64Cmp,
198014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Int64()},
199958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
200014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Word32Equal, "Word32Equal", kMips64Cmp,
201014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Int32()},
202958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
203014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Word32NotEqual, "Word32NotEqual", kMips64Cmp,
204014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Int32()},
205958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
206014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Int32LessThan, "Int32LessThan", kMips64Cmp,
207014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Int32()},
208958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
209958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::Int32LessThanOrEqual, "Int32LessThanOrEqual",
210014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64Cmp, MachineType::Int32()},
211958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
212014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Int32GreaterThan, "Int32GreaterThan", kMips64Cmp,
213014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Int32()},
214958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
215958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::Int32GreaterThanOrEqual, "Int32GreaterThanOrEqual",
216014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64Cmp, MachineType::Int32()},
217958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
218014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Uint32LessThan, "Uint32LessThan", kMips64Cmp,
219014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Uint32()},
220958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U},
221958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::Uint32LessThanOrEqual, "Uint32LessThanOrEqual",
222014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64Cmp, MachineType::Uint32()},
223958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     1U}};
224958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
225958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
226958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
227958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Conversion instructions.
228958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
229958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
230958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst Conversion kConversionInstructions[] = {
231958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // Conversion instructions are related to machine_operator.h:
232958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // FPU conversions:
233958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // Convert representation of integers between float64 and int32/uint32.
234958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // The precise rounding mode and handling of out of range inputs are *not*
235958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // defined for these operators, since they are intended only for use with
236958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // integers.
237958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // mips instructions:
238958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // mtc1, cvt.d.w
239958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::ChangeInt32ToFloat64, "ChangeInt32ToFloat64",
240014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64CvtDW, MachineType::Float64()},
241014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
242958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
243958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // mips instructions:
244958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // cvt.d.uw
245958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::ChangeUint32ToFloat64, "ChangeUint32ToFloat64",
246014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64CvtDUw, MachineType::Float64()},
247014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
248958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
249958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // mips instructions:
250958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // mfc1, trunc double to word, for more details look at mips macro
251958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // asm and mips asm file
252958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::ChangeFloat64ToInt32, "ChangeFloat64ToInt32",
253014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64TruncWD, MachineType::Float64()},
254014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()},
255958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
256958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // mips instructions:
257958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // trunc double to unsigned word, for more details look at mips macro
258958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // asm and mips asm file
259958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    {{&RawMachineAssembler::ChangeFloat64ToUint32, "ChangeFloat64ToUint32",
260014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64TruncUwD, MachineType::Float64()},
261014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Int32()}};
262014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
263014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochconst Conversion kFloat64RoundInstructions[] = {
264014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Float64RoundUp, "Float64RoundUp", kMips64CeilWD,
265014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Int32()},
266014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()},
267014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Float64RoundDown, "Float64RoundDown",
268014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64FloorWD, MachineType::Int32()},
269014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()},
270014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Float64RoundTiesEven, "Float64RoundTiesEven",
271014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64RoundWD, MachineType::Int32()},
272014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()},
273014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Float64RoundTruncate, "Float64RoundTruncate",
274014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64TruncWD, MachineType::Int32()},
275014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float64()}};
276014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
277014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochconst Conversion kFloat32RoundInstructions[] = {
278014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Float32RoundUp, "Float32RoundUp", kMips64CeilWS,
279014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      MachineType::Int32()},
280014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float32()},
281014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Float32RoundDown, "Float32RoundDown",
282014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64FloorWS, MachineType::Int32()},
283014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float32()},
284014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Float32RoundTiesEven, "Float32RoundTiesEven",
285014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64RoundWS, MachineType::Int32()},
286014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float32()},
287014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {{&RawMachineAssembler::Float32RoundTruncate, "Float32RoundTruncate",
288014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      kMips64TruncWS, MachineType::Int32()},
289014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch     MachineType::Float32()}};
290958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
291958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}  // namespace
292958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
293958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
294958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<FPCmp> InstructionSelectorFPCmpTest;
295958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
296958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorFPCmpTest, Parameter) {
297958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const FPCmp cmp = GetParam();
298014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Int32(), cmp.mi.machine_type,
299014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                  cmp.mi.machine_type);
300958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*cmp.mi.constructor)(m.Parameter(0), m.Parameter(1)));
301958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
302958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
303958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(cmp.mi.arch_opcode, s[0]->arch_opcode());
304958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(2U, s[0]->InputCount());
305958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
306958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(kFlags_set, s[0]->flags_mode());
307958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(cmp.cond, s[0]->flags_condition());
308958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
309958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
310958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFPCmpTest,
311958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kFPCmpInstructions));
312958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
313958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
314958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Arithmetic compare instructions integers
315958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
316958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<IntCmp> InstructionSelectorCmpTest;
317958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
318958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
319958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorCmpTest, Parameter) {
320958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const IntCmp cmp = GetParam();
321958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachineType type = cmp.mi.machine_type;
322958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  StreamBuilder m(this, type, type, type);
323958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*cmp.mi.constructor)(m.Parameter(0), m.Parameter(1)));
324958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
325958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(cmp.expected_size, s.size());
326958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(cmp.mi.arch_opcode, s[0]->arch_opcode());
327958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(2U, s[0]->InputCount());
328958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
329958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
330958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
331958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorCmpTest,
332958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kCmpInstructions));
333958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
334958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
335958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Shift instructions.
336958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
337958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MachInst2>
338958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorShiftTest;
339958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
340958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorShiftTest, Immediate) {
341958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachInst2 dpi = GetParam();
342958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachineType type = dpi.machine_type;
343014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, imm, 0,
344014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                  ((1 << ElementSizeLog2Of(type.representation())) * 8) - 1) {
345958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    StreamBuilder m(this, type, type);
346958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return((m.*dpi.constructor)(m.Parameter(0), m.Int32Constant(imm)));
347958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
348958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(1U, s.size());
349958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
350958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(2U, s[0]->InputCount());
351958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate());
352958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1)));
353958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(1U, s[0]->OutputCount());
354958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
355958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
356958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
357958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorShiftTest,
358958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kShiftInstructions));
359958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
360014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word32ShrWithWord32AndWithImmediate) {
361014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // The available shift operand range is `0 <= imm < 32`, but we also test
362014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // that immediates outside this range are handled properly (modulo-32).
363014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, -32, 63) {
364014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int32_t lsb = shift & 0x1f;
365014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    TRACED_FORRANGE(int32_t, width, 1, 32 - lsb) {
366014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint32_t jnk = rng()->NextInt();
367014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      jnk = (lsb > 0) ? (jnk >> (32 - lsb)) : 0;
368014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint32_t msk = ((0xffffffffu >> (32 - width)) << lsb) | jnk;
369014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
370014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      m.Return(m.Word32Shr(m.Word32And(m.Parameter(0), m.Int32Constant(msk)),
371014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                           m.Int32Constant(shift)));
372014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      Stream s = m.Build();
373014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(1U, s.size());
374014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(kMips64Ext, s[0]->arch_opcode());
375014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(3U, s[0]->InputCount());
376014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1)));
377014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(width, s.ToInt32(s[0]->InputAt(2)));
378014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
379014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
380014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, -32, 63) {
381014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int32_t lsb = shift & 0x1f;
382014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    TRACED_FORRANGE(int32_t, width, 1, 32 - lsb) {
383014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint32_t jnk = rng()->NextInt();
384014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      jnk = (lsb > 0) ? (jnk >> (32 - lsb)) : 0;
385014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint32_t msk = ((0xffffffffu >> (32 - width)) << lsb) | jnk;
386014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
387014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      m.Return(m.Word32Shr(m.Word32And(m.Int32Constant(msk), m.Parameter(0)),
388014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                           m.Int32Constant(shift)));
389014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      Stream s = m.Build();
390014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(1U, s.size());
391014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(kMips64Ext, s[0]->arch_opcode());
392014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(3U, s[0]->InputCount());
393014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1)));
394014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(width, s.ToInt32(s[0]->InputAt(2)));
395014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
396014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
397014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
398014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
399014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
400014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word64ShrWithWord64AndWithImmediate) {
401014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // The available shift operand range is `0 <= imm < 64`, but we also test
402014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // that immediates outside this range are handled properly (modulo-64).
403014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, -64, 127) {
404014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int32_t lsb = shift & 0x3f;
405014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    TRACED_FORRANGE(int32_t, width, 1, 64 - lsb) {
406014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint64_t jnk = rng()->NextInt64();
407014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      jnk = (lsb > 0) ? (jnk >> (64 - lsb)) : 0;
408014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint64_t msk =
409014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch          ((V8_UINT64_C(0xffffffffffffffff) >> (64 - width)) << lsb) | jnk;
410014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
411014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      m.Return(m.Word64Shr(m.Word64And(m.Parameter(0), m.Int64Constant(msk)),
412014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                           m.Int64Constant(shift)));
413014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      Stream s = m.Build();
414014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(1U, s.size());
415014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(kMips64Dext, s[0]->arch_opcode());
416014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(3U, s[0]->InputCount());
417014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1)));
418014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(width, s.ToInt64(s[0]->InputAt(2)));
419014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
420014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
421014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, -64, 127) {
422014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int32_t lsb = shift & 0x3f;
423014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    TRACED_FORRANGE(int32_t, width, 1, 64 - lsb) {
424014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint64_t jnk = rng()->NextInt64();
425014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      jnk = (lsb > 0) ? (jnk >> (64 - lsb)) : 0;
426014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint64_t msk =
427014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch          ((V8_UINT64_C(0xffffffffffffffff) >> (64 - width)) << lsb) | jnk;
428014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
429014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      m.Return(m.Word64Shr(m.Word64And(m.Int64Constant(msk), m.Parameter(0)),
430014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                           m.Int64Constant(shift)));
431014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      Stream s = m.Build();
432014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(1U, s.size());
433014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(kMips64Dext, s[0]->arch_opcode());
434014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(3U, s[0]->InputCount());
435014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1)));
436014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(width, s.ToInt64(s[0]->InputAt(2)));
437014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
438014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
439014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
440014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
441014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
442014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word32AndToClearBits) {
443014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, 1, 31) {
444014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int32_t mask = ~((1 << shift) - 1);
445014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
446014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word32And(m.Parameter(0), m.Int32Constant(mask)));
447014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
448014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
449014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Ins, s[0]->arch_opcode());
450014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(3U, s[0]->InputCount());
451014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(0, s.ToInt32(s[0]->InputAt(1)));
452014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(shift, s.ToInt32(s[0]->InputAt(2)));
453014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
454014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, 1, 31) {
455014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int32_t mask = ~((1 << shift) - 1);
456014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
457014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word32And(m.Int32Constant(mask), m.Parameter(0)));
458014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
459014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
460014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Ins, s[0]->arch_opcode());
461014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(3U, s[0]->InputCount());
462014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(0, s.ToInt32(s[0]->InputAt(1)));
463014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(shift, s.ToInt32(s[0]->InputAt(2)));
464014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
465014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
466014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
467014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
468014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word64AndToClearBits) {
469014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, 1, 31) {
470014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int64_t mask = ~((1 << shift) - 1);
471014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
472014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word64And(m.Parameter(0), m.Int64Constant(mask)));
473014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
474014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
475014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Dins, s[0]->arch_opcode());
476014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(3U, s[0]->InputCount());
477014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(0, s.ToInt32(s[0]->InputAt(1)));
478014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(shift, s.ToInt32(s[0]->InputAt(2)));
479014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
480014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, 1, 31) {
481014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int64_t mask = ~((1 << shift) - 1);
482014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
483014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word64And(m.Int64Constant(mask), m.Parameter(0)));
484014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
485014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
486014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Dins, s[0]->arch_opcode());
487014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(3U, s[0]->InputCount());
488014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(0, s.ToInt32(s[0]->InputAt(1)));
489014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(shift, s.ToInt32(s[0]->InputAt(2)));
490014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
491014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
492014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
493014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
494958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
495958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Logical instructions.
496958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
497958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MachInst2>
498958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorLogicalTest;
499958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
500958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
501958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorLogicalTest, Parameter) {
502958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachInst2 dpi = GetParam();
503958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachineType type = dpi.machine_type;
504958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  StreamBuilder m(this, type, type, type);
505958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
506958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
507958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
508958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
509958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(2U, s[0]->InputCount());
510958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
511958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
512958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
513958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorLogicalTest,
514958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kLogicalInstructions));
515958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
516014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
517014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word64XorMinusOneWithParameter) {
518014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
519014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
520014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word64Xor(m.Parameter(0), m.Int64Constant(-1)));
521014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
522014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
523014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Nor, s[0]->arch_opcode());
524014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(2U, s[0]->InputCount());
525014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
526014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
527014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
528014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
529014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word64Xor(m.Int64Constant(-1), m.Parameter(0)));
530014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
531014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
532014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Nor, s[0]->arch_opcode());
533014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(2U, s[0]->InputCount());
534014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
535014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
536014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
537014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
538014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
539014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word32XorMinusOneWithParameter) {
540014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
541014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
542014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word32Xor(m.Parameter(0), m.Int32Constant(-1)));
543014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
544014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
545014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Nor, s[0]->arch_opcode());
546014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(2U, s[0]->InputCount());
547014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
548014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
549014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
550014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
551014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word32Xor(m.Int32Constant(-1), m.Parameter(0)));
552014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
553014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
554014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Nor, s[0]->arch_opcode());
555014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(2U, s[0]->InputCount());
556014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
557014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
558014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
559014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
560014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
561014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word64XorMinusOneWithWord64Or) {
562014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
563014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
564014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word64Xor(m.Word64Or(m.Parameter(0), m.Parameter(0)),
565014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                         m.Int64Constant(-1)));
566014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
567014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
568014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Nor, s[0]->arch_opcode());
569014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(2U, s[0]->InputCount());
570014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
571014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
572014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
573014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
574014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word64Xor(m.Int64Constant(-1),
575014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                         m.Word64Or(m.Parameter(0), m.Parameter(0))));
576014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
577014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
578014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Nor, s[0]->arch_opcode());
579014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(2U, s[0]->InputCount());
580014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
581014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
582014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
583014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
584014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
585014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word32XorMinusOneWithWord32Or) {
586014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
587014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
588014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word32Xor(m.Word32Or(m.Parameter(0), m.Parameter(0)),
589014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                         m.Int32Constant(-1)));
590014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
591014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
592014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Nor, s[0]->arch_opcode());
593014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(2U, s[0]->InputCount());
594014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
595014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
596014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
597014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
598014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Word32Xor(m.Int32Constant(-1),
599014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                         m.Word32Or(m.Parameter(0), m.Parameter(0))));
600014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
601014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
602014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Nor, s[0]->arch_opcode());
603014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(2U, s[0]->InputCount());
604014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
605014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
606014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
607014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
608014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
609014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word32AndWithImmediateWithWord32Shr) {
610014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // The available shift operand range is `0 <= imm < 32`, but we also test
611014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // that immediates outside this range are handled properly (modulo-32).
612014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, -32, 63) {
613014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int32_t lsb = shift & 0x1f;
614014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    TRACED_FORRANGE(int32_t, width, 1, 31) {
615014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint32_t msk = (1 << width) - 1;
616014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
617014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      m.Return(m.Word32And(m.Word32Shr(m.Parameter(0), m.Int32Constant(shift)),
618014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                           m.Int32Constant(msk)));
619014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      Stream s = m.Build();
620014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(1U, s.size());
621014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(kMips64Ext, s[0]->arch_opcode());
622014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(3U, s[0]->InputCount());
623014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1)));
624014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      int32_t actual_width = (lsb + width > 32) ? (32 - lsb) : width;
625014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(actual_width, s.ToInt32(s[0]->InputAt(2)));
626014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
627014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
628014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, -32, 63) {
629014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int32_t lsb = shift & 0x1f;
630014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    TRACED_FORRANGE(int32_t, width, 1, 31) {
631014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint32_t msk = (1 << width) - 1;
632014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
633014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      m.Return(
634014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch          m.Word32And(m.Int32Constant(msk),
635014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                      m.Word32Shr(m.Parameter(0), m.Int32Constant(shift))));
636014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      Stream s = m.Build();
637014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(1U, s.size());
638014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(kMips64Ext, s[0]->arch_opcode());
639014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(3U, s[0]->InputCount());
640014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(lsb, s.ToInt32(s[0]->InputAt(1)));
641014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      int32_t actual_width = (lsb + width > 32) ? (32 - lsb) : width;
642014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(actual_width, s.ToInt32(s[0]->InputAt(2)));
643014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
644014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
645014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
646014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
647014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
648014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word64AndWithImmediateWithWord64Shr) {
649014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // The available shift operand range is `0 <= imm < 64`, but we also test
650014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // that immediates outside this range are handled properly (modulo-64).
651014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int64_t, shift, -64, 127) {
652014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int64_t lsb = shift & 0x3f;
653014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    TRACED_FORRANGE(int64_t, width, 1, 63) {
654014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint64_t msk = (V8_UINT64_C(1) << width) - 1;
655014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
656014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      m.Return(m.Word64And(m.Word64Shr(m.Parameter(0), m.Int64Constant(shift)),
657014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                           m.Int64Constant(msk)));
658014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      Stream s = m.Build();
659014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(1U, s.size());
660014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(kMips64Dext, s[0]->arch_opcode());
661014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(3U, s[0]->InputCount());
662014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1)));
663014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      int64_t actual_width = (lsb + width > 64) ? (64 - lsb) : width;
664014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(actual_width, s.ToInt64(s[0]->InputAt(2)));
665014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
666014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
667014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int64_t, shift, -64, 127) {
668014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    int64_t lsb = shift & 0x3f;
669014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    TRACED_FORRANGE(int64_t, width, 1, 63) {
670014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      uint64_t msk = (V8_UINT64_C(1) << width) - 1;
671014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
672014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      m.Return(
673014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch          m.Word64And(m.Int64Constant(msk),
674014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                      m.Word64Shr(m.Parameter(0), m.Int64Constant(shift))));
675014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      Stream s = m.Build();
676014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(1U, s.size());
677014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(kMips64Dext, s[0]->arch_opcode());
678014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      ASSERT_EQ(3U, s[0]->InputCount());
679014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(lsb, s.ToInt64(s[0]->InputAt(1)));
680014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      int64_t actual_width = (lsb + width > 64) ? (64 - lsb) : width;
681014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch      EXPECT_EQ(actual_width, s.ToInt64(s[0]->InputAt(2)));
682014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    }
683014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
684014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
685014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
686014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
687014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word32ShlWithWord32And) {
688014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, 0, 30) {
689014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
690014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Node* const p0 = m.Parameter(0);
691014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Node* const r =
692014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch        m.Word32Shl(m.Word32And(p0, m.Int32Constant((1 << (31 - shift)) - 1)),
693014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                    m.Int32Constant(shift + 1));
694014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(r);
695014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
696014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
697014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Shl, s[0]->arch_opcode());
698014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(2U, s[0]->InputCount());
699014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
700014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s[0]->OutputCount());
701014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->Output()));
702014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
703014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
704014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
705014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
706014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word64ShlWithWord64And) {
707014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  TRACED_FORRANGE(int32_t, shift, 0, 62) {
708014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
709014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Node* const p0 = m.Parameter(0);
710014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Node* const r =
711014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch        m.Word64Shl(m.Word64And(p0, m.Int64Constant((1L << (63 - shift)) - 1)),
712014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                    m.Int64Constant(shift + 1));
713014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(r);
714014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
715014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
716014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Dshl, s[0]->arch_opcode());
717014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(2U, s[0]->InputCount());
718014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
719014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s[0]->OutputCount());
720014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->Output()));
721014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
722014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
723014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
724014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
725958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
726958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// MUL/DIV instructions.
727958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
728958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MachInst2>
729958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorMulDivTest;
730958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
731958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorMulDivTest, Parameter) {
732958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachInst2 dpi = GetParam();
733958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachineType type = dpi.machine_type;
734958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  StreamBuilder m(this, type, type, type);
735958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
736958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
737958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
738958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
739958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(2U, s[0]->InputCount());
740958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
741958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
742958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
743958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMulDivTest,
744958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kMulDivInstructions));
745958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
746958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
747958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// MOD instructions.
748958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
749958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MachInst2> InstructionSelectorModTest;
750958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
751958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorModTest, Parameter) {
752958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachInst2 dpi = GetParam();
753958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachineType type = dpi.machine_type;
754958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  StreamBuilder m(this, type, type, type);
755958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
756958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
757958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
758958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
759958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(2U, s[0]->InputCount());
760958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
761958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
762958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
763958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorModTest,
764958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kModInstructions));
765958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
766958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
767958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Floating point instructions.
768958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
769958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MachInst2>
770958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorFPArithTest;
771958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
772958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorFPArithTest, Parameter) {
773958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachInst2 fpa = GetParam();
774958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  StreamBuilder m(this, fpa.machine_type, fpa.machine_type, fpa.machine_type);
775958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*fpa.constructor)(m.Parameter(0), m.Parameter(1)));
776958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
777958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
778958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(fpa.arch_opcode, s[0]->arch_opcode());
779958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(2U, s[0]->InputCount());
780958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
781958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
782958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
783958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorFPArithTest,
784958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kFPArithInstructions));
785958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
786958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Integer arithmetic
787958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
788958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MachInst2>
789958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorIntArithTwoTest;
790958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
791958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorIntArithTwoTest, Parameter) {
792958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachInst2 intpa = GetParam();
793958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  StreamBuilder m(this, intpa.machine_type, intpa.machine_type,
794958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                  intpa.machine_type);
795958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*intpa.constructor)(m.Parameter(0), m.Parameter(1)));
796958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
797958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
798958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(intpa.arch_opcode, s[0]->arch_opcode());
799958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(2U, s[0]->InputCount());
800958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
801958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
802958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
803958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
804958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        InstructionSelectorIntArithTwoTest,
805958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kAddSubInstructions));
806958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
807958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
808958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
809958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// One node.
810958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
811958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
812958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
813958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MachInst1>
814958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorIntArithOneTest;
815958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
816958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorIntArithOneTest, Parameter) {
817958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MachInst1 intpa = GetParam();
818958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  StreamBuilder m(this, intpa.machine_type, intpa.machine_type,
819958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                  intpa.machine_type);
820958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*intpa.constructor)(m.Parameter(0)));
821958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
822958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
823958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(intpa.arch_opcode, s[0]->arch_opcode());
824958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(2U, s[0]->InputCount());
825958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
826958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
827958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
828958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
829958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        InstructionSelectorIntArithOneTest,
830958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kAddSubOneInstructions));
831958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
832958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Conversions.
833958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
834958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<Conversion>
835958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorConversionTest;
836958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
837958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorConversionTest, Parameter) {
838958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const Conversion conv = GetParam();
839958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  StreamBuilder m(this, conv.mi.machine_type, conv.src_machine_type);
840958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return((m.*conv.mi.constructor)(m.Parameter(0)));
841958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
842958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
843958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(conv.mi.arch_opcode, s[0]->arch_opcode());
844958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->InputCount());
845958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(1U, s[0]->OutputCount());
846958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
847958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
848958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
849958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        InstructionSelectorConversionTest,
850958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kConversionInstructions));
851958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
852014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, ChangesFromToSmi) {
853014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
854014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
855014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.TruncateInt64ToInt32(
856014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch        m.Word64Sar(m.Parameter(0), m.Int32Constant(32))));
857014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
858014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
859014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Dsar, s[0]->arch_opcode());
860014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
861014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(2U, s[0]->InputCount());
862014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
863014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
864014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
865014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
866014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(
867014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch        m.Word64Shl(m.ChangeInt32ToInt64(m.Parameter(0)), m.Int32Constant(32)));
868014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
869014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
870014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Dshl, s[0]->arch_opcode());
871014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(2U, s[0]->InputCount());
872014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
873014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
874014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
875014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
876014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
877014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochtypedef InstructionSelectorTestWithParam<Conversion>
878014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    CombineChangeFloat64ToInt32WithRoundFloat64;
879014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
880014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_P(CombineChangeFloat64ToInt32WithRoundFloat64, Parameter) {
881014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
882014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    const Conversion conv = GetParam();
883014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, conv.mi.machine_type, conv.src_machine_type);
884014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.ChangeFloat64ToInt32((m.*conv.mi.constructor)(m.Parameter(0))));
885014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
886014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
887014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(conv.mi.arch_opcode, s[0]->arch_opcode());
888014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
889014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s[0]->InputCount());
890014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
891014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
892014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
893014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
894014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochINSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
895014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                        CombineChangeFloat64ToInt32WithRoundFloat64,
896014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                        ::testing::ValuesIn(kFloat64RoundInstructions));
897014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
898014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdochtypedef InstructionSelectorTestWithParam<Conversion>
899014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    CombineChangeFloat32ToInt32WithRoundFloat32;
900014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
901014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_P(CombineChangeFloat32ToInt32WithRoundFloat32, Parameter) {
902014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
903014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    const Conversion conv = GetParam();
904014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, conv.mi.machine_type, conv.src_machine_type);
905014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.ChangeFloat64ToInt32(
906014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch        m.ChangeFloat32ToFloat64((m.*conv.mi.constructor)(m.Parameter(0)))));
907014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
908014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
909014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(conv.mi.arch_opcode, s[0]->arch_opcode());
910014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
911014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s[0]->InputCount());
912014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
913014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
914014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
915014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
916014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochINSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
917014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                        CombineChangeFloat32ToInt32WithRoundFloat32,
918014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                        ::testing::ValuesIn(kFloat32RoundInstructions));
919014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
920014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
921014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, ChangeFloat64ToInt32OfChangeFloat32ToFloat64) {
922014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
923014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Float32());
924014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.ChangeFloat64ToInt32(m.ChangeFloat32ToFloat64(m.Parameter(0))));
925014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
926014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
927014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64TruncWS, s[0]->arch_opcode());
928014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
929014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s[0]->InputCount());
930014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
931014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
932014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
933014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
934014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
935014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest,
936014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch       TruncateFloat64ToFloat32OfChangeInt32ToFloat64) {
937014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
938014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Float32(), MachineType::Int32());
939014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(
940014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch        m.TruncateFloat64ToFloat32(m.ChangeInt32ToFloat64(m.Parameter(0))));
941014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
942014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
943014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64CvtSW, s[0]->arch_opcode());
944014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
945014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s[0]->InputCount());
946014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
947014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
948014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
949014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
950014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
951014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, CombineShiftsWithMul) {
952014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
953014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
954014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Int32Mul(m.Word64Sar(m.Parameter(0), m.Int32Constant(32)),
955014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                        m.Word64Sar(m.Parameter(0), m.Int32Constant(32))));
956014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
957014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
958014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64DMulHigh, s[0]->arch_opcode());
959014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
960014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(2U, s[0]->InputCount());
961014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
962014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
963014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
964014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
965014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
966014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, CombineShiftsWithDivMod) {
967014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
968014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
969014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Int32Div(m.Word64Sar(m.Parameter(0), m.Int32Constant(32)),
970014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                        m.Word64Sar(m.Parameter(0), m.Int32Constant(32))));
971014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
972014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
973014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Ddiv, s[0]->arch_opcode());
974014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
975014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(2U, s[0]->InputCount());
976014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
977014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
978014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  {
979014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
980014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Return(m.Int32Mod(m.Word64Sar(m.Parameter(0), m.Int32Constant(32)),
981014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                        m.Word64Sar(m.Parameter(0), m.Int32Constant(32))));
982014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    Stream s = m.Build();
983014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(1U, s.size());
984014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Dmod, s[0]->arch_opcode());
985014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
986014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    ASSERT_EQ(2U, s[0]->InputCount());
987014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(1U, s[0]->OutputCount());
988014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  }
989014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
990014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
991958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
992958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
993958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Loads and stores.
994958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
995958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
996958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
997958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniernamespace {
998958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
999958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstruct MemoryAccess {
1000958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  MachineType type;
1001958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ArchOpcode load_opcode;
1002958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ArchOpcode store_opcode;
1003958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier};
1004958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1005958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstatic const MemoryAccess kMemoryAccesses[] = {
1006014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int8(), kMips64Lb, kMips64Sb},
1007014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Uint8(), kMips64Lbu, kMips64Sb},
1008014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int16(), kMips64Lh, kMips64Sh},
1009014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Uint16(), kMips64Lhu, kMips64Sh},
1010014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int32(), kMips64Lw, kMips64Sw},
1011014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Float32(), kMips64Lwc1, kMips64Swc1},
1012014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Float64(), kMips64Ldc1, kMips64Sdc1},
1013014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int64(), kMips64Ld, kMips64Sd}};
1014958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1015958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1016958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstruct MemoryAccessImm {
1017958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  MachineType type;
1018958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ArchOpcode load_opcode;
1019958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ArchOpcode store_opcode;
1020958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  bool (InstructionSelectorTest::Stream::*val_predicate)(
1021958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      const InstructionOperand*) const;
1022958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const int32_t immediates[40];
1023958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier};
1024958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1025958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1026958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstd::ostream& operator<<(std::ostream& os, const MemoryAccessImm& acc) {
1027958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  return os << acc.type;
1028958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1029958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1030958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1031958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstruct MemoryAccessImm1 {
1032958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  MachineType type;
1033958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ArchOpcode load_opcode;
1034958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ArchOpcode store_opcode;
1035958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  bool (InstructionSelectorTest::Stream::*val_predicate)(
1036958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      const InstructionOperand*) const;
1037958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const int32_t immediates[5];
1038958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier};
1039958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1040958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1041958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierstd::ostream& operator<<(std::ostream& os, const MemoryAccessImm1& acc) {
1042958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  return os << acc.type;
1043958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1044958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1045958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1046958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1047958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Loads and stores immediate values
1048958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1049958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1050958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1051958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MemoryAccessImm kMemoryAccessesImm[] = {
1052014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int8(),
1053958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lb,
1054958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sb,
1055958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1056958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, -89,
1057958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      -87, -86, -82, -44, -23, -3, 0, 7, 10, 39, 52, 69, 71, 91, 92, 107, 109,
1058958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      115, 124, 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}},
1059014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Uint8(),
1060958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lbu,
1061958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sb,
1062958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1063958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, -89,
1064958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      -87, -86, -82, -44, -23, -3, 0, 7, 10, 39, 52, 69, 71, 91, 92, 107, 109,
1065958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      115, 124, 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}},
1066014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int16(),
1067958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lh,
1068958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sh,
1069958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1070958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, -89,
1071958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      -87, -86, -82, -44, -23, -3, 0, 7, 10, 39, 52, 69, 71, 91, 92, 107, 109,
1072958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      115, 124, 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}},
1073014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Uint16(),
1074958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lhu,
1075958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sh,
1076958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1077958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, -89,
1078958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      -87, -86, -82, -44, -23, -3, 0, 7, 10, 39, 52, 69, 71, 91, 92, 107, 109,
1079958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      115, 124, 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}},
1080014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int32(),
1081958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lw,
1082958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sw,
1083958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1084958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, -89,
1085958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      -87, -86, -82, -44, -23, -3, 0, 7, 10, 39, 52, 69, 71, 91, 92, 107, 109,
1086958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      115, 124, 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}},
1087014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Float32(),
1088958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lwc1,
1089958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Swc1,
1090958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsDouble,
1091958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, -89,
1092958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      -87, -86, -82, -44, -23, -3, 0, 7, 10, 39, 52, 69, 71, 91, 92, 107, 109,
1093958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      115, 124, 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}},
1094014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Float64(),
1095958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Ldc1,
1096958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sdc1,
1097958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsDouble,
1098958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, -89,
1099958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      -87, -86, -82, -44, -23, -3, 0, 7, 10, 39, 52, 69, 71, 91, 92, 107, 109,
1100958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      115, 124, 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}},
1101014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int64(),
1102958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Ld,
1103958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sd,
1104958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1105958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-4095, -3340, -3231, -3224, -3088, -1758, -1203, -123, -117, -91, -89,
1106958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      -87, -86, -82, -44, -23, -3, 0, 7, 10, 39, 52, 69, 71, 91, 92, 107, 109,
1107958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier      115, 124, 286, 655, 1362, 1569, 2587, 3067, 3096, 3462, 3510, 4095}}};
1108958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1109958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1110958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierconst MemoryAccessImm1 kMemoryAccessImmMoreThan16bit[] = {
1111014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int8(),
1112958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lb,
1113958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sb,
1114958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1115958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-65000, -55000, 32777, 55000, 65000}},
1116014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int8(),
1117958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lbu,
1118958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sb,
1119958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1120958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-65000, -55000, 32777, 55000, 65000}},
1121014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int16(),
1122958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lh,
1123958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sh,
1124958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1125958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-65000, -55000, 32777, 55000, 65000}},
1126014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int16(),
1127958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lhu,
1128958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sh,
1129958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1130958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-65000, -55000, 32777, 55000, 65000}},
1131014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int32(),
1132958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lw,
1133958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sw,
1134958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1135958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-65000, -55000, 32777, 55000, 65000}},
1136014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Float32(),
1137958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Lwc1,
1138958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Swc1,
1139958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsDouble,
1140958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-65000, -55000, 32777, 55000, 65000}},
1141014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Float64(),
1142958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Ldc1,
1143958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sdc1,
1144958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsDouble,
1145958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-65000, -55000, 32777, 55000, 65000}},
1146014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    {MachineType::Int64(),
1147958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Ld,
1148958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     kMips64Sd,
1149958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     &InstructionSelectorTest::Stream::IsInteger,
1150958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier     {-65000, -55000, 32777, 55000, 65000}}};
1151958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1152958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}  // namespace
1153958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1154958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1155958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MemoryAccess>
1156958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorMemoryAccessTest;
1157958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1158958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorMemoryAccessTest, LoadWithParameters) {
1159958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MemoryAccess memacc = GetParam();
1160014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, memacc.type, MachineType::Pointer(),
1161014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                  MachineType::Int32());
1162958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return(m.Load(memacc.type, m.Parameter(0)));
1163958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
1164958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
1165958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode());
1166958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(kMode_MRI, s[0]->addressing_mode());
1167958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1168958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1169958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1170958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) {
1171958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MemoryAccess memacc = GetParam();
1172014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer(),
1173014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                  MachineType::Int32(), memacc.type);
1174014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Store(memacc.type.representation(), m.Parameter(0), m.Parameter(1),
1175014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch          kNoWriteBarrier);
1176958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  m.Return(m.Int32Constant(0));
1177958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  Stream s = m.Build();
1178958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  ASSERT_EQ(1U, s.size());
1179958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode());
1180958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  EXPECT_EQ(kMode_MRI, s[0]->addressing_mode());
1181958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1182958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1183958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
1184958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        InstructionSelectorMemoryAccessTest,
1185958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kMemoryAccesses));
1186958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1187958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1188958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1189958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Load immediate.
1190958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1191958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1192958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1193958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MemoryAccessImm>
1194958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorMemoryAccessImmTest;
1195958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1196958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorMemoryAccessImmTest, LoadWithImmediateIndex) {
1197958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MemoryAccessImm memacc = GetParam();
1198958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  TRACED_FOREACH(int32_t, index, memacc.immediates) {
1199014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, memacc.type, MachineType::Pointer());
1200958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return(m.Load(memacc.type, m.Parameter(0), m.Int32Constant(index)));
1201958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
1202958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(1U, s.size());
1203958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode());
1204958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMode_MRI, s[0]->addressing_mode());
1205958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(2U, s[0]->InputCount());
1206958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind());
1207958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1)));
1208958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(1U, s[0]->OutputCount());
1209958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_TRUE((s.*memacc.val_predicate)(s[0]->Output()));
1210958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
1211958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1212958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1213958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1214958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1215958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Store immediate.
1216958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1217958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1218958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1219958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorMemoryAccessImmTest, StoreWithImmediateIndex) {
1220958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MemoryAccessImm memacc = GetParam();
1221958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  TRACED_FOREACH(int32_t, index, memacc.immediates) {
1222014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer(),
1223014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                    memacc.type);
1224014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Store(memacc.type.representation(), m.Parameter(0),
1225014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch            m.Int32Constant(index), m.Parameter(1), kNoWriteBarrier);
1226958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return(m.Int32Constant(0));
1227958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
1228958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(1U, s.size());
1229958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode());
1230958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMode_MRI, s[0]->addressing_mode());
1231958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(3U, s[0]->InputCount());
1232958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind());
1233958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1)));
1234958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(0U, s[0]->OutputCount());
1235958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
1236958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1237958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1238958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
1239958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        InstructionSelectorMemoryAccessImmTest,
1240958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kMemoryAccessesImm));
1241958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1242958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1243958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1244958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Load/store offsets more than 16 bits.
1245958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1246958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1247958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1248958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniertypedef InstructionSelectorTestWithParam<MemoryAccessImm1>
1249958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    InstructionSelectorMemoryAccessImmMoreThan16bitTest;
1250958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1251958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorMemoryAccessImmMoreThan16bitTest,
1252958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier       LoadWithImmediateIndex) {
1253958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MemoryAccessImm1 memacc = GetParam();
1254958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  TRACED_FOREACH(int32_t, index, memacc.immediates) {
1255014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, memacc.type, MachineType::Pointer());
1256958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return(m.Load(memacc.type, m.Parameter(0), m.Int32Constant(index)));
1257958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
1258958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(2U, s.size());
1259958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // kMips64Dadd is expected opcode
1260958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // size more than 16 bits wide
1261958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMips64Dadd, s[0]->arch_opcode());
1262958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
1263958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(2U, s[0]->InputCount());
1264958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(1U, s[0]->OutputCount());
1265958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
1266958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1267958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1268958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_P(InstructionSelectorMemoryAccessImmMoreThan16bitTest,
1269958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier       StoreWithImmediateIndex) {
1270958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  const MemoryAccessImm1 memacc = GetParam();
1271958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  TRACED_FOREACH(int32_t, index, memacc.immediates) {
1272014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer(),
1273014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                    memacc.type);
1274014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    m.Store(memacc.type.representation(), m.Parameter(0),
1275014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch            m.Int32Constant(index), m.Parameter(1), kNoWriteBarrier);
1276958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return(m.Int32Constant(0));
1277958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
1278958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(2U, s.size());
1279958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // kMips64Add is expected opcode
1280958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    // size more than 16 bits wide
1281958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMips64Dadd, s[0]->arch_opcode());
1282958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
1283958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(2U, s[0]->InputCount());
1284958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(1U, s[0]->OutputCount());
1285958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
1286958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1287958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1288958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierINSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
1289958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        InstructionSelectorMemoryAccessImmMoreThan16bitTest,
1290958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier                        ::testing::ValuesIn(kMemoryAccessImmMoreThan16bit));
1291958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1292958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1293958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1294958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// kMips64Cmp with zero testing.
1295958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// ----------------------------------------------------------------------------
1296958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1297958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1298958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_F(InstructionSelectorTest, Word32EqualWithZero) {
1299958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  {
1300014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
1301958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return(m.Word32Equal(m.Parameter(0), m.Int32Constant(0)));
1302958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
1303958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(1U, s.size());
1304014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Cmp, s[0]->arch_opcode());
1305958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
1306958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(2U, s[0]->InputCount());
1307958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(1U, s[0]->OutputCount());
1308958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kFlags_set, s[0]->flags_mode());
1309958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kEqual, s[0]->flags_condition());
1310958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
1311958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  {
1312014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int32(), MachineType::Int32());
1313958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return(m.Word32Equal(m.Int32Constant(0), m.Parameter(0)));
1314958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
1315958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(1U, s.size());
1316014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    EXPECT_EQ(kMips64Cmp, s[0]->arch_opcode());
1317958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
1318958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(2U, s[0]->InputCount());
1319958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(1U, s[0]->OutputCount());
1320958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kFlags_set, s[0]->flags_mode());
1321958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kEqual, s[0]->flags_condition());
1322958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
1323958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1324958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1325958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1326958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierTEST_F(InstructionSelectorTest, Word64EqualWithZero) {
1327958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  {
1328014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
1329958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return(m.Word64Equal(m.Parameter(0), m.Int64Constant(0)));
1330958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
1331958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(1U, s.size());
1332958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMips64Cmp, s[0]->arch_opcode());
1333958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
1334958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(2U, s[0]->InputCount());
1335958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(1U, s[0]->OutputCount());
1336958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kFlags_set, s[0]->flags_mode());
1337958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kEqual, s[0]->flags_condition());
1338958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
1339958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  {
1340014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch    StreamBuilder m(this, MachineType::Int64(), MachineType::Int64());
1341958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    m.Return(m.Word64Equal(m.Int32Constant(0), m.Parameter(0)));
1342958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    Stream s = m.Build();
1343958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(1U, s.size());
1344958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMips64Cmp, s[0]->arch_opcode());
1345958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kMode_None, s[0]->addressing_mode());
1346958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    ASSERT_EQ(2U, s[0]->InputCount());
1347958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(1U, s[0]->OutputCount());
1348958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kFlags_set, s[0]->flags_mode());
1349958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier    EXPECT_EQ(kEqual, s[0]->flags_condition());
1350958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier  }
1351958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}
1352958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier
1353014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1354014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word32Clz) {
1355014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Uint32(), MachineType::Uint32());
1356014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p0 = m.Parameter(0);
1357014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const n = m.Word32Clz(p0);
1358014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Return(n);
1359014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Stream s = m.Build();
1360014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s.size());
1361014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(kMips64Clz, s[0]->arch_opcode());
1362014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->InputCount());
1363014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
1364014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->OutputCount());
1365014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
1366014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
1367014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1368014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1369014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Word64Clz) {
1370014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Uint64(), MachineType::Uint64());
1371014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p0 = m.Parameter(0);
1372014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const n = m.Word64Clz(p0);
1373014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Return(n);
1374014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Stream s = m.Build();
1375014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s.size());
1376014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(kMips64Dclz, s[0]->arch_opcode());
1377014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->InputCount());
1378014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
1379014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->OutputCount());
1380014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
1381014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
1382014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1383014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1384014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Float32Abs) {
1385014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Float32(), MachineType::Float32());
1386014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p0 = m.Parameter(0);
1387014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const n = m.Float32Abs(p0);
1388014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Return(n);
1389014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Stream s = m.Build();
1390014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s.size());
1391014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(kMips64AbsS, s[0]->arch_opcode());
1392014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->InputCount());
1393014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
1394014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->OutputCount());
1395014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
1396014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
1397014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1398014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1399014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Float64Abs) {
1400014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Float64(), MachineType::Float64());
1401014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p0 = m.Parameter(0);
1402014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const n = m.Float64Abs(p0);
1403014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Return(n);
1404014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Stream s = m.Build();
1405014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s.size());
1406014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(kMips64AbsD, s[0]->arch_opcode());
1407014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->InputCount());
1408014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
1409014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->OutputCount());
1410014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
1411014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
1412014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1413014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1414014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Float32Max) {
1415014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Float32(), MachineType::Float32(),
1416014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                  MachineType::Float32());
1417014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p0 = m.Parameter(0);
1418014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p1 = m.Parameter(1);
1419014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const n = m.Float32Max(p0, p1);
1420014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Return(n);
1421014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Stream s = m.Build();
1422014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // Float32Max is `(b < a) ? a : b`.
1423014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s.size());
1424014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(kMips64Float32Max, s[0]->arch_opcode());
1425014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(2U, s[0]->InputCount());
1426014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->OutputCount());
1427014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
1428014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
1429014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1430014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1431014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Float32Min) {
1432014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Float32(), MachineType::Float32(),
1433014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                  MachineType::Float32());
1434014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p0 = m.Parameter(0);
1435014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p1 = m.Parameter(1);
1436014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const n = m.Float32Min(p0, p1);
1437014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Return(n);
1438014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Stream s = m.Build();
1439014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // Float32Min is `(a < b) ? a : b`.
1440014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s.size());
1441014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(kMips64Float32Min, s[0]->arch_opcode());
1442014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(2U, s[0]->InputCount());
1443014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->OutputCount());
1444014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
1445014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
1446014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1447014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1448014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Float64Max) {
1449014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Float64(), MachineType::Float64(),
1450014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                  MachineType::Float64());
1451014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p0 = m.Parameter(0);
1452014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p1 = m.Parameter(1);
1453014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const n = m.Float64Max(p0, p1);
1454014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Return(n);
1455014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Stream s = m.Build();
1456014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // Float64Max is `(b < a) ? a : b`.
1457014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s.size());
1458014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(kMips64Float64Max, s[0]->arch_opcode());
1459014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(2U, s[0]->InputCount());
1460014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->OutputCount());
1461014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
1462014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
1463014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1464014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1465014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben MurdochTEST_F(InstructionSelectorTest, Float64Min) {
1466014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  StreamBuilder m(this, MachineType::Float64(), MachineType::Float64(),
1467014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch                  MachineType::Float64());
1468014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p0 = m.Parameter(0);
1469014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const p1 = m.Parameter(1);
1470014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Node* const n = m.Float64Min(p0, p1);
1471014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  m.Return(n);
1472014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  Stream s = m.Build();
1473014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  // Float64Min is `(a < b) ? a : b`.
1474014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s.size());
1475014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(kMips64Float64Min, s[0]->arch_opcode());
1476014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(2U, s[0]->InputCount());
1477014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  ASSERT_EQ(1U, s[0]->OutputCount());
1478014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch  EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
1479014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch}
1480014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch
1481958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}  // namespace compiler
1482958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}  // namespace internal
1483958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier}  // namespace v8
1484