1 USING: accessors compiler.cfg compiler.cfg.debugger
2 compiler.cfg.instructions compiler.cfg.registers
3 compiler.cfg.representations.preferred cpu.architecture kernel
4 namespaces tools.test sequences arrays system literals layouts
5 math compiler.constants compiler.cfg.representations.conversion
6 compiler.cfg.representations.rewrite
7 compiler.cfg.comparisons compiler.cfg.utilities
9 FROM: alien.c-types => char ;
10 IN: compiler.cfg.representations
12 { { double-rep double-rep } } [
29 H{ } clone representations set
31 3 vreg-counter set-global
35 T{ ##allot f 2 16 float 4 }
36 T{ ##store-memory-imm f 1 2 $[ float-offset ] double-rep f }
40 2 1 tagged-rep double-rep emit-conversion
46 T{ ##load-memory-imm f 2 1 $[ float-offset ] double-rep f }
50 2 1 double-rep tagged-rep emit-conversion
54 : test-representations ( -- )
55 0 get block>cfg dup cfg set select-representations ;
57 ! Make sure cost calculation isn't completely wrong
66 T{ ##add-float f 3 1 2 }
67 T{ ##replace f 3 D 0 }
68 T{ ##replace f 3 D 1 }
69 T{ ##replace f 3 D 2 }
81 { } [ test-representations ] unit-test
83 { 1 } [ 1 get instructions>> [ ##allot? ] count ] unit-test
85 ! Don't dereference the result of a peek
97 T{ ##add-float f 2 1 1 }
98 T{ ##replace f 2 D 0 }
104 T{ ##add-float f 3 1 1 }
105 T{ ##replace f 3 D 0 }
113 { } [ test-representations ] unit-test
120 } [ 1 get instructions>> ] unit-test
122 ! We cannot untag-fixnum the result of a peek if there are usages
123 ! of it as a tagged-rep
135 T{ ##replace f 1 R 0 }
142 T{ ##replace f 2 D 0 }
156 { } [ test-representations ] unit-test
163 } [ 1 get instructions>> ] unit-test
165 ! But its ok to untag-fixnum the result of a peek if all usages use
185 T{ ##replace f 2 D 0 }
186 T{ ##replace f 3 D 1 }
200 3 vreg-counter set-global
202 { } [ test-representations ] unit-test
207 T{ ##sar-imm f 1 4 $[ tag-bits get ] }
210 } [ 1 get instructions>> ] unit-test
212 ! scalar-rep => int-rep conversion
221 T{ ##vector>scalar f 3 2 int-4-rep }
222 T{ ##replace f 3 D 0 }
234 { } [ test-representations ] unit-test
236 { t } [ 1 get instructions>> 4 swap nth ##scalar>integer? ] unit-test
238 ! Test phi node behavior
245 T{ ##load-integer f 1 1 }
250 T{ ##load-integer f 2 2 }
255 T{ ##phi f 3 H{ { 1 1 } { 2 2 } } }
256 T{ ##replace f 3 D 0 }
270 { } [ test-representations ] unit-test
272 { T{ ##load-tagged f 1 $[ 1 tag-fixnum ] } }
273 [ 1 get instructions>> first ]
276 { T{ ##load-tagged f 2 $[ 2 tag-fixnum ] } }
277 [ 2 get instructions>> first ]
280 ! ##load-reference corner case
294 T{ ##load-reference f 3 f }
299 T{ ##phi f 4 H{ { 1 2 } { 2 3 } } }
300 T{ ##replace f 4 D 0 }
314 { } [ test-representations ] unit-test
317 { 2 } [ 2 get instructions>> length ] unit-test
321 ! Make sure load-constant is converted into load-double
329 T{ ##load-reference f 2 0.5 }
330 T{ ##add-float f 3 1 2 }
331 T{ ##replace f 3 D 0 }
343 [ ] [ test-representations ] unit-test
345 [ t ] [ 1 get instructions>> second ##load-double? ] unit-test
347 ! Make sure phi nodes are handled in a sane way
355 T{ ##compare-imm-branch f 1 2 cc= }
359 T{ ##load-reference f 2 1.5 }
364 T{ ##load-reference f 3 2.5 }
369 T{ ##phi f 4 H{ { 2 2 } { 3 3 } } }
371 T{ ##add-float f 6 4 5 }
372 T{ ##replace f 6 D 0 }
383 [ ] [ test-representations ] unit-test
385 [ t ] [ 2 get instructions>> first ##load-double? ] unit-test
387 [ t ] [ 3 get instructions>> first ##load-double? ] unit-test
389 [ t ] [ 4 get instructions>> first ##phi? ] unit-test
392 : test-peephole ( insns -- insns )
395 0 get instructions>> ;
397 ! Don't convert the def site into anything but tagged-rep since
398 ! we might lose precision
399 5 vreg-counter set-global
405 T{ ##tagged>integer f 2 1 }
406 T{ ##add-float f 3 0 0 }
407 T{ ##store-memory-imm f 3 2 0 float-rep f }
408 T{ ##store-memory-imm f 3 2 4 float-rep f }
409 T{ ##mul-float f 4 0 0 }
410 T{ ##replace f 4 D 0 }
412 [ ##single>double-float? ] any?
415 ! Converting a ##load-integer into a ##load-tagged
418 T{ ##load-tagged f 1 $[ 100 tag-fixnum ] }
419 T{ ##replace f 1 D 0 }
423 T{ ##load-integer f 1 100 }
424 T{ ##replace f 1 D 0 }
428 ! Peephole optimization if input to ##shl-imm is tagged
429 3 vreg-counter set-global
434 T{ ##sar-imm f 2 1 1 }
436 T{ ##shl-imm f 3 4 $[ tag-bits get ] }
437 T{ ##replace f 3 D 0 }
442 T{ ##shl-imm f 2 1 3 }
444 T{ ##replace f 3 D 0 }
448 3 vreg-counter set-global
453 T{ ##shl-imm f 2 1 $[ 10 tag-bits get - ] }
455 T{ ##shl-imm f 3 4 $[ tag-bits get ] }
456 T{ ##replace f 3 D 0 }
461 T{ ##shl-imm f 2 1 10 }
463 T{ ##replace f 3 D 0 }
470 T{ ##copy f 2 1 int-rep }
472 T{ ##shl-imm f 3 5 $[ tag-bits get ] }
473 T{ ##replace f 3 D 0 }
478 T{ ##shl-imm f 2 1 $[ tag-bits get ] }
480 T{ ##replace f 3 D 0 }
484 ! Peephole optimization if output of ##shl-imm needs to be tagged
487 T{ ##load-integer f 1 100 }
488 T{ ##shl-imm f 2 1 $[ 3 tag-bits get + ] }
489 T{ ##replace f 2 D 0 }
493 T{ ##load-integer f 1 100 }
494 T{ ##shl-imm f 2 1 3 }
495 T{ ##replace f 2 D 0 }
499 ! Peephole optimization if both input and output of ##shl-imm
504 T{ ##shl-imm f 1 0 3 }
505 T{ ##replace f 1 D 0 }
510 T{ ##shl-imm f 1 0 3 }
511 T{ ##replace f 1 D 0 }
515 ! Peephole optimization if neither input nor output of ##shl-imm need to be tagged
518 T{ ##load-integer f 1 100 }
519 T{ ##shl-imm f 2 1 3 }
520 T{ ##load-integer f 3 100 }
521 T{ ##load-integer f 4 100 }
522 T{ ##store-memory f 2 3 4 0 0 int-rep char }
526 T{ ##load-integer f 1 100 }
527 T{ ##shl-imm f 2 1 3 }
528 T{ ##load-integer f 3 100 }
529 T{ ##load-integer f 4 100 }
530 T{ ##store-memory f 2 3 4 0 0 int-rep char }
534 6 vreg-counter set-global
536 ! Peephole optimization if input to ##sar-imm is tagged
540 T{ ##sar-imm f 7 1 $[ 3 tag-bits get + ] }
541 T{ ##shl-imm f 2 7 $[ tag-bits get ] }
542 T{ ##replace f 2 D 0 }
547 T{ ##sar-imm f 2 1 3 }
548 T{ ##replace f 2 D 0 }
552 6 vreg-counter set-global
554 ! (Lack of) peephole optimization if output of ##sar-imm needs to be tagged
557 T{ ##load-integer f 1 100 }
558 T{ ##sar-imm f 7 1 3 }
559 T{ ##shl-imm f 2 7 $[ tag-bits get ] }
560 T{ ##replace f 2 D 0 }
564 T{ ##load-integer f 1 100 }
565 T{ ##sar-imm f 2 1 3 }
566 T{ ##replace f 2 D 0 }
570 ! Peephole optimization if input of ##sar-imm is tagged but output is untagged
575 T{ ##sar-imm f 1 0 $[ 3 tag-bits get + ] }
576 T{ ##load-integer f 3 100 }
577 T{ ##load-integer f 4 100 }
578 T{ ##store-memory f 1 3 4 0 0 int-rep char }
583 T{ ##sar-imm f 1 0 3 }
584 T{ ##load-integer f 3 100 }
585 T{ ##load-integer f 4 100 }
586 T{ ##store-memory f 1 3 4 0 0 int-rep char }
590 ! Peephole optimization if neither input nor output of ##sar-imm need to be tagged
593 T{ ##load-integer f 1 100 }
594 T{ ##sar-imm f 2 1 3 }
595 T{ ##load-integer f 3 100 }
596 T{ ##load-integer f 4 100 }
597 T{ ##store-memory f 2 3 4 0 0 int-rep char }
601 T{ ##load-integer f 1 100 }
602 T{ ##sar-imm f 2 1 3 }
603 T{ ##load-integer f 3 100 }
604 T{ ##load-integer f 4 100 }
605 T{ ##store-memory f 2 3 4 0 0 int-rep char }
611 T{ ##load-vector f 0 B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } short-8-rep }
612 T{ ##select-vector f 1 0 0 short-8-rep }
613 T{ ##sar-imm f 2 1 3 }
614 T{ ##load-integer f 3 100 }
616 T{ ##load-integer f 5 100 }
617 T{ ##load-integer f 6 100 }
618 T{ ##store-memory f 4 5 6 0 0 int-rep char }
622 T{ ##load-vector f 0 B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } short-8-rep }
623 T{ ##select-vector f 1 0 0 short-8-rep }
624 T{ ##sar-imm f 2 1 3 }
625 T{ ##load-integer f 3 100 }
627 T{ ##load-integer f 5 100 }
628 T{ ##load-integer f 6 100 }
629 T{ ##store-memory f 4 5 6 0 0 int-rep char }
633 6 vreg-counter set-global
637 T{ ##load-vector f 0 B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } int-4-rep }
638 T{ ##select-vector f 1 0 0 int-4-rep }
639 T{ ##sar-imm f 2 1 3 }
640 T{ ##load-integer f 3 100 }
642 T{ ##shl-imm f 4 7 $[ tag-bits get ] }
643 T{ ##replace f 4 D 0 }
647 T{ ##load-vector f 0 B{ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 } int-4-rep }
648 T{ ##select-vector f 1 0 0 int-4-rep }
649 T{ ##sar-imm f 2 1 3 }
650 T{ ##load-integer f 3 100 }
652 T{ ##replace f 4 D 0 }
656 ! Tag/untag elimination
660 T{ ##add-imm f 2 1 $[ 100 tag-fixnum ] }
661 T{ ##replace f 2 D 0 }
666 T{ ##add-imm f 2 1 100 }
667 T{ ##replace f 2 D 0 }
676 T{ ##replace f 2 D 0 }
683 T{ ##replace f 2 D 0 }
687 ! Make sure we don't exceed immediate bounds
689 4 vreg-counter set-global
694 T{ ##sar-imm f 5 0 $[ tag-bits get ] }
695 T{ ##add-imm f 6 5 $[ 30 2^ ] }
696 T{ ##shl-imm f 2 6 $[ tag-bits get ] }
697 T{ ##replace f 2 D 0 }
702 T{ ##add-imm f 2 0 $[ 30 2^ ] }
703 T{ ##replace f 2 D 0 }
709 T{ ##load-integer f 0 100 }
710 T{ ##mul-imm f 7 0 $[ 30 2^ ] }
711 T{ ##shl-imm f 1 7 $[ tag-bits get ] }
712 T{ ##replace f 1 D 0 }
716 T{ ##load-integer f 0 100 }
717 T{ ##mul-imm f 1 0 $[ 30 2^ ] }
718 T{ ##replace f 1 D 0 }
723 ! Tag/untag elimination for ##mul-imm
727 T{ ##mul-imm f 1 0 100 }
728 T{ ##replace f 1 D 0 }
733 T{ ##mul-imm f 1 0 100 }
734 T{ ##replace f 1 D 0 }
738 4 vreg-counter set-global
744 T{ ##sar-imm f 5 1 $[ tag-bits get ] }
745 T{ ##add-imm f 2 5 30 }
746 T{ ##mul-imm f 3 2 $[ 100 tag-fixnum ] }
747 T{ ##replace f 3 D 0 }
753 T{ ##add-imm f 2 1 30 }
754 T{ ##mul-imm f 3 2 100 }
755 T{ ##replace f 3 D 0 }
759 ! Tag/untag elimination for ##compare-integer and ##test
764 T{ ##test f 2 0 1 cc= }
765 T{ ##replace f 2 D 0 }
771 T{ ##test f 2 0 1 cc= }
772 T{ ##replace f 2 D 0 }
780 T{ ##compare-integer f 2 0 1 cc= }
781 T{ ##replace f 2 D 0 }
787 T{ ##compare-integer f 2 0 1 cc= }
788 T{ ##replace f 2 D 0 }
796 T{ ##compare-integer-branch f 0 1 cc= }
802 T{ ##compare-integer-branch f 0 1 cc= }
810 T{ ##test-branch f 0 1 cc= }
816 T{ ##test-branch f 0 1 cc= }
824 T{ ##compare-integer-imm-branch f 0 $[ 10 tag-fixnum ] cc= }
830 T{ ##compare-integer-imm-branch f 0 10 cc= }
838 T{ ##test-imm-branch f 0 $[ 10 tag-fixnum ] cc= }
844 T{ ##test-imm-branch f 0 10 cc= }
848 ! Tag/untag elimination for ##neg
853 T{ ##replace f 1 D 0 }
859 T{ ##replace f 1 D 0 }
863 4 vreg-counter set-global
867 T{ ##peek { dst 0 } { loc D 0 } }
868 T{ ##peek { dst 1 } { loc D 1 } }
869 T{ ##sar-imm { dst 5 } { src1 0 } { src2 4 } }
870 T{ ##sar-imm { dst 6 } { src1 1 } { src2 4 } }
871 T{ ##mul { dst 2 } { src1 5 } { src2 6 } }
872 T{ ##mul-imm { dst 3 } { src1 2 } { src2 -16 } }
873 T{ ##replace { src 3 } { loc D 0 } }
881 T{ ##replace f 3 D 0 }
885 ! Tag/untag elimination for ##not
886 2 vreg-counter set-global
892 T{ ##xor-imm f 1 3 $[ tag-mask get ] }
893 T{ ##replace f 1 D 0 }
899 T{ ##replace f 1 D 0 }