Skip to content

Welcome to WCPL

This is a test. I will be posting some notes on WCPL design here.

For now, here is a small test of freshly minted support for WASM SIMD and LLVM-compatible wasm_simd128.h header:

#include <wasm_simd128.h>
#include <stdio.h>

void multiply_arrays(int* out, int* in_a, int* in_b, int size) 
{
  for (int i = 0; i < size; i += 4) {
    v128_t a = wasm_v128_load(&in_a[i]);
    v128_t b = wasm_v128_load(&in_b[i]);
    v128_t prod = wasm_i32x4_mul(a, b);
    wasm_v128_store(&out[i], prod);
  }
}

int main()
{
  int a1[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  int a2[8] = { 1, 10, 100, 1000, 1000, 100, 10, 1 };
  int a3[8], i;
  multiply_arrays(&a3[0], &a2[0], &a1[0], 8);
  printf("a3[8] = { %d, %d, %d, %d, %d, %d, %d, %d };\n", 
    a3[0], a3[1], a3[2], a3[3], a3[4], a3[5], a3[6], a3[7]);
  v128_t v1 = wasm_i16x8_const(1, 2, 3, 4, 5, 6, 7, 8);
  v128_t v2 = wasm_i16x8_const(10, 20, 30, 40, 50, 60, 70, 80);
  v128_t v3 = wasm_i16x8_mul(v1, v2);
  a3[0] = wasm_i16x8_extract_lane(v3, 0);
  a3[1] = wasm_i16x8_extract_lane(v3, 1);
  a3[2] = wasm_i16x8_extract_lane(v3, 2);
  a3[3] = wasm_i16x8_extract_lane(v3, 3);
  a3[4] = wasm_i16x8_extract_lane(v3, 4);
  a3[5] = wasm_i16x8_extract_lane(v3, 5);
  a3[6] = wasm_i16x8_extract_lane(v3, 6);
  a3[7] = wasm_i16x8_extract_lane(v3, 7);
  printf("a3[8] = { %d, %d, %d, %d, %d, %d, %d, %d };\n", 
    a3[0], a3[1], a3[2], a3[3], a3[4], a3[5], a3[6], a3[7]);
  return 0;
}

#=> prints 'a3[8] = { 1, 20, 300, 4000, 5000, 600, 70, 8 };' to STDOUT.
#=> prints 'a3[8] = { 10, 40, 90, 160, 250, 360, 490, 640 };' to STDOUT.

Check out the LLVM’s original wasm_simd128.h for more info.