|
331 | 331 | #f |
332 | 332 | (eq? b1 b2))))) |
333 | 333 |
|
334 | | -;; --- Stage 2: immediate-value placeholders --- |
| 334 | +;; --- immediate-value placeholders --- |
335 | 335 |
|
336 | 336 | ;; imm64 placeholder: movq (imm64 :val), %rax |
337 | 337 | ;; Encoding: REX.W(48) B8 <8 bytes immediate> -- 10 bytes total |
|
421 | 421 | '((start . 0)) |
422 | 422 | labels))) |
423 | 423 |
|
424 | | -;; --- Stage 3: data-directive placeholders --- |
| 424 | +;; --- data-directive placeholders --- |
425 | 425 |
|
426 | 426 | ;; .dataq placeholder: 8-byte hole |
427 | 427 | (let () |
|
479 | 479 | '(#x08 #x07 #x06 #x05 #x04 #x03 #x02 #x01) |
480 | 480 | (u8vector->list b)))) |
481 | 481 |
|
| 482 | +;; --- movs_ instruction-variant placeholder --- |
| 483 | + |
| 484 | +;; ((movs_ :op) %xmm0 %xmm1) -- sse->sse form |
| 485 | +;; Default encoding: F2 0F 10 ModRM |
| 486 | +;; ModRM: mod=3(reg-reg), reg=1(xmm1/dst), r/m=1(xmm1/dst) -> 0b11_001_001 = #xc9 |
| 487 | +(let () |
| 488 | + (define tmpl (asm-template '(((movs_ :op) %xmm0 %xmm1)))) |
| 489 | + ;; Default is movsd |
| 490 | + (receive (b _) (asm-instantiate tmpl '()) |
| 491 | + (test* "movs_ sse->sse default (movsd)" |
| 492 | + '(#xf2 #x0f #x10 #xc9) |
| 493 | + (u8vector->list b))) |
| 494 | + ;; Explicit movsd |
| 495 | + (receive (b _) (asm-instantiate tmpl '((:op . movsd))) |
| 496 | + (test* "movs_ sse->sse explicit movsd" |
| 497 | + '(#xf2 #x0f #x10 #xc9) |
| 498 | + (u8vector->list b))) |
| 499 | + ;; Switch to movss |
| 500 | + (receive (b _) (asm-instantiate tmpl '((:op . movss))) |
| 501 | + (test* "movs_ sse->sse switched to movss" |
| 502 | + '(#xf3 #x0f #x10 #xc9) |
| 503 | + (u8vector->list b))) |
| 504 | + ;; Re-instantiate as movsd again (template not mutated) |
| 505 | + (receive (b _) (asm-instantiate tmpl '((:op . movsd))) |
| 506 | + (test* "movs_ sse->sse back to movsd" |
| 507 | + '(#xf2 #x0f #x10 #xc9) |
| 508 | + (u8vector->list b)))) |
| 509 | + |
| 510 | +;; ((movs_ :op) (%rax) %xmm1) -- mem->sse form |
| 511 | +;; Default encoding: F2 0F 10 ModRM |
| 512 | +;; ModRM: mod=0, reg=1(xmm1/dst), r/m=0(%rax) -> 0b00_001_000 = #x08 |
| 513 | +(let () |
| 514 | + (define tmpl (asm-template '(((movs_ :op) (%rax) %xmm1)))) |
| 515 | + (receive (b _) (asm-instantiate tmpl '()) |
| 516 | + (test* "movs_ mem->sse default (movsd)" |
| 517 | + '(#xf2 #x0f #x10 #x08) |
| 518 | + (u8vector->list b))) |
| 519 | + (receive (b _) (asm-instantiate tmpl '((:op . movss))) |
| 520 | + (test* "movs_ mem->sse switched to movss" |
| 521 | + '(#xf3 #x0f #x10 #x08) |
| 522 | + (u8vector->list b)))) |
| 523 | + |
| 524 | +;; ((movs_ :op) %xmm0 (%rax)) -- sse->mem form |
| 525 | +;; Default encoding: F2 0F 11 ModRM |
| 526 | +;; ModRM: mod=0, reg=0(xmm0/src), r/m=0(%rax) -> #x00 |
| 527 | +(let () |
| 528 | + (define tmpl (asm-template '(((movs_ :op) %xmm0 (%rax))))) |
| 529 | + (receive (b _) (asm-instantiate tmpl '()) |
| 530 | + (test* "movs_ sse->mem default (movsd)" |
| 531 | + '(#xf2 #x0f #x11 #x00) |
| 532 | + (u8vector->list b))) |
| 533 | + (receive (b _) (asm-instantiate tmpl '((:op . movss))) |
| 534 | + (test* "movs_ sse->mem switched to movss" |
| 535 | + '(#xf3 #x0f #x11 #x00) |
| 536 | + (u8vector->list b)))) |
| 537 | + |
| 538 | +;; movs_ combined with other placeholders in a sequence |
| 539 | +(let () |
| 540 | + (define tmpl (asm-template '((.dataq :fn-ptr) |
| 541 | + ((movs_ :variant) (%rax) %xmm0) |
| 542 | + (ret)))) |
| 543 | + (receive (b _) (asm-instantiate tmpl `((:fn-ptr . #xdeadbeef) (:variant . movss))) |
| 544 | + (test* "movs_ combined with .dataq placeholder" |
| 545 | + (append '(#xef #xbe #xad #xde 0 0 0 0) ; .dataq :fn-ptr |
| 546 | + '(#xf3 #x0f #x10 #x00) ; movss (%rax),%xmm0 |
| 547 | + '(#xc3)) ; ret |
| 548 | + (u8vector->list b)))) |
| 549 | + |
482 | 550 | ;;---------------------------------------------------------------------- |
483 | 551 | (test-section "lang.c") |
484 | 552 |
|
|
0 commit comments