Code Monkey home page Code Monkey logo

learn_wasm's Introduction

WASM

Là một assembly chạy được trong web browser, nodejs

  • Giúp tăng performance.
  • Giúp run Unity, các code C/C++, Rust, ...

Từ cuối 2019, WASM trở thành chuẩn của web, đứng ngang hàng với HTML, CSS, JS.

Browser nào support WASM

https://caniuse.com/wasm

IDE trên web

https://webassembly.studio/

Thử viết một hàm bằng native WASM

Hàm có dạng function sum(a:i32, b:i32) => a + b

  1. create a file math.wat
(module    
    (func $sum (param i32 i32) (result i32)
        local.get 0
        local.get 1
        i32.add
    )

    (export "sum" (func $sum))
)
  1. Compile the file math.wat to math.wasm

npx wat2wasm math.wat -o math.wasm

  1. Call the wasm function math.sum from nodejs
import fs from 'fs';
const mathwasm = fs.readFileSync('./math.wasm');
const math = await WebAssembly.instantiate(new Uint8Array(mathwasm)).then(({instance}) => instance.exports);

console.log(math.sum(1, 2));

Questions & Notes

  • javascript and wasm run in the same thread?
  • Tốc độ gọi qua lại giữa javascript và wasm?
  • 64-bit integer, được interop với javascript ntn?
  • Không có kiểu string, bool.
  • Không GC, cũng không động vào GC của V8-engine.
  • Có vẻ số nguyên không phân biệt signed/unsigned, operator sẽ quyết định sign.
  • WebAssembly vscode extension báo lỗi vì chưa có language server chưa support windows.

learn_wasm's People

Contributors

damphat avatar

Watchers

 avatar Anh Dang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.