Skip to content

Commit fe3510c

Browse files
authored
Benchmark improvements (emscripten-core#5798)
* cleanup benchmark code * add cheerp benchmark target * add utilities to get binaryen and its bin dir * get the binaryen port when we actually need it, so we don't fetch it early (which, for the wasm backend, might be during compilation of system libraries in ports) * add a test for the wasm backend building ok with the binaryen port
1 parent a6ae6e3 commit fe3510c

8 files changed

Lines changed: 238 additions & 36 deletions

File tree

emcc.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,9 +1184,6 @@ def check(input_file):
11841184
if shared.Settings.BINARYEN_PASSES:
11851185
shared.Settings.BINARYEN_PASSES += ','
11861186
shared.Settings.BINARYEN_PASSES += 'safe-heap'
1187-
# ensure the binaryen port is available, if we are using it. if we do, then
1188-
# we need it to build to wasm
1189-
system_libs.get_port('binaryen', shared.Settings)
11901187

11911188
# wasm outputs are only possible with a side wasm
11921189
if target.endswith(WASM_ENDINGS):
@@ -2240,7 +2237,7 @@ def binaryen_method_sanity_check():
22402237
def do_binaryen(final, target, asm_target, options, memfile, wasm_binary_target,
22412238
wasm_text_target, misc_temp_files, optimizer):
22422239
logging.debug('using binaryen, with method: ' + shared.Settings.BINARYEN_METHOD)
2243-
binaryen_bin = os.path.join(shared.Settings.BINARYEN_ROOT, 'bin')
2240+
binaryen_bin = shared.Building.get_binaryen_bin()
22442241
# Emit wasm.js at the top of the js. This is *not* optimized with the rest of the code, since
22452242
# (1) it contains asm.js, whose validation would be broken, and (2) it's very large so it would
22462243
# be slow in cleanup/JSDCE etc.

tests/benchmark_memcpy.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <memory.h>
21
#include <string.h>
32
#include <stdio.h>
43
#include <stdlib.h>

tests/benchmark_memset.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <memory.h>
21
#include <string.h>
32
#include <stdio.h>
43
#include <stdlib.h>

tests/box2d/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ OBJECTS = \
5151
all: box2d.a
5252

5353
%.o: %.cpp
54-
$(CXX) -I. $< -o $@ -O2 -c
54+
$(CXX) $(CFLAGS) -I. $< -o $@ -O2 -c
5555

5656
box2d.a: $(OBJECTS)
5757
$(AR) rvs $@ $(OBJECTS)

tests/test_benchmark.py

Lines changed: 192 additions & 20 deletions
Large diffs are not rendered by default.

tests/test_sanity.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,26 @@ def test_with_fake(report, expected):
965965
finally:
966966
del os.environ['EMCC_WASM_BACKEND']
967967

968+
def test_wasm_backend_builds(self):
969+
# we can build a program using the wasm backend, rebuilding binaryen etc. as needed
970+
restore()
971+
def check():
972+
print(self.do([PYTHON, EMCC, '--clear-cache']))
973+
print(self.do([PYTHON, EMCC, '--clear-ports']))
974+
try:
975+
os.environ['EMCC_WASM_BACKEND'] = '1'
976+
self.check_working([EMCC, 'tests/hello_world.c'], '')
977+
finally:
978+
del os.environ['EMCC_WASM_BACKEND']
979+
print('normally')
980+
check()
981+
print('with no BINARYEN_ROOT')
982+
open(CONFIG_FILE, 'a').write('''
983+
BINARYEN_ROOT = ''
984+
''')
985+
print(open(CONFIG_FILE).read())
986+
check()
987+
968988
def test_binaryen(self):
969989
import tools.ports.binaryen as binaryen
970990
tag_file = Cache.get_path('binaryen_tag_' + binaryen.TAG + '.txt')

tests/zlib/benchmark.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66

77

88
// don't inline, to be friendly to js engine osr
9-
void __attribute__ ((noinline)) doit(char *buffer, int size, int i) {
10-
static char *buffer2 = NULL;
11-
static char *buffer3 = NULL;
9+
void __attribute__ ((noinline)) doit(unsigned char *buffer, int size, int i) {
10+
static unsigned char *buffer2 = NULL;
11+
static unsigned char *buffer3 = NULL;
1212

1313
unsigned long maxCompressedSize = compressBound(size);
1414

15-
if (!buffer2) buffer2 = (char*)malloc(maxCompressedSize);
16-
if (!buffer3) buffer3 = (char*)malloc(size);
15+
if (!buffer2) buffer2 = (unsigned char*)malloc(maxCompressedSize);
16+
if (!buffer3) buffer3 = (unsigned char*)malloc(size);
1717

1818
unsigned long compressedSize = maxCompressedSize;
1919
compress(buffer2, &compressedSize, buffer, size);
20-
if (i == 0) printf("sizes: %d,%d\n", size, compressedSize);
20+
if (i == 0) printf("sizes: %d,%d\n", size, (int)compressedSize);
2121

2222
unsigned long decompressedSize = size;
23-
uncompress(buffer3, &decompressedSize, buffer2, compressedSize);
23+
uncompress(buffer3, &decompressedSize, buffer2, (int)compressedSize);
2424
assert(decompressedSize == size);
25-
if (i == 0) assert(strcmp(buffer, buffer3) == 0);
25+
if (i == 0) assert(strcmp((char*)buffer, (char*)buffer3) == 0);
2626
}
2727

2828
int main(int argc, char **argv) {
@@ -38,7 +38,7 @@ int main(int argc, char **argv) {
3838
default: printf("error: %d\\n", arg); return -1;
3939
}
4040

41-
char *buffer = malloc(size);
41+
unsigned char *buffer = (unsigned char*)malloc(size);
4242

4343
int i = 0;
4444
int run = 0;

tools/shared.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,6 +2297,21 @@ def path_to_system_js_libraries_for_settings(link_settings):
22972297
if 'USE_SDL=2' in link_settings: system_js_libraries += ['library_egl.js', 'library_glut.js', 'library_gl.js']
22982298
return [path_from_root('src', x) for x in system_js_libraries]
22992299

2300+
@staticmethod
2301+
def get_binaryen():
2302+
# fetch the port, so we have binaryen set up. indicate we need binaryen
2303+
# using the settings
2304+
import system_libs
2305+
old = Settings.BINARYEN
2306+
Settings.BINARYEN = 1
2307+
system_libs.get_port('binaryen', Settings)
2308+
Settings.BINARYEN = old
2309+
2310+
@staticmethod
2311+
def get_binaryen_bin():
2312+
Building.get_binaryen()
2313+
return os.path.join(Settings.BINARYEN_ROOT, 'bin')
2314+
23002315
# compatibility with existing emcc, etc. scripts
23012316
Cache = cache.Cache(debug=DEBUG_CACHE)
23022317
chunkify = cache.chunkify

0 commit comments

Comments
 (0)