WebAssembly / simd

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

Make i8 and i16 work correctly on their own #528

Closed ngzhian closed 2 years ago

ngzhian commented 2 years ago

Previously, i8 and i16 was careless w.r.t. the top bits, because they were only used by v128, which uses Bytes.get/set that appropriate masks the top bits when storing into the byte array.

With this change, i8 and i16 are self contained small integers implemented using int32. They are always stored signed-extended, e.g. INT8_MIN (-128) is stored as 0xffffff80.

This requires adding sign-extension operation (Rep.sx) in a couple of places, that will make sure to extend the sign bit to the rest of the int32.

Also add a small, non-exhaustive test for these small integers in a new file test/smallint.ml. This is the first ml test we are adding (all previous tests are wasm/wast tests that we run using the interpreter), so there are some modifications to the Makefile to build and run this test (make smallinttest, make test will also run it).