WebAssembly / simd

Branch of the spec repo scoped to discussion of SIMD in WebAssembly
Other
527 stars 43 forks source link

No `i8x16.mul`? #524

Closed Cyborus04 closed 2 years ago

Cyborus04 commented 2 years ago

Is there a reason why i8x16.mul is not included? I find it a bit odd, since i16x8.mul, i32x4.mul, and i64x2.mul exist. Is there something I'm missing?

penzn commented 2 years ago

This is instruction was dropped (#98), because result of i8 multiplication isn't likely to fit into an i8: https://github.com/WebAssembly/simd/issues/28#issuecomment-377585364

Do you have code where you would need it?

Cyborus04 commented 2 years ago

I was making a toy SIMD library in Rust which only operates on 128 bits (like in WebAssembly), where each type for the lanes would implement a trait for their associated instructions. I hit the roadblock of mul as I didn't see a way to implement this trait for i8/u8 (except maybe extracting each lane and multiplying them manually, but that kinda defeats the point)

ngzhian commented 2 years ago

You can try using i16x8.extmul_low_i8x16 + i16x8.extmul_high_i8x16 + i8x16.narrowi16x8{s,u}, that's 3 instructions, which will be better than extracting individual lanes.

Cyborus04 commented 2 years ago

Oh, that works. Thank you!