First Commit
This commit is contained in:
52
wasm_add.c
Normal file
52
wasm_add.c
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
|
||||
#define ARRAY_SIZE 15000576 // 100 million items
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
int* alloc( int size ) {
|
||||
|
||||
return ( int * ) malloc( size );
|
||||
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void dealloc( int * ptr, int size ) {
|
||||
|
||||
free( ptr );
|
||||
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
float* alloc_float_array(int size) {
|
||||
|
||||
return ( float * ) malloc(size * sizeof(float));
|
||||
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void dealloc_float_array(float* ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void init_arrays(float* a, float* b) {
|
||||
for (int i = 0; i < ARRAY_SIZE; i++) {
|
||||
a[i] = i;
|
||||
b[i] = i * 2;
|
||||
}
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void calculate(float* a, float* b, float* c) {
|
||||
for (int i = 0; i < ARRAY_SIZE; i++) {
|
||||
c[i] = a[i] + b[i];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user