Skip to content

Commit bf282bb

Browse files
authored
threads: add remaining instructions (#1664)
* Add the `wast` instructions This refactors the way memory orderings are attached to instructions by introducing `Ordered<T>`. This allows any kind of existing instruction argument to be wrapped up in its ordered equivalent, which is essentially what many of the shared-everything-threads instructions do. * Add the instructions everywhere else * Add tests * Fix formatting * Deduplicate validation of `struct|array.atomic.rmw.*` instructions
1 parent 4c7a005 commit bf282bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3879
-73
lines changed

crates/wasm-encoder/src/core/code.rs

Lines changed: 376 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,122 @@ pub enum Instruction<'a> {
10871087
ordering: Ordering,
10881088
global_index: u32,
10891089
},
1090+
TableAtomicGet {
1091+
ordering: Ordering,
1092+
table_index: u32,
1093+
},
1094+
TableAtomicSet {
1095+
ordering: Ordering,
1096+
table_index: u32,
1097+
},
1098+
TableAtomicRmwXchg {
1099+
ordering: Ordering,
1100+
table_index: u32,
1101+
},
1102+
TableAtomicRmwCmpxchg {
1103+
ordering: Ordering,
1104+
table_index: u32,
1105+
},
1106+
StructAtomicGet {
1107+
ordering: Ordering,
1108+
struct_type_index: u32,
1109+
field_index: u32,
1110+
},
1111+
StructAtomicGetS {
1112+
ordering: Ordering,
1113+
struct_type_index: u32,
1114+
field_index: u32,
1115+
},
1116+
StructAtomicGetU {
1117+
ordering: Ordering,
1118+
struct_type_index: u32,
1119+
field_index: u32,
1120+
},
1121+
StructAtomicSet {
1122+
ordering: Ordering,
1123+
struct_type_index: u32,
1124+
field_index: u32,
1125+
},
1126+
StructAtomicRmwAdd {
1127+
ordering: Ordering,
1128+
struct_type_index: u32,
1129+
field_index: u32,
1130+
},
1131+
StructAtomicRmwSub {
1132+
ordering: Ordering,
1133+
struct_type_index: u32,
1134+
field_index: u32,
1135+
},
1136+
StructAtomicRmwAnd {
1137+
ordering: Ordering,
1138+
struct_type_index: u32,
1139+
field_index: u32,
1140+
},
1141+
StructAtomicRmwOr {
1142+
ordering: Ordering,
1143+
struct_type_index: u32,
1144+
field_index: u32,
1145+
},
1146+
StructAtomicRmwXor {
1147+
ordering: Ordering,
1148+
struct_type_index: u32,
1149+
field_index: u32,
1150+
},
1151+
StructAtomicRmwXchg {
1152+
ordering: Ordering,
1153+
struct_type_index: u32,
1154+
field_index: u32,
1155+
},
1156+
StructAtomicRmwCmpxchg {
1157+
ordering: Ordering,
1158+
struct_type_index: u32,
1159+
field_index: u32,
1160+
},
1161+
ArrayAtomicGet {
1162+
ordering: Ordering,
1163+
array_type_index: u32,
1164+
},
1165+
ArrayAtomicGetS {
1166+
ordering: Ordering,
1167+
array_type_index: u32,
1168+
},
1169+
ArrayAtomicGetU {
1170+
ordering: Ordering,
1171+
array_type_index: u32,
1172+
},
1173+
ArrayAtomicSet {
1174+
ordering: Ordering,
1175+
array_type_index: u32,
1176+
},
1177+
ArrayAtomicRmwAdd {
1178+
ordering: Ordering,
1179+
array_type_index: u32,
1180+
},
1181+
ArrayAtomicRmwSub {
1182+
ordering: Ordering,
1183+
array_type_index: u32,
1184+
},
1185+
ArrayAtomicRmwAnd {
1186+
ordering: Ordering,
1187+
array_type_index: u32,
1188+
},
1189+
ArrayAtomicRmwOr {
1190+
ordering: Ordering,
1191+
array_type_index: u32,
1192+
},
1193+
ArrayAtomicRmwXor {
1194+
ordering: Ordering,
1195+
array_type_index: u32,
1196+
},
1197+
ArrayAtomicRmwXchg {
1198+
ordering: Ordering,
1199+
array_type_index: u32,
1200+
},
1201+
ArrayAtomicRmwCmpxchg {
1202+
ordering: Ordering,
1203+
array_type_index: u32,
1204+
},
1205+
RefI31Shared,
10901206
}
10911207

10921208
impl Encode for Instruction<'_> {
@@ -3319,6 +3435,266 @@ impl Encode for Instruction<'_> {
33193435
ordering.encode(sink);
33203436
global_index.encode(sink);
33213437
}
3438+
Instruction::TableAtomicGet {
3439+
ordering,
3440+
table_index,
3441+
} => {
3442+
sink.push(0xFE);
3443+
sink.push(0x58);
3444+
ordering.encode(sink);
3445+
table_index.encode(sink);
3446+
}
3447+
Instruction::TableAtomicSet {
3448+
ordering,
3449+
table_index,
3450+
} => {
3451+
sink.push(0xFE);
3452+
sink.push(0x59);
3453+
ordering.encode(sink);
3454+
table_index.encode(sink);
3455+
}
3456+
Instruction::TableAtomicRmwXchg {
3457+
ordering,
3458+
table_index,
3459+
} => {
3460+
sink.push(0xFE);
3461+
sink.push(0x5A);
3462+
ordering.encode(sink);
3463+
table_index.encode(sink);
3464+
}
3465+
Instruction::TableAtomicRmwCmpxchg {
3466+
ordering,
3467+
table_index,
3468+
} => {
3469+
sink.push(0xFE);
3470+
sink.push(0x5B);
3471+
ordering.encode(sink);
3472+
table_index.encode(sink);
3473+
}
3474+
Instruction::StructAtomicGet {
3475+
ordering,
3476+
struct_type_index,
3477+
field_index,
3478+
} => {
3479+
sink.push(0xFE);
3480+
sink.push(0x5C);
3481+
ordering.encode(sink);
3482+
struct_type_index.encode(sink);
3483+
field_index.encode(sink);
3484+
}
3485+
Instruction::StructAtomicGetS {
3486+
ordering,
3487+
struct_type_index,
3488+
field_index,
3489+
} => {
3490+
sink.push(0xFE);
3491+
sink.push(0x5D);
3492+
ordering.encode(sink);
3493+
struct_type_index.encode(sink);
3494+
field_index.encode(sink);
3495+
}
3496+
Instruction::StructAtomicGetU {
3497+
ordering,
3498+
struct_type_index,
3499+
field_index,
3500+
} => {
3501+
sink.push(0xFE);
3502+
sink.push(0x5E);
3503+
ordering.encode(sink);
3504+
struct_type_index.encode(sink);
3505+
field_index.encode(sink);
3506+
}
3507+
Instruction::StructAtomicSet {
3508+
ordering,
3509+
struct_type_index,
3510+
field_index,
3511+
} => {
3512+
sink.push(0xFE);
3513+
sink.push(0x5F);
3514+
ordering.encode(sink);
3515+
struct_type_index.encode(sink);
3516+
field_index.encode(sink);
3517+
}
3518+
Instruction::StructAtomicRmwAdd {
3519+
ordering,
3520+
struct_type_index,
3521+
field_index,
3522+
} => {
3523+
sink.push(0xFE);
3524+
sink.push(0x60);
3525+
ordering.encode(sink);
3526+
struct_type_index.encode(sink);
3527+
field_index.encode(sink);
3528+
}
3529+
Instruction::StructAtomicRmwSub {
3530+
ordering,
3531+
struct_type_index,
3532+
field_index,
3533+
} => {
3534+
sink.push(0xFE);
3535+
sink.push(0x61);
3536+
ordering.encode(sink);
3537+
struct_type_index.encode(sink);
3538+
field_index.encode(sink);
3539+
}
3540+
Instruction::StructAtomicRmwAnd {
3541+
ordering,
3542+
struct_type_index,
3543+
field_index,
3544+
} => {
3545+
sink.push(0xFE);
3546+
sink.push(0x62);
3547+
ordering.encode(sink);
3548+
struct_type_index.encode(sink);
3549+
field_index.encode(sink);
3550+
}
3551+
Instruction::StructAtomicRmwOr {
3552+
ordering,
3553+
struct_type_index,
3554+
field_index,
3555+
} => {
3556+
sink.push(0xFE);
3557+
sink.push(0x63);
3558+
ordering.encode(sink);
3559+
struct_type_index.encode(sink);
3560+
field_index.encode(sink);
3561+
}
3562+
Instruction::StructAtomicRmwXor {
3563+
ordering,
3564+
struct_type_index,
3565+
field_index,
3566+
} => {
3567+
sink.push(0xFE);
3568+
sink.push(0x64);
3569+
ordering.encode(sink);
3570+
struct_type_index.encode(sink);
3571+
field_index.encode(sink);
3572+
}
3573+
Instruction::StructAtomicRmwXchg {
3574+
ordering,
3575+
struct_type_index,
3576+
field_index,
3577+
} => {
3578+
sink.push(0xFE);
3579+
sink.push(0x65);
3580+
ordering.encode(sink);
3581+
struct_type_index.encode(sink);
3582+
field_index.encode(sink);
3583+
}
3584+
Instruction::StructAtomicRmwCmpxchg {
3585+
ordering,
3586+
struct_type_index,
3587+
field_index,
3588+
} => {
3589+
sink.push(0xFE);
3590+
sink.push(0x66);
3591+
ordering.encode(sink);
3592+
struct_type_index.encode(sink);
3593+
field_index.encode(sink);
3594+
}
3595+
Instruction::ArrayAtomicGet {
3596+
ordering,
3597+
array_type_index,
3598+
} => {
3599+
sink.push(0xFE);
3600+
sink.push(0x67);
3601+
ordering.encode(sink);
3602+
array_type_index.encode(sink);
3603+
}
3604+
Instruction::ArrayAtomicGetS {
3605+
ordering,
3606+
array_type_index,
3607+
} => {
3608+
sink.push(0xFE);
3609+
sink.push(0x68);
3610+
ordering.encode(sink);
3611+
array_type_index.encode(sink);
3612+
}
3613+
Instruction::ArrayAtomicGetU {
3614+
ordering,
3615+
array_type_index,
3616+
} => {
3617+
sink.push(0xFE);
3618+
sink.push(0x69);
3619+
ordering.encode(sink);
3620+
array_type_index.encode(sink);
3621+
}
3622+
Instruction::ArrayAtomicSet {
3623+
ordering,
3624+
array_type_index,
3625+
} => {
3626+
sink.push(0xFE);
3627+
sink.push(0x6A);
3628+
ordering.encode(sink);
3629+
array_type_index.encode(sink);
3630+
}
3631+
Instruction::ArrayAtomicRmwAdd {
3632+
ordering,
3633+
array_type_index,
3634+
} => {
3635+
sink.push(0xFE);
3636+
sink.push(0x6B);
3637+
ordering.encode(sink);
3638+
array_type_index.encode(sink);
3639+
}
3640+
Instruction::ArrayAtomicRmwSub {
3641+
ordering,
3642+
array_type_index,
3643+
} => {
3644+
sink.push(0xFE);
3645+
sink.push(0x6C);
3646+
ordering.encode(sink);
3647+
array_type_index.encode(sink);
3648+
}
3649+
Instruction::ArrayAtomicRmwAnd {
3650+
ordering,
3651+
array_type_index,
3652+
} => {
3653+
sink.push(0xFE);
3654+
sink.push(0x6D);
3655+
ordering.encode(sink);
3656+
array_type_index.encode(sink);
3657+
}
3658+
Instruction::ArrayAtomicRmwOr {
3659+
ordering,
3660+
array_type_index,
3661+
} => {
3662+
sink.push(0xFE);
3663+
sink.push(0x6E);
3664+
ordering.encode(sink);
3665+
array_type_index.encode(sink);
3666+
}
3667+
Instruction::ArrayAtomicRmwXor {
3668+
ordering,
3669+
array_type_index,
3670+
} => {
3671+
sink.push(0xFE);
3672+
sink.push(0x6F);
3673+
ordering.encode(sink);
3674+
array_type_index.encode(sink);
3675+
}
3676+
Instruction::ArrayAtomicRmwXchg {
3677+
ordering,
3678+
array_type_index,
3679+
} => {
3680+
sink.push(0xFE);
3681+
sink.push(0x70);
3682+
ordering.encode(sink);
3683+
array_type_index.encode(sink);
3684+
}
3685+
Instruction::ArrayAtomicRmwCmpxchg {
3686+
ordering,
3687+
array_type_index,
3688+
} => {
3689+
sink.push(0xFE);
3690+
sink.push(0x71);
3691+
ordering.encode(sink);
3692+
array_type_index.encode(sink);
3693+
}
3694+
Instruction::RefI31Shared => {
3695+
sink.push(0xFE);
3696+
sink.push(0x1F);
3697+
}
33223698
}
33233699
}
33243700
}

0 commit comments

Comments
 (0)