OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/instructions.h" | 9 #include "vm/instructions.h" |
10 #include "vm/stub_code.h" | 10 #include "vm/stub_code.h" |
11 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 #define __ assembler-> | 15 #define __ assembler-> |
16 | 16 |
17 ASSEMBLER_TEST_GENERATE(NotAny, assembler) { | |
18 __ nop(); | |
19 __ ret(); | |
20 } | |
21 | |
22 ASSEMBLER_TEST_RUN(NotAny, entry) { | |
23 ICLoadReceiver load(entry); | |
24 EXPECT(!load.IsValid()); | |
25 JumpIfZero jump(entry); | |
26 EXPECT(!jump.IsValid()); | |
27 CmpEaxWithImmediate cmp(entry); | |
28 EXPECT(!cmp.IsValid()); | |
29 TestEaxIsSmi test(entry); | |
30 EXPECT(!test.IsValid()); | |
31 ICCheckReceiverClass check_class(entry); | |
32 EXPECT(!check_class.IsValid()); | |
33 } | |
34 | |
35 | |
36 ASSEMBLER_TEST_GENERATE(ICLoadReceiver, assembler) { | |
37 __ movl(EAX, FieldAddress(EDX, Array::data_offset())); | |
38 __ movl(EAX, Address(ESP, EAX, TIMES_2, 0)); | |
39 __ ret(); | |
40 } | |
41 | |
42 ASSEMBLER_TEST_RUN(ICLoadReceiver, entry) { | |
43 ICLoadReceiver load(entry); | |
44 EXPECT(load.IsValid()); | |
45 } | |
46 | |
47 | |
48 ASSEMBLER_TEST_GENERATE(JumpIfZero, assembler) { | |
49 __ j(ZERO, &StubCode::MegamorphicLookupLabel()); | |
50 __ ret(); | |
51 } | |
52 | |
53 ASSEMBLER_TEST_RUN(JumpIfZero, entry) { | |
54 JumpIfZero jump(entry); | |
55 EXPECT(jump.IsValid()); | |
56 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), jump.TargetAddress()); | |
57 } | |
58 | |
59 | |
60 ASSEMBLER_TEST_GENERATE(CmpEaxWithImmediate, assembler) { | |
61 const Immediate raw_null = | |
62 Immediate(reinterpret_cast<intptr_t>(Object::null())); | |
63 __ cmpl(EAX, raw_null); | |
64 __ ret(); | |
65 } | |
66 | |
67 ASSEMBLER_TEST_RUN(CmpEaxWithImmediate, entry) { | |
68 CmpEaxWithImmediate cmp(entry); | |
69 EXPECT(cmp.IsValid()); | |
70 const Immediate raw_null = | |
71 Immediate(reinterpret_cast<intptr_t>(Object::null())); | |
72 EXPECT_EQ(raw_null.value(), cmp.immediate()->value()); | |
73 } | |
74 | |
75 | |
76 ASSEMBLER_TEST_GENERATE(TestEaxIsSmi, assembler) { | |
77 __ testl(EAX, Immediate(kSmiTagMask)); | |
78 __ j(ZERO, &StubCode::MegamorphicLookupLabel()); | |
79 __ ret(); | |
80 } | |
81 | |
82 ASSEMBLER_TEST_RUN(TestEaxIsSmi, entry) { | |
83 TestEaxIsSmi test(entry); | |
84 EXPECT(test.IsValid()); | |
85 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), test.TargetAddress()); | |
86 } | |
87 | |
88 | |
89 ASSEMBLER_TEST_GENERATE(ICCheckReceiverClass, assembler) { | |
90 const Class& test_class = | |
91 Class::ZoneHandle(Isolate::Current()->object_store()->double_class()); | |
92 __ CompareObject(EBX, test_class); | |
93 __ j(ZERO, &StubCode::MegamorphicLookupLabel()); | |
94 __ ret(); | |
95 } | |
96 | |
97 ASSEMBLER_TEST_RUN(ICCheckReceiverClass, entry) { | |
98 ICCheckReceiverClass class_check(entry); | |
99 EXPECT(class_check.IsValid()); | |
100 EXPECT_EQ(Isolate::Current()->object_store()->double_class(), | |
101 class_check.TestClass()); | |
102 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), | |
103 class_check.TargetAddress()); | |
104 } | |
105 | |
106 | |
107 ASSEMBLER_TEST_GENERATE(LoadObjectClass, assembler) { | |
108 __ movl(EBX, FieldAddress(EAX, Object::class_offset())); | |
109 __ ret(); | |
110 } | |
111 | |
112 ASSEMBLER_TEST_RUN(LoadObjectClass, entry) { | |
113 LoadObjectClass load(entry); | |
114 EXPECT(load.IsValid()); | |
115 } | |
116 | |
117 | |
118 ASSEMBLER_TEST_GENERATE(Call, assembler) { | 17 ASSEMBLER_TEST_GENERATE(Call, assembler) { |
119 __ call(&StubCode::MegamorphicLookupLabel()); | 18 __ call(&StubCode::MegamorphicLookupLabel()); |
120 __ ret(); | 19 __ ret(); |
121 } | 20 } |
122 | 21 |
123 | 22 |
124 ASSEMBLER_TEST_RUN(Call, entry) { | 23 ASSEMBLER_TEST_RUN(Call, entry) { |
125 Call call(entry); | 24 Call call(entry); |
126 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), call.TargetAddress()); | 25 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), call.TargetAddress()); |
127 } | 26 } |
128 | 27 |
129 | 28 |
130 ASSEMBLER_TEST_GENERATE(Jump, assembler) { | 29 ASSEMBLER_TEST_GENERATE(Jump, assembler) { |
131 __ jmp(&StubCode::MegamorphicLookupLabel()); | 30 __ jmp(&StubCode::MegamorphicLookupLabel()); |
132 __ jmp(&StubCode::CallInstanceFunctionLabel()); | 31 __ jmp(&StubCode::OptimizeInvokedFunctionLabel()); |
133 __ ret(); | 32 __ ret(); |
134 } | 33 } |
135 | 34 |
136 | 35 |
137 ASSEMBLER_TEST_RUN(Jump, entry) { | 36 ASSEMBLER_TEST_RUN(Jump, entry) { |
138 Jump jump1(entry); | 37 Jump jump1(entry); |
139 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), | 38 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), |
140 jump1.TargetAddress()); | 39 jump1.TargetAddress()); |
141 Jump jump2(entry + jump1.pattern_length_in_bytes()); | 40 Jump jump2(entry + jump1.pattern_length_in_bytes()); |
142 EXPECT_EQ(StubCode::CallInstanceFunctionLabel().address(), | 41 EXPECT_EQ(StubCode::OptimizeInvokedFunctionLabel().address(), |
143 jump2.TargetAddress()); | 42 jump2.TargetAddress()); |
144 uword target1 = jump1.TargetAddress(); | 43 uword target1 = jump1.TargetAddress(); |
145 uword target2 = jump2.TargetAddress(); | 44 uword target2 = jump2.TargetAddress(); |
146 jump1.SetTargetAddress(target2); | 45 jump1.SetTargetAddress(target2); |
147 jump2.SetTargetAddress(target1); | 46 jump2.SetTargetAddress(target1); |
148 EXPECT_EQ(StubCode::CallInstanceFunctionLabel().address(), | 47 EXPECT_EQ(StubCode::OptimizeInvokedFunctionLabel().address(), |
149 jump1.TargetAddress()); | 48 jump1.TargetAddress()); |
150 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), | 49 EXPECT_EQ(StubCode::MegamorphicLookupLabel().address(), |
151 jump2.TargetAddress()); | 50 jump2.TargetAddress()); |
152 } | 51 } |
153 | 52 |
154 } // namespace dart | 53 } // namespace dart |
155 | 54 |
156 #endif // defined TARGET_ARCH_IA32 | 55 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |