Skip to content

Commit 7777122

Browse files
authored
Add cmp+select instruction fusion (#1497)
* add new cmp+select instructions * implement cmp+select instructions in executor * fix docs typo * add TryIntoCmpSelectInstr trait and impl * implement new select translation * remove old select instruction handlers * convert translation test * remove outdated select tests * fix local_set test with select * move CmpOp enum to mod.rs * add new cmp+select translation tests * remove old select instructions * fix broken doc link
1 parent 7b994f1 commit 7777122

File tree

12 files changed

+1719
-1084
lines changed

12 files changed

+1719
-1084
lines changed

crates/ir/src/enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ macro_rules! define_enum {
3131
/// This type represents all such words and for simplicity we call the type [`Instruction`], still.
3232
///
3333
/// Most instructions are composed of a single instruction word. An example of
34-
/// this is [`Instruction::I32Add`]. However, some instructions, like
35-
/// [`Instruction::Select`], are composed of two or more instruction words.
34+
/// this is [`Instruction::I32Add`]. However, some instructions, like the `select` instructions
35+
/// are composed of two or more instruction words.
3636
///
3737
/// The Wasmi bytecode translation makes sure that instructions always appear in valid sequences.
3838
/// The Wasmi executor relies on the guarantees that the Wasmi translator provides.

crates/ir/src/for_each_op.rs

Lines changed: 831 additions & 56 deletions
Large diffs are not rendered by default.

crates/wasmi/src/engine/executor/instrs.rs

Lines changed: 200 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -448,24 +448,210 @@ impl<'engine> Executor<'engine> {
448448
Instr::CallIndirectImm16 { results, func_type } => {
449449
self.execute_call_indirect_imm16(store, results, func_type)?
450450
}
451-
Instr::Select { result, lhs } => self.execute_select(result, lhs),
452-
Instr::SelectImm32Rhs { result, lhs } => self.execute_select_imm32_rhs(result, lhs),
453-
Instr::SelectImm32Lhs { result, lhs } => self.execute_select_imm32_lhs(result, lhs),
454-
Instr::SelectImm32 { result, lhs } => self.execute_select_imm32(result, lhs),
455-
Instr::SelectI64Imm32Rhs { result, lhs } => {
456-
self.execute_select_i64imm32_rhs(result, lhs)
451+
Instr::SelectI32Eq { result, lhs, rhs } => {
452+
self.execute_select_i32_eq(result, lhs, rhs)
457453
}
458-
Instr::SelectI64Imm32Lhs { result, lhs } => {
459-
self.execute_select_i64imm32_lhs(result, lhs)
454+
Instr::SelectI32EqImm16 { result, lhs, rhs } => {
455+
self.execute_select_i32_eq_imm16(result, lhs, rhs)
460456
}
461-
Instr::SelectI64Imm32 { result, lhs } => self.execute_select_i64imm32(result, lhs),
462-
Instr::SelectF64Imm32Rhs { result, lhs } => {
463-
self.execute_select_f64imm32_rhs(result, lhs)
457+
Instr::SelectI32Ne { result, lhs, rhs } => {
458+
self.execute_select_i32_ne(result, lhs, rhs)
464459
}
465-
Instr::SelectF64Imm32Lhs { result, lhs } => {
466-
self.execute_select_f64imm32_lhs(result, lhs)
460+
Instr::SelectI32NeImm16 { result, lhs, rhs } => {
461+
self.execute_select_i32_ne_imm16(result, lhs, rhs)
462+
}
463+
Instr::SelectI32LtS { result, lhs, rhs } => {
464+
self.execute_select_i32_lt_s(result, lhs, rhs)
465+
}
466+
Instr::SelectI32LtSImm16Rhs { result, lhs, rhs } => {
467+
self.execute_select_i32_lt_s_imm16_rhs(result, lhs, rhs)
468+
}
469+
Instr::SelectI32LtSImm16Lhs { result, lhs, rhs } => {
470+
self.execute_select_i32_lt_s_imm16_lhs(result, lhs, rhs)
471+
}
472+
Instr::SelectI32LtU { result, lhs, rhs } => {
473+
self.execute_select_i32_lt_u(result, lhs, rhs)
474+
}
475+
Instr::SelectI32LtUImm16Rhs { result, lhs, rhs } => {
476+
self.execute_select_i32_lt_u_imm16_rhs(result, lhs, rhs)
477+
}
478+
Instr::SelectI32LtUImm16Lhs { result, lhs, rhs } => {
479+
self.execute_select_i32_lt_u_imm16_lhs(result, lhs, rhs)
480+
}
481+
Instr::SelectI32LeS { result, lhs, rhs } => {
482+
self.execute_select_i32_le_s(result, lhs, rhs)
483+
}
484+
Instr::SelectI32LeSImm16Rhs { result, lhs, rhs } => {
485+
self.execute_select_i32_le_s_imm16_rhs(result, lhs, rhs)
486+
}
487+
Instr::SelectI32LeSImm16Lhs { result, lhs, rhs } => {
488+
self.execute_select_i32_le_s_imm16_lhs(result, lhs, rhs)
489+
}
490+
Instr::SelectI32LeU { result, lhs, rhs } => {
491+
self.execute_select_i32_le_u(result, lhs, rhs)
492+
}
493+
Instr::SelectI32LeUImm16Rhs { result, lhs, rhs } => {
494+
self.execute_select_i32_le_u_imm16_rhs(result, lhs, rhs)
495+
}
496+
Instr::SelectI32LeUImm16Lhs { result, lhs, rhs } => {
497+
self.execute_select_i32_le_u_imm16_lhs(result, lhs, rhs)
498+
}
499+
Instr::SelectI32And { result, lhs, rhs } => {
500+
self.execute_select_i32_and(result, lhs, rhs)
501+
}
502+
Instr::SelectI32AndImm16 { result, lhs, rhs } => {
503+
self.execute_select_i32_and_imm16(result, lhs, rhs)
504+
}
505+
Instr::SelectI32Or { result, lhs, rhs } => {
506+
self.execute_select_i32_or(result, lhs, rhs)
507+
}
508+
Instr::SelectI32OrImm16 { result, lhs, rhs } => {
509+
self.execute_select_i32_or_imm16(result, lhs, rhs)
510+
}
511+
Instr::SelectI32Xor { result, lhs, rhs } => {
512+
self.execute_select_i32_xor(result, lhs, rhs)
513+
}
514+
Instr::SelectI32XorImm16 { result, lhs, rhs } => {
515+
self.execute_select_i32_xor_imm16(result, lhs, rhs)
516+
}
517+
Instr::SelectI32Nand { result, lhs, rhs } => {
518+
self.execute_select_i32_nand(result, lhs, rhs)
519+
}
520+
Instr::SelectI32NandImm16 { result, lhs, rhs } => {
521+
self.execute_select_i32_nand_imm16(result, lhs, rhs)
522+
}
523+
Instr::SelectI32Nor { result, lhs, rhs } => {
524+
self.execute_select_i32_nor(result, lhs, rhs)
525+
}
526+
Instr::SelectI32NorImm16 { result, lhs, rhs } => {
527+
self.execute_select_i32_nor_imm16(result, lhs, rhs)
528+
}
529+
Instr::SelectI32Xnor { result, lhs, rhs } => {
530+
self.execute_select_i32_xnor(result, lhs, rhs)
531+
}
532+
Instr::SelectI32XnorImm16 { result, lhs, rhs } => {
533+
self.execute_select_i32_xnor_imm16(result, lhs, rhs)
534+
}
535+
Instr::SelectI64Eq { result, lhs, rhs } => {
536+
self.execute_select_i64_eq(result, lhs, rhs)
537+
}
538+
Instr::SelectI64EqImm16 { result, lhs, rhs } => {
539+
self.execute_select_i64_eq_imm16(result, lhs, rhs)
540+
}
541+
Instr::SelectI64Ne { result, lhs, rhs } => {
542+
self.execute_select_i64_ne(result, lhs, rhs)
543+
}
544+
Instr::SelectI64NeImm16 { result, lhs, rhs } => {
545+
self.execute_select_i64_ne_imm16(result, lhs, rhs)
546+
}
547+
Instr::SelectI64LtS { result, lhs, rhs } => {
548+
self.execute_select_i64_lt_s(result, lhs, rhs)
549+
}
550+
Instr::SelectI64LtSImm16Rhs { result, lhs, rhs } => {
551+
self.execute_select_i64_lt_s_imm16_rhs(result, lhs, rhs)
552+
}
553+
Instr::SelectI64LtSImm16Lhs { result, lhs, rhs } => {
554+
self.execute_select_i64_lt_s_imm16_lhs(result, lhs, rhs)
555+
}
556+
Instr::SelectI64LtU { result, lhs, rhs } => {
557+
self.execute_select_i64_lt_u(result, lhs, rhs)
558+
}
559+
Instr::SelectI64LtUImm16Rhs { result, lhs, rhs } => {
560+
self.execute_select_i64_lt_u_imm16_rhs(result, lhs, rhs)
561+
}
562+
Instr::SelectI64LtUImm16Lhs { result, lhs, rhs } => {
563+
self.execute_select_i64_lt_u_imm16_lhs(result, lhs, rhs)
564+
}
565+
Instr::SelectI64LeS { result, lhs, rhs } => {
566+
self.execute_select_i64_le_s(result, lhs, rhs)
567+
}
568+
Instr::SelectI64LeSImm16Rhs { result, lhs, rhs } => {
569+
self.execute_select_i64_le_s_imm16_rhs(result, lhs, rhs)
570+
}
571+
Instr::SelectI64LeSImm16Lhs { result, lhs, rhs } => {
572+
self.execute_select_i64_le_s_imm16_lhs(result, lhs, rhs)
573+
}
574+
Instr::SelectI64LeU { result, lhs, rhs } => {
575+
self.execute_select_i64_le_u(result, lhs, rhs)
576+
}
577+
Instr::SelectI64LeUImm16Rhs { result, lhs, rhs } => {
578+
self.execute_select_i64_le_u_imm16_rhs(result, lhs, rhs)
579+
}
580+
Instr::SelectI64LeUImm16Lhs { result, lhs, rhs } => {
581+
self.execute_select_i64_le_u_imm16_lhs(result, lhs, rhs)
582+
}
583+
Instr::SelectI64And { result, lhs, rhs } => {
584+
self.execute_select_i64_and(result, lhs, rhs)
585+
}
586+
Instr::SelectI64AndImm16 { result, lhs, rhs } => {
587+
self.execute_select_i64_and_imm16(result, lhs, rhs)
588+
}
589+
Instr::SelectI64Or { result, lhs, rhs } => {
590+
self.execute_select_i64_or(result, lhs, rhs)
591+
}
592+
Instr::SelectI64OrImm16 { result, lhs, rhs } => {
593+
self.execute_select_i64_or_imm16(result, lhs, rhs)
594+
}
595+
Instr::SelectI64Xor { result, lhs, rhs } => {
596+
self.execute_select_i64_xor(result, lhs, rhs)
597+
}
598+
Instr::SelectI64XorImm16 { result, lhs, rhs } => {
599+
self.execute_select_i64_xor_imm16(result, lhs, rhs)
600+
}
601+
Instr::SelectI64Nand { result, lhs, rhs } => {
602+
self.execute_select_i64_nand(result, lhs, rhs)
603+
}
604+
Instr::SelectI64NandImm16 { result, lhs, rhs } => {
605+
self.execute_select_i64_nand_imm16(result, lhs, rhs)
606+
}
607+
Instr::SelectI64Nor { result, lhs, rhs } => {
608+
self.execute_select_i64_nor(result, lhs, rhs)
609+
}
610+
Instr::SelectI64NorImm16 { result, lhs, rhs } => {
611+
self.execute_select_i64_nor_imm16(result, lhs, rhs)
612+
}
613+
Instr::SelectI64Xnor { result, lhs, rhs } => {
614+
self.execute_select_i64_xnor(result, lhs, rhs)
615+
}
616+
Instr::SelectI64XnorImm16 { result, lhs, rhs } => {
617+
self.execute_select_i64_xnor_imm16(result, lhs, rhs)
618+
}
619+
Instr::SelectF32Eq { result, lhs, rhs } => {
620+
self.execute_select_f32_eq(result, lhs, rhs)
621+
}
622+
Instr::SelectF32Ne { result, lhs, rhs } => {
623+
self.execute_select_f32_ne(result, lhs, rhs)
624+
}
625+
Instr::SelectF32Lt { result, lhs, rhs } => {
626+
self.execute_select_f32_lt(result, lhs, rhs)
627+
}
628+
Instr::SelectF32Le { result, lhs, rhs } => {
629+
self.execute_select_f32_le(result, lhs, rhs)
630+
}
631+
Instr::SelectF32NotLt { result, lhs, rhs } => {
632+
self.execute_select_f32_not_lt(result, lhs, rhs)
633+
}
634+
Instr::SelectF32NotLe { result, lhs, rhs } => {
635+
self.execute_select_f32_not_le(result, lhs, rhs)
636+
}
637+
Instr::SelectF64Eq { result, lhs, rhs } => {
638+
self.execute_select_f64_eq(result, lhs, rhs)
639+
}
640+
Instr::SelectF64Ne { result, lhs, rhs } => {
641+
self.execute_select_f64_ne(result, lhs, rhs)
642+
}
643+
Instr::SelectF64Lt { result, lhs, rhs } => {
644+
self.execute_select_f64_lt(result, lhs, rhs)
645+
}
646+
Instr::SelectF64Le { result, lhs, rhs } => {
647+
self.execute_select_f64_le(result, lhs, rhs)
648+
}
649+
Instr::SelectF64NotLt { result, lhs, rhs } => {
650+
self.execute_select_f64_not_lt(result, lhs, rhs)
651+
}
652+
Instr::SelectF64NotLe { result, lhs, rhs } => {
653+
self.execute_select_f64_not_le(result, lhs, rhs)
467654
}
468-
Instr::SelectF64Imm32 { result, lhs } => self.execute_select_f64imm32(result, lhs),
469655
Instr::RefFunc { result, func } => self.execute_ref_func(result, func),
470656
Instr::GlobalGet { result, global } => {
471657
self.execute_global_get(store.inner(), result, global)

0 commit comments

Comments
 (0)