Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: test/cctest/test-disasm-mips.cc

Issue 6994013: Add cctest/test-disasm-mips which was mistakenly omitted from r7825. (Closed) Base URL: http://github.com/v8/v8.git@bleeding_edge
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 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 "v8.h"
32
33 #include "debug.h"
34 #include "disasm.h"
35 #include "disassembler.h"
36 #include "macro-assembler.h"
37 #include "serialize.h"
38 #include "cctest.h"
39
40 using namespace v8::internal;
41
42
43 static v8::Persistent<v8::Context> env;
44
45 static void InitializeVM() {
46 // Disable compilation of natives.
47 FLAG_disable_native_files = true;
48 if (env.IsEmpty()) {
49 env = v8::Context::New();
50 }
51 }
52
53
54 bool DisassembleAndCompare(byte* pc, const char* compare_string) {
55 disasm::NameConverter converter;
56 disasm::Disassembler disasm(converter);
57 EmbeddedVector<char, 128> disasm_buffer;
58
59 disasm.InstructionDecode(disasm_buffer, pc);
60
61 if (strcmp(compare_string, disasm_buffer.start()) != 0) {
62 fprintf(stderr,
63 "expected: \n"
64 "%s\n"
65 "disassembled: \n"
66 "%s\n\n",
67 compare_string, disasm_buffer.start());
68 return false;
69 }
70 return true;
71 }
72
73
74 // Setup V8 to a state where we can at least run the assembler and
75 // disassembler. Declare the variables and allocate the data structures used
76 // in the rest of the macros.
77 #define SETUP() \
78 InitializeVM(); \
79 v8::HandleScope scope; \
80 byte *buffer = reinterpret_cast<byte*>(malloc(4*1024)); \
81 Assembler assm(Isolate::Current(), buffer, 4*1024); \
82 bool failure = false;
83
84
85 // This macro assembles one instruction using the preallocated assembler and
86 // disassembles the generated instruction, comparing the output to the expected
87 // value. If the comparison fails an error message is printed, but the test
88 // continues to run until the end.
89 #define COMPARE(asm_, compare_string) \
90 { \
91 int pc_offset = assm.pc_offset(); \
92 byte *progcounter = &buffer[pc_offset]; \
93 assm.asm_; \
94 if (!DisassembleAndCompare(progcounter, compare_string)) failure = true; \
95 }
96
97
98 // Verify that all invocations of the COMPARE macro passed successfully.
99 // Exit with a failure if at least one of the tests failed.
100 #define VERIFY_RUN() \
101 if (failure) { \
102 V8_Fatal(__FILE__, __LINE__, "MIPS Disassembler tests failed.\n"); \
103 }
104
105
106 TEST(Type0) {
107 SETUP();
108
109 COMPARE(addu(a0, a1, a2),
110 "00a62021 addu a0, a1, a2");
111 COMPARE(addu(t2, t3, t4),
112 "016c5021 addu t2, t3, t4");
113 COMPARE(addu(v0, v1, s0),
114 "00701021 addu v0, v1, s0");
115
116 COMPARE(subu(a0, a1, a2),
117 "00a62023 subu a0, a1, a2");
118 COMPARE(subu(t2, t3, t4),
119 "016c5023 subu t2, t3, t4");
120 COMPARE(subu(v0, v1, s0),
121 "00701023 subu v0, v1, s0");
122
123 COMPARE(mult(a0, a1),
124 "00850018 mult a0, a1");
125 COMPARE(mult(t2, t3),
126 "014b0018 mult t2, t3");
127 COMPARE(mult(v0, v1),
128 "00430018 mult v0, v1");
129
130 COMPARE(multu(a0, a1),
131 "00850019 multu a0, a1");
132 COMPARE(multu(t2, t3),
133 "014b0019 multu t2, t3");
134 COMPARE(multu(v0, v1),
135 "00430019 multu v0, v1");
136
137 COMPARE(div(a0, a1),
138 "0085001a div a0, a1");
139 COMPARE(div(t2, t3),
140 "014b001a div t2, t3");
141 COMPARE(div(v0, v1),
142 "0043001a div v0, v1");
143
144 COMPARE(divu(a0, a1),
145 "0085001b divu a0, a1");
146 COMPARE(divu(t2, t3),
147 "014b001b divu t2, t3");
148 COMPARE(divu(v0, v1),
149 "0043001b divu v0, v1");
150
151 COMPARE(mul(a0, a1, a2),
152 "70a62002 mul a0, a1, a2");
153 COMPARE(mul(t2, t3, t4),
154 "716c5002 mul t2, t3, t4");
155 COMPARE(mul(v0, v1, s0),
156 "70701002 mul v0, v1, s0");
157
158 COMPARE(addiu(a0, a1, 0x0),
159 "24a40000 addiu a0, a1, 0");
160 COMPARE(addiu(s0, s1, 32767),
161 "26307fff addiu s0, s1, 32767");
162 COMPARE(addiu(t2, t3, -32768),
163 "256a8000 addiu t2, t3, -32768");
164 COMPARE(addiu(v0, v1, -1),
165 "2462ffff addiu v0, v1, -1");
166
167 COMPARE(and_(a0, a1, a2),
168 "00a62024 and a0, a1, a2");
169 COMPARE(and_(s0, s1, s2),
170 "02328024 and s0, s1, s2");
171 COMPARE(and_(t2, t3, t4),
172 "016c5024 and t2, t3, t4");
173 COMPARE(and_(v0, v1, a2),
174 "00661024 and v0, v1, a2");
175
176 COMPARE(or_(a0, a1, a2),
177 "00a62025 or a0, a1, a2");
178 COMPARE(or_(s0, s1, s2),
179 "02328025 or s0, s1, s2");
180 COMPARE(or_(t2, t3, t4),
181 "016c5025 or t2, t3, t4");
182 COMPARE(or_(v0, v1, a2),
183 "00661025 or v0, v1, a2");
184
185 COMPARE(xor_(a0, a1, a2),
186 "00a62026 xor a0, a1, a2");
187 COMPARE(xor_(s0, s1, s2),
188 "02328026 xor s0, s1, s2");
189 COMPARE(xor_(t2, t3, t4),
190 "016c5026 xor t2, t3, t4");
191 COMPARE(xor_(v0, v1, a2),
192 "00661026 xor v0, v1, a2");
193
194 COMPARE(nor(a0, a1, a2),
195 "00a62027 nor a0, a1, a2");
196 COMPARE(nor(s0, s1, s2),
197 "02328027 nor s0, s1, s2");
198 COMPARE(nor(t2, t3, t4),
199 "016c5027 nor t2, t3, t4");
200 COMPARE(nor(v0, v1, a2),
201 "00661027 nor v0, v1, a2");
202
203 COMPARE(andi(a0, a1, 0x1),
204 "30a40001 andi a0, a1, 0x1");
205 COMPARE(andi(v0, v1, 0xffff),
206 "3062ffff andi v0, v1, 0xffff");
207
208 COMPARE(ori(a0, a1, 0x1),
209 "34a40001 ori a0, a1, 0x1");
210 COMPARE(ori(v0, v1, 0xffff),
211 "3462ffff ori v0, v1, 0xffff");
212
213 COMPARE(xori(a0, a1, 0x1),
214 "38a40001 xori a0, a1, 0x1");
215 COMPARE(xori(v0, v1, 0xffff),
216 "3862ffff xori v0, v1, 0xffff");
217
218 COMPARE(lui(a0, 0x1),
219 "3c040001 lui a0, 0x1");
220 COMPARE(lui(v0, 0xffff),
221 "3c02ffff lui v0, 0xffff");
222
223 COMPARE(sll(a0, a1, 0),
224 "00052000 sll a0, a1, 0");
225 COMPARE(sll(s0, s1, 8),
226 "00118200 sll s0, s1, 8");
227 COMPARE(sll(t2, t3, 24),
228 "000b5600 sll t2, t3, 24");
229 COMPARE(sll(v0, v1, 31),
230 "000317c0 sll v0, v1, 31");
231
232 COMPARE(sllv(a0, a1, a2),
233 "00c52004 sllv a0, a1, a2");
234 COMPARE(sllv(s0, s1, s2),
235 "02518004 sllv s0, s1, s2");
236 COMPARE(sllv(t2, t3, t4),
237 "018b5004 sllv t2, t3, t4");
238 COMPARE(sllv(v0, v1, fp),
239 "03c31004 sllv v0, v1, fp");
240
241 COMPARE(srl(a0, a1, 0),
242 "00052002 srl a0, a1, 0");
243 COMPARE(srl(s0, s1, 8),
244 "00118202 srl s0, s1, 8");
245 COMPARE(srl(t2, t3, 24),
246 "000b5602 srl t2, t3, 24");
247 COMPARE(srl(v0, v1, 31),
248 "000317c2 srl v0, v1, 31");
249
250 COMPARE(srlv(a0, a1, a2),
251 "00c52006 srlv a0, a1, a2");
252 COMPARE(srlv(s0, s1, s2),
253 "02518006 srlv s0, s1, s2");
254 COMPARE(srlv(t2, t3, t4),
255 "018b5006 srlv t2, t3, t4");
256 COMPARE(srlv(v0, v1, fp),
257 "03c31006 srlv v0, v1, fp");
258
259 COMPARE(sra(a0, a1, 0),
260 "00052003 sra a0, a1, 0");
261 COMPARE(sra(s0, s1, 8),
262 "00118203 sra s0, s1, 8");
263 COMPARE(sra(t2, t3, 24),
264 "000b5603 sra t2, t3, 24");
265 COMPARE(sra(v0, v1, 31),
266 "000317c3 sra v0, v1, 31");
267
268 COMPARE(srav(a0, a1, a2),
269 "00c52007 srav a0, a1, a2");
270 COMPARE(srav(s0, s1, s2),
271 "02518007 srav s0, s1, s2");
272 COMPARE(srav(t2, t3, t4),
273 "018b5007 srav t2, t3, t4");
274 COMPARE(srav(v0, v1, fp),
275 "03c31007 srav v0, v1, fp");
276
277 COMPARE(rotr(a0, a1, 0),
278 "00252002 rotr a0, a1, 0");
279 COMPARE(rotr(s0, s1, 8),
280 "00318202 rotr s0, s1, 8");
281 COMPARE(rotr(t2, t3, 24),
282 "002b5602 rotr t2, t3, 24");
283 COMPARE(rotr(v0, v1, 31),
284 "002317c2 rotr v0, v1, 31");
285
286 COMPARE(rotrv(a0, a1, a2),
287 "00c52046 rotrv a0, a1, a2");
288 COMPARE(rotrv(s0, s1, s2),
289 "02518046 rotrv s0, s1, s2");
290 COMPARE(rotrv(t2, t3, t4),
291 "018b5046 rotrv t2, t3, t4");
292 COMPARE(rotrv(v0, v1, fp),
293 "03c31046 rotrv v0, v1, fp");
294
295 COMPARE(break_(0),
296 "0000000d break, code: 0x00000 (0)");
297 COMPARE(break_(261120),
298 "00ff000d break, code: 0x3fc00 (261120)");
299 COMPARE(break_(1047552),
300 "03ff000d break, code: 0xffc00 (1047552)");
301
302 COMPARE(tge(a0, a1, 0),
303 "00850030 tge a0, a1, code: 0x000");
304 COMPARE(tge(s0, s1, 1023),
305 "0211fff0 tge s0, s1, code: 0x3ff");
306 COMPARE(tgeu(a0, a1, 0),
307 "00850031 tgeu a0, a1, code: 0x000");
308 COMPARE(tgeu(s0, s1, 1023),
309 "0211fff1 tgeu s0, s1, code: 0x3ff");
310 COMPARE(tlt(a0, a1, 0),
311 "00850032 tlt a0, a1, code: 0x000");
312 COMPARE(tlt(s0, s1, 1023),
313 "0211fff2 tlt s0, s1, code: 0x3ff");
314 COMPARE(tltu(a0, a1, 0),
315 "00850033 tltu a0, a1, code: 0x000");
316 COMPARE(tltu(s0, s1, 1023),
317 "0211fff3 tltu s0, s1, code: 0x3ff");
318 COMPARE(teq(a0, a1, 0),
319 "00850034 teq a0, a1, code: 0x000");
320 COMPARE(teq(s0, s1, 1023),
321 "0211fff4 teq s0, s1, code: 0x3ff");
322 COMPARE(tne(a0, a1, 0),
323 "00850036 tne a0, a1, code: 0x000");
324 COMPARE(tne(s0, s1, 1023),
325 "0211fff6 tne s0, s1, code: 0x3ff");
326
327 COMPARE(mfhi(a0),
328 "00002010 mfhi a0");
329 COMPARE(mfhi(s2),
330 "00009010 mfhi s2");
331 COMPARE(mfhi(t4),
332 "00006010 mfhi t4");
333 COMPARE(mfhi(v1),
334 "00001810 mfhi v1");
335 COMPARE(mflo(a0),
336 "00002012 mflo a0");
337 COMPARE(mflo(s2),
338 "00009012 mflo s2");
339 COMPARE(mflo(t4),
340 "00006012 mflo t4");
341 COMPARE(mflo(v1),
342 "00001812 mflo v1");
343
344 COMPARE(slt(a0, a1, a2),
345 "00a6202a slt a0, a1, a2");
346 COMPARE(slt(s0, s1, s2),
347 "0232802a slt s0, s1, s2");
348 COMPARE(slt(t2, t3, t4),
349 "016c502a slt t2, t3, t4");
350 COMPARE(slt(v0, v1, a2),
351 "0066102a slt v0, v1, a2");
352 COMPARE(sltu(a0, a1, a2),
353 "00a6202b sltu a0, a1, a2");
354 COMPARE(sltu(s0, s1, s2),
355 "0232802b sltu s0, s1, s2");
356 COMPARE(sltu(t2, t3, t4),
357 "016c502b sltu t2, t3, t4");
358 COMPARE(sltu(v0, v1, a2),
359 "0066102b sltu v0, v1, a2");
360
361 COMPARE(slti(a0, a1, 0),
362 "28a40000 slti a0, a1, 0");
363 COMPARE(slti(s0, s1, 32767),
364 "2a307fff slti s0, s1, 32767");
365 COMPARE(slti(t2, t3, -32768),
366 "296a8000 slti t2, t3, -32768");
367 COMPARE(slti(v0, v1, -1),
368 "2862ffff slti v0, v1, -1");
369 COMPARE(sltiu(a0, a1, 0),
370 "2ca40000 sltiu a0, a1, 0");
371 COMPARE(sltiu(s0, s1, 32767),
372 "2e307fff sltiu s0, s1, 32767");
373 COMPARE(sltiu(t2, t3, -32768),
374 "2d6a8000 sltiu t2, t3, -32768");
375 COMPARE(sltiu(v0, v1, -1),
376 "2c62ffff sltiu v0, v1, -1");
377
378 COMPARE(movz(a0, a1, a2),
379 "00a6200a movz a0, a1, a2");
380 COMPARE(movz(s0, s1, s2),
381 "0232800a movz s0, s1, s2");
382 COMPARE(movz(t2, t3, t4),
383 "016c500a movz t2, t3, t4");
384 COMPARE(movz(v0, v1, a2),
385 "0066100a movz v0, v1, a2");
386 COMPARE(movn(a0, a1, a2),
387 "00a6200b movn a0, a1, a2");
388 COMPARE(movn(s0, s1, s2),
389 "0232800b movn s0, s1, s2");
390 COMPARE(movn(t2, t3, t4),
391 "016c500b movn t2, t3, t4");
392 COMPARE(movn(v0, v1, a2),
393 "0066100b movn v0, v1, a2");
394
395 COMPARE(movt(a0, a1, 1),
396 "00a52001 movt a0, a1, 1");
397 COMPARE(movt(s0, s1, 2),
398 "02298001 movt s0, s1, 2");
399 COMPARE(movt(t2, t3, 3),
400 "016d5001 movt t2, t3, 3");
401 COMPARE(movt(v0, v1, 7),
402 "007d1001 movt v0, v1, 7");
403 COMPARE(movf(a0, a1, 0),
404 "00a02001 movf a0, a1, 0");
405 COMPARE(movf(s0, s1, 4),
406 "02308001 movf s0, s1, 4");
407 COMPARE(movf(t2, t3, 5),
408 "01745001 movf t2, t3, 5");
409 COMPARE(movf(v0, v1, 6),
410 "00781001 movf v0, v1, 6");
411
412 COMPARE(clz(a0, a1),
413 "70a42020 clz a0, a1");
414 COMPARE(clz(s6, s7),
415 "72f6b020 clz s6, s7");
416 COMPARE(clz(v0, v1),
417 "70621020 clz v0, v1");
418 COMPARE(ins_(a0, a1, 31, 1),
419 "7ca4ffc4 ins a0, a1, 31, 1");
420 COMPARE(ins_(s6, s7, 30, 2),
421 "7ef6ff84 ins s6, s7, 30, 2");
422 COMPARE(ins_(v0, v1, 0, 32),
423 "7c62f804 ins v0, v1, 0, 32");
424 COMPARE(ext_(a0, a1, 31, 1),
425 "7ca407c0 ext a0, a1, 31, 1");
426 COMPARE(ext_(s6, s7, 30, 2),
427 "7ef60f80 ext s6, s7, 30, 2");
428 COMPARE(ext_(v0, v1, 0, 32),
429 "7c62f800 ext v0, v1, 0, 32");
430
431 VERIFY_RUN();
432 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698