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

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

Issue 422063005: Contribution of PowerPC port. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: re-upload - catch up to 8/19 level Created 6 years, 3 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 | Annotate | Revision Log
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 "src/v8.h"
32
33 #include "src/debug.h"
34 #include "src/disasm.h"
35 #include "src/disassembler.h"
36 #include "src/macro-assembler.h"
37 #include "src/serialize.h"
38 #include "test/cctest/cctest.h"
39
40 using namespace v8::internal;
41
42
43 bool DisassembleAndCompare(byte* pc, const char* compare_string) {
44 disasm::NameConverter converter;
45 disasm::Disassembler disasm(converter);
46 EmbeddedVector<char, 128> disasm_buffer;
47
48 disasm.InstructionDecode(disasm_buffer, pc);
49
50 if (strcmp(compare_string, disasm_buffer.start()) != 0) {
51 fprintf(stderr,
52 "expected: \n"
53 "%s\n"
54 "disassembled: \n"
55 "%s\n\n",
56 compare_string, disasm_buffer.start());
57 return false;
58 }
59 return true;
60 }
61
62
63 // Set up V8 to a state where we can at least run the assembler and
64 // disassembler. Declare the variables and allocate the data structures used
65 // in the rest of the macros.
66 #define SET_UP() \
67 CcTest::InitializeVM(); \
68 Isolate* isolate = Isolate::Current(); \
69 HandleScope scope(isolate); \
70 byte* buffer = reinterpret_cast<byte*>(malloc(4 * 1024)); \
71 Assembler assm(isolate, buffer, 4 * 1024); \
72 bool failure = false;
73
74
75 // This macro assembles one instruction using the preallocated assembler and
76 // disassembles the generated instruction, comparing the output to the expected
77 // value. If the comparison fails an error message is printed, but the test
78 // continues to run until the end.
79 #define COMPARE(asm_, compare_string) \
80 { \
81 int pc_offset = assm.pc_offset(); \
82 byte* progcounter = &buffer[pc_offset]; \
83 assm.asm_; \
84 if (!DisassembleAndCompare(progcounter, compare_string)) failure = true; \
85 }
86
87 // Force emission of any pending literals into a pool.
88 #define EMIT_PENDING_LITERALS() assm.CheckConstPool(true, false)
89
90
91 // Verify that all invocations of the COMPARE macro passed successfully.
92 // Exit with a failure if at least one of the tests failed.
93 #define VERIFY_RUN() \
94 if (failure) { \
95 V8_Fatal(__FILE__, __LINE__, "PPC Disassembler tests failed.\n"); \
96 }
97
98 TEST(DisasmPPC) {
99 SET_UP();
100
101 COMPARE(addc(r9, r7, r9), "7d274814 addc r9, r7, r9");
102 COMPARE(addic(r3, r5, Operand(20)), "30650014 addic r3, r5, 20");
103 COMPARE(addi(r0, ip, Operand(63)), "380c003f addi r0, r12, 63");
104 COMPARE(add(r5, r7, r0), "7ca70214 add r5, r7, r0");
105 COMPARE(addze(r0, r0, LeaveOE, SetRC), "7c000195 addze. r0, r0");
106 COMPARE(andi(r0, r3, Operand(4)), "70600004 andi. r0, r3, 4");
107 COMPARE(and_(r3, r6, r5), "7cc32838 and r3, r6, r5");
108 COMPARE(and_(r6, r0, r6, SetRC), "7c063039 and. r6, r0, r6");
109 // skipping branches (for now?)
110 COMPARE(bctr(), "4e800420 bctr");
111 COMPARE(blr(), "4e800020 blr");
112 COMPARE(bclr(BA, SetLK), "4e800021 blrl");
113 // skipping call - only used in simulator
114 #if V8_TARGET_ARCH_PPC64
115 COMPARE(cmpi(r0, Operand(5)), "2fa00005 cmpi r0, 5");
116 #else
117 COMPARE(cmpi(r0, Operand(5)), "2f800005 cmpi r0, 5");
118 #endif
119 #if V8_TARGET_ARCH_PPC64
120 COMPARE(cmpl(r6, r7), "7fa63840 cmpl r6, r7");
121 #else
122 COMPARE(cmpl(r6, r7), "7f863840 cmpl r6, r7");
123 #endif
124 #if V8_TARGET_ARCH_PPC64
125 COMPARE(cmp(r5, r11), "7fa55800 cmp r5, r11");
126 #else
127 COMPARE(cmp(r5, r11), "7f855800 cmp r5, r11");
128 #endif
129 // skipping crxor - incomplete disassembly
130 COMPARE(lbz(r4, MemOperand(r4, 7)), "88840007 lbz r4, 7(r4)");
131 COMPARE(lfd(d0, MemOperand(sp, 128)), "c8010080 lfd d0, 128(sp)");
132 COMPARE(li(r0, Operand(16)), "38000010 li r0, 16");
133 COMPARE(lis(r8, Operand(22560)), "3d005820 lis r8, 22560");
134 COMPARE(lwz(ip, MemOperand(r19, 44)), "8193002c lwz r12, 44(r19)");
135 COMPARE(lwzx(r0, MemOperand(r5, ip)), "7c05602e lwzx r0, r5, r12");
136 COMPARE(mflr(r0), "7c0802a6 mflr r0");
137 COMPARE(mr(r15, r4), "7c8f2378 mr r15, r4");
138 COMPARE(mtctr(r0), "7c0903a6 mtctr r0");
139 COMPARE(mtlr(r15), "7de803a6 mtlr r15");
140 COMPARE(ori(r8, r8, Operand(42849)), "6108a761 ori r8, r8, 42849");
141 COMPARE(orx(r5, r3, r4), "7c652378 or r5, r3, r4");
142 COMPARE(rlwinm(r4, r3, 2, 0, 29), "5464103a rlwinm r4, r3, 2, 0, 29");
143 COMPARE(rlwinm(r0, r3, 0, 31, 31, SetRC),
144 "546007ff rlwinm. r0, r3, 0, 31, 31");
145 COMPARE(srawi(r3, r6, 1), "7cc30e70 srawi r3,r6,1");
146 COMPARE(stb(r5, MemOperand(r11, 11)), "98ab000b stb r5, 11(r11)");
147 COMPARE(stfd(d2, MemOperand(sp, 8)), "d8410008 stfd d2, 8(sp)");
148 COMPARE(stw(r16, MemOperand(sp, 64)), "92010040 stw r16, 64(sp)");
149 COMPARE(stwu(r3, MemOperand(sp, -4)), "9461fffc stwu r3, -4(sp)");
150 COMPARE(sub(r3, r3, r4), "7c641850 subf r3, r4, r3");
151 COMPARE(sub(r0, r9, r8, LeaveOE, SetRC), "7c084851 subf. r0, r8, r9");
152 COMPARE(xor_(r6, r5, r4), "7ca62278 xor r6, r5, r4");
153
154 VERIFY_RUN();
155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698