1// Copyright 2012 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27//
28
29#include <stdlib.h>
30
31#include "src/v8.h"
32
33#include "src/debug/debug.h"
34#include "src/disasm.h"
35#include "src/disassembler.h"
36#include "src/macro-assembler.h"
37#include "test/cctest/cctest.h"
38
39using namespace v8::internal;
40
41bool prev_instr_compact_branch = false;
42
43bool DisassembleAndCompare(byte* pc, const char* compare_string) {
44  disasm::NameConverter converter;
45  disasm::Disassembler disasm(converter);
46  EmbeddedVector<char, 128> disasm_buffer;
47
48  if (prev_instr_compact_branch) {
49    disasm.InstructionDecode(disasm_buffer, pc);
50    pc += 4;
51  }
52
53  disasm.InstructionDecode(disasm_buffer, pc);
54
55  if (strcmp(compare_string, disasm_buffer.start()) != 0) {
56    fprintf(stderr,
57            "expected: \n"
58            "%s\n"
59            "disassembled: \n"
60            "%s\n\n",
61            compare_string, disasm_buffer.start());
62    return false;
63  }
64  return true;
65}
66
67
68// Set up V8 to a state where we can at least run the assembler and
69// disassembler. Declare the variables and allocate the data structures used
70// in the rest of the macros.
71#define SET_UP()                                          \
72  CcTest::InitializeVM();                                 \
73  Isolate* isolate = CcTest::i_isolate();                  \
74  HandleScope scope(isolate);                             \
75  byte *buffer = reinterpret_cast<byte*>(malloc(4*1024)); \
76  Assembler assm(isolate, buffer, 4*1024);                \
77  bool failure = false;
78
79
80// This macro assembles one instruction using the preallocated assembler and
81// disassembles the generated instruction, comparing the output to the expected
82// value. If the comparison fails an error message is printed, but the test
83// continues to run until the end.
84#define COMPARE(asm_, compare_string) \
85  { \
86    int pc_offset = assm.pc_offset(); \
87    byte *progcounter = &buffer[pc_offset]; \
88    assm.asm_; \
89    if (!DisassembleAndCompare(progcounter, compare_string)) failure = true; \
90  }
91
92
93// Verify that all invocations of the COMPARE macro passed successfully.
94// Exit with a failure if at least one of the tests failed.
95#define VERIFY_RUN() \
96if (failure) { \
97    V8_Fatal(__FILE__, __LINE__, "MIPS Disassembler tests failed.\n"); \
98  }
99
100#define COMPARE_PC_REL_COMPACT(asm_, compare_string, offset)                   \
101  {                                                                            \
102    int pc_offset = assm.pc_offset();                                          \
103    byte *progcounter = &buffer[pc_offset];                                    \
104    char str_with_address[100];                                                \
105    prev_instr_compact_branch = assm.IsPrevInstrCompactBranch();               \
106    if (prev_instr_compact_branch) {                                           \
107      snprintf(str_with_address, sizeof(str_with_address), "%s -> %p",         \
108               compare_string,                                                 \
109               static_cast<void *>(progcounter + 8 + (offset * 4)));           \
110    } else {                                                                   \
111      snprintf(str_with_address, sizeof(str_with_address), "%s -> %p",         \
112               compare_string,                                                 \
113               static_cast<void *>(progcounter + 4 + (offset * 4)));           \
114    }                                                                          \
115    assm.asm_;                                                                 \
116    if (!DisassembleAndCompare(progcounter, str_with_address)) failure = true; \
117  }
118
119#define COMPARE_PC_REL(asm_, compare_string, offset)                           \
120  {                                                                            \
121    int pc_offset = assm.pc_offset();                                          \
122    byte *progcounter = &buffer[pc_offset];                                    \
123    char str_with_address[100];                                                \
124    snprintf(str_with_address, sizeof(str_with_address), "%s -> %p",           \
125             compare_string, static_cast<void *>(progcounter + (offset * 4))); \
126    assm.asm_;                                                                 \
127    if (!DisassembleAndCompare(progcounter, str_with_address)) failure = true; \
128  }
129
130#define COMPARE_PC_JUMP(asm_, compare_string, target)                          \
131  {                                                                            \
132    int pc_offset = assm.pc_offset();                                          \
133    byte *progcounter = &buffer[pc_offset];                                    \
134    char str_with_address[100];                                                \
135    int instr_index = (target >> 2) & kImm26Mask;                              \
136    snprintf(                                                                  \
137        str_with_address, sizeof(str_with_address), "%s %p -> %p",             \
138        compare_string, reinterpret_cast<void *>(target),                      \
139        reinterpret_cast<void *>(((uint32_t)(progcounter + 4) & ~0xfffffff) |  \
140                                 (instr_index << 2)));                         \
141    assm.asm_;                                                                 \
142    if (!DisassembleAndCompare(progcounter, str_with_address)) failure = true; \
143  }
144
145#define GET_PC_REGION(pc_region)                                         \
146  {                                                                      \
147    int pc_offset = assm.pc_offset();                                    \
148    byte *progcounter = &buffer[pc_offset];                              \
149    pc_region = reinterpret_cast<int32_t>(progcounter + 4) & ~0xfffffff; \
150  }
151
152
153TEST(Type0) {
154  SET_UP();
155
156  COMPARE(addu(a0, a1, a2),
157          "00a62021       addu    a0, a1, a2");
158  COMPARE(addu(t2, t3, t4),
159          "016c5021       addu    t2, t3, t4");
160  COMPARE(addu(v0, v1, s0),
161          "00701021       addu    v0, v1, s0");
162
163  COMPARE(subu(a0, a1, a2),
164          "00a62023       subu    a0, a1, a2");
165  COMPARE(subu(t2, t3, t4),
166          "016c5023       subu    t2, t3, t4");
167  COMPARE(subu(v0, v1, s0),
168          "00701023       subu    v0, v1, s0");
169
170  if (!IsMipsArchVariant(kMips32r6)) {
171    COMPARE(mult(a0, a1),
172            "00850018       mult    a0, a1");
173    COMPARE(mult(t2, t3),
174            "014b0018       mult    t2, t3");
175    COMPARE(mult(v0, v1),
176            "00430018       mult    v0, v1");
177
178    COMPARE(multu(a0, a1),
179            "00850019       multu   a0, a1");
180    COMPARE(multu(t2, t3),
181            "014b0019       multu   t2, t3");
182    COMPARE(multu(v0, v1),
183            "00430019       multu   v0, v1");
184
185    COMPARE(div(a0, a1),
186            "0085001a       div     a0, a1");
187    COMPARE(div(t2, t3),
188            "014b001a       div     t2, t3");
189    COMPARE(div(v0, v1),
190            "0043001a       div     v0, v1");
191
192    COMPARE(divu(a0, a1),
193            "0085001b       divu    a0, a1");
194    COMPARE(divu(t2, t3),
195            "014b001b       divu    t2, t3");
196    COMPARE(divu(v0, v1),
197            "0043001b       divu    v0, v1");
198
199    if (!IsMipsArchVariant(kLoongson)) {
200      COMPARE(mul(a0, a1, a2),
201              "70a62002       mul     a0, a1, a2");
202      COMPARE(mul(t2, t3, t4),
203              "716c5002       mul     t2, t3, t4");
204      COMPARE(mul(v0, v1, s0),
205              "70701002       mul     v0, v1, s0");
206    }
207  } else {  // MIPS32r6.
208    COMPARE(mul(a0, a1, a2),
209            "00a62098       mul    a0, a1, a2");
210    COMPARE(muh(a0, a1, a2),
211            "00a620d8       muh    a0, a1, a2");
212    COMPARE(mul(t1, t2, t3),
213            "014b4898       mul    t1, t2, t3");
214    COMPARE(muh(t1, t2, t3),
215            "014b48d8       muh    t1, t2, t3");
216    COMPARE(mul(v0, v1, a0),
217            "00641098       mul    v0, v1, a0");
218    COMPARE(muh(v0, v1, a0),
219            "006410d8       muh    v0, v1, a0");
220
221    COMPARE(mulu(a0, a1, a2),
222            "00a62099       mulu   a0, a1, a2");
223    COMPARE(muhu(a0, a1, a2),
224            "00a620d9       muhu   a0, a1, a2");
225    COMPARE(mulu(t1, t2, t3),
226            "014b4899       mulu   t1, t2, t3");
227    COMPARE(muhu(t1, t2, t3),
228            "014b48d9       muhu   t1, t2, t3");
229    COMPARE(mulu(v0, v1, a0),
230            "00641099       mulu   v0, v1, a0");
231    COMPARE(muhu(v0, v1, a0),
232            "006410d9       muhu   v0, v1, a0");
233
234    COMPARE(div(a0, a1, a2),
235            "00a6209a       div    a0, a1, a2");
236    COMPARE(mod(a0, a1, a2),
237            "00a620da       mod    a0, a1, a2");
238    COMPARE(div(t1, t2, t3),
239            "014b489a       div    t1, t2, t3");
240    COMPARE(mod(t1, t2, t3),
241            "014b48da       mod    t1, t2, t3");
242    COMPARE(div(v0, v1, a0),
243            "0064109a       div    v0, v1, a0");
244    COMPARE(mod(v0, v1, a0),
245            "006410da       mod    v0, v1, a0");
246
247    COMPARE(divu(a0, a1, a2),
248            "00a6209b       divu   a0, a1, a2");
249    COMPARE(modu(a0, a1, a2),
250            "00a620db       modu   a0, a1, a2");
251    COMPARE(divu(t1, t2, t3),
252            "014b489b       divu   t1, t2, t3");
253    COMPARE(modu(t1, t2, t3),
254            "014b48db       modu   t1, t2, t3");
255    COMPARE(divu(v0, v1, a0),
256            "0064109b       divu   v0, v1, a0");
257    COMPARE(modu(v0, v1, a0),
258            "006410db       modu   v0, v1, a0");
259
260    COMPARE_PC_REL_COMPACT(bovc(a0, a0, static_cast<int16_t>(0)),
261                           "20840000       bovc  a0, a0, 0", 0);
262    COMPARE_PC_REL_COMPACT(bovc(a1, a0, static_cast<int16_t>(0)),
263                           "20a40000       bovc  a1, a0, 0", 0);
264    COMPARE_PC_REL_COMPACT(bovc(a1, a0, 32767),
265                           "20a47fff       bovc  a1, a0, 32767", 32767);
266    COMPARE_PC_REL_COMPACT(bovc(a1, a0, -32768),
267                           "20a48000       bovc  a1, a0, -32768", -32768);
268
269    COMPARE_PC_REL_COMPACT(bnvc(a0, a0, static_cast<int16_t>(0)),
270                           "60840000       bnvc  a0, a0, 0", 0);
271    COMPARE_PC_REL_COMPACT(bnvc(a1, a0, static_cast<int16_t>(0)),
272                           "60a40000       bnvc  a1, a0, 0", 0);
273    COMPARE_PC_REL_COMPACT(bnvc(a1, a0, 32767),
274                           "60a47fff       bnvc  a1, a0, 32767", 32767);
275    COMPARE_PC_REL_COMPACT(bnvc(a1, a0, -32768),
276                           "60a48000       bnvc  a1, a0, -32768", -32768);
277
278    COMPARE_PC_REL_COMPACT(beqzc(a0, -1048576),
279                           "d8900000       beqzc   a0, -1048576", -1048576);
280    COMPARE_PC_REL_COMPACT(beqzc(a0, -1), "d89fffff       beqzc   a0, -1", -1);
281    COMPARE_PC_REL_COMPACT(beqzc(a0, 0), "d8800000       beqzc   a0, 0", 0);
282    COMPARE_PC_REL_COMPACT(beqzc(a0, 1), "d8800001       beqzc   a0, 1", 1);
283    COMPARE_PC_REL_COMPACT(beqzc(a0, 1048575),
284                           "d88fffff       beqzc   a0, 1048575", 1048575);
285
286    COMPARE_PC_REL_COMPACT(bnezc(a0, 0), "f8800000       bnezc   a0, 0", 0);
287    COMPARE_PC_REL_COMPACT(bnezc(a0, 1048575),  // int21 maximal value.
288                           "f88fffff       bnezc   a0, 1048575", 1048575);
289    COMPARE_PC_REL_COMPACT(bnezc(a0, -1048576),  // int21 minimal value.
290                           "f8900000       bnezc   a0, -1048576", -1048576);
291
292    COMPARE_PC_REL_COMPACT(bc(-33554432), "ca000000       bc      -33554432",
293                           -33554432);
294    COMPARE_PC_REL_COMPACT(bc(-1), "cbffffff       bc      -1", -1);
295    COMPARE_PC_REL_COMPACT(bc(0), "c8000000       bc      0", 0);
296    COMPARE_PC_REL_COMPACT(bc(1), "c8000001       bc      1", 1);
297    COMPARE_PC_REL_COMPACT(bc(33554431), "c9ffffff       bc      33554431",
298                           33554431);
299
300    COMPARE_PC_REL_COMPACT(balc(-33554432), "ea000000       balc    -33554432",
301                           -33554432);
302    COMPARE_PC_REL_COMPACT(balc(-1), "ebffffff       balc    -1", -1);
303    COMPARE_PC_REL_COMPACT(balc(0), "e8000000       balc    0", 0);
304    COMPARE_PC_REL_COMPACT(balc(1), "e8000001       balc    1", 1);
305    COMPARE_PC_REL_COMPACT(balc(33554431), "e9ffffff       balc    33554431",
306                           33554431);
307
308    COMPARE_PC_REL_COMPACT(bgeuc(a0, a1, -32768),
309                           "18858000       bgeuc   a0, a1, -32768", -32768);
310    COMPARE_PC_REL_COMPACT(bgeuc(a0, a1, -1),
311                           "1885ffff       bgeuc   a0, a1, -1", -1);
312    COMPARE_PC_REL_COMPACT(bgeuc(a0, a1, 1), "18850001       bgeuc   a0, a1, 1",
313                           1);
314    COMPARE_PC_REL_COMPACT(bgeuc(a0, a1, 32767),
315                           "18857fff       bgeuc   a0, a1, 32767", 32767);
316
317    COMPARE_PC_REL_COMPACT(bgezalc(a0, -32768),
318                           "18848000       bgezalc a0, -32768", -32768);
319    COMPARE_PC_REL_COMPACT(bgezalc(a0, -1), "1884ffff       bgezalc a0, -1",
320                           -1);
321    COMPARE_PC_REL_COMPACT(bgezalc(a0, 1), "18840001       bgezalc a0, 1", 1);
322    COMPARE_PC_REL_COMPACT(bgezalc(a0, 32767),
323                           "18847fff       bgezalc a0, 32767", 32767);
324
325    COMPARE_PC_REL_COMPACT(blezalc(a0, -32768),
326                           "18048000       blezalc a0, -32768", -32768);
327    COMPARE_PC_REL_COMPACT(blezalc(a0, -1), "1804ffff       blezalc a0, -1",
328                           -1);
329    COMPARE_PC_REL_COMPACT(blezalc(a0, 1), "18040001       blezalc a0, 1", 1);
330    COMPARE_PC_REL_COMPACT(blezalc(a0, 32767),
331                           "18047fff       blezalc a0, 32767", 32767);
332
333    COMPARE_PC_REL_COMPACT(bltuc(a0, a1, -32768),
334                           "1c858000       bltuc   a0, a1, -32768", -32768);
335    COMPARE_PC_REL_COMPACT(bltuc(a0, a1, -1),
336                           "1c85ffff       bltuc   a0, a1, -1", -1);
337    COMPARE_PC_REL_COMPACT(bltuc(a0, a1, 1), "1c850001       bltuc   a0, a1, 1",
338                           1);
339    COMPARE_PC_REL_COMPACT(bltuc(a0, a1, 32767),
340                           "1c857fff       bltuc   a0, a1, 32767", 32767);
341
342    COMPARE_PC_REL_COMPACT(bltzalc(a0, -32768),
343                           "1c848000       bltzalc a0, -32768", -32768);
344    COMPARE_PC_REL_COMPACT(bltzalc(a0, -1), "1c84ffff       bltzalc a0, -1",
345                           -1);
346    COMPARE_PC_REL_COMPACT(bltzalc(a0, 1), "1c840001       bltzalc a0, 1", 1);
347    COMPARE_PC_REL_COMPACT(bltzalc(a0, 32767),
348                           "1c847fff       bltzalc a0, 32767", 32767);
349
350    COMPARE_PC_REL_COMPACT(bgtzalc(a0, -32768),
351                           "1c048000       bgtzalc a0, -32768", -32768);
352    COMPARE_PC_REL_COMPACT(bgtzalc(a0, -1), "1c04ffff       bgtzalc a0, -1",
353                           -1);
354    COMPARE_PC_REL_COMPACT(bgtzalc(a0, 1), "1c040001       bgtzalc a0, 1", 1);
355    COMPARE_PC_REL_COMPACT(bgtzalc(a0, 32767),
356                           "1c047fff       bgtzalc a0, 32767", 32767);
357
358    COMPARE_PC_REL_COMPACT(bgezc(a0, -32768),
359                           "58848000       bgezc    a0, -32768", -32768);
360    COMPARE_PC_REL_COMPACT(bgezc(a0, -1), "5884ffff       bgezc    a0, -1", -1);
361    COMPARE_PC_REL_COMPACT(bgezc(a0, 1), "58840001       bgezc    a0, 1", 1);
362    COMPARE_PC_REL_COMPACT(bgezc(a0, 32767),
363                           "58847fff       bgezc    a0, 32767", 32767);
364
365    COMPARE_PC_REL_COMPACT(bgec(a0, a1, -32768),
366                           "58858000       bgec     a0, a1, -32768", -32768);
367    COMPARE_PC_REL_COMPACT(bgec(a0, a1, -1),
368                           "5885ffff       bgec     a0, a1, -1", -1);
369    COMPARE_PC_REL_COMPACT(bgec(a0, a1, 1), "58850001       bgec     a0, a1, 1",
370                           1);
371    COMPARE_PC_REL_COMPACT(bgec(a0, a1, 32767),
372                           "58857fff       bgec     a0, a1, 32767", 32767);
373
374    COMPARE_PC_REL_COMPACT(blezc(a0, -32768),
375                           "58048000       blezc    a0, -32768", -32768);
376    COMPARE_PC_REL_COMPACT(blezc(a0, -1), "5804ffff       blezc    a0, -1", -1);
377    COMPARE_PC_REL_COMPACT(blezc(a0, 1), "58040001       blezc    a0, 1", 1);
378    COMPARE_PC_REL_COMPACT(blezc(a0, 32767),
379                           "58047fff       blezc    a0, 32767", 32767);
380
381    COMPARE_PC_REL_COMPACT(bltzc(a0, -32768),
382                           "5c848000       bltzc    a0, -32768", -32768);
383    COMPARE_PC_REL_COMPACT(bltzc(a0, -1), "5c84ffff       bltzc    a0, -1", -1);
384    COMPARE_PC_REL_COMPACT(bltzc(a0, 1), "5c840001       bltzc    a0, 1", 1);
385    COMPARE_PC_REL_COMPACT(bltzc(a0, 32767),
386                           "5c847fff       bltzc    a0, 32767", 32767);
387
388    COMPARE_PC_REL_COMPACT(bltc(a0, a1, -32768),
389                           "5c858000       bltc    a0, a1, -32768", -32768);
390    COMPARE_PC_REL_COMPACT(bltc(a0, a1, -1),
391                           "5c85ffff       bltc    a0, a1, -1", -1);
392    COMPARE_PC_REL_COMPACT(bltc(a0, a1, 1), "5c850001       bltc    a0, a1, 1",
393                           1);
394    COMPARE_PC_REL_COMPACT(bltc(a0, a1, 32767),
395                           "5c857fff       bltc    a0, a1, 32767", 32767);
396
397    COMPARE_PC_REL_COMPACT(bgtzc(a0, -32768),
398                           "5c048000       bgtzc    a0, -32768", -32768);
399    COMPARE_PC_REL_COMPACT(bgtzc(a0, -1), "5c04ffff       bgtzc    a0, -1", -1);
400    COMPARE_PC_REL_COMPACT(bgtzc(a0, 1), "5c040001       bgtzc    a0, 1", 1);
401    COMPARE_PC_REL_COMPACT(bgtzc(a0, 32767),
402                           "5c047fff       bgtzc    a0, 32767", 32767);
403
404    COMPARE_PC_REL_COMPACT(bc1eqz(-32768, f1),
405                           "45218000       bc1eqz    f1, -32768", -32768);
406    COMPARE_PC_REL_COMPACT(bc1eqz(-1, f1), "4521ffff       bc1eqz    f1, -1",
407                           -1);
408    COMPARE_PC_REL_COMPACT(bc1eqz(1, f1), "45210001       bc1eqz    f1, 1", 1);
409    COMPARE_PC_REL_COMPACT(bc1eqz(32767, f1),
410                           "45217fff       bc1eqz    f1, 32767", 32767);
411
412    COMPARE_PC_REL_COMPACT(bc1nez(-32768, f1),
413                           "45a18000       bc1nez    f1, -32768", -32768);
414    COMPARE_PC_REL_COMPACT(bc1nez(-1, f1), "45a1ffff       bc1nez    f1, -1",
415                           -1);
416    COMPARE_PC_REL_COMPACT(bc1nez(1, f1), "45a10001       bc1nez    f1, 1", 1);
417    COMPARE_PC_REL_COMPACT(bc1nez(32767, f1),
418                           "45a17fff       bc1nez    f1, 32767", 32767);
419
420    COMPARE_PC_REL_COMPACT(bovc(a1, a0, -1), "20a4ffff       bovc  a1, a0, -1",
421                           -1);
422    COMPARE_PC_REL_COMPACT(bovc(a0, a0, 1), "20840001       bovc  a0, a0, 1",
423                           1);
424
425    COMPARE_PC_REL_COMPACT(beqc(a0, a1, -32768),
426                           "20858000       beqc    a0, a1, -32768", -32768);
427    COMPARE_PC_REL_COMPACT(beqc(a0, a1, -1),
428                           "2085ffff       beqc    a0, a1, -1", -1);
429    COMPARE_PC_REL_COMPACT(beqc(a0, a1, 1), "20850001       beqc    a0, a1, 1",
430                           1);
431    COMPARE_PC_REL_COMPACT(beqc(a0, a1, 32767),
432                           "20857fff       beqc    a0, a1, 32767", 32767);
433
434    COMPARE_PC_REL_COMPACT(bnec(a0, a1, -32768),
435                           "60858000       bnec  a0, a1, -32768", -32768);
436    COMPARE_PC_REL_COMPACT(bnec(a0, a1, -1), "6085ffff       bnec  a0, a1, -1",
437                           -1);
438    COMPARE_PC_REL_COMPACT(bnec(a0, a1, 1), "60850001       bnec  a0, a1, 1",
439                           1);
440    COMPARE_PC_REL_COMPACT(bnec(a0, a1, 32767),
441                           "60857fff       bnec  a0, a1, 32767", 32767);
442  }
443
444  COMPARE_PC_REL_COMPACT(bne(a0, a1, -32768),
445                         "14858000       bne     a0, a1, -32768", -32768);
446  COMPARE_PC_REL_COMPACT(bne(a0, a1, -1), "1485ffff       bne     a0, a1, -1",
447                         -1);
448  COMPARE_PC_REL_COMPACT(bne(a0, a1, 1), "14850001       bne     a0, a1, 1", 1);
449  COMPARE_PC_REL_COMPACT(bne(a0, a1, 32767),
450                         "14857fff       bne     a0, a1, 32767", 32767);
451
452  COMPARE_PC_REL_COMPACT(beq(a0, a1, -32768),
453                         "10858000       beq     a0, a1, -32768", -32768);
454  COMPARE_PC_REL_COMPACT(beq(a0, a1, -1), "1085ffff       beq     a0, a1, -1",
455                         -1);
456  COMPARE_PC_REL_COMPACT(beq(a0, a1, 1), "10850001       beq     a0, a1, 1", 1);
457  COMPARE_PC_REL_COMPACT(beq(a0, a1, 32767),
458                         "10857fff       beq     a0, a1, 32767", 32767);
459
460  COMPARE_PC_REL_COMPACT(bltz(a0, -32768), "04808000       bltz    a0, -32768",
461                         -32768);
462  COMPARE_PC_REL_COMPACT(bltz(a0, -1), "0480ffff       bltz    a0, -1", -1);
463  COMPARE_PC_REL_COMPACT(bltz(a0, 1), "04800001       bltz    a0, 1", 1);
464  COMPARE_PC_REL_COMPACT(bltz(a0, 32767), "04807fff       bltz    a0, 32767",
465                         32767);
466
467  COMPARE_PC_REL_COMPACT(bgez(a0, -32768), "04818000       bgez    a0, -32768",
468                         -32768);
469  COMPARE_PC_REL_COMPACT(bgez(a0, -1), "0481ffff       bgez    a0, -1", -1);
470  COMPARE_PC_REL_COMPACT(bgez(a0, 1), "04810001       bgez    a0, 1", 1);
471  COMPARE_PC_REL_COMPACT(bgez(a0, 32767), "04817fff       bgez    a0, 32767",
472                         32767);
473
474  COMPARE_PC_REL_COMPACT(blez(a0, -32768), "18808000       blez    a0, -32768",
475                         -32768);
476  COMPARE_PC_REL_COMPACT(blez(a0, -1), "1880ffff       blez    a0, -1", -1);
477  COMPARE_PC_REL_COMPACT(blez(a0, 1), "18800001       blez    a0, 1", 1);
478  COMPARE_PC_REL_COMPACT(blez(a0, 32767), "18807fff       blez    a0, 32767",
479                         32767);
480
481  COMPARE_PC_REL_COMPACT(bgtz(a0, -32768), "1c808000       bgtz    a0, -32768",
482                         -32768);
483  COMPARE_PC_REL_COMPACT(bgtz(a0, -1), "1c80ffff       bgtz    a0, -1", -1);
484  COMPARE_PC_REL_COMPACT(bgtz(a0, 1), "1c800001       bgtz    a0, 1", 1);
485  COMPARE_PC_REL_COMPACT(bgtz(a0, 32767), "1c807fff       bgtz    a0, 32767",
486                         32767);
487
488  int32_t pc_region;
489  GET_PC_REGION(pc_region);
490
491  int32_t target = pc_region | 0x4;
492  COMPARE_PC_JUMP(j(target), "08000001       j      ", target);
493  target = pc_region | 0xffffffc;
494  COMPARE_PC_JUMP(j(target), "0bffffff       j      ", target);
495
496  target = pc_region | 0x4;
497  COMPARE_PC_JUMP(jal(target), "0c000001       jal    ", target);
498  target = pc_region | 0xffffffc;
499  COMPARE_PC_JUMP(jal(target), "0fffffff       jal    ", target);
500
501  COMPARE(addiu(a0, a1, 0x0),
502          "24a40000       addiu   a0, a1, 0");
503  COMPARE(addiu(s0, s1, 32767),
504          "26307fff       addiu   s0, s1, 32767");
505  COMPARE(addiu(t2, t3, -32768),
506          "256a8000       addiu   t2, t3, -32768");
507  COMPARE(addiu(v0, v1, -1),
508          "2462ffff       addiu   v0, v1, -1");
509
510  COMPARE(and_(a0, a1, a2),
511          "00a62024       and     a0, a1, a2");
512  COMPARE(and_(s0, s1, s2),
513          "02328024       and     s0, s1, s2");
514  COMPARE(and_(t2, t3, t4),
515          "016c5024       and     t2, t3, t4");
516  COMPARE(and_(v0, v1, a2),
517          "00661024       and     v0, v1, a2");
518
519  COMPARE(or_(a0, a1, a2),
520          "00a62025       or      a0, a1, a2");
521  COMPARE(or_(s0, s1, s2),
522          "02328025       or      s0, s1, s2");
523  COMPARE(or_(t2, t3, t4),
524          "016c5025       or      t2, t3, t4");
525  COMPARE(or_(v0, v1, a2),
526          "00661025       or      v0, v1, a2");
527
528  COMPARE(xor_(a0, a1, a2),
529          "00a62026       xor     a0, a1, a2");
530  COMPARE(xor_(s0, s1, s2),
531          "02328026       xor     s0, s1, s2");
532  COMPARE(xor_(t2, t3, t4),
533          "016c5026       xor     t2, t3, t4");
534  COMPARE(xor_(v0, v1, a2),
535          "00661026       xor     v0, v1, a2");
536
537  COMPARE(nor(a0, a1, a2),
538          "00a62027       nor     a0, a1, a2");
539  COMPARE(nor(s0, s1, s2),
540          "02328027       nor     s0, s1, s2");
541  COMPARE(nor(t2, t3, t4),
542          "016c5027       nor     t2, t3, t4");
543  COMPARE(nor(v0, v1, a2),
544          "00661027       nor     v0, v1, a2");
545
546  COMPARE(andi(a0, a1, 0x1),
547          "30a40001       andi    a0, a1, 0x1");
548  COMPARE(andi(v0, v1, 0xffff),
549          "3062ffff       andi    v0, v1, 0xffff");
550
551  COMPARE(ori(a0, a1, 0x1),
552          "34a40001       ori     a0, a1, 0x1");
553  COMPARE(ori(v0, v1, 0xffff),
554          "3462ffff       ori     v0, v1, 0xffff");
555
556  COMPARE(xori(a0, a1, 0x1),
557          "38a40001       xori    a0, a1, 0x1");
558  COMPARE(xori(v0, v1, 0xffff),
559          "3862ffff       xori    v0, v1, 0xffff");
560
561  COMPARE(lui(a0, 0x1),
562          "3c040001       lui     a0, 0x1");
563  COMPARE(lui(v0, 0xffff),
564          "3c02ffff       lui     v0, 0xffff");
565
566  if (IsMipsArchVariant(kMips32r6)) {
567    COMPARE(aui(a0, a1, 0x1), "3ca40001       aui     a0, a1, 0x1");
568    COMPARE(aui(v0, v1, 0xffff), "3c62ffff       aui     v0, v1, 0xffff");
569  }
570
571  COMPARE(sll(a0, a1, 0),
572          "00052000       sll     a0, a1, 0");
573  COMPARE(sll(s0, s1, 8),
574          "00118200       sll     s0, s1, 8");
575  COMPARE(sll(t2, t3, 24),
576          "000b5600       sll     t2, t3, 24");
577  COMPARE(sll(v0, v1, 31),
578          "000317c0       sll     v0, v1, 31");
579
580  COMPARE(sllv(a0, a1, a2),
581          "00c52004       sllv    a0, a1, a2");
582  COMPARE(sllv(s0, s1, s2),
583          "02518004       sllv    s0, s1, s2");
584  COMPARE(sllv(t2, t3, t4),
585          "018b5004       sllv    t2, t3, t4");
586  COMPARE(sllv(v0, v1, fp),
587          "03c31004       sllv    v0, v1, fp");
588
589  COMPARE(srl(a0, a1, 0),
590          "00052002       srl     a0, a1, 0");
591  COMPARE(srl(s0, s1, 8),
592          "00118202       srl     s0, s1, 8");
593  COMPARE(srl(t2, t3, 24),
594          "000b5602       srl     t2, t3, 24");
595  COMPARE(srl(v0, v1, 31),
596          "000317c2       srl     v0, v1, 31");
597
598  COMPARE(srlv(a0, a1, a2),
599          "00c52006       srlv    a0, a1, a2");
600  COMPARE(srlv(s0, s1, s2),
601          "02518006       srlv    s0, s1, s2");
602  COMPARE(srlv(t2, t3, t4),
603          "018b5006       srlv    t2, t3, t4");
604  COMPARE(srlv(v0, v1, fp),
605          "03c31006       srlv    v0, v1, fp");
606
607  COMPARE(sra(a0, a1, 0),
608          "00052003       sra     a0, a1, 0");
609  COMPARE(sra(s0, s1, 8),
610          "00118203       sra     s0, s1, 8");
611  COMPARE(sra(t2, t3, 24),
612          "000b5603       sra     t2, t3, 24");
613  COMPARE(sra(v0, v1, 31),
614          "000317c3       sra     v0, v1, 31");
615
616  COMPARE(srav(a0, a1, a2),
617          "00c52007       srav    a0, a1, a2");
618  COMPARE(srav(s0, s1, s2),
619          "02518007       srav    s0, s1, s2");
620  COMPARE(srav(t2, t3, t4),
621          "018b5007       srav    t2, t3, t4");
622  COMPARE(srav(v0, v1, fp),
623          "03c31007       srav    v0, v1, fp");
624
625  if (IsMipsArchVariant(kMips32r2)) {
626    COMPARE(rotr(a0, a1, 0),
627            "00252002       rotr    a0, a1, 0");
628    COMPARE(rotr(s0, s1, 8),
629            "00318202       rotr    s0, s1, 8");
630    COMPARE(rotr(t2, t3, 24),
631            "002b5602       rotr    t2, t3, 24");
632    COMPARE(rotr(v0, v1, 31),
633            "002317c2       rotr    v0, v1, 31");
634
635    COMPARE(rotrv(a0, a1, a2),
636            "00c52046       rotrv   a0, a1, a2");
637    COMPARE(rotrv(s0, s1, s2),
638            "02518046       rotrv   s0, s1, s2");
639    COMPARE(rotrv(t2, t3, t4),
640            "018b5046       rotrv   t2, t3, t4");
641    COMPARE(rotrv(v0, v1, fp),
642            "03c31046       rotrv   v0, v1, fp");
643  }
644
645  COMPARE(break_(0),
646          "0000000d       break, code: 0x00000 (0)");
647  COMPARE(break_(261120),
648          "00ff000d       break, code: 0x3fc00 (261120)");
649  COMPARE(break_(1047552),
650          "03ff000d       break, code: 0xffc00 (1047552)");
651
652  COMPARE(tge(a0, a1, 0),
653          "00850030       tge     a0, a1, code: 0x000");
654  COMPARE(tge(s0, s1, 1023),
655          "0211fff0       tge     s0, s1, code: 0x3ff");
656  COMPARE(tgeu(a0, a1, 0),
657          "00850031       tgeu    a0, a1, code: 0x000");
658  COMPARE(tgeu(s0, s1, 1023),
659          "0211fff1       tgeu    s0, s1, code: 0x3ff");
660  COMPARE(tlt(a0, a1, 0),
661          "00850032       tlt     a0, a1, code: 0x000");
662  COMPARE(tlt(s0, s1, 1023),
663          "0211fff2       tlt     s0, s1, code: 0x3ff");
664  COMPARE(tltu(a0, a1, 0),
665          "00850033       tltu    a0, a1, code: 0x000");
666  COMPARE(tltu(s0, s1, 1023),
667          "0211fff3       tltu    s0, s1, code: 0x3ff");
668  COMPARE(teq(a0, a1, 0),
669          "00850034       teq     a0, a1, code: 0x000");
670  COMPARE(teq(s0, s1, 1023),
671          "0211fff4       teq     s0, s1, code: 0x3ff");
672  COMPARE(tne(a0, a1, 0),
673          "00850036       tne     a0, a1, code: 0x000");
674  COMPARE(tne(s0, s1, 1023),
675          "0211fff6       tne     s0, s1, code: 0x3ff");
676
677  COMPARE(mfhi(a0),
678          "00002010       mfhi    a0");
679  COMPARE(mfhi(s2),
680          "00009010       mfhi    s2");
681  COMPARE(mfhi(t4),
682          "00006010       mfhi    t4");
683  COMPARE(mfhi(v1),
684          "00001810       mfhi    v1");
685  COMPARE(mflo(a0),
686          "00002012       mflo    a0");
687  COMPARE(mflo(s2),
688          "00009012       mflo    s2");
689  COMPARE(mflo(t4),
690          "00006012       mflo    t4");
691  COMPARE(mflo(v1),
692          "00001812       mflo    v1");
693
694  COMPARE(slt(a0, a1, a2),
695          "00a6202a       slt     a0, a1, a2");
696  COMPARE(slt(s0, s1, s2),
697          "0232802a       slt     s0, s1, s2");
698  COMPARE(slt(t2, t3, t4),
699          "016c502a       slt     t2, t3, t4");
700  COMPARE(slt(v0, v1, a2),
701          "0066102a       slt     v0, v1, a2");
702  COMPARE(sltu(a0, a1, a2),
703          "00a6202b       sltu    a0, a1, a2");
704  COMPARE(sltu(s0, s1, s2),
705          "0232802b       sltu    s0, s1, s2");
706  COMPARE(sltu(t2, t3, t4),
707          "016c502b       sltu    t2, t3, t4");
708  COMPARE(sltu(v0, v1, a2),
709          "0066102b       sltu    v0, v1, a2");
710
711  COMPARE(slti(a0, a1, 0),
712          "28a40000       slti    a0, a1, 0");
713  COMPARE(slti(s0, s1, 32767),
714          "2a307fff       slti    s0, s1, 32767");
715  COMPARE(slti(t2, t3, -32768),
716          "296a8000       slti    t2, t3, -32768");
717  COMPARE(slti(v0, v1, -1),
718          "2862ffff       slti    v0, v1, -1");
719  COMPARE(sltiu(a0, a1, 0),
720          "2ca40000       sltiu   a0, a1, 0");
721  COMPARE(sltiu(s0, s1, 32767),
722          "2e307fff       sltiu   s0, s1, 32767");
723  COMPARE(sltiu(t2, t3, -32768),
724          "2d6a8000       sltiu   t2, t3, -32768");
725  COMPARE(sltiu(v0, v1, -1),
726          "2c62ffff       sltiu   v0, v1, -1");
727
728  if (!IsMipsArchVariant(kLoongson)) {
729    COMPARE(movz(a0, a1, a2),
730            "00a6200a       movz    a0, a1, a2");
731    COMPARE(movz(s0, s1, s2),
732            "0232800a       movz    s0, s1, s2");
733    COMPARE(movz(t2, t3, t4),
734            "016c500a       movz    t2, t3, t4");
735    COMPARE(movz(v0, v1, a2),
736            "0066100a       movz    v0, v1, a2");
737    COMPARE(movn(a0, a1, a2),
738            "00a6200b       movn    a0, a1, a2");
739    COMPARE(movn(s0, s1, s2),
740            "0232800b       movn    s0, s1, s2");
741    COMPARE(movn(t2, t3, t4),
742            "016c500b       movn    t2, t3, t4");
743    COMPARE(movn(v0, v1, a2),
744            "0066100b       movn    v0, v1, a2");
745
746    COMPARE(movt(a0, a1, 1),
747            "00a52001       movt    a0, a1, 1");
748    COMPARE(movt(s0, s1, 2),
749            "02298001       movt    s0, s1, 2");
750    COMPARE(movt(t2, t3, 3),
751            "016d5001       movt    t2, t3, 3");
752    COMPARE(movt(v0, v1, 7),
753            "007d1001       movt    v0, v1, 7");
754    COMPARE(movf(a0, a1, 0),
755            "00a02001       movf    a0, a1, 0");
756    COMPARE(movf(s0, s1, 4),
757            "02308001       movf    s0, s1, 4");
758    COMPARE(movf(t2, t3, 5),
759            "01745001       movf    t2, t3, 5");
760    COMPARE(movf(v0, v1, 6),
761            "00781001       movf    v0, v1, 6");
762
763    if (IsMipsArchVariant(kMips32r6)) {
764      COMPARE(clz(a0, a1),
765              "00a02050       clz     a0, a1");
766      COMPARE(clz(s6, s7),
767              "02e0b050       clz     s6, s7");
768      COMPARE(clz(v0, v1),
769              "00601050       clz     v0, v1");
770    } else {
771      COMPARE(clz(a0, a1),
772              "70a42020       clz     a0, a1");
773      COMPARE(clz(s6, s7),
774              "72f6b020       clz     s6, s7");
775      COMPARE(clz(v0, v1),
776              "70621020       clz     v0, v1");
777    }
778  }
779
780  if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
781    COMPARE(seb(a0, a1), "7c052420       seb     a0, a1");
782    COMPARE(seb(s6, s7), "7c17b420       seb     s6, s7");
783    COMPARE(seb(v0, v1), "7c031420       seb     v0, v1");
784
785    COMPARE(seh(a0, a1), "7c052620       seh     a0, a1");
786    COMPARE(seh(s6, s7), "7c17b620       seh     s6, s7");
787    COMPARE(seh(v0, v1), "7c031620       seh     v0, v1");
788
789    COMPARE(wsbh(a0, a1), "7c0520a0       wsbh    a0, a1");
790    COMPARE(wsbh(s6, s7), "7c17b0a0       wsbh    s6, s7");
791    COMPARE(wsbh(v0, v1), "7c0310a0       wsbh    v0, v1");
792  }
793
794  if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
795    COMPARE(ins_(a0, a1, 31, 1),
796            "7ca4ffc4       ins     a0, a1, 31, 1");
797    COMPARE(ins_(s6, s7, 30, 2),
798            "7ef6ff84       ins     s6, s7, 30, 2");
799    COMPARE(ins_(v0, v1, 0, 32),
800            "7c62f804       ins     v0, v1, 0, 32");
801    COMPARE(ext_(a0, a1, 31, 1),
802            "7ca407c0       ext     a0, a1, 31, 1");
803    COMPARE(ext_(s6, s7, 30, 2),
804            "7ef60f80       ext     s6, s7, 30, 2");
805    COMPARE(ext_(v0, v1, 0, 32),
806            "7c62f800       ext     v0, v1, 0, 32");
807  }
808  COMPARE(add_s(f4, f6, f8), "46083100       add.s   f4, f6, f8");
809  COMPARE(add_d(f12, f14, f16), "46307300       add.d   f12, f14, f16");
810
811  if (IsMipsArchVariant(kMips32r6)) {
812    COMPARE(bitswap(a0, a1), "7c052020       bitswap a0, a1");
813    COMPARE(bitswap(t8, s0), "7c10c020       bitswap t8, s0");
814  }
815
816  COMPARE(abs_s(f6, f8), "46004185       abs.s   f6, f8");
817  COMPARE(abs_d(f10, f12), "46206285       abs.d   f10, f12");
818
819  COMPARE(div_s(f2, f4, f6), "46062083       div.s   f2, f4, f6");
820  COMPARE(div_d(f2, f4, f6), "46262083       div.d   f2, f4, f6");
821
822  if (IsMipsArchVariant(kMips32r6)) {
823    COMPARE(align(v0, a0, a1, 0), "7c851220       align  v0, a0, a1, 0");
824    COMPARE(align(v0, a0, a1, 1), "7c851260       align  v0, a0, a1, 1");
825    COMPARE(align(v0, a0, a1, 2), "7c8512a0       align  v0, a0, a1, 2");
826    COMPARE(align(v0, a0, a1, 3), "7c8512e0       align  v0, a0, a1, 3");
827  }
828
829  if (IsMipsArchVariant(kMips32r6)) {
830    COMPARE(aluipc(v0, 0), "ec5f0000       aluipc  v0, 0");
831    COMPARE(aluipc(v0, 1), "ec5f0001       aluipc  v0, 1");
832    COMPARE(aluipc(v0, 32767), "ec5f7fff       aluipc  v0, 32767");
833    COMPARE(aluipc(v0, -32768), "ec5f8000       aluipc  v0, -32768");
834    COMPARE(aluipc(v0, -1), "ec5fffff       aluipc  v0, -1");
835  }
836
837  if (IsMipsArchVariant(kMips32r6)) {
838    COMPARE(auipc(t8, 0), "ef1e0000       auipc   t8, 0");
839    COMPARE(auipc(t8, 1), "ef1e0001       auipc   t8, 1");
840    COMPARE(auipc(t8, 32767), "ef1e7fff       auipc   t8, 32767");
841    COMPARE(auipc(t8, -32768), "ef1e8000       auipc   t8, -32768");
842    COMPARE(auipc(t8, -1), "ef1effff       auipc   t8, -1");
843  }
844
845  if (IsMipsArchVariant(kMips32r6)) {
846    COMPARE(lwpc(t1, 0), "ed280000       lwpc    t1, 0");
847    COMPARE(lwpc(t1, 4), "ed280004       lwpc    t1, 4");
848    COMPARE(lwpc(t1, -4), "ed2ffffc       lwpc    t1, -4");
849  }
850
851  if (IsMipsArchVariant(kMips32r6)) {
852    COMPARE(jic(t0, -32768), "d8088000       jic     t0, -32768");
853    COMPARE(jic(t0, -1), "d808ffff       jic     t0, -1");
854    COMPARE(jic(t0, 0), "d8080000       jic     t0, 0");
855    COMPARE(jic(t0, 4), "d8080004       jic     t0, 4");
856    COMPARE(jic(t0, 32767), "d8087fff       jic     t0, 32767");
857  }
858
859  if (IsMipsArchVariant(kMips32r6)) {
860    COMPARE(addiupc(a0, 262143), "ec83ffff       addiupc a0, 262143");
861    COMPARE(addiupc(a0, -1), "ec87ffff       addiupc a0, -1");
862    COMPARE(addiupc(v0, 0), "ec400000       addiupc v0, 0");
863    COMPARE(addiupc(s1, 1), "ee200001       addiupc s1, 1");
864    COMPARE(addiupc(a0, -262144), "ec840000       addiupc a0, -262144");
865  }
866
867  if (IsMipsArchVariant(kMips32r6)) {
868    COMPARE(jialc(a0, -32768), "f8048000       jialc   a0, -32768");
869    COMPARE(jialc(a0, -1), "f804ffff       jialc   a0, -1");
870    COMPARE(jialc(v0, 0), "f8020000       jialc   v0, 0");
871    COMPARE(jialc(s1, 1), "f8110001       jialc   s1, 1");
872    COMPARE(jialc(a0, 32767), "f8047fff       jialc   a0, 32767");
873  }
874
875  VERIFY_RUN();
876}
877
878
879TEST(Type1) {
880  SET_UP();
881  if (IsMipsArchVariant(kMips32r6)) {
882    COMPARE(seleqz(a0, a1, a2), "00a62035       seleqz    a0, a1, a2");
883    COMPARE(selnez(a0, a1, a2), "00a62037       selnez    a0, a1, a2");
884
885
886    COMPARE(seleqz_d(f3, f4, f5), "462520d4       seleqz.d    f3, f4, f5");
887    COMPARE(selnez_d(f3, f4, f5), "462520d7       selnez.d    f3, f4, f5");
888    COMPARE(seleqz_s(f3, f4, f5), "460520d4       seleqz.s    f3, f4, f5");
889    COMPARE(selnez_s(f3, f4, f5), "460520d7       selnez.s    f3, f4, f5");
890
891    COMPARE(min_d(f3, f4, f5), "462520dc       min.d    f3, f4, f5");
892    COMPARE(max_d(f3, f4, f5), "462520de       max.d    f3, f4, f5");
893
894    COMPARE(sel_s(f3, f4, f5), "460520d0       sel.s      f3, f4, f5");
895    COMPARE(sel_d(f3, f4, f5), "462520d0       sel.d      f3, f4, f5");
896
897    COMPARE(rint_d(f8, f6), "4620321a       rint.d    f8, f6");
898    COMPARE(rint_s(f8, f6), "4600321a       rint.s    f8, f6");
899
900    COMPARE(min_s(f3, f4, f5), "460520dc       min.s    f3, f4, f5");
901    COMPARE(max_s(f3, f4, f5), "460520de       max.s    f3, f4, f5");
902
903    COMPARE(mina_d(f3, f4, f5), "462520dd       mina.d   f3, f4, f5");
904    COMPARE(mina_s(f3, f4, f5), "460520dd       mina.s   f3, f4, f5");
905
906    COMPARE(maxa_d(f3, f4, f5), "462520df       maxa.d   f3, f4, f5");
907    COMPARE(maxa_s(f3, f4, f5), "460520df       maxa.s   f3, f4, f5");
908  }
909
910  if ((IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) &&
911      IsFp64Mode()) {
912    COMPARE(trunc_l_d(f8, f6), "46203209       trunc.l.d f8, f6");
913    COMPARE(trunc_l_s(f8, f6), "46003209       trunc.l.s f8, f6");
914
915    COMPARE(round_l_s(f8, f6), "46003208       round.l.s f8, f6");
916    COMPARE(round_l_d(f8, f6), "46203208       round.l.d f8, f6");
917
918    COMPARE(floor_l_s(f8, f6), "4600320b       floor.l.s f8, f6");
919    COMPARE(floor_l_d(f8, f6), "4620320b       floor.l.d f8, f6");
920
921    COMPARE(ceil_l_s(f8, f6), "4600320a       ceil.l.s f8, f6");
922    COMPARE(ceil_l_d(f8, f6), "4620320a       ceil.l.d f8, f6");
923  }
924
925  COMPARE(trunc_w_d(f8, f6), "4620320d       trunc.w.d f8, f6");
926  COMPARE(trunc_w_s(f8, f6), "4600320d       trunc.w.s f8, f6");
927
928  COMPARE(round_w_s(f8, f6), "4600320c       round.w.s f8, f6");
929  COMPARE(round_w_d(f8, f6), "4620320c       round.w.d f8, f6");
930
931  COMPARE(floor_w_s(f8, f6), "4600320f       floor.w.s f8, f6");
932  COMPARE(floor_w_d(f8, f6), "4620320f       floor.w.d f8, f6");
933
934  COMPARE(ceil_w_s(f8, f6), "4600320e       ceil.w.s f8, f6");
935  COMPARE(ceil_w_d(f8, f6), "4620320e       ceil.w.d f8, f6");
936
937  COMPARE(sub_s(f10, f8, f6), "46064281       sub.s   f10, f8, f6");
938  COMPARE(sub_d(f10, f8, f6), "46264281       sub.d   f10, f8, f6");
939
940  COMPARE(sqrt_s(f8, f6), "46003204       sqrt.s  f8, f6");
941  COMPARE(sqrt_d(f8, f6), "46203204       sqrt.d  f8, f6");
942
943  COMPARE(neg_s(f8, f6), "46003207       neg.s   f8, f6");
944  COMPARE(neg_d(f8, f6), "46203207       neg.d   f8, f6");
945
946  COMPARE(mul_s(f8, f6, f4), "46043202       mul.s   f8, f6, f4");
947  COMPARE(mul_d(f8, f6, f4), "46243202       mul.d   f8, f6, f4");
948
949  if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) {
950    COMPARE(rsqrt_s(f8, f6), "46003216       rsqrt.s  f8, f6");
951    COMPARE(rsqrt_d(f8, f6), "46203216       rsqrt.d  f8, f6");
952
953    COMPARE(recip_s(f8, f6), "46003215       recip.s  f8, f6");
954    COMPARE(recip_d(f8, f6), "46203215       recip.d  f8, f6");
955  }
956
957  COMPARE(mov_s(f6, f4), "46002186       mov.s   f6, f4");
958  COMPARE(mov_d(f6, f4), "46202186       mov.d   f6, f4");
959
960  if (IsMipsArchVariant(kMips32r2)) {
961    COMPARE(movz_s(f6, f4, t0), "46082192       movz.s    f6, f4, t0");
962    COMPARE(movz_d(f6, f4, t0), "46282192       movz.d    f6, f4, t0");
963
964    COMPARE(movt_s(f6, f4, 4), "46112191       movt.s    f6, f4, cc(1)");
965    COMPARE(movt_d(f6, f4, 4), "46312191       movt.d    f6, f4, cc(1)");
966
967    COMPARE(movf_s(f6, f4, 4), "46102191       movf.s    f6, f4, cc(1)");
968    COMPARE(movf_d(f6, f4, 4), "46302191       movf.d    f6, f4, cc(1)");
969
970    COMPARE(movn_s(f6, f4, t0), "46082193       movn.s    f6, f4, t0");
971    COMPARE(movn_d(f6, f4, t0), "46282193       movn.d    f6, f4, t0");
972  }
973  VERIFY_RUN();
974}
975
976
977TEST(Type2) {
978  if (IsMipsArchVariant(kMips32r6)) {
979    SET_UP();
980
981    COMPARE(class_s(f3, f4), "460020db       class.s f3, f4");
982    COMPARE(class_d(f2, f3), "4620189b       class.d f2, f3");
983
984    VERIFY_RUN();
985  }
986}
987
988
989TEST(C_FMT_DISASM) {
990  if (IsMipsArchVariant(kMips32r1) || IsMipsArchVariant(kMips32r2)) {
991    SET_UP();
992
993    COMPARE(c_s(F, f8, f10, 0), "460a4030       c.f.s   f8, f10, cc(0)");
994    COMPARE(c_d(F, f8, f10, 0), "462a4030       c.f.d   f8, f10, cc(0)");
995
996    COMPARE(c_s(UN, f8, f10, 2), "460a4231       c.un.s  f8, f10, cc(2)");
997    COMPARE(c_d(UN, f8, f10, 2), "462a4231       c.un.d  f8, f10, cc(2)");
998
999    COMPARE(c_s(EQ, f8, f10, 4), "460a4432       c.eq.s  f8, f10, cc(4)");
1000    COMPARE(c_d(EQ, f8, f10, 4), "462a4432       c.eq.d  f8, f10, cc(4)");
1001
1002    COMPARE(c_s(UEQ, f8, f10, 6), "460a4633       c.ueq.s f8, f10, cc(6)");
1003    COMPARE(c_d(UEQ, f8, f10, 6), "462a4633       c.ueq.d f8, f10, cc(6)");
1004
1005    COMPARE(c_s(OLT, f8, f10, 0), "460a4034       c.olt.s f8, f10, cc(0)");
1006    COMPARE(c_d(OLT, f8, f10, 0), "462a4034       c.olt.d f8, f10, cc(0)");
1007
1008    COMPARE(c_s(ULT, f8, f10, 2), "460a4235       c.ult.s f8, f10, cc(2)");
1009    COMPARE(c_d(ULT, f8, f10, 2), "462a4235       c.ult.d f8, f10, cc(2)");
1010
1011    COMPARE(c_s(OLE, f8, f10, 4), "460a4436       c.ole.s f8, f10, cc(4)");
1012    COMPARE(c_d(OLE, f8, f10, 4), "462a4436       c.ole.d f8, f10, cc(4)");
1013
1014    COMPARE(c_s(ULE, f8, f10, 6), "460a4637       c.ule.s f8, f10, cc(6)");
1015    COMPARE(c_d(ULE, f8, f10, 6), "462a4637       c.ule.d f8, f10, cc(6)");
1016
1017    VERIFY_RUN();
1018  }
1019}
1020
1021
1022TEST(COND_FMT_DISASM) {
1023  if (IsMipsArchVariant(kMips32r6)) {
1024    SET_UP();
1025
1026    COMPARE(cmp_s(F, f6, f8, f10), "468a4180       cmp.af.s    f6, f8, f10");
1027    COMPARE(cmp_d(F, f6, f8, f10), "46aa4180       cmp.af.d  f6,  f8, f10");
1028
1029    COMPARE(cmp_s(UN, f6, f8, f10), "468a4181       cmp.un.s    f6, f8, f10");
1030    COMPARE(cmp_d(UN, f6, f8, f10), "46aa4181       cmp.un.d  f6,  f8, f10");
1031
1032    COMPARE(cmp_s(EQ, f6, f8, f10), "468a4182       cmp.eq.s    f6, f8, f10");
1033    COMPARE(cmp_d(EQ, f6, f8, f10), "46aa4182       cmp.eq.d  f6,  f8, f10");
1034
1035    COMPARE(cmp_s(UEQ, f6, f8, f10), "468a4183       cmp.ueq.s   f6, f8, f10");
1036    COMPARE(cmp_d(UEQ, f6, f8, f10), "46aa4183       cmp.ueq.d  f6,  f8, f10");
1037
1038    COMPARE(cmp_s(LT, f6, f8, f10), "468a4184       cmp.lt.s    f6, f8, f10");
1039    COMPARE(cmp_d(LT, f6, f8, f10), "46aa4184       cmp.lt.d  f6,  f8, f10");
1040
1041    COMPARE(cmp_s(ULT, f6, f8, f10), "468a4185       cmp.ult.s   f6, f8, f10");
1042    COMPARE(cmp_d(ULT, f6, f8, f10), "46aa4185       cmp.ult.d  f6,  f8, f10");
1043
1044    COMPARE(cmp_s(LE, f6, f8, f10), "468a4186       cmp.le.s    f6, f8, f10");
1045    COMPARE(cmp_d(LE, f6, f8, f10), "46aa4186       cmp.le.d  f6,  f8, f10");
1046
1047    COMPARE(cmp_s(ULE, f6, f8, f10), "468a4187       cmp.ule.s   f6, f8, f10");
1048    COMPARE(cmp_d(ULE, f6, f8, f10), "46aa4187       cmp.ule.d  f6,  f8, f10");
1049
1050    COMPARE(cmp_s(ORD, f6, f8, f10), "468a4191       cmp.or.s    f6, f8, f10");
1051    COMPARE(cmp_d(ORD, f6, f8, f10), "46aa4191       cmp.or.d  f6,  f8, f10");
1052
1053    COMPARE(cmp_s(UNE, f6, f8, f10), "468a4192       cmp.une.s   f6, f8, f10");
1054    COMPARE(cmp_d(UNE, f6, f8, f10), "46aa4192       cmp.une.d  f6,  f8, f10");
1055
1056    COMPARE(cmp_s(NE, f6, f8, f10), "468a4193       cmp.ne.s    f6, f8, f10");
1057    COMPARE(cmp_d(NE, f6, f8, f10), "46aa4193       cmp.ne.d  f6,  f8, f10");
1058
1059    VERIFY_RUN();
1060  }
1061}
1062
1063
1064TEST(CVT_DISSASM) {
1065  SET_UP();
1066  COMPARE(cvt_d_s(f22, f24), "4600c5a1       cvt.d.s f22, f24");
1067  COMPARE(cvt_d_w(f22, f24), "4680c5a1       cvt.d.w f22, f24");
1068
1069  COMPARE(cvt_s_d(f22, f24), "4620c5a0       cvt.s.d f22, f24");
1070  COMPARE(cvt_s_w(f22, f24), "4680c5a0       cvt.s.w f22, f24");
1071
1072  if ((IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) &&
1073      IsFp64Mode()) {
1074    COMPARE(cvt_d_l(f22, f24), "46a0c5a1       cvt.d.l f22, f24");
1075    COMPARE(cvt_l_d(f22, f24), "4620c5a5       cvt.l.d f22, f24");
1076
1077    COMPARE(cvt_s_l(f22, f24), "46a0c5a0       cvt.s.l f22, f24");
1078    COMPARE(cvt_l_s(f22, f24), "4600c5a5       cvt.l.s f22, f24");
1079  }
1080
1081  VERIFY_RUN();
1082}
1083
1084
1085TEST(ctc1_cfc1_disasm) {
1086  SET_UP();
1087  COMPARE(abs_d(f10, f31), "4620fa85       abs.d   f10, f31");
1088  COMPARE(ceil_w_s(f8, f31), "4600fa0e       ceil.w.s f8, f31");
1089  COMPARE(ctc1(a0, FCSR), "44c4f800       ctc1    a0, FCSR");
1090  COMPARE(cfc1(a0, FCSR), "4444f800       cfc1    a0, FCSR");
1091  VERIFY_RUN();
1092}
1093