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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 assm.GetCode(&desc); | 194 assm.GetCode(&desc); |
195 // Call the function from C++. | 195 // Call the function from C++. |
196 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 196 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
197 CHECK_EQ(0, result); | 197 CHECK_EQ(0, result); |
198 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); | 198 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); |
199 CHECK_EQ(1, result); | 199 CHECK_EQ(1, result); |
200 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); | 200 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); |
201 CHECK_EQ(-1, result); | 201 CHECK_EQ(-1, result); |
202 } | 202 } |
203 | 203 |
| 204 TEST(AssemblerX64testbwOperation) { |
| 205 CcTest::InitializeVM(); |
| 206 v8::HandleScope scope(CcTest::isolate()); |
| 207 // Allocate an executable page of memory. |
| 208 size_t actual_size; |
| 209 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 210 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 211 CHECK(buffer); |
| 212 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 213 |
| 214 __ pushq(rbx); |
| 215 __ pushq(rdi); |
| 216 __ pushq(rsi); |
| 217 __ pushq(r12); |
| 218 __ pushq(r13); |
| 219 __ pushq(r14); |
| 220 __ pushq(r15); |
| 221 |
| 222 // Assemble a simple function that tests testb and testw |
| 223 Label bad; |
| 224 Label done; |
| 225 |
| 226 // Test immediate testb and testw |
| 227 __ movq(rax, Immediate(2)); |
| 228 __ movq(rbx, Immediate(4)); |
| 229 __ movq(rcx, Immediate(8)); |
| 230 __ movq(rdx, Immediate(16)); |
| 231 __ movq(rsi, Immediate(32)); |
| 232 __ movq(rdi, Immediate(64)); |
| 233 __ movq(r10, Immediate(128)); |
| 234 __ movq(r11, Immediate(0)); |
| 235 __ movq(r12, Immediate(0)); |
| 236 __ movq(r13, Immediate(0)); |
| 237 __ testb(rax, Immediate(2)); |
| 238 __ j(zero, &bad); |
| 239 __ testb(rbx, Immediate(4)); |
| 240 __ j(zero, &bad); |
| 241 __ testb(rcx, Immediate(8)); |
| 242 __ j(zero, &bad); |
| 243 __ testb(rdx, Immediate(16)); |
| 244 __ j(zero, &bad); |
| 245 __ testb(rsi, Immediate(32)); |
| 246 __ j(zero, &bad); |
| 247 __ testb(rdi, Immediate(64)); |
| 248 __ j(zero, &bad); |
| 249 __ testb(r10, Immediate(128)); |
| 250 __ j(zero, &bad); |
| 251 __ testw(rax, Immediate(2)); |
| 252 __ j(zero, &bad); |
| 253 __ testw(rbx, Immediate(4)); |
| 254 __ j(zero, &bad); |
| 255 __ testw(rcx, Immediate(8)); |
| 256 __ j(zero, &bad); |
| 257 __ testw(rdx, Immediate(16)); |
| 258 __ j(zero, &bad); |
| 259 __ testw(rsi, Immediate(32)); |
| 260 __ j(zero, &bad); |
| 261 __ testw(rdi, Immediate(64)); |
| 262 __ j(zero, &bad); |
| 263 __ testw(r10, Immediate(128)); |
| 264 __ j(zero, &bad); |
| 265 |
| 266 // Test reg, reg testb and testw |
| 267 __ movq(rax, Immediate(2)); |
| 268 __ movq(rbx, Immediate(2)); |
| 269 __ testb(rax, rbx); |
| 270 __ j(zero, &bad); |
| 271 __ movq(rbx, Immediate(4)); |
| 272 __ movq(rax, Immediate(4)); |
| 273 __ testb(rbx, rax); |
| 274 __ j(zero, &bad); |
| 275 __ movq(rax, Immediate(8)); |
| 276 __ testb(rcx, rax); |
| 277 __ j(zero, &bad); |
| 278 __ movq(rax, Immediate(16)); |
| 279 __ testb(rdx, rax); |
| 280 __ j(zero, &bad); |
| 281 __ movq(rax, Immediate(32)); |
| 282 __ testb(rsi, rax); |
| 283 __ j(zero, &bad); |
| 284 __ movq(rax, Immediate(64)); |
| 285 __ testb(rdi, rax); |
| 286 __ j(zero, &bad); |
| 287 __ movq(rax, Immediate(128)); |
| 288 __ testb(r10, rax); |
| 289 __ j(zero, &bad); |
| 290 __ movq(rax, Immediate(2)); |
| 291 __ movq(rbx, Immediate(2)); |
| 292 __ testw(rax, rbx); |
| 293 __ j(zero, &bad); |
| 294 __ movq(rbx, Immediate(4)); |
| 295 __ movq(rax, Immediate(4)); |
| 296 __ testw(rbx, rax); |
| 297 __ j(zero, &bad); |
| 298 __ movq(rax, Immediate(8)); |
| 299 __ testw(rcx, rax); |
| 300 __ j(zero, &bad); |
| 301 __ movq(rax, Immediate(16)); |
| 302 __ testw(rdx, rax); |
| 303 __ j(zero, &bad); |
| 304 __ movq(rax, Immediate(32)); |
| 305 __ testw(rsi, rax); |
| 306 __ j(zero, &bad); |
| 307 __ movq(rax, Immediate(64)); |
| 308 __ testw(rdi, rax); |
| 309 __ j(zero, &bad); |
| 310 __ movq(rax, Immediate(128)); |
| 311 __ testw(r10, rax); |
| 312 __ j(zero, &bad); |
| 313 |
| 314 // Test diffrrent extended register coding combinations. |
| 315 __ movq(rax, Immediate(5)); |
| 316 __ movq(r11, Immediate(5)); |
| 317 __ testb(r11, rax); |
| 318 __ j(zero, &bad); |
| 319 __ testb(rax, r11); |
| 320 __ j(zero, &bad); |
| 321 __ testw(r11, rax); |
| 322 __ j(zero, &bad); |
| 323 __ testw(rax, r11); |
| 324 __ j(zero, &bad); |
| 325 __ movq(r11, Immediate(3)); |
| 326 __ movq(r12, Immediate(3)); |
| 327 __ movq(rdi, Immediate(3)); |
| 328 __ testb(r12, rdi); |
| 329 __ j(zero, &bad); |
| 330 __ testb(rdi, r12); |
| 331 __ j(zero, &bad); |
| 332 __ testb(r12, r11); |
| 333 __ j(zero, &bad); |
| 334 __ testb(r11, r12); |
| 335 __ j(zero, &bad); |
| 336 __ testw(r12, r11); |
| 337 __ j(zero, &bad); |
| 338 __ testw(r11, r12); |
| 339 __ j(zero, &bad); |
| 340 |
| 341 // All tests passed |
| 342 __ movq(rax, Immediate(1)); |
| 343 __ jmp(&done); |
| 344 |
| 345 __ bind(&bad); |
| 346 __ movq(rax, Immediate(0)); |
| 347 __ bind(&done); |
| 348 |
| 349 __ popq(r15); |
| 350 __ popq(r14); |
| 351 __ popq(r13); |
| 352 __ popq(r12); |
| 353 __ popq(rsi); |
| 354 __ popq(rdi); |
| 355 __ popq(rbx); |
| 356 |
| 357 __ ret(0); |
| 358 |
| 359 CodeDesc desc; |
| 360 assm.GetCode(&desc); |
| 361 // Call the function from C++. |
| 362 int result = FUNCTION_CAST<F2>(buffer)(0, 0); |
| 363 CHECK_EQ(1, result); |
| 364 } |
204 | 365 |
205 TEST(AssemblerX64XchglOperations) { | 366 TEST(AssemblerX64XchglOperations) { |
206 CcTest::InitializeVM(); | 367 CcTest::InitializeVM(); |
207 // Allocate an executable page of memory. | 368 // Allocate an executable page of memory. |
208 size_t actual_size; | 369 size_t actual_size; |
209 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( | 370 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
210 Assembler::kMinimalBufferSize, &actual_size, true)); | 371 Assembler::kMinimalBufferSize, &actual_size, true)); |
211 CHECK(buffer); | 372 CHECK(buffer); |
212 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); | 373 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
213 | 374 |
(...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 #ifdef OBJECT_PRINT | 2507 #ifdef OBJECT_PRINT |
2347 OFStream os(stdout); | 2508 OFStream os(stdout); |
2348 code->Print(os); | 2509 code->Print(os); |
2349 #endif | 2510 #endif |
2350 | 2511 |
2351 F9 f = FUNCTION_CAST<F9>(code->entry()); | 2512 F9 f = FUNCTION_CAST<F9>(code->entry()); |
2352 CHECK_EQ(-1.5, f(1.5, -1.5)); | 2513 CHECK_EQ(-1.5, f(1.5, -1.5)); |
2353 } | 2514 } |
2354 | 2515 |
2355 #undef __ | 2516 #undef __ |
OLD | NEW |