OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 __ nop(); | 103 __ nop(); |
104 __ ret(0); | 104 __ ret(0); |
105 | 105 |
106 CodeDesc desc; | 106 CodeDesc desc; |
107 assm.GetCode(&desc); | 107 assm.GetCode(&desc); |
108 // Call the function from C++. | 108 // Call the function from C++. |
109 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 109 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
110 CHECK_EQ(2, result); | 110 CHECK_EQ(2, result); |
111 } | 111 } |
112 | 112 |
| 113 |
113 TEST(AssemblerX64StackOperations) { | 114 TEST(AssemblerX64StackOperations) { |
114 OS::SetUp(); | 115 OS::SetUp(); |
115 // Allocate an executable page of memory. | 116 // Allocate an executable page of memory. |
116 size_t actual_size; | 117 size_t actual_size; |
117 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 118 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
118 &actual_size, | 119 &actual_size, |
119 true)); | 120 true)); |
120 CHECK(buffer); | 121 CHECK(buffer); |
121 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 122 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
122 | 123 |
(...skipping 12 matching lines...) Expand all Loading... |
135 __ nop(); | 136 __ nop(); |
136 __ ret(0); | 137 __ ret(0); |
137 | 138 |
138 CodeDesc desc; | 139 CodeDesc desc; |
139 assm.GetCode(&desc); | 140 assm.GetCode(&desc); |
140 // Call the function from C++. | 141 // Call the function from C++. |
141 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 142 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
142 CHECK_EQ(2, result); | 143 CHECK_EQ(2, result); |
143 } | 144 } |
144 | 145 |
| 146 |
145 TEST(AssemblerX64ArithmeticOperations) { | 147 TEST(AssemblerX64ArithmeticOperations) { |
146 OS::SetUp(); | 148 OS::SetUp(); |
147 // Allocate an executable page of memory. | 149 // Allocate an executable page of memory. |
148 size_t actual_size; | 150 size_t actual_size; |
149 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 151 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
150 &actual_size, | 152 &actual_size, |
151 true)); | 153 true)); |
152 CHECK(buffer); | 154 CHECK(buffer); |
153 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 155 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
154 | 156 |
155 // Assemble a simple function that adds arguments returning the sum. | 157 // Assemble a simple function that adds arguments returning the sum. |
156 __ movq(rax, arg2); | 158 __ movq(rax, arg2); |
157 __ addq(rax, arg1); | 159 __ addq(rax, arg1); |
158 __ ret(0); | 160 __ ret(0); |
159 | 161 |
160 CodeDesc desc; | 162 CodeDesc desc; |
161 assm.GetCode(&desc); | 163 assm.GetCode(&desc); |
162 // Call the function from C++. | 164 // Call the function from C++. |
163 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 165 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
164 CHECK_EQ(5, result); | 166 CHECK_EQ(5, result); |
165 } | 167 } |
166 | 168 |
| 169 |
167 TEST(AssemblerX64ImulOperation) { | 170 TEST(AssemblerX64ImulOperation) { |
168 OS::SetUp(); | 171 OS::SetUp(); |
169 // Allocate an executable page of memory. | 172 // Allocate an executable page of memory. |
170 size_t actual_size; | 173 size_t actual_size; |
171 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 174 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
172 &actual_size, | 175 &actual_size, |
173 true)); | 176 true)); |
174 CHECK(buffer); | 177 CHECK(buffer); |
175 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 178 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
176 | 179 |
177 // Assemble a simple function that multiplies arguments returning the high | 180 // Assemble a simple function that multiplies arguments returning the high |
178 // word. | 181 // word. |
179 __ movq(rax, arg2); | 182 __ movq(rax, arg2); |
180 __ imul(arg1); | 183 __ imul(arg1); |
181 __ movq(rax, rdx); | 184 __ movq(rax, rdx); |
182 __ ret(0); | 185 __ ret(0); |
183 | 186 |
184 CodeDesc desc; | 187 CodeDesc desc; |
185 assm.GetCode(&desc); | 188 assm.GetCode(&desc); |
186 // Call the function from C++. | 189 // Call the function from C++. |
187 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 190 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
188 CHECK_EQ(0, result); | 191 CHECK_EQ(0, result); |
189 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); | 192 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); |
190 CHECK_EQ(1, result); | 193 CHECK_EQ(1, result); |
191 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); | 194 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); |
192 CHECK_EQ(-1, result); | 195 CHECK_EQ(-1, result); |
193 } | 196 } |
194 | 197 |
| 198 |
195 TEST(AssemblerX64MemoryOperands) { | 199 TEST(AssemblerX64MemoryOperands) { |
196 OS::SetUp(); | 200 OS::SetUp(); |
197 // Allocate an executable page of memory. | 201 // Allocate an executable page of memory. |
198 size_t actual_size; | 202 size_t actual_size; |
199 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 203 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
200 &actual_size, | 204 &actual_size, |
201 true)); | 205 true)); |
202 CHECK(buffer); | 206 CHECK(buffer); |
203 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 207 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
204 | 208 |
(...skipping 14 matching lines...) Expand all Loading... |
219 __ nop(); | 223 __ nop(); |
220 __ ret(0); | 224 __ ret(0); |
221 | 225 |
222 CodeDesc desc; | 226 CodeDesc desc; |
223 assm.GetCode(&desc); | 227 assm.GetCode(&desc); |
224 // Call the function from C++. | 228 // Call the function from C++. |
225 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 229 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
226 CHECK_EQ(3, result); | 230 CHECK_EQ(3, result); |
227 } | 231 } |
228 | 232 |
| 233 |
229 TEST(AssemblerX64ControlFlow) { | 234 TEST(AssemblerX64ControlFlow) { |
230 OS::SetUp(); | 235 OS::SetUp(); |
231 // Allocate an executable page of memory. | 236 // Allocate an executable page of memory. |
232 size_t actual_size; | 237 size_t actual_size; |
233 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 238 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
234 &actual_size, | 239 &actual_size, |
235 true)); | 240 true)); |
236 CHECK(buffer); | 241 CHECK(buffer); |
237 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 242 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
238 | 243 |
239 // Assemble a simple function that copies argument 1 and returns it. | 244 // Assemble a simple function that copies argument 1 and returns it. |
240 __ push(rbp); | 245 __ push(rbp); |
241 | 246 |
242 __ movq(rbp, rsp); | 247 __ movq(rbp, rsp); |
243 __ movq(rax, arg1); | 248 __ movq(rax, arg1); |
244 Label target; | 249 Label target; |
245 __ jmp(&target); | 250 __ jmp(&target); |
246 __ movq(rax, arg2); | 251 __ movq(rax, arg2); |
247 __ bind(&target); | 252 __ bind(&target); |
248 __ pop(rbp); | 253 __ pop(rbp); |
249 __ ret(0); | 254 __ ret(0); |
250 | 255 |
251 CodeDesc desc; | 256 CodeDesc desc; |
252 assm.GetCode(&desc); | 257 assm.GetCode(&desc); |
253 // Call the function from C++. | 258 // Call the function from C++. |
254 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 259 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
255 CHECK_EQ(3, result); | 260 CHECK_EQ(3, result); |
256 } | 261 } |
257 | 262 |
| 263 |
258 TEST(AssemblerX64LoopImmediates) { | 264 TEST(AssemblerX64LoopImmediates) { |
259 OS::SetUp(); | 265 OS::SetUp(); |
260 // Allocate an executable page of memory. | 266 // Allocate an executable page of memory. |
261 size_t actual_size; | 267 size_t actual_size; |
262 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 268 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
263 &actual_size, | 269 &actual_size, |
264 true)); | 270 true)); |
265 CHECK(buffer); | 271 CHECK(buffer); |
266 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 272 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
267 // Assemble two loops using rax as counter, and verify the ending counts. | 273 // Assemble two loops using rax as counter, and verify the ending counts. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 431 |
426 F0 f = FUNCTION_CAST<F0>(code->entry()); | 432 F0 f = FUNCTION_CAST<F0>(code->entry()); |
427 int res = f(); | 433 int res = f(); |
428 CHECK_EQ(42, res); | 434 CHECK_EQ(42, res); |
429 } | 435 } |
430 | 436 |
431 | 437 |
432 | 438 |
433 | 439 |
434 #undef __ | 440 #undef __ |
OLD | NEW |