Skip to content

Instantly share code, notes, and snippets.

View kiyoakii's full-sized avatar

Jin Li kiyoakii

View GitHub Profile
@kiyoakii
kiyoakii / create.py
Last active June 16, 2023 21:42
Naive matrix multiplication program copied from somewhere
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
random.seed(1234)
def createRandomMatrix(n):
maxVal = 1000 # I don't want to get Java / C++ into trouble
@kiyoakii
kiyoakii / #Wasm-bounds-check.md
Last active June 7, 2023 15:19
This Gist shows how C++ .at() looks like in compiled Wasm code.

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=4 means 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.eq means 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.