The bounds check of .at() is probably implemented by the following wasm instructions:
-
i32.load: This loads a 32-bit value from a memory address given by an operand plus an offset.For example,
i32.load offset=4means load a 32-bit value from the address given by the operand plus 4 bytes. This is used to access the elements of the vectors. -
i32.eq: This compares two 32-bit values for equality and returns 1 if they are equal or 0 if they are not.For example,
local.get 5 local.get 4 i32.eqmeans compare the values of local variables 5 and 4 and return the result (push to stack). This is used to check if the index is equal to the size of the vector. -
i32.le_u: This compares two 32-bit values for unsigned less than or equal and returns 1 if the first value is less than or equal to the second value or 0 if it is not.