6#if defined(TARGET_ARCH_X64)
21#define EXPECT_DISASSEMBLY(expected)
22#define EXPECT_DISASSEMBLY_ENDS_WITH(expected)
23#define EXPECT_DISASSEMBLY_NOT_WINDOWS(expected)
24#define EXPECT_DISASSEMBLY_NOT_WINDOWS_ENDS_WITH(expected)
26#define EXPECT_DISASSEMBLY(expected) \
27 EXPECT_STREQ(expected, test->RelativeDisassembly())
28#define EXPECT_DISASSEMBLY_ENDS_WITH(expected_arg) \
29 char* disassembly = test->RelativeDisassembly(); \
30 const char* expected = expected_arg; \
31 intptr_t dis_len = strlen(disassembly); \
32 intptr_t exp_len = strlen(expected); \
33 EXPECT_GT(dis_len, exp_len); \
34 EXPECT_STREQ(expected, disassembly + dis_len - exp_len);
35#if defined(DART_TARGET_OS_WINDOWS)
39#define EXPECT_DISASSEMBLY_NOT_WINDOWS(expected)
40#define EXPECT_DISASSEMBLY_NOT_WINDOWS_ENDS_WITH(expected)
42#define EXPECT_DISASSEMBLY_NOT_WINDOWS(expected) EXPECT_DISASSEMBLY(expected)
43#define EXPECT_DISASSEMBLY_NOT_WINDOWS_ENDS_WITH(expected) \
44 EXPECT_DISASSEMBLY_ENDS_WITH(expected)
56 typedef int64_t (*ReadArgumentCode)(int64_t n);
57 ReadArgumentCode
id =
reinterpret_cast<ReadArgumentCode
>(
test->entry());
58 EXPECT_EQ(42,
id(42));
59 EXPECT_EQ(87,
id(87));
60 const int64_t kLargeConstant = 0x1234567812345678LL;
61 EXPECT_EQ(kLargeConstant,
id(kLargeConstant));
62 EXPECT_DISASSEMBLY_NOT_WINDOWS(
270 "movq rax,[rsp+0x8]\n"
271 "movq rax,[rbp+0x8]\n"
272 "movq rax,[rax+0x8]\n"
273 "movq rax,[r10+0x8]\n"
274 "movq rax,[r12+0x8]\n"
275 "movq rax,[r13+0x8]\n"
276 "movq rax,[rsp-0x8]\n"
277 "movq rax,[rbp-0x8]\n"
278 "movq rax,[rax-0x8]\n"
279 "movq rax,[r10-0x8]\n"
280 "movq rax,[r12-0x8]\n"
281 "movq rax,[r13-0x8]\n"
282 "movq rax,[rsp+0x800]\n"
283 "movq rax,[rbp+0x800]\n"
284 "movq rax,[rax+0x800]\n"
285 "movq rax,[r10+0x800]\n"
286 "movq rax,[r12+0x800]\n"
287 "movq rax,[r13+0x800]\n"
288 "movq rax,[rsp-0x800]\n"
289 "movq rax,[rbp-0x800]\n"
290 "movq rax,[rax-0x800]\n"
291 "movq rax,[r10-0x800]\n"
292 "movq rax,[r12-0x800]\n"
293 "movq rax,[r13-0x800]\n"
294 "movq rax,[rax*1+0]\n"
295 "movq rax,[rax*2+0]\n"
296 "movq rax,[rax*4+0]\n"
297 "movq rax,[rax*8+0]\n"
298 "movq rax,[rbp*2+0]\n"
299 "movq rax,[rax*2+0]\n"
300 "movq rax,[r10*2+0]\n"
301 "movq rax,[r12*2+0]\n"
302 "movq rax,[r13*2+0]\n"
303 "movq rax,[rbp*2+0x8]\n"
304 "movq rax,[rax*2+0x8]\n"
305 "movq rax,[r10*2+0x8]\n"
306 "movq rax,[r12*2+0x8]\n"
307 "movq rax,[r13*2+0x8]\n"
308 "movq rax,[rbp*2+0x800]\n"
309 "movq rax,[rax*2+0x800]\n"
310 "movq rax,[r10*2+0x800]\n"
311 "movq rax,[r12*2+0x800]\n"
312 "movq rax,[r13*2+0x800]\n"
313 "movq rax,[rax+rbp*2]\n"
314 "movq rax,[rax+rax*2]\n"
315 "movq rax,[rax+r10*2]\n"
316 "movq rax,[rax+r12*2]\n"
317 "movq rax,[rax+r13*2]\n"
318 "movq rax,[rbp+rbp*2+0]\n"
319 "movq rax,[rbp+rax*2+0]\n"
320 "movq rax,[rbp+r10*2+0]\n"
321 "movq rax,[rbp+r12*2+0]\n"
322 "movq rax,[rbp+r13*2+0]\n"
323 "movq rax,[rsp+rbp*2]\n"
324 "movq rax,[rsp+rax*2]\n"
325 "movq rax,[rsp+r10*2]\n"
326 "movq rax,[rsp+r12*2]\n"
327 "movq rax,[rsp+r13*2]\n"
328 "movq rax,[r10+rbp*2]\n"
329 "movq rax,[r10+rax*2]\n"
330 "movq rax,[r10+r10*2]\n"
331 "movq rax,[r10+r12*2]\n"
332 "movq rax,[r10+r13*2]\n"
333 "movq rax,[r12+rbp*2]\n"
334 "movq rax,[r12+rax*2]\n"
335 "movq rax,[r12+r10*2]\n"
336 "movq rax,[r12+r12*2]\n"
337 "movq rax,[r12+r13*2]\n"
338 "movq rax,[r13+rbp*2+0]\n"
339 "movq rax,[r13+rax*2+0]\n"
340 "movq rax,[r13+r10*2+0]\n"
341 "movq rax,[r13+r12*2+0]\n"
342 "movq rax,[r13+r13*2+0]\n"
343 "movq rax,[rax+rbp*2+0x8]\n"
344 "movq rax,[rax+rax*2+0x8]\n"
345 "movq rax,[rax+r10*2+0x8]\n"
346 "movq rax,[rax+r12*2+0x8]\n"
347 "movq rax,[rax+r13*2+0x8]\n"
348 "movq rax,[rbp+rbp*2+0x8]\n"
349 "movq rax,[rbp+rax*2+0x8]\n"
350 "movq rax,[rbp+r10*2+0x8]\n"
351 "movq rax,[rbp+r12*2+0x8]\n"
352 "movq rax,[rbp+r13*2+0x8]\n"
353 "movq rax,[rsp+rbp*2+0x8]\n"
354 "movq rax,[rsp+rax*2+0x8]\n"
355 "movq rax,[rsp+r10*2+0x8]\n"
356 "movq rax,[rsp+r12*2+0x8]\n"
357 "movq rax,[rsp+r13*2+0x8]\n"
358 "movq rax,[r10+rbp*2+0x8]\n"
359 "movq rax,[r10+rax*2+0x8]\n"
360 "movq rax,[r10+r10*2+0x8]\n"
361 "movq rax,[r10+r12*2+0x8]\n"
362 "movq rax,[r10+r13*2+0x8]\n"
363 "movq rax,[r12+rbp*2+0x8]\n"
364 "movq rax,[r12+rax*2+0x8]\n"
365 "movq rax,[r12+r10*2+0x8]\n"
366 "movq rax,[r12+r12*2+0x8]\n"
367 "movq rax,[r12+r13*2+0x8]\n"
368 "movq rax,[r13+rbp*2+0x8]\n"
369 "movq rax,[r13+rax*2+0x8]\n"
370 "movq rax,[r13+r10*2+0x8]\n"
371 "movq rax,[r13+r12*2+0x8]\n"
372 "movq rax,[r13+r13*2+0x8]\n"
373 "movq rax,[rax+rbp*2+0x800]\n"
374 "movq rax,[rax+rax*2+0x800]\n"
375 "movq rax,[rax+r10*2+0x800]\n"
376 "movq rax,[rax+r12*2+0x800]\n"
377 "movq rax,[rax+r13*2+0x800]\n"
378 "movq rax,[rbp+rbp*2+0x800]\n"
379 "movq rax,[rbp+rax*2+0x800]\n"
380 "movq rax,[rbp+r10*2+0x800]\n"
381 "movq rax,[rbp+r12*2+0x800]\n"
382 "movq rax,[rbp+r13*2+0x800]\n"
383 "movq rax,[rsp+rbp*2+0x800]\n"
384 "movq rax,[rsp+rax*2+0x800]\n"
385 "movq rax,[rsp+r10*2+0x800]\n"
386 "movq rax,[rsp+r12*2+0x800]\n"
387 "movq rax,[rsp+r13*2+0x800]\n"
388 "movq rax,[r10+rbp*2+0x800]\n"
389 "movq rax,[r10+rax*2+0x800]\n"
390 "movq rax,[r10+r10*2+0x800]\n"
391 "movq rax,[r10+r12*2+0x800]\n"
392 "movq rax,[r10+r13*2+0x800]\n"
393 "movq rax,[r12+rbp*2+0x800]\n"
394 "movq rax,[r12+rax*2+0x800]\n"
395 "movq rax,[r12+r10*2+0x800]\n"
396 "movq rax,[r12+r12*2+0x800]\n"
397 "movq rax,[r12+r13*2+0x800]\n"
398 "movq rax,[r13+rbp*2+0x800]\n"
399 "movq rax,[r13+rax*2+0x800]\n"
400 "movq rax,[r13+r10*2+0x800]\n"
401 "movq rax,[r13+r12*2+0x800]\n"
402 "movq rax,[r13+r13*2+0x800]\n"
410 "movq rax,[rsp+0x8]\n"
411 "movq rax,[rbp+0x8]\n"
412 "movq rax,[rax+0x8]\n"
413 "movq rax,[r10+0x8]\n"
414 "movq rax,[r12+0x8]\n"
415 "movq rax,[r13+0x8]\n"
416 "movq rax,[rsp-0x8]\n"
417 "movq rax,[rbp-0x8]\n"
418 "movq rax,[rax-0x8]\n"
419 "movq rax,[r10-0x8]\n"
420 "movq rax,[r12-0x8]\n"
421 "movq rax,[r13-0x8]\n");
428 condition =
static_cast<Condition>(condition + 1)) {
436 __ movq(
RAX, Immediate(0));
445 EXPECT(!instr->IsBreakPoint());
446 typedef void (*JumpAroundCrashCode)();
447 reinterpret_cast<JumpAroundCrashCode
>(
test->entry())();
472 __ movq(
RAX, Immediate(0));
473 __ movq(
RCX, Immediate(0));
476 __ addq(
RAX, Immediate(2));
478 __ cmpq(
RCX, Immediate(87));
484 typedef int (*SimpleLoopCode)();
485 EXPECT_EQ(2 * 87,
reinterpret_cast<SimpleLoopCode
>(
test->entry())());
498 __ movq(
RAX, Immediate(1));
499 __ pushq(Immediate(0xffffff11));
500 __ cmpb(Address(
RSP, 0), Immediate(0x11));
502 __ movq(
RAX, Immediate(0));
509 typedef int (*CmpbCode)();
510 EXPECT_EQ(1,
reinterpret_cast<CmpbCode
>(
test->entry())());
513 "movl tmp,0xffffff11\n"
524 __ movq(
RAX, Immediate(1));
525 __ movq(
RCX, Immediate(0));
526 __ pushq(Immediate(0xffffff11));
527 __ testb(Address(
RSP, 0), Immediate(0x10));
530 __ testb(Address(
RSP, 0), Immediate(0x20));
533 __ movq(
RAX, Immediate(0));
540 typedef int (*TestbCode)();
541 EXPECT_EQ(1,
reinterpret_cast<TestbCode
>(
test->entry())());
545 "movl tmp,0xffffff11\n"
557 Label
done, ok1, ok2, ok3, ok4, ok5, ok6, ok7;
559 __ movq(
RAX, Immediate(0xffffefff));
561 __ cmpq(
RCX, Immediate(31));
566 __ sarq(
RAX, Immediate(1));
567 __ cmpq(
RAX, Immediate(0x7ffff7ff));
572 __ movq(
RAX, Immediate(0x7fffffff));
574 __ cmpq(
RCX, Immediate(30));
579 __ cmpq(
RAX, Immediate(0x7fffffff));
584 __ movq(
RAX, Immediate(0x101020408));
585 __ andq(
RAX, Immediate(0xffffffff));
586 __ cmpq(
RAX, Immediate(0x1020408));
591 __ movq(
RCX, Immediate(0x101020408));
592 __ andq(
RCX, Immediate(0xffffffff));
593 __ cmpq(
RCX, Immediate(0x1020408));
598 __ movq(
RAX, Immediate(0x0fffeff0));
600 __ cmpq(
RCX, Immediate(4));
605 __ movq(
RAX, Immediate(42));
610 typedef int64_t (*Testb2Code)();
611 EXPECT_EQ(42,
reinterpret_cast<Testb2Code
>(
test->entry())());
613 "movl rax,0xffffefff\n"
620 "cmpq rax,0x7ffff7ff\n"
624 "movl rax,0x7fffffff\n"
630 "cmpq rax,0x7fffffff\n"
634 "movq rax,0x0000000101020408\n"
635 "andl rax,0xffffffff\n"
636 "cmpq rax,0x01020408\n"
640 "movq rcx,0x0000000101020408\n"
641 "andl rcx,0xffffffff\n"
642 "cmpq rcx,0x01020408\n"
646 "movl rax,0x0fffeff0\n"
659 __ movq(
RDX, Immediate(0x10));
662 __ movq(
RAX, Immediate(1));
666 __ movq(
RAX, Immediate(0));
672 typedef int (*TestbCode)(
int);
673 EXPECT_EQ(1,
reinterpret_cast<TestbCode
>(
test->entry())(0x11));
674 EXPECT_EQ(0,
reinterpret_cast<TestbCode
>(
test->entry())(0x101));
675 EXPECT_DISASSEMBLY_NOT_WINDOWS(
689 __ movq(
RCX, Immediate(-1));
691 __ movq(
RCX, Immediate(0xf));
701 typedef int64_t (*PopcntCode)();
702 EXPECT_EQ(68,
reinterpret_cast<PopcntCode
>(
test->entry())());
713 __ movq(
RCX, Immediate(0x0f00));
715 __ movq(
RCX, Immediate(0x00f0));
725 typedef int64_t (*LzcntCode)();
726 EXPECT_EQ(108,
reinterpret_cast<LzcntCode
>(
test->entry())());
747static JumpAddress jump_address;
748static uword jump_address_offset;
757 jump_address_offset =
__ CodeSize();
758 __ movl(
RAX, Immediate(42));
763 memset(&jump_address, 0,
sizeof(jump_address));
764 jump_address.target =
test->entry() + jump_address_offset;
766 typedef int (*TestCode)(
void*);
767 EXPECT_EQ(42,
reinterpret_cast<TestCode
>(
test->entry())(&jump_address));
768 EXPECT_DISASSEMBLY_NOT_WINDOWS(
780 __ movq(
RAX, Immediate(0));
782 __ incl(Address(
RSP, 0));
783 __ incq(Address(
RSP, 0));
792 typedef int (*IncrementCode)();
793 EXPECT_EQ(3,
reinterpret_cast<IncrementCode
>(
test->entry())());
807 __ movq(
RAX, Immediate(0xffffffff));
809 __ incq(Address(
RSP, 0));
818 typedef int64_t (*IncrementCodeLong)();
819 EXPECT_EQ(0x100000001,
reinterpret_cast<IncrementCodeLong
>(
test->entry())());
821 "movl rax,0xffffffff\n"
832 __ movq(
RAX, Immediate(3));
834 __ decl(Address(
RSP, 0));
835 __ decq(Address(
RSP, 0));
844 typedef int (*DecrementCode)();
845 EXPECT_EQ(0,
reinterpret_cast<DecrementCode
>(
test->entry())());
859 __ movq(
RAX, Immediate(0x100000001));
861 __ decq(Address(
RSP, 0));
870 typedef int64_t (*DecrementCodeLong)();
871 EXPECT_EQ(0xffffffff,
reinterpret_cast<DecrementCodeLong
>(
test->entry())());
873 "movq rax,0x0000000100000001\n"
884 __ movl(
RAX, Immediate(2));
885 __ movl(
RCX, Immediate(4));
887 __ imull(
RAX, Immediate(1000));
892 typedef int (*SignedMultiply)();
893 EXPECT_EQ(8000,
reinterpret_cast<SignedMultiply
>(
test->entry())());
898 "imull rax,rax,0x3e8\n"
903 __ movl(
RAX, Immediate(-1));
904 __ movl(
RCX, Immediate(16));
911 typedef int (*UnsignedMultiply)();
912 EXPECT_EQ(15,
reinterpret_cast<UnsignedMultiply
>(
test->entry())());
916 "mull (rax,rdx),rcx\n"
922 __ movq(
RAX, Immediate(7));
923 __ movq(
RDX, Immediate(-3));
930 typedef int (*SignedMultiply64Implicit)();
931 EXPECT_EQ(-22,
reinterpret_cast<SignedMultiply64Implicit
>(
test->entry())());
935 "imulq (rax,rdx),rdx\n"
942 __ movq(
RAX, Immediate(2));
943 __ movq(
RCX, Immediate(4));
946 __ movq(
R8, Immediate(2));
947 __ movq(
R9, Immediate(4));
953 __ movq(
R10, Immediate(2));
954 __ movq(
TMP, Immediate(4));
958 __ movq(
R15, Immediate(2));
959 __ imulq(
R15, Immediate(4));
966 typedef int64_t (*SignedMultiply64)();
967 EXPECT_EQ(32,
reinterpret_cast<SignedMultiply64
>(
test->entry())());
990static constexpr int64_t kLargeConstant = 0x1234567887654321;
991static constexpr int64_t kAnotherLargeConstant = 987654321987654321LL;
992static constexpr int64_t kProductLargeConstants = 0x5bbb29a7f52fbbd1;
996 __ movq(
RAX, Immediate(kLargeConstant));
997 __ movq(
RCX, Immediate(kAnotherLargeConstant));
999 __ MulImmediate(
RCX, Immediate(kLargeConstant));
1008 typedef int64_t (*SignedMultiplyLong)();
1009 EXPECT_EQ(kProductLargeConstants,
1010 reinterpret_cast<SignedMultiplyLong
>(
test->entry())());
1012 "movq rax,0x1234567887654321\n"
1013 "movq rcx,0x0db4da5f7ef412b1\n"
1015 "movq tmp,0x1234567887654321\n"
1024 __ movl(
RDX, Immediate(0));
1025 __ movl(
RAX, Immediate(0x0fffffff));
1026 __ movl(
RCX, Immediate(0x0fffffff));
1033 typedef int (*OverflowSignedMultiply)();
1034 EXPECT_EQ(0,
reinterpret_cast<OverflowSignedMultiply
>(
test->entry())());
1037 "movl rax,0x0fffffff\n"
1038 "movl rcx,0x0fffffff\n"
1045 __ movl(
RDX, Immediate(2));
1046 __ movl(
RCX, Immediate(4));
1048 __ imull(
RDX, Immediate(1000));
1054 typedef int (*SignedMultiply1)();
1055 EXPECT_EQ(8000,
reinterpret_cast<SignedMultiply1
>(
test->entry())());
1060 "imull rdx,rdx,0x3e8\n"
1067 __ movl(
R15, Immediate(2));
1068 __ imull(
R15, Immediate(1000));
1075 typedef int (*SignedMultiply2)();
1076 EXPECT_EQ(2000,
reinterpret_cast<SignedMultiply2
>(
test->entry())());
1080 "imull pp,pp,0x3e8\n"
1087 __ movq(
RAX, Immediate(-1));
1088 __ movq(
RCX, Immediate(16));
1095 typedef int64_t (*UnsignedMultiplyLong)();
1096 EXPECT_EQ(15,
reinterpret_cast<UnsignedMultiplyLong
>(
test->entry())());
1100 "mulq (rax,rdx),rcx\n"
1106 __ movl(
RAX, Immediate(-87));
1107 __ movl(
RDX, Immediate(123));
1109 __ movl(
RCX, Immediate(42));
1115 typedef int32_t (*SignedDivide)();
1116 EXPECT_EQ(-87 / 42,
reinterpret_cast<SignedDivide
>(
test->entry())());
1118 "movl rax,-0x00000057\n"
1122 "idivl (rax,rdx),rcx\n"
1127 const int32_t
low = 0;
1128 const int32_t
high = 0xf0000000;
1129 const int32_t divisor = 0xffffffff;
1130 __ movl(
RAX, Immediate(low));
1131 __ movl(
RDX, Immediate(high));
1132 __ movl(
RCX, Immediate(divisor));
1139 typedef uint32_t (*UnsignedDivide)();
1140 EXPECT_EQ(0xf0000000,
reinterpret_cast<UnsignedDivide
>(
test->entry())());
1143 "movl rdx,-0x10000000\n"
1145 "divl (rax,rdx),rcx\n"
1150 __ movq(
RAX, Immediate(kLargeConstant));
1151 __ movq(
RDX, Immediate(123));
1153 __ movq(
RCX, Immediate(42));
1159 typedef int64_t (*SignedDivideLong)();
1160 EXPECT_EQ(kLargeConstant / 42,
1161 reinterpret_cast<SignedDivideLong
>(
test->entry())());
1163 "movq rax,0x1234567887654321\n"
1167 "idivq (rax,rdx),rcx\n"
1172 const int64_t
low = 0;
1173 const int64_t
high = 0xf000000000000000;
1174 const int64_t divisor = 0xffffffffffffffff;
1175 __ movq(
RAX, Immediate(low));
1176 __ movq(
RDX, Immediate(high));
1177 __ movq(
RCX, Immediate(divisor));
1185 typedef uint64_t (*UnsignedDivideLong)();
1186 EXPECT_EQ(0xf000000000000000,
1187 reinterpret_cast<UnsignedDivideLong
>(
test->entry())());
1190 "movq rdx,0xf000000000000000\n"
1192 "divq (rax,rdx),rcx\n"
1197 __ movq(
RCX, Immediate(42));
1204 typedef int (*Negate)();
1205 EXPECT_EQ(-42,
reinterpret_cast<Negate
>(
test->entry())());
1216 __ movq(
RAX, Immediate(666));
1223 typedef int (*Bsr)(
int input);
1224 Bsr
call =
reinterpret_cast<Bsr
>(
test->entry());
1225 EXPECT_EQ(666,
call(0));
1226 EXPECT_EQ(0,
call(1));
1227 EXPECT_EQ(1,
call(2));
1228 EXPECT_EQ(1,
call(3));
1229 EXPECT_EQ(2,
call(4));
1230 EXPECT_EQ(5,
call(42));
1231 EXPECT_EQ(31,
call(-1));
1232 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1242 __ movq(
RDX, Immediate(0xffff));
1252 typedef int (*MoveExtend)();
1253 EXPECT_EQ(0xff - 1 + 0xffff,
reinterpret_cast<MoveExtend
>(
test->entry())());
1265 __ movq(
RDX, Immediate(0xffffffff));
1267 __ movq(
RAX, Immediate(0x7fffffff));
1274 typedef intptr_t (*MoveExtend)();
1275 EXPECT_EQ(0x7ffffffe,
reinterpret_cast<MoveExtend
>(
test->entry())());
1277 "movl rdx,0xffffffff\n"
1279 "movl rax,0x7fffffff\n"
1286 __ movq(
RDX, Immediate(0x123456781234ffff));
1290 __ movsxw(
R8, Address(
RSP, 0));
1300 typedef int (*MoveExtendMemory)();
1301 EXPECT_EQ(0xff - 1 + 0xffff,
1302 reinterpret_cast<MoveExtendMemory
>(
test->entry())());
1304 "movq rdx,0x123456781234ffff\n"
1306 "movzxbq rax,[rsp]\n"
1307 "movsxwq r8,[rsp]\n"
1308 "movzxwq rcx,[rsp]\n"
1316 __ pushq(Immediate(0xffffffff));
1317 __ pushq(Immediate(0x7fffffff));
1327 typedef intptr_t (*MoveExtend)();
1328 EXPECT_EQ(0x7ffffffe,
reinterpret_cast<MoveExtend
>(
test->entry())());
1330 "movl tmp,0xffffffff\n"
1333 "movsxdq rdx,[rsp+0x8]\n"
1334 "movsxdq rax,[rsp]\n"
1342 __ pushq(Immediate(0));
1344 __ movq(
RCX, Immediate(-1));
1352 typedef int (*MoveWord)();
1353 EXPECT_EQ(0xffff,
reinterpret_cast<MoveWord
>(
test->entry())());
1360 "movzxwq rax,[rax]\n"
1366 __ movq(
RAX, Immediate(0x0102030405060708));
1368 __ addw(Address(
RSP, 0), Immediate(-0x201));
1369 __ subw(Address(
RSP, 2), Immediate(0x201));
1370 __ xorw(Address(
RSP, 4), Immediate(0x201));
1371 __ andw(Address(
RSP, 6), Immediate(0x301));
1372 __ andw(Address(
RSP, 0), Immediate(-1));
1378 typedef int64_t (*WordOps)();
1379 EXPECT_EQ(0x0100010503050507,
reinterpret_cast<WordOps
>(
test->entry())());
1381 "movq rax,0x0102030405060708\n"
1383 "addw [rsp],0xfdff\n"
1384 "subw [rsp+0x2],0x201\n"
1385 "xorw [rsp+0x4],0x201\n"
1386 "andw [rsp+0x6],0x301\n"
1393 __ movq(
RAX, Immediate(0x0102030405060708));
1395 __ addb(Address(
RSP, 0), Immediate(0xff));
1396 __ subb(Address(
RSP, 2), Immediate(1));
1397 __ xorb(Address(
RSP, 4), Immediate(1));
1398 __ andb(Address(
RSP, 6), Immediate(1));
1399 __ andb(Address(
RSP, 0), Immediate(-1));
1405 typedef int64_t (*ByteOps)();
1406 EXPECT_EQ(0x0100030505050707,
reinterpret_cast<ByteOps
>(
test->entry())());
1408 "movq rax,0x0102030405060708\n"
1411 "subb [rsp+0x2],1\n"
1412 "xorb [rsp+0x4],1\n"
1413 "andb [rsp+0x6],1\n"
1420 __ pushq(Immediate(0));
1422 __ movq(
R9, Immediate(-1));
1423 __ movw(Address(
R8, 0),
R9);
1424 __ movzxw(
R8, Address(
R8, 0));
1432 typedef int (*MoveWordRex)();
1433 EXPECT_EQ(0xffff,
reinterpret_cast<MoveWordRex
>(
test->entry())());
1452 __ movl(
R8, Address(
RSP, 12));
1464 typedef int64_t (*LongAddRegCode)(int64_t
a, int64_t
b);
1467 int64_t res =
reinterpret_cast<LongAddRegCode
>(
test->entry())(
a,
b);
1468 EXPECT_EQ((
a +
b), res);
1471 res =
reinterpret_cast<LongAddRegCode
>(
test->entry())(
a,
b);
1472 EXPECT_EQ((
a +
b), res);
1473 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1477 "movl rdx,[rsp+0x4]\n"
1478 "movl rcx,[rsp+0x8]\n"
1479 "movl r8,[rsp+0xc]\n"
1483 "movl [rsp+0x4],rdx\n"
1493 __ addl(
RAX, Immediate(12));
1494 __ adcl(
RDX, Immediate(11));
1503 typedef int64_t (*LongAddImmediateCode)(int64_t
a);
1504 int64_t
a = (13LL << 32) + 14;
1505 int64_t
b = (11LL << 32) + 12;
1506 int64_t res =
reinterpret_cast<LongAddImmediateCode
>(
test->entry())(
a);
1507 EXPECT_EQ((
a +
b), res);
1508 a = (13LL << 32) - 1;
1509 res =
reinterpret_cast<LongAddImmediateCode
>(
test->entry())(
a);
1510 EXPECT_EQ((
a +
b), res);
1511 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1514 "movl rdx,[rsp+0x4]\n"
1518 "movl [rsp+0x4],rdx\n"
1539 typedef int64_t (*LongAddAddressCode)(int64_t
a, int64_t
b);
1542 int64_t res =
reinterpret_cast<LongAddAddressCode
>(
test->entry())(
a,
b);
1543 EXPECT_EQ((
a +
b), res);
1546 res =
reinterpret_cast<LongAddAddressCode
>(
test->entry())(
a,
b);
1547 EXPECT_EQ((
a +
b), res);
1548 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1552 "movl rdx,[rsp+0x4]\n"
1553 "addl rax,[rsp+0x8]\n"
1554 "adcl rdx,[rsp+0xc]\n"
1556 "movl [rsp+0x4],rdx\n"
1568 __ movl(
R8, Address(
RSP, 12));
1580 typedef int64_t (*LongSubRegCode)(int64_t
a, int64_t
b);
1583 int64_t res =
reinterpret_cast<LongSubRegCode
>(
test->entry())(
a,
b);
1584 EXPECT_EQ((
a -
b), res);
1587 res =
reinterpret_cast<LongSubRegCode
>(
test->entry())(
a,
b);
1588 EXPECT_EQ((
a -
b), res);
1589 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1593 "movl rdx,[rsp+0x4]\n"
1594 "movl rcx,[rsp+0x8]\n"
1595 "movl r8,[rsp+0xc]\n"
1599 "movl [rsp+0x4],rdx\n"
1607 __ movl(
RAX, Immediate(0));
1613 __ subl(
RAX, Immediate(12));
1614 __ sbbl(
RDX, Immediate(11));
1623 typedef int64_t (*LongSubImmediateCode)(int64_t
a);
1624 int64_t
a = (13LL << 32) + 14;
1625 int64_t
b = (11LL << 32) + 12;
1626 int64_t res =
reinterpret_cast<LongSubImmediateCode
>(
test->entry())(
a);
1627 EXPECT_EQ((
a -
b), res);
1628 a = (13LL << 32) + 10;
1629 res =
reinterpret_cast<LongSubImmediateCode
>(
test->entry())(
a);
1630 EXPECT_EQ((
a -
b), res);
1631 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1636 "movl rdx,[rsp+0x4]\n"
1640 "movl [rsp+0x4],rdx\n"
1661 typedef int64_t (*LongSubAddressCode)(int64_t
a, int64_t
b);
1664 int64_t res =
reinterpret_cast<LongSubAddressCode
>(
test->entry())(
a,
b);
1665 EXPECT_EQ((
a -
b), res);
1668 res =
reinterpret_cast<LongSubAddressCode
>(
test->entry())(
a,
b);
1669 EXPECT_EQ((
a -
b), res);
1670 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1674 "movl rdx,[rsp+0x4]\n"
1675 "subl rax,[rsp+0x8]\n"
1676 "sbbl rdx,[rsp+0xc]\n"
1678 "movl [rsp+0x4],rdx\n"
1694 typedef int64_t (*AddRegCode)(int64_t al, int64_t ah, int64_t bl, int64_t bh);
1699 int64_t res =
reinterpret_cast<AddRegCode
>(
test->entry())(al, ah, bl, bh);
1700 EXPECT_EQ((ah + bh), res);
1702 res =
reinterpret_cast<AddRegCode
>(
test->entry())(al, ah, bl, bh);
1703 EXPECT_EQ((ah + bh + 1), res);
1704 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1714 __ addq(
R10, Immediate(13));
1716 __ adcq(
RAX, Immediate(14));
1722 typedef int64_t (*AddImmediateCode)(int64_t al, int64_t ah);
1726 int64_t res =
reinterpret_cast<AddImmediateCode
>(
test->entry())(al, ah);
1727 EXPECT_EQ((ah + bh), res);
1729 res =
reinterpret_cast<AddImmediateCode
>(
test->entry())(al, ah);
1730 EXPECT_EQ((ah + bh + 1), res);
1731 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1754 typedef int64_t (*AddCode)(int64_t al, int64_t ah, int64_t bl, int64_t bh);
1759 int64_t res =
reinterpret_cast<AddCode
>(
test->entry())(al, ah, bl, bh);
1760 EXPECT_EQ((ah + bh), res);
1762 res =
reinterpret_cast<AddCode
>(
test->entry())(al, ah, bl, bh);
1763 EXPECT_EQ((ah + bh + 1), res);
1764 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1770 "addq r10,[rsp+0x10]\n"
1771 "movq rax,[rsp+0x8]\n"
1772 "adcq rax,[rsp+0x18]\n"
1790 typedef int64_t (*SubRegCode)(int64_t al, int64_t ah, int64_t bl, int64_t bh);
1795 int64_t res =
reinterpret_cast<SubRegCode
>(
test->entry())(al, ah, bl, bh);
1796 EXPECT_EQ((ah - bh), res);
1798 res =
reinterpret_cast<SubRegCode
>(
test->entry())(al, ah, bl, bh);
1799 EXPECT_EQ((ah - bh - 1), res);
1800 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1810 __ subq(
R10, Immediate(12));
1812 __ sbbq(
RAX, Immediate(11));
1818 typedef int64_t (*SubImmediateCode)(int64_t al, int64_t ah);
1822 int64_t res =
reinterpret_cast<SubImmediateCode
>(
test->entry())(al, ah);
1823 EXPECT_EQ((ah - bh), res);
1825 res =
reinterpret_cast<SubImmediateCode
>(
test->entry())(al, ah);
1826 EXPECT_EQ((ah - bh - 1), res);
1827 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1850 typedef int64_t (*SubCode)(int64_t al, int64_t ah, int64_t bl, int64_t bh);
1855 int64_t res =
reinterpret_cast<SubCode
>(
test->entry())(al, ah, bl, bh);
1856 EXPECT_EQ((ah - bh), res);
1858 res =
reinterpret_cast<SubCode
>(
test->entry())(al, ah, bl, bh);
1859 EXPECT_EQ((ah - bh - 1), res);
1860 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1866 "subq r10,[rsp+0x10]\n"
1867 "movq rax,[rsp+0x8]\n"
1868 "sbbq rax,[rsp+0x18]\n"
1877 __ movq(
R10, Immediate(-1));
1880 __ movl(
RCX, Immediate(42));
1882 __ orl(
RCX, Immediate(256));
1883 __ movl(
RAX, Immediate(4));
1885 __ movl(
RAX, Immediate(0xfff0));
1887 __ movl(
RAX, Immediate(1));
1896 typedef int (*Bitwise)(
void*,
void*);
1897 int result =
reinterpret_cast<Bitwise
>(
test->entry())(&f1, &f2);
1898 EXPECT_EQ(256 + 1,
result);
1901 EXPECT_DISASSEMBLY_NOT_WINDOWS(
1920 __ movq(
RAX, Immediate(42));
1924 __ cmpq(
RAX, Immediate(0));
1926 __ movq(
RCX, Immediate(0xFF));
1927 __ movq(
RAX, Immediate(0x5));
1929 __ cmpq(
RCX, Immediate(0xFF ^ 0x5));
1931 __ pushq(Immediate(0xFF));
1932 __ movq(
RCX, Immediate(0x5));
1935 __ cmpq(
RCX, Immediate(0xFF ^ 0x5));
1938 __ orq(
RCX, Immediate(256));
1939 __ movq(
RAX, Immediate(4));
1941 __ movq(
RAX, Immediate(0xfff0));
1943 __ movq(
RAX, Immediate(1));
1946 __ xorq(
RCX, Immediate(0));
1951 __ movq(
RAX, Immediate(-1));
1956 typedef int (*Bitwise64)();
1957 EXPECT_EQ(256 + 1,
reinterpret_cast<Bitwise64
>(
test->entry())());
1995 __ movl(
RAX, Immediate(4));
1996 __ andl(
RAX, Immediate(2));
1997 __ cmpl(
RAX, Immediate(0));
2000 __ movl(
RAX, Immediate(0));
2005 __ movl(
RCX, Immediate(4));
2006 __ andl(
RCX, Immediate(4));
2007 __ cmpl(
RCX, Immediate(0));
2010 __ movl(
RAX, Immediate(0));
2015 __ movl(
RAX, Immediate(0));
2016 __ orl(
RAX, Immediate(0));
2017 __ cmpl(
RAX, Immediate(0));
2020 __ movl(
RAX, Immediate(0));
2025 __ movl(
RAX, Immediate(4));
2026 __ orl(
RAX, Immediate(0));
2027 __ cmpl(
RAX, Immediate(0));
2030 __ movl(
RAX, Immediate(0));
2036 __ movl(
RAX, Immediate(0xff));
2038 __ cmpl(Address(
RSP, 0), Immediate(0xff));
2041 __ movq(
RAX, Immediate(0));
2047 __ movl(
RAX, Immediate(1));
2048 __ shll(
RAX, Immediate(3));
2049 __ cmpl(
RAX, Immediate(8));
2052 __ movl(
RAX, Immediate(0));
2057 __ movl(
RAX, Immediate(2));
2058 __ shrl(
RAX, Immediate(1));
2059 __ cmpl(
RAX, Immediate(1));
2062 __ movl(
RAX, Immediate(0));
2067 __ movl(
RAX, Immediate(8));
2068 __ shrl(
RAX, Immediate(3));
2069 __ cmpl(
RAX, Immediate(1));
2072 __ movl(
RAX, Immediate(0));
2077 __ movl(
RAX, Immediate(1));
2078 __ movl(
RCX, Immediate(3));
2080 __ cmpl(
RAX, Immediate(8));
2083 __ movl(
RAX, Immediate(0));
2088 __ movl(
RAX, Immediate(8));
2089 __ movl(
RCX, Immediate(3));
2091 __ cmpl(
RAX, Immediate(1));
2094 __ movl(
RAX, Immediate(0));
2099 __ movl(
RAX, Immediate(1));
2100 __ shlq(
RAX, Immediate(3));
2101 __ cmpl(
RAX, Immediate(8));
2104 __ movl(
RAX, Immediate(0));
2109 __ movl(
RAX, Immediate(2));
2110 __ shrq(
RAX, Immediate(1));
2111 __ cmpl(
RAX, Immediate(1));
2114 __ movl(
RAX, Immediate(0));
2119 __ movl(
RAX, Immediate(8));
2120 __ shrq(
RAX, Immediate(3));
2121 __ cmpl(
RAX, Immediate(1));
2124 __ movl(
RAX, Immediate(0));
2129 __ movl(
RAX, Immediate(1));
2130 __ movl(
RCX, Immediate(3));
2132 __ cmpl(
RAX, Immediate(8));
2135 __ movl(
RAX, Immediate(0));
2140 __ movl(
RAX, Immediate(8));
2141 __ movl(
RCX, Immediate(3));
2143 __ cmpl(
RAX, Immediate(1));
2146 __ movl(
RAX, Immediate(0));
2151 __ movl(
RAX, Immediate(1));
2152 __ shlq(
RAX, Immediate(31));
2153 __ shrq(
RAX, Immediate(3));
2154 __ cmpq(
RAX, Immediate(0x10000000));
2157 __ movl(
RAX, Immediate(0));
2162 __ movl(
RAX, Immediate(1));
2163 __ shlq(
RAX, Immediate(31));
2164 __ sarl(
RAX, Immediate(3));
2165 __ cmpl(
RAX, Immediate(0xfffffffff0000000));
2168 __ movl(
RAX, Immediate(0));
2173 __ movl(
RAX, Immediate(1));
2174 __ movl(
RCX, Immediate(3));
2175 __ shlq(
RAX, Immediate(31));
2177 __ cmpl(
RAX, Immediate(0xfffffffff0000000));
2180 __ movl(
RAX, Immediate(0));
2186 const int32_t
left = 0xff000000;
2187 const int32_t
right = 0xffffffff;
2188 const int32_t shifted = 0xf0000003;
2189 __ movl(
RDX, Immediate(left));
2190 __ movl(
R8, Immediate(right));
2191 __ movl(
RCX, Immediate(2));
2193 __ shldl(
RDX,
R8, Immediate(2));
2195 __ cmpl(
RDX, Immediate(shifted));
2203 const int64_t
left = 0xff00000000000000;
2204 const int64_t
right = 0xffffffffffffffff;
2205 const int64_t shifted = 0xf000000000000003;
2206 __ movq(
RDX, Immediate(left));
2207 __ movq(
R8, Immediate(right));
2208 __ movq(
RCX, Immediate(2));
2210 __ shldq(
RDX,
R8, Immediate(2));
2213 __ cmpq(
RDX, Immediate(shifted));
2221 const int64_t
left = 0xff00000000000000;
2222 const int64_t
right = 0xffffffffffffffff;
2223 const int64_t shifted = 0xf000000000000003;
2224 __ movq(
RDX, Immediate(left));
2225 __ movq(
R8, Immediate(right));
2226 __ movq(
RCX, Immediate(2));
2231 __ cmpq(
RDX, Immediate(shifted));
2239 const int64_t
left = 0xff00000000000000;
2240 const int64_t
right = 0xffffffffffffffff;
2241 const int64_t shifted = 0xcff0000000000000;
2242 __ movq(
RDX, Immediate(left));
2243 __ movq(
R8, Immediate(right));
2244 __ movq(
RCX, Immediate(2));
2249 __ cmpq(
RDX, Immediate(shifted));
2255 __ movl(
RAX, Immediate(0));
2260 typedef int (*LogicalOpsCode)();
2261 EXPECT_EQ(0,
reinterpret_cast<LogicalOpsCode
>(
test->entry())());
2362 "cmpq rax,0x10000000\n"
2369 "cmpl rax,0xf0000000\n"
2377 "cmpl rax,0xf0000000\n"
2381 "movl rdx,-0x01000000\n"
2386 "cmpl rdx,0xf0000003\n"
2389 "movq rdx,0xff00000000000000\n"
2394 "movq tmp,0xf000000000000003\n"
2398 "movq rdx,0xff00000000000000\n"
2403 "movq tmp,0xf000000000000003\n"
2407 "movq rdx,0xff00000000000000\n"
2412 "movq tmp,0xcff0000000000000\n"
2422 __ movq(
RAX, Immediate(4));
2423 __ andq(
RAX, Immediate(2));
2424 __ cmpq(
RAX, Immediate(0));
2430 __ movq(
RCX, Immediate(4));
2434 __ cmpq(
RCX, Immediate(0));
2440 __ movq(
RAX, Immediate(0));
2441 __ orq(
RAX, Immediate(0));
2442 __ cmpq(
RAX, Immediate(0));
2448 __ movq(
RAX, Immediate(4));
2449 __ orq(
RAX, Immediate(0));
2450 __ cmpq(
RAX, Immediate(0));
2457 __ movq(
RAX, Immediate(0xff));
2459 __ cmpq(Address(
RSP, 0), Immediate(0xff));
2466 __ movq(
RAX, Immediate(1));
2467 __ shlq(
RAX, Immediate(3));
2468 __ cmpq(
RAX, Immediate(8));
2474 __ movq(
RAX, Immediate(2));
2475 __ shrq(
RAX, Immediate(1));
2476 __ cmpq(
RAX, Immediate(1));
2482 __ movq(
RAX, Immediate(8));
2483 __ shrq(
RAX, Immediate(3));
2484 __ cmpq(
RAX, Immediate(1));
2490 __ movq(
RAX, Immediate(1));
2491 __ movq(
RCX, Immediate(3));
2493 __ cmpq(
RAX, Immediate(8));
2499 __ movq(
RAX, Immediate(8));
2500 __ movq(
RCX, Immediate(3));
2502 __ cmpq(
RAX, Immediate(1));
2508 __ movq(
RAX, Immediate(1));
2509 __ shlq(
RAX, Immediate(3));
2510 __ cmpq(
RAX, Immediate(8));
2513 __ movq(
RAX, Immediate(0));
2518 __ movq(
RAX, Immediate(2));
2519 __ shrq(
RAX, Immediate(1));
2520 __ cmpq(
RAX, Immediate(1));
2526 __ movq(
RAX, Immediate(8));
2527 __ shrq(
RAX, Immediate(3));
2528 __ cmpq(
RAX, Immediate(1));
2534 __ movq(
RAX, Immediate(1));
2535 __ movq(
RCX, Immediate(3));
2537 __ cmpq(
RAX, Immediate(8));
2543 __ movq(
RAX, Immediate(8));
2544 __ movq(
RCX, Immediate(3));
2546 __ cmpq(
RAX, Immediate(1));
2552 __ movq(
RAX, Immediate(1));
2553 __ shlq(
RAX, Immediate(31));
2554 __ shrq(
RAX, Immediate(3));
2555 __ cmpq(
RAX, Immediate(0x10000000));
2561 __ movq(
RAX, Immediate(1));
2562 __ shlq(
RAX, Immediate(63));
2563 __ sarq(
RAX, Immediate(3));
2564 __ cmpq(
RAX, Immediate(0xf000000000000000));
2570 __ movq(
RAX, Immediate(1));
2571 __ movq(
RCX, Immediate(3));
2572 __ shlq(
RAX, Immediate(63));
2574 __ cmpq(
RAX, Immediate(0xf000000000000000));
2579 Label donetest14, donetest15;
2581 __ movq(
R15, Immediate(0xf000000000000001));
2582 __ andq(
R15, Immediate(-1));
2583 __ andq(
R15, Immediate(0x8000000000000001));
2584 __ orq(
R15, Immediate(2));
2585 __ orq(
R15, Immediate(0xf800000000000000));
2586 __ xorq(
R15, Immediate(1));
2587 __ xorq(
R15, Immediate(0x0800000000000000));
2588 __ cmpq(
R15, Immediate(0xf000000000000002));
2592 __ andq(
R15, Immediate(2));
2593 __ cmpq(
R15, Immediate(2));
2599 __ movq(
RAX, Immediate(0));
2604 typedef int (*LogicalOpsCode)();
2605 EXPECT_EQ(0,
reinterpret_cast<LogicalOpsCode
>(
test->entry())());
2694 "cmpq rax,0x10000000\n"
2700 "movq tmp,0xf000000000000000\n"
2708 "movq tmp,0xf000000000000000\n"
2713 "movq pp,0xf000000000000001\n"
2715 "movq tmp,0x8000000000000001\n"
2718 "movq tmp,0xf800000000000000\n"
2721 "movq tmp,0x0800000000000000\n"
2723 "movq tmp,0xf000000000000002\n"
2738 __ movl(
RAX, Immediate(4));
2739 __ movl(
RCX, Immediate(2));
2743 __ movl(
RAX, Immediate(0));
2748 __ movl(
RDX, Immediate(4));
2749 __ movl(
RCX, Immediate(4));
2753 __ movl(
RAX, Immediate(0));
2758 __ movl(
RAX, Immediate(0));
2759 __ testl(
RAX, Immediate(0));
2762 __ movl(
RAX, Immediate(0));
2767 __ movl(
RCX, Immediate(4));
2768 __ testl(
RCX, Immediate(4));
2771 __ movl(
RAX, Immediate(0));
2775 __ movl(
RAX, Immediate(0));
2780 typedef int (*LogicalTestCode)();
2781 EXPECT_EQ(0,
reinterpret_cast<LogicalTestCode
>(
test->entry())());
2811 __ movq(
RAX, Immediate(4));
2812 __ movq(
RCX, Immediate(2));
2816 __ movq(
RAX, Immediate(0));
2821 __ movq(
RDX, Immediate(4));
2822 __ movq(
RCX, Immediate(4));
2826 __ movq(
RAX, Immediate(0));
2831 __ movq(
RAX, Immediate(0));
2832 __ testq(
RAX, Immediate(0));
2835 __ movq(
RAX, Immediate(0));
2840 __ movq(
RCX, Immediate(4));
2841 __ testq(
RCX, Immediate(4));
2844 __ movq(
RAX, Immediate(0));
2849 __ movq(
RCX, Immediate(0xff));
2850 __ testq(
RCX, Immediate(0xff));
2853 __ movq(
RAX, Immediate(0));
2858 __ movq(
RAX, Immediate(0xff));
2859 __ testq(
RAX, Immediate(0xff));
2862 __ movq(
RAX, Immediate(0));
2866 __ movq(
RAX, Immediate(0));
2871 typedef int (*LogicalTestCode)();
2872 EXPECT_EQ(0,
reinterpret_cast<LogicalTestCode
>(
test->entry())());
2911 __ movq(
RAX, Immediate(0));
2913 __ movq(
RAX, Immediate(4));
2914 __ movq(
RCX, Immediate(0));
2916 __ LockCmpxchgq(Address(
RSP, 0),
RCX);
2922 typedef int (*CompareSwapEQCode)();
2923 EXPECT_EQ(0,
reinterpret_cast<CompareSwapEQCode
>(
test->entry())());
2930 "lock cmpxchgq rcx,[rsp]\n"
2936 __ movq(
RAX, Immediate(0));
2938 __ movq(
RAX, Immediate(2));
2939 __ movq(
RCX, Immediate(4));
2941 __ LockCmpxchgq(Address(
RSP, 0),
RCX);
2947 typedef int (*CompareSwapNEQCode)();
2948 EXPECT_EQ(4,
reinterpret_cast<CompareSwapNEQCode
>(
test->entry())());
2955 "lock cmpxchgq rcx,[rsp]\n"
2961 __ movq(
RAX, Immediate(0x100000000));
2963 __ movq(
RAX, Immediate(4));
2964 __ movq(
RCX, Immediate(0));
2968 __ LockCmpxchgl(Address(
RSP, 0),
RCX);
2975 typedef intptr_t (*CompareSwapEQ32Code)();
2976 EXPECT_EQ(0x100000000,
2977 reinterpret_cast<CompareSwapEQ32Code
>(
test->entry())());
2979 "movq rax,0x0000000100000000\n"
2984 "lock cmpxchgl rcx,[rsp]\n"
2990 __ movq(
RAX, Immediate(0x100000000));
2992 __ movq(
RAX, Immediate(2));
2993 __ movq(
RCX, Immediate(4));
2995 __ LockCmpxchgl(Address(
RSP, 0),
RCX);
3001 typedef intptr_t (*CompareSwapNEQ32Code)();
3002 EXPECT_EQ(0x100000004l,
3003 reinterpret_cast<CompareSwapNEQ32Code
>(
test->entry())());
3005 "movq rax,0x0000000100000000\n"
3010 "lock cmpxchgl rcx,[rsp]\n"
3016 __ movq(
RAX, Immediate(kLargeConstant));
3017 __ movq(
RDX, Immediate(kAnotherLargeConstant));
3024 typedef int64_t (*Exchange)();
3025 EXPECT_EQ(kAnotherLargeConstant - kLargeConstant,
3026 reinterpret_cast<Exchange
>(
test->entry())());
3028 "movq rax,0x1234567887654321\n"
3029 "movq rdx,0x0db4da5f7ef412b1\n"
3036 __ movq(
RAX, Immediate(kLargeConstant));
3041 typedef int64_t (*LargeConstantCode)();
3042 EXPECT_EQ(kLargeConstant,
3043 reinterpret_cast<LargeConstantCode
>(
test->entry())());
3045 "movq rax,0x1234567887654321\n"
3049static int ComputeStackSpaceReservation(
int needed,
int fixed) {
3056static int LeafReturn42() {
3060static int LeafReturnArgument(
int x) {
3065 ExternalLabel call1(
reinterpret_cast<uword>(LeafReturn42));
3066 ExternalLabel call2(
reinterpret_cast<uword>(LeafReturnArgument));
3067 int space = ComputeStackSpaceReservation(0, 8);
3068 __ subq(
RSP, Immediate(space));
3070 __ addq(
RSP, Immediate(space));
3071 space = ComputeStackSpaceReservation(0, 8);
3072 __ subq(
RSP, Immediate(space));
3075 __ addq(
RSP, Immediate(space));
3080 typedef int (*CallSimpleLeafCode)();
3081 EXPECT_EQ(42 + 87,
reinterpret_cast<CallSimpleLeafCode
>(
test->entry())());
3082 EXPECT_DISASSEMBLY_ENDS_WITH(
3089 ExternalLabel call1(
reinterpret_cast<uword>(LeafReturn42));
3091 int space = ComputeStackSpaceReservation(0, 8);
3092 __ subq(
RSP, Immediate(space));
3094 __ addq(
RSP, Immediate(space));
3101 typedef int (*JumpSimpleLeafCode)();
3102 EXPECT_EQ(42,
reinterpret_cast<JumpSimpleLeafCode
>(
test->entry())());
3103 EXPECT_DISASSEMBLY_ENDS_WITH(
"jmp tmp\n");
3107 ExternalLabel call1(
reinterpret_cast<uword>(LeafReturn42));
3114 typedef int (*JumpIndirect)(
uword*);
3115 EXPECT_EQ(42,
reinterpret_cast<JumpIndirect
>(
test->entry())(&temp));
3119 __ movq(
RAX, Immediate(bit_cast<int32_t, float>(234.0f)));
3138 __ movq(Address(
RSP, 0), Immediate(0));
3173 typedef float (*SingleFPMovesCode)();
3174 EXPECT_EQ(234,
reinterpret_cast<SingleFPMovesCode
>(
test->entry())());
3176 "movl rax,0x436a0000\n"
3196 "movss xmm0,[rsp]\n"
3197 "movss [rsp],xmm7\n"
3198 "movss xmm1,[rsp]\n"
3200 "movss [r10],xmm1\n"
3201 "movss xmm2,[r10]\n"
3206 "movss [rax],xmm3\n"
3207 "movss xmm1,[rax]\n"
3208 "movss xmm15,[rax]\n"
3230 __ movq(
RAX, Immediate(bit_cast<int32_t, float>(234.0f)));
3235 __ movq(Address(
RSP, 0), Immediate(0));
3239 __ movq(Address(
RSP, 0), Immediate(0));
3249 typedef float (*SingleFPMoves2Code)();
3250 EXPECT_EQ(234,
reinterpret_cast<SingleFPMoves2Code
>(
test->entry())());
3252 "movl rax,0x436a0000\n"
3258 "movss xmm0,[rsp]\n"
3259 "movss [rsp],xmm1\n"
3260 "movss xmm0,[rsp]\n"
3263 "movss [rsp],xmm9\n"
3264 "movss xmm8,[rsp]\n"
3271 __ movq(
RAX, Immediate(bit_cast<int32_t, float>(234.5f)));
3279 typedef uint64_t (*MovqXmmToCpuCode)();
3280 EXPECT_EQ((bit_cast<uint64_t, double>(234.5f)),
3281 reinterpret_cast<MovqXmmToCpuCode
>(
test->entry())());
3283 "movl rax,0x436a8000\n"
3285 "cvtss2sd xmm0,xmm0\n"
3294 } constant0 = {1.0, 2.0};
3298 } constant1 = {3.0, 4.0};
3299 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3301 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant1)));
3309 typedef double (*PackedDoubleAdd)();
3310 double res =
reinterpret_cast<PackedDoubleAdd
>(
test->entry())();
3311 EXPECT_FLOAT_EQ(4.0, res, 0.000001f);
3312 EXPECT_DISASSEMBLY_ENDS_WITH(
3313 "movups xmm11,[rax]\n"
3314 "addpd xmm10,xmm11\n"
3315 "movaps xmm0,xmm10\n"
3323 } constant0 = {1.0, 2.0};
3327 } constant1 = {3.0, 4.0};
3328 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3330 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant1)));
3338 typedef double (*PackedDoubleSub)();
3339 double res =
reinterpret_cast<PackedDoubleSub
>(
test->entry())();
3340 EXPECT_FLOAT_EQ(-2.0, res, 0.000001f);
3341 EXPECT_DISASSEMBLY_ENDS_WITH(
3342 "movups xmm11,[rax]\n"
3343 "subpd xmm10,xmm11\n"
3344 "movaps xmm0,xmm10\n"
3357 __ LoadPoolPointer(
PP);
3371 } constant0 = {1.0, 2.0};
3373 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3382 double res =
test->InvokeWithCodeAndThread<
double>();
3383 EXPECT_FLOAT_EQ(-1.0, res, 0.000001f);
3384 EXPECT_DISASSEMBLY_NOT_WINDOWS_ENDS_WITH(
3385 "movups xmm10,[rax]\n"
3386 "movq tmp,[thr+0x...]\n"
3387 "xorpd xmm10,[tmp]\n"
3388 "movaps xmm0,xmm10\n"
3401 } constant0 = {-1.0, 2.0};
3403 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3411 double res =
test->InvokeWithCodeAndThread<
double>();
3412 EXPECT_FLOAT_EQ(1.0, res, 0.000001f);
3413 EXPECT_DISASSEMBLY_NOT_WINDOWS_ENDS_WITH(
3414 "movups xmm10,[rax]\n"
3415 "movq tmp,[thr+0x...]\n"
3416 "movups xmm0,[tmp]\n"
3417 "andpd xmm0,xmm10\n"
3430 } constant0 = {3.0, 2.0};
3434 } constant1 = {3.0, 4.0};
3435 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3437 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant1)));
3445 typedef double (*PackedDoubleMul)();
3446 double res =
reinterpret_cast<PackedDoubleMul
>(
test->entry())();
3447 EXPECT_FLOAT_EQ(9.0, res, 0.000001f);
3448 EXPECT_DISASSEMBLY_ENDS_WITH(
3449 "movups xmm11,[rax]\n"
3450 "mulpd xmm10,xmm11\n"
3451 "movaps xmm0,xmm10\n"
3459 } constant0 = {9.0, 2.0};
3463 } constant1 = {3.0, 4.0};
3464 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3466 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant1)));
3474 typedef double (*PackedDoubleDiv)();
3475 double res =
reinterpret_cast<PackedDoubleDiv
>(
test->entry())();
3476 EXPECT_FLOAT_EQ(3.0, res, 0.000001f);
3477 EXPECT_DISASSEMBLY_ENDS_WITH(
3478 "movups xmm11,[rax]\n"
3479 "divpd xmm10,xmm11\n"
3480 "movaps xmm0,xmm10\n"
3488 } constant0 = {16.0, 2.0};
3489 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3497 typedef double (*PackedDoubleSqrt)();
3498 double res =
reinterpret_cast<PackedDoubleSqrt
>(
test->entry())();
3499 EXPECT_FLOAT_EQ(4.0, res, 0.000001f);
3500 EXPECT_DISASSEMBLY_ENDS_WITH(
3501 "movups xmm10,[rax]\n"
3502 "sqrtpd xmm10,xmm10\n"
3503 "movaps xmm0,xmm10\n"
3511 } constant0 = {9.0, 2.0};
3515 } constant1 = {3.0, 4.0};
3516 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3518 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant1)));
3526 typedef double (*PackedDoubleMin)();
3527 double res =
reinterpret_cast<PackedDoubleMin
>(
test->entry())();
3528 EXPECT_FLOAT_EQ(3.0, res, 0.000001f);
3529 EXPECT_DISASSEMBLY_ENDS_WITH(
3530 "movups xmm11,[rax]\n"
3531 "minpd xmm10,xmm11\n"
3532 "movaps xmm0,xmm10\n"
3540 } constant0 = {9.0, 2.0};
3544 } constant1 = {3.0, 4.0};
3545 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3547 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant1)));
3555 typedef double (*PackedDoubleMax)();
3556 double res =
reinterpret_cast<PackedDoubleMax
>(
test->entry())();
3557 EXPECT_FLOAT_EQ(9.0, res, 0.000001f);
3558 EXPECT_DISASSEMBLY_ENDS_WITH(
3559 "movups xmm11,[rax]\n"
3560 "maxpd xmm10,xmm11\n"
3561 "movaps xmm0,xmm10\n"
3569 } constant0 = {2.0, 9.0};
3570 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3582 typedef double (*PackedDoubleShuffle)();
3583 double res =
reinterpret_cast<PackedDoubleShuffle
>(
test->entry())();
3584 EXPECT_FLOAT_EQ(9.0, res, 0.000001f);
3585 EXPECT_DISASSEMBLY_ENDS_WITH(
3586 "movups xmm10,[rax]\n"
3587 "shufpd xmm10, xmm10 [33]\n"
3588 "shufpd xmm10, xmm10 [0]\n"
3589 "movaps xmm0,xmm10\n"
3597 } constant0 = {9.0, 2.0};
3598 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3606 typedef float (*PackedDoubleToSingle)();
3607 float res =
reinterpret_cast<PackedDoubleToSingle
>(
test->entry())();
3608 EXPECT_FLOAT_EQ(9.0f, res, 0.000001f);
3609 EXPECT_DISASSEMBLY_ENDS_WITH(
3610 "movups xmm11,[rax]\n"
3611 "cvtpd2ps xmm10,xmm11\n"
3612 "movaps xmm0,xmm10\n"
3622 } constant0 = {9.0f, 2.0f, 3.0f, 4.0f};
3623 __ movq(
RAX, Immediate(
reinterpret_cast<uword>(&constant0)));
3631 typedef double (*PackedSingleToDouble)();
3632 double res =
reinterpret_cast<PackedSingleToDouble
>(
test->entry())();
3633 EXPECT_FLOAT_EQ(9.0f, res, 0.000001f);
3634 EXPECT_DISASSEMBLY_ENDS_WITH(
3635 "movups xmm11,[rax]\n"
3636 "cvtps2pd xmm10,xmm11\n"
3637 "movaps xmm0,xmm10\n"
3644 __ movq(
RBX, Immediate(bit_cast<int32_t, float>(12.3f)));
3647 __ movq(
RCX, Immediate(bit_cast<int32_t, float>(3.4f)));
3665 typedef float (*SingleFPOperationsCode)();
3666 float res =
reinterpret_cast<SingleFPOperationsCode
>(
test->entry())();
3667 EXPECT_FLOAT_EQ(0.0f, res, 0.001f);
3671 "movl rbx,0x4144cccd\n"
3674 "movl rcx,0x4059999a\n"
3692 __ movq(
RAX, Immediate(bit_cast<int32_t, float>(12.3f)));
3695 __ movq(
RAX, Immediate(bit_cast<int32_t, float>(3.4f)));
3708 typedef float (*PackedFPOperationsCode)();
3709 float res =
reinterpret_cast<PackedFPOperationsCode
>(
test->entry())();
3710 EXPECT_FLOAT_EQ(14.7f, res, 0.001f);
3712 "movl rax,0x4144cccd\n"
3714 "shufps xmm10,xmm10 [0]\n"
3715 "movl rax,0x4059999a\n"
3717 "shufps xmm9,xmm9 [0]\n"
3718 "addps xmm10,xmm9\n"
3719 "mulps xmm10,xmm9\n"
3720 "subps xmm10,xmm9\n"
3721 "divps xmm10,xmm9\n"
3722 "movaps xmm0,xmm10\n"
3723 "shufps xmm0,xmm0 [55]\n"
3728 __ movl(
RAX, Immediate(0x2));
3731 __ movl(
RAX, Immediate(0x1));
3744 typedef uint32_t (*PackedIntOperationsCode)();
3745 uint32_t res =
reinterpret_cast<PackedIntOperationsCode
>(
test->entry())();
3746 EXPECT_EQ(
static_cast<uword>(0x5), res);
3750 "shufps xmm0,xmm0 [0]\n"
3753 "shufps xmm1,xmm1 [0]\n"
3758 "movss [rsp],xmm0\n"
3765 const intptr_t cpu_register_set = 0;
3766 const intptr_t fpu_register_set =
3768 const RegisterSet register_set(cpu_register_set, fpu_register_set);
3769 __ PushRegisters(register_set);
3770 __ movl(
RAX, Immediate(0x2));
3773 __ movl(
RAX, Immediate(0x1));
3782 __ PopRegisters(register_set);
3787 typedef uint32_t (*PackedIntOperationsCode)();
3788 uint32_t res =
reinterpret_cast<PackedIntOperationsCode
>(
test->entry())();
3789 EXPECT_EQ(
static_cast<uword>(0x5), res);
3790 EXPECT_DISASSEMBLY_NOT_WINDOWS(
3792 "movups [rsp],xmm10\n"
3793 "movups [rsp+0x10],xmm11\n"
3796 "shufps xmm10,xmm10 [0]\n"
3799 "shufps xmm11,xmm11 [0]\n"
3800 "paddd xmm10,xmm11\n"
3801 "paddd xmm10,xmm10\n"
3802 "psubd xmm10,xmm11\n"
3804 "movss [rsp],xmm10\n"
3806 "movups xmm10,[rsp]\n"
3807 "movups xmm11,[rsp+0x10]\n"
3813 __ movq(
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
3827 typedef float (*PackedFPOperations2Code)();
3828 float res =
reinterpret_cast<PackedFPOperations2Code
>(
test->entry())();
3829 EXPECT_FLOAT_EQ(0.0f, res, 0.001f);
3831 "movl rax,0x40800000\n"
3833 "shufps xmm0,xmm0 [0]\n"
3834 "movaps xmm11,xmm0\n"
3835 "rcpps xmm11,xmm11\n"
3836 "sqrtps xmm11,xmm11\n"
3837 "rsqrtps xmm0,xmm0\n"
3838 "subps xmm0,xmm11\n"
3839 "shufps xmm0,xmm0 [0]\n"
3844 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(2.0f)));
3845 __ set1ps(
XMM1,
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
3854 typedef uint32_t (*PackedCompareEQCode)();
3855 uint32_t res =
reinterpret_cast<PackedCompareEQCode
>(
test->entry())();
3856 EXPECT_EQ(
static_cast<uword>(0x0), res);
3858 "movl rax,0x40000000\n"
3860 "shufps xmm0,xmm0 [0]\n"
3861 "movl rax,0x40800000\n"
3863 "shufps xmm1,xmm1 [0]\n"
3864 "cmpps xmm0,xmm1 [eq]\n"
3866 "movss [rsp],xmm0\n"
3881 __ movl(
RAX, Immediate(0));
3886 typedef intptr_t (*XmmAluTest)();
3887 intptr_t res =
reinterpret_cast<XmmAluTest
>(
test->entry())();
3894 "cvtss2sd xmm0,xmm0\n"
3895 "cvtsd2ss xmm0,xmm0\n"
3896 "cvtps2pd xmm0,xmm0\n"
3897 "cvtpd2ps xmm0,xmm0\n"
3903 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(2.0f)));
3904 __ set1ps(
XMM1,
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
3913 typedef uint32_t (*PackedCompareNEQCode)();
3914 uint32_t res =
reinterpret_cast<PackedCompareNEQCode
>(
test->entry())();
3915 EXPECT_EQ(
static_cast<uword>(0xFFFFFFFF), res);
3917 "movl rax,0x40000000\n"
3919 "shufps xmm0,xmm0 [0]\n"
3920 "movl rax,0x40800000\n"
3922 "shufps xmm1,xmm1 [0]\n"
3923 "cmpps xmm0,xmm1 [neq]\n"
3925 "movss [rsp],xmm0\n"
3931 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(2.0f)));
3932 __ set1ps(
XMM1,
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
3941 typedef uint32_t (*PackedCompareLTCode)();
3942 uint32_t res =
reinterpret_cast<PackedCompareLTCode
>(
test->entry())();
3943 EXPECT_EQ(
static_cast<uword>(0xFFFFFFFF), res);
3945 "movl rax,0x40000000\n"
3947 "shufps xmm0,xmm0 [0]\n"
3948 "movl rax,0x40800000\n"
3950 "shufps xmm1,xmm1 [0]\n"
3951 "cmpps xmm0,xmm1 [lt]\n"
3953 "movss [rsp],xmm0\n"
3959 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(2.0f)));
3960 __ set1ps(
XMM1,
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
3969 typedef uint32_t (*PackedCompareLECode)();
3970 uint32_t res =
reinterpret_cast<PackedCompareLECode
>(
test->entry())();
3971 EXPECT_EQ(
static_cast<uword>(0xFFFFFFFF), res);
3973 "movl rax,0x40000000\n"
3975 "shufps xmm0,xmm0 [0]\n"
3976 "movl rax,0x40800000\n"
3978 "shufps xmm1,xmm1 [0]\n"
3979 "cmpps xmm0,xmm1 [le]\n"
3981 "movss [rsp],xmm0\n"
3987 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(2.0f)));
3988 __ set1ps(
XMM1,
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
3997 typedef uint32_t (*PackedCompareNLTCode)();
3998 uint32_t res =
reinterpret_cast<PackedCompareNLTCode
>(
test->entry())();
3999 EXPECT_EQ(
static_cast<uword>(0x0), res);
4001 "movl rax,0x40000000\n"
4003 "shufps xmm0,xmm0 [0]\n"
4004 "movl rax,0x40800000\n"
4006 "shufps xmm1,xmm1 [0]\n"
4007 "cmpps xmm0,xmm1 [nlt]\n"
4009 "movss [rsp],xmm0\n"
4015 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(2.0f)));
4016 __ set1ps(
XMM1,
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
4025 typedef uint32_t (*PackedCompareNLECode)();
4026 uint32_t res =
reinterpret_cast<PackedCompareNLECode
>(
test->entry())();
4027 EXPECT_EQ(
static_cast<uword>(0x0), res);
4029 "movl rax,0x40000000\n"
4031 "shufps xmm0,xmm0 [0]\n"
4032 "movl rax,0x40800000\n"
4034 "shufps xmm1,xmm1 [0]\n"
4035 "cmpps xmm0,xmm1 [nle]\n"
4037 "movss [rsp],xmm0\n"
4044 __ movl(
RAX, Immediate(bit_cast<int32_t, float>(12.3f)));
4054 float res =
test->InvokeWithCodeAndThread<
float>();
4055 EXPECT_FLOAT_EQ(-12.3f, res, 0.001f);
4056 EXPECT_DISASSEMBLY_NOT_WINDOWS(
4064 "movq pp,[r12+0x27]\n"
4065 "movl rax,0x4144cccd\n"
4067 "shufps xmm0,xmm0 [0]\n"
4068 "movq tmp,[thr+0x...]\n"
4069 "xorps xmm0,[tmp]\n"
4070 "shufps xmm0,xmm0 [aa]\n"
4081 __ movl(
RAX, Immediate(bit_cast<int32_t, float>(-15.3f)));
4091 float res =
test->InvokeWithCodeAndThread<
float>();
4092 EXPECT_FLOAT_EQ(15.3f, res, 0.001f);
4093 EXPECT_DISASSEMBLY_NOT_WINDOWS(
4101 "movq pp,[r12+0x27]\n"
4102 "movl rax,-0x3e8b3333\n"
4104 "shufps xmm0,xmm0 [0]\n"
4105 "movq tmp,[thr+0x...]\n"
4106 "andps xmm0,[tmp]\n"
4107 "shufps xmm0,xmm0 [aa]\n"
4118 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(12.3f)));
4126 float res =
test->InvokeWithCodeAndThread<
float>();
4127 EXPECT_FLOAT_EQ(0.0f, res, 0.001f);
4128 EXPECT_DISASSEMBLY_NOT_WINDOWS(
4136 "movq pp,[r12+0x27]\n"
4137 "movl rax,0x4144cccd\n"
4139 "shufps xmm0,xmm0 [0]\n"
4140 "movq tmp,[thr+0x...]\n"
4141 "andps xmm0,[tmp]\n"
4142 "shufps xmm0,xmm0 [ff]\n"
4152 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(2.0f)));
4153 __ set1ps(
XMM1,
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
4159 typedef float (*PackedMinCode)();
4160 float res =
reinterpret_cast<PackedMinCode
>(
test->entry())();
4161 EXPECT_FLOAT_EQ(2.0f, res, 0.001f);
4163 "movl rax,0x40000000\n"
4165 "shufps xmm0,xmm0 [0]\n"
4166 "movl rax,0x40800000\n"
4168 "shufps xmm1,xmm1 [0]\n"
4174 __ set1ps(
XMM0,
RAX, Immediate(bit_cast<int32_t, float>(2.0f)));
4175 __ set1ps(
XMM1,
RAX, Immediate(bit_cast<int32_t, float>(4.0f)));
4181 typedef float (*PackedMaxCode)();
4182 float res =
reinterpret_cast<PackedMaxCode
>(
test->entry())();
4183 EXPECT_FLOAT_EQ(4.0f, res, 0.001f);
4185 "movl rax,0x40000000\n"
4187 "shufps xmm0,xmm0 [0]\n"
4188 "movl rax,0x40800000\n"
4190 "shufps xmm1,xmm1 [0]\n"
4201 } constant1 = {0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0};
4207 } constant2 = {0x0F0F0F0F, 0x0F0F0F0F, 0x0F0F0F0F, 0x0F0F0F0F};
4208 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4210 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant2)));
4220 typedef uint32_t (*PackedLogicalOrCode)();
4221 uint32_t res =
reinterpret_cast<PackedLogicalOrCode
>(
test->entry())();
4222 EXPECT_EQ(0xFFFFFFFF, res);
4223 EXPECT_DISASSEMBLY_ENDS_WITH(
4224 "movups xmm1,[rax]\n"
4227 "movss [rsp],xmm0\n"
4238 } constant1 = {0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0, 0xF0F0F0F0};
4244 } constant2 = {0x0F0FFF0F, 0x0F0F0F0F, 0x0F0F0F0F, 0x0F0F0F0F};
4245 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4247 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant2)));
4256 typedef uint32_t (*PackedLogicalAndCode)();
4257 uint32_t res =
reinterpret_cast<PackedLogicalAndCode
>(
test->entry())();
4258 EXPECT_EQ(
static_cast<uword>(0x0000F000), res);
4259 EXPECT_DISASSEMBLY_ENDS_WITH(
4260 "andps xmm0,[rax]\n"
4262 "movss [rsp],xmm0\n"
4273 } constant1 = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
4275 __ LoadImmediate(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4286 uint32_t res =
test->InvokeWithCodeAndThread<uint32_t>();
4287 EXPECT_EQ(
static_cast<uword>(0x0), res);
4288 EXPECT_DISASSEMBLY_NOT_WINDOWS_ENDS_WITH(
4289 "movups xmm9,[rax]\n"
4290 "movq tmp,[thr+0x...]\n"
4291 "movups xmm0,[tmp]\n"
4294 "movss [rsp],xmm0\n"
4310 } constant0 = {1.0, 2.0, 3.0, 4.0};
4316 } constant1 = {5.0, 6.0, 7.0, 8.0};
4318 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant0)));
4321 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4336 typedef float (*PackedMoveHighLow)();
4337 float res =
reinterpret_cast<PackedMoveHighLow
>(
test->entry())();
4338 EXPECT_FLOAT_EQ(15.0f, res, 0.001f);
4339 EXPECT_DISASSEMBLY_ENDS_WITH(
4340 "movups xmm1,[rax]\n"
4341 "movhlps xmm9,xmm1\n"
4343 "movaps xmm1,xmm9\n"
4344 "shufps xmm9,xmm9 [0]\n"
4345 "shufps xmm1,xmm1 [55]\n"
4347 "movaps xmm0,xmm9\n"
4357 } constant0 = {1.0, 2.0, 3.0, 4.0};
4363 } constant1 = {5.0, 6.0, 7.0, 8.0};
4365 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant0)));
4368 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4383 typedef float (*PackedMoveLowHigh)();
4384 float res =
reinterpret_cast<PackedMoveLowHigh
>(
test->entry())();
4385 EXPECT_FLOAT_EQ(11.0f, res, 0.001f);
4386 EXPECT_DISASSEMBLY_ENDS_WITH(
4387 "movups xmm1,[rax]\n"
4388 "movlhps xmm9,xmm1\n"
4390 "movaps xmm1,xmm9\n"
4391 "shufps xmm9,xmm9 [aa]\n"
4392 "shufps xmm1,xmm1 [ff]\n"
4394 "movaps xmm0,xmm9\n"
4404 } constant0 = {1.0, 2.0, 3.0, 4.0};
4410 } constant1 = {5.0, 6.0, 7.0, 8.0};
4412 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant0)));
4415 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4429 typedef float (*PackedUnpackLow)();
4430 float res =
reinterpret_cast<PackedUnpackLow
>(
test->entry())();
4431 EXPECT_FLOAT_EQ(11.0f, res, 0.001f);
4432 EXPECT_DISASSEMBLY_ENDS_WITH(
4433 "movups xmm1,[rax]\n"
4434 "unpcklps xmm9,xmm1\n"
4435 "movaps xmm1,xmm9\n"
4436 "shufps xmm9,xmm9 [55]\n"
4437 "shufps xmm1,xmm1 [ff]\n"
4439 "movaps xmm0,xmm9\n"
4449 } constant0 = {1.0, 2.0, 3.0, 4.0};
4455 } constant1 = {5.0, 6.0, 7.0, 8.0};
4457 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant0)));
4460 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4474 typedef float (*PackedUnpackHigh)();
4475 float res =
reinterpret_cast<PackedUnpackHigh
>(
test->entry())();
4476 EXPECT_FLOAT_EQ(7.0f, res, 0.001f);
4477 EXPECT_DISASSEMBLY_ENDS_WITH(
4478 "movups xmm1,[rax]\n"
4479 "unpckhps xmm9,xmm1\n"
4480 "movaps xmm1,xmm9\n"
4481 "shufps xmm9,xmm9 [0]\n"
4482 "shufps xmm1,xmm1 [aa]\n"
4484 "movaps xmm0,xmm9\n"
4494 } constant0 = {1.0, 2.0, 3.0, 4.0};
4500 } constant1 = {5.0, 6.0, 7.0, 8.0};
4502 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant0)));
4505 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4519 typedef float (*PackedUnpackLowPair)();
4520 float res =
reinterpret_cast<PackedUnpackLowPair
>(
test->entry())();
4521 EXPECT_FLOAT_EQ(6.0f, res, 0.001f);
4522 EXPECT_DISASSEMBLY_ENDS_WITH(
4523 "movups xmm1,[rax]\n"
4524 "unpcklpd xmm9,xmm1\n"
4525 "movaps xmm1,xmm9\n"
4526 "shufps xmm9,xmm9 [0]\n"
4527 "shufps xmm1,xmm1 [aa]\n"
4529 "movaps xmm0,xmm9\n"
4539 } constant0 = {1.0, 2.0, 3.0, 4.0};
4545 } constant1 = {5.0, 6.0, 7.0, 8.0};
4547 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant0)));
4550 __ movq(
RAX, Immediate(
reinterpret_cast<intptr_t
>(&constant1)));
4564 typedef float (*PackedUnpackHighPair)();
4565 float res =
reinterpret_cast<PackedUnpackHighPair
>(
test->entry())();
4566 EXPECT_FLOAT_EQ(12.0f, res, 0.001f);
4567 EXPECT_DISASSEMBLY_ENDS_WITH(
4568 "movups xmm1,[rax]\n"
4569 "unpckhpd xmm9,xmm1\n"
4570 "movaps xmm1,xmm9\n"
4571 "shufps xmm9,xmm9 [55]\n"
4572 "shufps xmm1,xmm1 [ff]\n"
4574 "movaps xmm0,xmm9\n"
4579 __ movq(
RAX, Immediate(bit_cast<int64_t, double>(1024.67)));
4598 __ movq(Address(
RSP, 0), Immediate(0));
4633 typedef double (*DoubleFPMovesCode)();
4634 EXPECT_FLOAT_EQ(1024.67,
reinterpret_cast<DoubleFPMovesCode
>(
test->entry())(),
4637 "movq rax,0x409002ae147ae148\n"
4640 "movsd xmm0,[rsp]\n"
4650 "movsd xmm10,xmm9\n"
4651 "movsd xmm11,xmm10\n"
4652 "movsd xmm12,xmm11\n"
4653 "movsd xmm13,xmm12\n"
4654 "movsd xmm14,xmm13\n"
4655 "movsd xmm15,xmm14\n"
4657 "movsd xmm0,[rsp]\n"
4658 "movsd [rsp],xmm15\n"
4659 "movsd xmm1,[rsp]\n"
4661 "movsd [r10],xmm1\n"
4662 "movsd xmm2,[r10]\n"
4667 "movsd [rax],xmm3\n"
4668 "movsd xmm4,[rax]\n"
4669 "movsd xmm15,[rsp]\n"
4670 "movaps xmm14,xmm15\n"
4671 "movaps xmm13,xmm14\n"
4672 "movaps xmm12,xmm13\n"
4673 "movaps xmm11,xmm12\n"
4674 "movaps xmm10,xmm11\n"
4675 "movaps xmm9,xmm10\n"
4676 "movaps xmm8,xmm9\n"
4677 "movaps xmm7,xmm8\n"
4678 "movaps xmm6,xmm7\n"
4679 "movaps xmm5,xmm6\n"
4680 "movaps xmm4,xmm5\n"
4681 "movaps xmm3,xmm4\n"
4682 "movaps xmm2,xmm3\n"
4683 "movaps xmm1,xmm2\n"
4684 "movaps xmm0,xmm1\n"
4691 __ movq(
RAX, Immediate(bit_cast<int64_t, double>(12.3)));
4695 __ movq(
RAX, Immediate(bit_cast<int64_t, double>(3.4)));
4715 typedef double (*SingleFPOperationsCode)();
4716 double res =
reinterpret_cast<SingleFPOperationsCode
>(
test->entry())();
4717 EXPECT_FLOAT_EQ(7.668, res, 0.001);
4719 "movq rax,0x402899999999999a\n"
4721 "movsd xmm0,[rsp]\n"
4722 "movsd xmm8,[rsp]\n"
4723 "movq rax,0x400b333333333333\n"
4725 "movsd xmm12,[rsp]\n"
4726 "addsd xmm8,xmm12\n"
4727 "mulsd xmm8,xmm12\n"
4728 "subsd xmm8,xmm12\n"
4729 "divsd xmm8,xmm12\n"
4730 "sqrtsd xmm8,xmm8\n"
4731 "movsd xmm1,[rsp]\n"
4736 "sqrtsd xmm0,xmm0\n"
4744 __ movq(
R11, Immediate(0x1111111100000006));
4747 __ movq(
R11, Immediate(0x2222222200000008));
4754 typedef double (*Int32ToDoubleConversion)();
4755 double res =
reinterpret_cast<Int32ToDoubleConversion
>(
test->entry())();
4756 EXPECT_FLOAT_EQ(-2.0, res, 0.001);
4758 "movq tmp,0x1111111100000006\n"
4759 "cvtsi2sd xmm0,tmp\n"
4760 "movq tmp,0x2222222200000008\n"
4761 "cvtsi2sd xmm8,tmp\n"
4767 __ movq(
RDX, Immediate(12LL << 32));
4776 typedef double (*Int64ToDoubleConversionCode)();
4777 double res =
reinterpret_cast<Int64ToDoubleConversionCode
>(
test->entry())();
4778 EXPECT_FLOAT_EQ(
static_cast<double>(12LL << 32), res, 0.001);
4780 "movq rdx,0x0000000c00000000\n"
4781 "cvtsi2sd xmm0,rdx\n"
4782 "movsd xmm15,xmm0\n"
4784 "movsd xmm0,xmm15\n"
4789 __ movq(
RAX, Immediate(bit_cast<int64_t, double>(4.2e22)));
4794 __ CompareImmediate(
RAX, Immediate(0x8000000000000000ll));
4799 __ movq(
RAX, Immediate(bit_cast<int64_t, double>(4.2e11)));
4816 typedef int64_t (*DoubleToInt64ConversionCode)();
4817 int64_t res =
reinterpret_cast<DoubleToInt64ConversionCode
>(
test->entry())();
4818 EXPECT_EQ(420000000000l, res);
4820 "movq rax,0x44a1c9a62d04ed0c\n"
4822 "movsd xmm9,[rsp]\n"
4824 "cvttsd2siq rax,xmm9\n"
4825 "movq tmp,0x8000000000000000\n"
4829 "movq rax,0x4258727cda000000\n"
4831 "movsd xmm9,[rsp]\n"
4832 "movsd xmm6,[rsp]\n"
4834 "cvttsd2siq r10,xmm6\n"
4835 "cvttsd2siq rdx,xmm6\n"
4836 "cvttsd2siq r10,xmm9\n"
4837 "cvttsd2siq rdx,xmm9\n"
4848 __ movq(
RAX, Immediate(bit_cast<int64_t, double>(4.2e11)));
4853 __ CompareImmediate(
RAX, Immediate(0x80000000ll));
4863 __ movq(
RAX, Immediate(bit_cast<int64_t, double>(-42.0)));
4868 __ movq(
R10, Immediate(-1));
4871 __ CompareImmediate(
R10, Immediate(-42 & 0xffffffffll));
4880 __ movq(
RAX, Immediate(bit_cast<int64_t, double>(42.0)));
4897 typedef int64_t (*DoubleToInt32ConversionCode)();
4898 int64_t res =
reinterpret_cast<DoubleToInt32ConversionCode
>(
test->entry())();
4901 "movq rax,0x4258727cda000000\n"
4903 "movsd xmm9,[rsp]\n"
4905 "cvttsd2sil rax,xmm9\n"
4906 "movl tmp,0x80000000\n"
4910 "movq rax,0xc045000000000000\n"
4912 "movsd xmm9,[rsp]\n"
4915 "cvttsd2sil r10,xmm9\n"
4916 "movl tmp,0xffffffd6\n"
4920 "movq rax,0x4045000000000000\n"
4922 "movsd xmm9,[rsp]\n"
4923 "movsd xmm6,[rsp]\n"
4925 "cvttsd2sil r10,xmm6\n"
4926 "cvttsd2sil rdx,xmm6\n"
4927 "cvttsd2sil r10,xmm9\n"
4928 "cvttsd2sil rdx,xmm9\n"
4941 __ LoadObject(
RAX, obj);
4942 __ CompareObject(
RAX, obj);
4944 __ LoadObject(
RCX, obj);
4945 __ CompareObject(
RCX, obj);
4948 __ LoadObject(
RCX, smi);
4949 __ CompareObject(
RCX, smi);
4952 __ StoreObject(Address(
RSP, 0), obj);
4954 __ CompareObject(
RCX, obj);
4957 __ StoreObject(Address(
RSP, 0), smi);
4959 __ CompareObject(
RCX, smi);
4961 __ movl(
RAX, Immediate(1));
4965 __ movl(
RAX, Immediate(0));
4971 bool res =
test->InvokeWithCodeAndThread<
bool>();
4972 EXPECT_EQ(
true, res);
4973#if !defined(DART_COMPRESSED_POINTERS)
4974 EXPECT_DISASSEMBLY_NOT_WINDOWS(
4982 "movq pp,[r12+0x27]\n"
4983 "movq rax,[pp+0xf]\n"
4984 "cmpq rax,[pp+0xf]\n"
4986 "movq rcx,[pp+0xf]\n"
4987 "cmpq rcx,[pp+0xf]\n"
4993 "movq tmp,[pp+0xf]\n"
4996 "cmpq rcx,[pp+0xf]\n"
5018 EXPECT_DISASSEMBLY_NOT_WINDOWS(
5026 "movq pp,[r12+0x27]\n"
5027 "movq rax,[pp+0xf]\n"
5028 "cmpl rax,[pp+0xf]\n"
5030 "movq rcx,[pp+0xf]\n"
5031 "cmpl rcx,[pp+0xf]\n"
5037 "movq tmp,[pp+0xf]\n"
5040 "cmpl rcx,[pp+0xf]\n"
5073 __ movq(
RAX, Immediate(assembler->CodeSize()));
5078 typedef int (*TestNop)();
5079 int res =
reinterpret_cast<TestNop
>(
test->payload_start())();
5096 __ movq(
RAX, Immediate(assembler->CodeSize()));
5101 typedef int (*TestAlign0)();
5102 int res =
reinterpret_cast<TestAlign0
>(
test->payload_start())();
5112 __ movq(
RAX, Immediate(assembler->CodeSize()));
5117 typedef int (*TestAlign1)();
5118 int res =
reinterpret_cast<TestAlign1
>(
test->payload_start())();
5130 __ movq(
RAX, Immediate(assembler->CodeSize()));
5135 typedef int (*TestAlign1Offset1)();
5136 int res =
reinterpret_cast<TestAlign1Offset1
>(
test->payload_start())();
5148 __ movq(
RAX, Immediate(assembler->CodeSize()));
5153 typedef int (*TestAlignLarge)();
5154 int res =
reinterpret_cast<TestAlignLarge
>(
test->payload_start())();
5165 __ movq(
RAX, Immediate(4));
5167 __ addq(Address(
RSP, 0), Immediate(5));
5169 __ addq(Address(
RSP, 0), Immediate(-2));
5171 __ movq(
RCX, Immediate(3));
5174 __ movq(
RAX, Immediate(10));
5182 typedef int (*TestAdds)();
5183 int res =
reinterpret_cast<TestAdds
>(
test->entry())();
5199 __ movq(
RAX, Immediate(0xFFFFFFFF00000000));
5205 typedef int (*TestNot)();
5206 unsigned int res =
reinterpret_cast<TestNot
>(
test->entry())();
5207 EXPECT_EQ(0xFFFFFFFF, res);
5209 "movq rax,0xffffffff00000000\n"
5215 __ movq(
RAX, Immediate(0x0));
5221 typedef int (*TestNot)();
5222 unsigned int res =
reinterpret_cast<TestNot
>(
test->entry())();
5223 EXPECT_EQ(0xFFFFFFFF, res);
5239 typedef double (*XorpdZeroingCode)(
double d);
5240 double res =
reinterpret_cast<XorpdZeroingCode
>(
test->entry())(12.56e3);
5241 EXPECT_FLOAT_EQ(0.0, res, 0.0001);
5244 "movsd [rsp],xmm0\n"
5245 "xorpd xmm0,[rsp]\n"
5263 typedef double (*XorpdZeroing2Code)(
double d);
5264 double res =
reinterpret_cast<XorpdZeroing2Code
>(
test->entry())(12.56e3);
5265 EXPECT_FLOAT_EQ(0.0, res, 0.0001);
5267 "xorpd xmm15,xmm15\n"
5269 "xorpd xmm0,xmm15\n"
5270 "comisd xmm0,xmm15\n"
5282 typedef double (*PxorCode)(
double d);
5283 double res =
reinterpret_cast<PxorCode
>(
test->entry())(12.3456e3);
5284 EXPECT_FLOAT_EQ(0.0, res, 0.0);
5296 typedef double (*SquareRootDoubleCode)(
double d);
5297 const double kDoubleConst = .7;
5299 reinterpret_cast<SquareRootDoubleCode
>(
test->entry())(kDoubleConst);
5300 EXPECT_FLOAT_EQ(
sqrt(kDoubleConst), res, 0.0001);
5302 "sqrtsd xmm0,xmm0\n"
5321 int64_t l = bit_cast<int64_t, double>(1024.67);
5322 __ movq(
RAX, Immediate(l));
5324 __ fldl(Address(
RSP, 0));
5325 __ movq(Address(
RSP, 0), Immediate(0));
5326 __ fstpl(Address(
RSP, 0));
5332 typedef int64_t (*DoubleFPUStackMovesCode)();
5333 int64_t res =
reinterpret_cast<DoubleFPUStackMovesCode
>(
test->entry())();
5334 EXPECT_FLOAT_EQ(1024.67, (bit_cast<double, int64_t>(res)), 0.001);
5336 "movq rax,0x409002ae147ae148\n"
5348 __ fldl(Address(
RSP, 0));
5350 __ fstpl(Address(
RSP, 0));
5357 typedef double (*SineCode)(
double d);
5358 const double kDoubleConst = 0.7;
5359 double res =
reinterpret_cast<SineCode
>(
test->entry())(kDoubleConst);
5360 EXPECT_FLOAT_EQ(sin(kDoubleConst), res, 0.0001);
5363 "movsd [rsp],xmm0\n"
5367 "movsd xmm0,[rsp]\n"
5375 __ fldl(Address(
RSP, 0));
5377 __ fstpl(Address(
RSP, 0));
5384 typedef double (*CosineCode)(
double f);
5385 const double kDoubleConst = 0.7;
5386 double res =
reinterpret_cast<CosineCode
>(
test->entry())(kDoubleConst);
5387 EXPECT_FLOAT_EQ(cos(kDoubleConst), res, 0.0001);
5390 "movsd [rsp],xmm0\n"
5394 "movsd xmm0,[rsp]\n"
5400 __ movq(
RDX, Immediate(6));
5406 typedef double (*IntToDoubleConversionCode)();
5407 double res =
reinterpret_cast<IntToDoubleConversionCode
>(
test->entry())();
5408 EXPECT_FLOAT_EQ(6.0, res, 0.001);
5411 "cvtsi2sd xmm0,rdx\n"
5421 typedef double (*DoubleToDoubleTruncCode)(
double d);
5422 double res =
reinterpret_cast<DoubleToDoubleTruncCode
>(
test->entry())(12.3);
5423 EXPECT_EQ(12.0, res);
5424 res =
reinterpret_cast<DoubleToDoubleTruncCode
>(
test->entry())(12.8);
5425 EXPECT_EQ(12.0, res);
5426 res =
reinterpret_cast<DoubleToDoubleTruncCode
>(
test->entry())(-12.3);
5427 EXPECT_EQ(-12.0, res);
5428 res =
reinterpret_cast<DoubleToDoubleTruncCode
>(
test->entry())(-12.8);
5429 EXPECT_EQ(-12.0, res);
5431 "roundsd rax, rax, 3\n"
5437#if defined(DART_HOST_OS_WINDOWS)
5451 double val = -12.45;
5452 double res =
test->InvokeWithCodeAndThread<double,
double>(val);
5453 EXPECT_FLOAT_EQ(-val, res, 0.001);
5455 res =
test->InvokeWithCodeAndThread<double,
double>(val);
5456 EXPECT_FLOAT_EQ(val, res, 0.001);
5457 EXPECT_DISASSEMBLY_NOT_WINDOWS(
5465 "movq pp,[r12+0x27]\n"
5466 "movq tmp,[thr+0x...]\n"
5467 "andpd xmm0,[tmp]\n"
5478 __ andq(
RAX, Immediate(0x1));
5483 typedef int (*ExtractSignBits)(
double d);
5484 int res =
reinterpret_cast<ExtractSignBits
>(
test->entry())(1.0);
5486 res =
reinterpret_cast<ExtractSignBits
>(
test->entry())(-1.0);
5488 res =
reinterpret_cast<ExtractSignBits
>(
test->entry())(-0.0);
5491 "movmskpd rax,xmm0\n"
5497 __ movq(
RAX, Immediate(0xFFFFFFFF));
5504 typedef uword (*TestSetCC)();
5505 uword res =
reinterpret_cast<TestSetCC
>(
test->entry())();
5506 EXPECT_EQ(0xFFFFFF00, res);
5508 "movl rax,0xffffffff\n"
5516 __ movq(
RBX, Immediate(0xFFFFFFFF));
5525 typedef uword (*TestSetCC)();
5526 uword res =
reinterpret_cast<TestSetCC
>(
test->entry())();
5527 EXPECT_EQ(0xFFFF01FF, res);
5530 "movl rbx,0xffffffff\n"
5540 __ movq(
R10, Immediate(0xFFFFFFFF));
5549 typedef uword (*TestSetCC)();
5550 uword res =
reinterpret_cast<TestSetCC
>(
test->entry())();
5551 EXPECT_EQ(0xFFFFFF00, res);
5554 "movl r10,0xffffffff\n"
5564 __ movq(
RSI, Immediate(0xFFFFFFFF));
5573 typedef uword (*TestSetCC)();
5574 uword res =
reinterpret_cast<TestSetCC
>(
test->entry())();
5575 EXPECT_EQ(0xFFFFFF01, res);
5578 "movl rsi,0xffffffff\n"
5606 const char* from =
"0123456789x";
5607 char* to =
new char[11]{0};
5609 typedef void (*TestRepMovsBytes)(
const char* from,
char* to,
int count);
5610 reinterpret_cast<TestRepMovsBytes
>(
test->entry())(from, to, 10);
5611 EXPECT_EQ(to[0],
'0');
5612 for (
int i = 0;
i < 10;
i++) {
5613 EXPECT_EQ(from[
i], to[
i]);
5615 EXPECT_EQ(to[10],
'y');
5617 EXPECT_DISASSEMBLY_NOT_WINDOWS(
5623 "movq rsi,[rsp+0x10]\n"
5624 "movq rdi,[rsp+0x8]\n"
5655 const uint16_t from[11] = {0x0123, 0x1234, 0x2345, 0x3456, 0x4567, 0x5678,
5656 0x6789, 0x789A, 0x89AB, 0x9ABC, 0xABCD};
5657 uint16_t* to =
new uint16_t[11]{0};
5659 typedef void (*TestRepMovsWords)(
const uint16_t* from, uint16_t* to,
5661 reinterpret_cast<TestRepMovsWords
>(
test->entry())(from, to, 10);
5662 EXPECT_EQ(to[0], 0x0123u);
5663 for (
int i = 0;
i < 10;
i++) {
5664 EXPECT_EQ(from[
i], to[
i]);
5666 EXPECT_EQ(to[10], 0xFEFEu);
5668 EXPECT_DISASSEMBLY_NOT_WINDOWS(
5674 "movq rsi,[rsp+0x10]\n"
5675 "movq rdi,[rsp+0x8]\n"
5706 const uint32_t from[11] = {0x01234567, 0x12345678, 0x23456789, 0x3456789A,
5707 0x456789AB, 0x56789ABC, 0x6789ABCD, 0x789ABCDE,
5708 0x89ABCDEF, 0x9ABCDEF0, 0xABCDEF01};
5709 uint32_t* to =
new uint32_t[11]{0};
5710 to[10] = 0xFEFEFEFE;
5711 typedef void (*TestRepMovsDwords)(
const uint32_t* from, uint32_t* to,
5713 reinterpret_cast<TestRepMovsDwords
>(
test->entry())(from, to, 10);
5714 EXPECT_EQ(to[0], 0x01234567u);
5715 for (
int i = 0;
i < 10;
i++) {
5716 EXPECT_EQ(from[
i], to[
i]);
5718 EXPECT_EQ(to[10], 0xFEFEFEFEu);
5720 EXPECT_DISASSEMBLY_NOT_WINDOWS(
5726 "movq rsi,[rsp+0x10]\n"
5727 "movq rdi,[rsp+0x8]\n"
5758 const uint64_t from[11] = {
5759 0x0123456789ABCDEF, 0x123456789ABCDEF0, 0x23456789ABCDEF01,
5760 0x3456789ABCDEF012, 0x456789ABCDEF0123, 0x56789ABCDEF01234,
5761 0x6789ABCDEF012345, 0x789ABCDEF0123456, 0x89ABCDEF01234567,
5762 0x9ABCDEF012345678, 0xABCDEF0123456789};
5763 uint64_t* to =
new uint64_t[11]{0};
5764 to[10] = 0xFEFEFEFEFEFEFEFE;
5765 typedef void (*TestRepMovsQwords)(
const uint64_t* from, uint64_t* to,
5767 reinterpret_cast<TestRepMovsQwords
>(
test->entry())(from, to, 10);
5768 EXPECT_EQ(to[0], 0x0123456789ABCDEFu);
5769 for (
int i = 0;
i < 10;
i++) {
5770 EXPECT_EQ(from[
i], to[
i]);
5772 EXPECT_EQ(to[10], 0xFEFEFEFEFEFEFEFEu);
5774 EXPECT_DISASSEMBLY_NOT_WINDOWS(
5780 "movq rsi,[rsp+0x10]\n"
5781 "movq rdi,[rsp+0x8]\n"
5794 __ movq(
RDX, Immediate(1));
5795 __ movq(
RCX, Immediate(-1));
5802 typedef int (*ConditionalMovesCompareCode)(
int i,
int j);
5803 int res =
reinterpret_cast<ConditionalMovesCompareCode
>(
test->entry())(10, 5);
5805 res =
reinterpret_cast<ConditionalMovesCompareCode
>(
test->entry())(5, 5);
5807 res =
reinterpret_cast<ConditionalMovesCompareCode
>(
test->entry())(2, 5);
5809 EXPECT_DISASSEMBLY_ENDS_WITH(
5818 __ movq(
RAX, Immediate(4));
5819 __ movq(
R11, Immediate(2));
5825 __ movq(
RAX, Immediate(1));
5830 typedef int (*BitTest)();
5831 EXPECT_EQ(1,
reinterpret_cast<BitTest
>(
test->entry())());
5843 __ movq(
R11, Immediate(32));
5849 __ movq(
RAX, Immediate(1));
5854 typedef int (*BitTestImmediate)();
5855 EXPECT_EQ(1,
reinterpret_cast<BitTestImmediate
>(
test->entry())());
5869 __ movq(
RCX, Immediate(1));
5870 __ cmpq(
RDX, Immediate(785));
5876 typedef int (*ConditionalMovesEqualCode)(
int i);
5877 int res =
reinterpret_cast<ConditionalMovesEqualCode
>(
test->entry())(785);
5879 res =
reinterpret_cast<ConditionalMovesEqualCode
>(
test->entry())(-12);
5881 EXPECT_DISASSEMBLY_ENDS_WITH(
5893 __ movq(
RAX, Immediate(1));
5894 __ movq(
RCX, Immediate(0));
5900 typedef int (*ConditionalMovesNoOverflowCode)(int64_t
i, int64_t j);
5901 int res =
reinterpret_cast<ConditionalMovesNoOverflowCode
>(
test->entry())(
5902 0x7fffffffffffffff, 2);
5904 res =
reinterpret_cast<ConditionalMovesNoOverflowCode
>(
test->entry())(1, 1);
5906 EXPECT_DISASSEMBLY_NOT_WINDOWS(
5916 const intptr_t kBillion = 1000 * 1000 * 1000;
5918 __ LoadImmediate(
RAX, Immediate(42));
5919 __ MulImmediate(
RAX, Immediate(kBillion));
5921 __ CompareImmediate(
RAX, Immediate(42 * kBillion));
5927 __ LoadImmediate(
RAX, Immediate(42));
5930 __ CompareImmediate(
RAX, Immediate((42 * kBillion) & 0xffffffffll));
5936 __ LoadImmediate(
RAX, Immediate(kBillion));
5937 __ AddImmediate(
RAX, Immediate(41 * kBillion));
5939 __ CompareImmediate(
RAX, Immediate(42 * kBillion));
5945 __ LoadImmediate(
RAX, Immediate(kBillion));
5950 __ CompareImmediate(
RAX, Immediate((4 * kBillion) & 0xffffffffll));
5956 __ LoadImmediate(
RAX, Immediate(kBillion));
5957 __ AddImmediate(
RAX, Immediate(
static_cast<int32_t
>(3 * kBillion)),
5962 __ CompareImmediate(
RAX, Immediate((4 * kBillion) & 0xffffffffll));
5968 __ LoadImmediate(
RAX, Immediate(kBillion));
5969 __ SubImmediate(
RAX, Immediate(43 * kBillion));
5971 __ CompareImmediate(
RAX, Immediate(-42 * kBillion));
5977 __ LoadImmediate(
RAX, Immediate(-kBillion));
5982 __ CompareImmediate(
RAX, Immediate((-4 * kBillion) & 0xffffffffll));
5988 __ LoadImmediate(
RAX, Immediate(kBillion));
5989 __ SubImmediate(
RAX, Immediate((-3 * kBillion) & 0xffffffffll),
kFourBytes);
5993 __ CompareImmediate(
RAX, Immediate((4 * kBillion) & 0xffffffffll));
5998 __ LoadImmediate(
RAX, Immediate(42));
6003 typedef int (*ImmediateMacrosCode)();
6004 int res =
reinterpret_cast<ImmediateMacrosCode
>(
test->entry())();
6008 "imulq rax,rax,0x3b9aca00\n"
6009 "movq tmp,0x00000009c7652400\n"
6014 "imull rax,rax,0x3b9aca00\n"
6015 "movl tmp,0xc7652400\n"
6019 "movl rax,0x3b9aca00\n"
6020 "movq tmp,0x000000098bca5a00\n"
6022 "movq tmp,0x00000009c7652400\n"
6026 "movl rax,0x3b9aca00\n"
6027 "addl rax,0x3b9aca00\n"
6028 "addl rax,0x3b9aca00\n"
6029 "addl rax,0x3b9aca00\n"
6030 "movl tmp,0xee6b2800\n"
6034 "movl rax,0x3b9aca00\n"
6035 "subl rax,0x4d2fa200\n"
6036 "addl rax,0x3b9aca00\n"
6037 "subl rax,0x3b9aca00\n"
6038 "movl tmp,0xee6b2800\n"
6042 "movl rax,0x3b9aca00\n"
6043 "movq tmp,0x0000000a02ffee00\n"
6045 "movq tmp,0xfffffff6389adc00\n"
6049 "movq rax,-0x3b9aca00\n"
6050 "subl rax,0x3b9aca00\n"
6051 "subl rax,0x3b9aca00\n"
6052 "subl rax,0x3b9aca00\n"
6053 "cmpq rax,0x1194d800\n"
6056 "movl rax,0x3b9aca00\n"
6057 "subl rax,0x4d2fa200\n"
6058 "subl rax,0x3b9aca00\n"
6059 "addl rax,0x3b9aca00\n"
6060 "movl tmp,0xee6b2800\n"
6069 const intptr_t kTrillion = 1000000000000;
6071 __ LoadImmediate(
RAX, kTrillion);
6073 __ CompareImmediate(
RAX, kTrillion);
6079 __ LoadImmediate(
RAX, 3);
6080 __ AddImmediate(
RAX, kTrillion);
6082 __ CompareImmediate(
RAX, 3 + kTrillion);
6088 __ LoadImmediate(
RAX, 5);
6089 __ AddImmediate(
RCX,
RAX, kTrillion);
6091 __ CompareImmediate(
RCX, 5 + kTrillion);
6096 __ LoadImmediate(
RAX, 42);
6101 typedef int (*ImmediateMacrosCode)();
6102 int res =
reinterpret_cast<ImmediateMacrosCode
>(
test->entry())();
6105 "movq rax,0x000000e8d4a51000\n"
6106 "movq tmp,0x000000e8d4a51000\n"
6111 "movq tmp,0x000000e8d4a51000\n"
6113 "movq tmp,0x000000e8d4a51003\n"
6118 "movq rcx,0x000000e8d4a51000\n"
6120 "movq tmp,0x000000e8d4a51005\n"
6129#define ALU_TEST(NAME, WIDTH, INTRO, LHS, RHS, OUTRO) \
6130 ASSEMBLER_TEST_GENERATE(NAME, assembler) { \
6131 int32_t input1_w = static_cast<int32_t>(0x87654321); \
6132 int32_t input1_l = input1_w; \
6133 int64_t input1_q = 0xfedcba987654321ll; \
6134 input1_##WIDTH += input1_w * 0 + input1_l * 0 + input1_q * 0; \
6135 int32_t input2_w = static_cast<int32_t>(0x12345678); \
6136 int32_t input2_l = input2_w; \
6137 int64_t input2_q = 0xabcdef912345678ll; \
6138 input2_##WIDTH += input2_w * 0 + input2_l * 0 + input2_q * 0; \
6140 __ movq(RAX, Immediate(input1_##WIDTH)); \
6141 __ movq(RCX, Immediate(input2_##WIDTH)); \
6145 __ and##WIDTH(LHS, RHS); \
6146 __ or##WIDTH(RHS, LHS); \
6147 __ xor##WIDTH(LHS, RHS); \
6148 __ add##WIDTH(RHS, LHS); \
6149 __ cmp##WIDTH(LHS, RHS); \
6150 __ adc##WIDTH(LHS, RHS); \
6151 __ sub##WIDTH(RHS, LHS); \
6152 __ sbb##WIDTH(LHS, RHS); \
6156 __ xorq(RCX, RCX); \
6157 __ add##WIDTH(RCX, RAX); \
6158 __ andq(RAX, RCX); \
6162 ASSEMBLER_TEST_RUN(NAME, test) { \
6163 typedef uint64_t (*NAME)(); \
6164 uint64_t expectation_q = 0xaed1be942649381ll; \
6165 uint32_t expectation_l = expectation_q; \
6166 uint16_t expectation_w = expectation_l; \
6167 uint64_t expectation = expectation_##WIDTH | expectation_w; \
6168 EXPECT_EQ(expectation, reinterpret_cast<NAME>(test->entry())()); \
6172ALU_TEST(RegRegW,
w, ,
RAX,
RCX, )
6175ALU_TEST(RegRegL, l, ,
RAX,
RCX, )
6178ALU_TEST(RegRegQ, q, ,
RAX,
RCX, )
6182#define IMMEDIATE_TEST(NAME, REG, MASK, INTRO, VALUE, OUTRO) \
6183 ASSEMBLER_TEST_GENERATE(NAME, assembler) { \
6184 __ movl(REG, Immediate(static_cast<int32_t>(0x87654321))); \
6188 __ andl(VALUE, Immediate(static_cast<int32_t>(0xa8df51d3 & MASK))); \
6189 __ orl(VALUE, Immediate(0x1582a681 & MASK)); \
6190 __ xorl(VALUE, Immediate(static_cast<int32_t>(0xa5a5a5a5 & MASK))); \
6191 __ addl(VALUE, Immediate(0x7fffffff & MASK)); \
6192 __ cmpl(VALUE, Immediate(0x40404040 & MASK)); \
6193 __ adcl(VALUE, Immediate(0x6eeeeeee & MASK)); \
6194 __ subl(VALUE, Immediate(0x7eeeeeee & MASK)); \
6195 __ sbbl(VALUE, Immediate(0x6fffffff & MASK)); \
6199 __ movl(RAX, REG); \
6203 ASSEMBLER_TEST_RUN(NAME, test) { \
6204 typedef uint64_t (*NAME)(); \
6205 unsigned expectation = MASK < 0x100 ? 0x24 : 0x30624223; \
6206 EXPECT_EQ(expectation, reinterpret_cast<NAME>(test->entry())()); \
6212IMMEDIATE_TEST(RegImmRAX,
RAX, 0xffffffff, ,
RAX, )
6213IMMEDIATE_TEST(RegImmRCX,
RCX, 0xffffffff, ,
RCX, )
6214IMMEDIATE_TEST(RegImmRAXByte,
RAX, 0x7f, ,
RAX, )
6215IMMEDIATE_TEST(RegImmRCXByte,
RCX, 0x7f, ,
RCX, )
6216IMMEDIATE_TEST(AddrImmRAX,
6222IMMEDIATE_TEST(AddrImmRAXByte,
6230 if (FLAG_target_thread_sanitizer) {
6243 __ movq(
RCX, Immediate(bit_cast<int32_t, float>(12.34f +
i)));
6244 __ movd(xmm_reg,
RCX);
6254 __ movq(reg, Immediate(0xAABBCCDD +
i));
6276 __ cmpq(reg, Immediate(0xAABBCCDD +
i));
6290 __ movq(
RCX, xmm_reg);
6291 __ cmpq(
RCX, Immediate(bit_cast<int32_t, float>(12.34f +
i)));
6304 const intptr_t res =
test->InvokeWithCodeAndThread<intptr_t>(123);
6305 EXPECT_EQ(123, res);
6309 if (FLAG_target_thread_sanitizer) {
6318 __ subq(
RSP, Immediate(1024));
6321 __ addq(
RSP, Immediate(1024));
6328 const intptr_t res =
test->InvokeWithCodeAndThread<intptr_t>(123);
6329 EXPECT_EQ(123, res);
6330 if (!FLAG_target_thread_sanitizer) {
6331 EXPECT_DISASSEMBLY_NOT_WINDOWS(
6336 "movq [rsp+0x400],rdx\n"
6337 "movq rax,[rsp+0x400]\n"
6346 __ pushq(Immediate(0x1234567887654321));
6354 __ shrq(
RBX, Immediate(8));
6373 intptr_t res =
test->InvokeWithCodeAndThread<intptr_t>();
6374 EXPECT_EQ(0x21 + 0x21 + 0x21 + 0x21, res);
6382 __ movq(return_reg, Immediate(0));
6385 __ movq(return_reg, Immediate(1));
6392 RangeCheck(assembler,
value, temp);
6397 result =
test->Invoke<intptr_t, intptr_t>(kErrorCid);
6399 result =
test->Invoke<intptr_t, intptr_t>(kUnwindErrorCid);
6401 result =
test->Invoke<intptr_t, intptr_t>(kFunctionCid);
6403 result =
test->Invoke<intptr_t, intptr_t>(kMintCid);
6410 RangeCheck(assembler,
value, temp);
6415 result =
test->Invoke<intptr_t, intptr_t>(kErrorCid);
6417 result =
test->Invoke<intptr_t, intptr_t>(kUnwindErrorCid);
6419 result =
test->Invoke<intptr_t, intptr_t>(kFunctionCid);
6421 result =
test->Invoke<intptr_t, intptr_t>(kMintCid);
6439 result =
test->Invoke<intptr_t, intptr_t>(kErrorCid);
6440 EXPECT_EQ(kErrorCid,
result);
6441 result =
test->Invoke<intptr_t, intptr_t>(kUnwindErrorCid);
6442 EXPECT_EQ(kUnwindErrorCid,
result);
6443 result =
test->Invoke<intptr_t, intptr_t>(kFunctionCid);
6444 EXPECT_EQ(kFunctionCid,
result);
6445 result =
test->Invoke<intptr_t, intptr_t>(kMintCid);
6446 EXPECT_EQ(kMintCid,
result);
6452 const auto& do_nothing_just_return =
6457 const RegisterSet clobbered_regs(
6460 __ PushRegisters(clobbered_regs);
6464 const auto check_all_allocatable_registers_are_preserved_by_call = [&]() {
6466 __ LoadImmediate(reg,
static_cast<int32_t
>(reg));
6468 __ Call(do_nothing_just_return);
6471 if (!FLAG_precompiled_mode && reg ==
CODE_REG)
continue;
6474 __ CompareImmediate(reg,
static_cast<int32_t
>(reg));
6476 __ LoadImmediate(
RAX, reg);
6482 check_all_allocatable_registers_are_preserved_by_call();
6484 FLAG_precompiled_mode =
true;
6485 check_all_allocatable_registers_are_preserved_by_call();
6486 FLAG_precompiled_mode =
false;
6488 __ LoadImmediate(
RAX, 42);
6490 __ PopRegisters(clobbered_regs);
6496 const intptr_t
result =
test->InvokeWithCodeAndThread<int64_t>();
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
static void fail(const SkString &err)
static bool ok(int result)
static const Code & Generate(const char *name, const std::function< void(compiler::Assembler *assembler)> &generator)
static constexpr RegList kVolatileXmmRegisters
static constexpr intptr_t kVolatileCpuRegisters
static constexpr Register kArg3Reg
static constexpr Register kArg1Reg
static constexpr Register kReturnReg
static constexpr Register kArg2Reg
static constexpr Register kArg4Reg
static intptr_t data_offset()
static bool popcnt_supported()
static bool abm_supported()
static Instr * At(uword pc)
ObjectStore * object_store() const
static IsolateGroup * Current()
static intptr_t ActivationFrameAlignment()
static Object & ZoneHandle()
static SmiPtr New(intptr_t value)
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
static Address AddressBaseImm32(Register base, int32_t disp)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
const uint8_t uint32_t uint32_t GError ** error
static constexpr intptr_t kWordSize
void LeaveTestFrame(Assembler *assembler)
ASSEMBLER_TEST_GENERATE(InstantiateTypeArgumentsHashKeys, assembler)
void EnterTestFrame(Assembler *assembler)
static Utils::BitsRange< Register > RegisterRange(uint32_t regs)
static const ClassId kLastErrorCid
constexpr uint32_t kMaxUint32
static const ClassId kFirstErrorCid
constexpr RegList kDartAvailableCpuRegs
ASSEMBLER_TEST_RUN(StoreIntoObject, test)
COMPILE_ASSERT(kUnreachableReference==WeakTable::kNoValue)
ByteRegister ByteRegisterOf(Register reg)
static bool Bind(PassBindingsCacheMTL &pass, ShaderStage stage, size_t bind_index, const BufferView &view)
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
SIN Vec< N, uint16_t > mull(const Vec< N, uint8_t > &x, const Vec< N, uint8_t > &y)
#define OFFSET_OF(type, field)