Commit 283d187
committed
feat: complete @kernel elementwise stride-4 SIMD loop vectorization
Add end-to-end support for @kernel elementwise inside compute() blocks.
When the body matches `for i in range { arr[i] = arr[i] OP scalar }`,
the compiler pattern-extracts the operands and emits a stride-4 SIMD
loop (VectorLoad F32x4, VectorSplat, vector binary op, VectorStore)
with a scalar remainder path for len % 4 elements.
HIR:
- Add VectorLoad and VectorStore instructions with replace_uses,
operands, and result extraction in hir.rs, analysis.rs, hir_dump.rs
- Cranelift lowering for both via load/store with F32X4/F64X2/I32X4/I64X2
SSA builder (ssa.rs):
- emit_elementwise_simd_loop: 200-line stride-4 SIMD loop emitter using
alloca-based loop counter, VectorLoad/Store, VectorSplat, and both
vector and scalar body paths
- try_extract_elementwise_pattern: matches for-loop body assignment pattern
- emit_list_data_ptr / emit_list_len: extract fields from List<T> struct
- hint_elem_ty_from_expr: F64→F32 normalization for 128-bit SIMD
- FpTrunc scalar cast when grammar's F64 literals meet F32 SIMD path
- simd_continue_block field to redirect process_statement after SIMD loop
- new_from_function, finish, alloc_value, push_instruction,
set_terminator: public API for direct HIR construction in tests
- Remove remaining DEBUG eprintln spam
Grammar (ml.zyn):
- Add index_assign_stmt rule: arr[idx] = expr
Tests:
- 5 new cranelift_backend tests (VectorLoad/Store compile+execute,
emit_elementwise_simd_loop_f32_mul)
- 1 new e2e test (test_execute_kernel_elementwise_simd)
- New compute_simd.zynml example with both @kernel reduce and elementwise
64 cranelift_backend tests pass, 235 e2e tests pass.1 parent 81a7309 commit 283d187
11 files changed
Lines changed: 2006 additions & 127 deletions
File tree
- crates
- compiler
- src
- tests
- zynml
- examples
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
481 | 490 | | |
482 | 491 | | |
483 | 492 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
621 | 694 | | |
622 | 695 | | |
623 | 696 | | |
| |||
837 | 910 | | |
838 | 911 | | |
839 | 912 | | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
840 | 934 | | |
841 | 935 | | |
842 | 936 | | |
| |||
993 | 1087 | | |
994 | 1088 | | |
995 | 1089 | | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
996 | 1111 | | |
997 | 1112 | | |
998 | 1113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
918 | 918 | | |
919 | 919 | | |
920 | 920 | | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
921 | 953 | | |
922 | 954 | | |
923 | 955 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2998 | 2998 | | |
2999 | 2999 | | |
3000 | 3000 | | |
3001 | | - | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
3002 | 3007 | | |
3003 | 3008 | | |
3004 | 3009 | | |
| |||
0 commit comments