Skip to content

Commit adbd1f8

Browse files
Add fmod functions to wasm_libc_rt (#5375)
* Add fmod to wasm_libc_rt, add f128 functions as well * Better triage for some failing tests * Remove unnecessary math.h import from test_float_builtins.c * Add comment, rename op->func
1 parent fa05ebb commit adbd1f8

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

emscripten.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,8 @@ def wrapped():
19791979
args += ['--global-base=%d' % shared.Settings.GLOBAL_BASE]
19801980
args += ['--initial-memory=%d' % shared.Settings.TOTAL_MEMORY]
19811981
args += ['--allow-memory-growth'] if shared.Settings.ALLOW_MEMORY_GROWTH else []
1982-
args += ['-l', compiler_rt_lib, '-l', libc_rt_lib]
1982+
args += ['-l', libc_rt_lib]
1983+
args += ['-l', compiler_rt_lib]
19831984
return args
19841985

19851986

tests/core/test_float_builtins.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#include <stdio.h>
2-
#include <math.h>
2+
3+
// Prints the float/double/long double versions of the given function
4+
// e.g.: TEST(fmax) prints fmaxf : fmax : fmaxl
5+
#define TEST(func) \
6+
printf("%f : %f : %Lf\n", \
7+
__builtin_##func##f(f1, f2), \
8+
__builtin_##func(d1, d2), \
9+
__builtin_##func##l(l1, l2));
310

411
int main() {
512
float f1 = 0.1234f;
613
float f2 = 0.5678f;
714
double d1 = 1.0101;
815
double d2 = 0.10101;
9-
printf(
10-
"%f\n%f\n%f\n%f\n",
11-
__builtin_fmaxf(f1, f2),
12-
__builtin_fminf(f1, f2),
13-
__builtin_fmax(d1, d2),
14-
__builtin_fmin(d1, d2)
15-
);
16+
long double l1 = 12.0123L;
17+
long double l2 = 21.3201L;
18+
puts("***start***");
19+
TEST(fmax)
20+
TEST(fmin)
21+
TEST(fmod)
22+
puts("***end***");
1623
return 0;
1724
}

tests/core/test_float_builtins.out

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
0.567800
2-
0.123400
3-
1.010100
4-
0.101010
1+
***start***
2+
0.567800 : 1.010100 : 21.320100
3+
0.123400 : 0.101010 : 12.012300
4+
0.123400 : 0.101010 : 12.012300
5+
***end***

tests/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def test_line_endings(self):
198198
def test_literal_negative_zero(self):
199199
self.do_run_in_out_file_test('tests', 'core', 'test_literal_negative_zero')
200200

201-
@no_wasm_backend('todo')
201+
@no_wasm_backend('test uses calls to expected js imports, rather than using llvm intrinsics directly')
202202
def test_llvm_intrinsics(self):
203203
Settings.PRECISE_I64_MATH = 2 # for bswap64
204204

@@ -6068,7 +6068,7 @@ def test_large_exported_response(self):
60686068
assert '_exported_func_from_response_file_1' in open('src.cpp.o.js').read()
60696069

60706070
@sync
6071-
@no_wasm_backend('RuntimeError: function signature mismatch')
6071+
@no_wasm_backend('no jsCall function pointers are created for wasm backend')
60726072
def test_add_function(self):
60736073
Settings.INVOKE_RUN = 0
60746074
Settings.RESERVED_FUNCTION_POINTERS = 1

tools/system_libs.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ def read_symbols(path):
5757

5858
# XXX we should disable EMCC_DEBUG when building libs, just like in the relooper
5959

60+
def musl_internal_includes():
61+
return [
62+
'-I', shared.path_from_root('system', 'lib', 'libc', 'musl', 'src', 'internal'),
63+
'-I', shared.path_from_root('system', 'lib', 'libc', 'musl', 'arch', 'js'),
64+
]
65+
6066
def build_libc(lib_filename, files, lib_opts):
6167
o_s = []
62-
musl_internal_includes = ['-I', shared.path_from_root('system', 'lib', 'libc', 'musl', 'src', 'internal'), '-I', shared.path_from_root('system', 'lib', 'libc', 'musl', 'arch', 'js')]
6368
commands = []
6469
# Hide several musl warnings that produce a lot of spam to unit test build server logs.
6570
# TODO: When updating musl the next time, feel free to recheck which of their warnings might have been fixed, and which ones of these could be cleaned up.
@@ -68,7 +73,7 @@ def build_libc(lib_filename, files, lib_opts):
6873
c_opts.append('-Wno-error=absolute-value')
6974
for src in files:
7075
o = in_temp(os.path.basename(src) + '.o')
71-
commands.append([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', src), '-o', o] + musl_internal_includes + default_opts + c_opts + lib_opts)
76+
commands.append([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', src), '-o', o] + musl_internal_includes() + default_opts + c_opts + lib_opts)
7277
o_s.append(o)
7378
run_commands(commands)
7479
shared.Building.link(o_s, in_temp(lib_filename))
@@ -300,7 +305,10 @@ def create_wasm_rt_lib(libname, files):
300305
o = in_temp(os.path.basename(src) + '.o')
301306
# Use clang directly instead of emcc. Since emcc's intermediate format (produced by -S) is LLVM IR, there's no way to
302307
# get emcc to output wasm .s files, which is what we archive in compiler_rt.
303-
commands.append([shared.CLANG_CC, '--target=wasm32', '-mthread-model', 'single', '-S', shared.path_from_root('system', 'lib', src), '-O2', '-o', o] + shared.EMSDK_OPTS)
308+
commands.append([
309+
shared.CLANG_CC, '--target=wasm32', '-mthread-model', 'single',
310+
'-S', shared.path_from_root('system', 'lib', src),
311+
'-O2', '-o', o] + musl_internal_includes() + shared.EMSDK_OPTS)
304312
o_s.append(o)
305313
run_commands(commands)
306314
lib = in_temp(libname)
@@ -332,7 +340,11 @@ def create_wasm_libc_rt(libname):
332340
# that gets included at the same time as compiler-rt.
333341
math_files = files_in_path(
334342
path_components=['system', 'lib', 'libc', 'musl', 'src', 'math'],
335-
filenames=['fmaxf.c', 'fminf.c', 'fmax.c', 'fmin.c'])
343+
filenames=[
344+
'fmin.c', 'fminf.c', 'fminl.c',
345+
'fmax.c', 'fmaxf.c', 'fmaxl.c',
346+
'fmod.c', 'fmodf.c', 'fmodl.c',
347+
])
336348
string_files = files_in_path(
337349
path_components=['system', 'lib', 'libc', 'musl', 'src', 'string'],
338350
filenames=['memcpy.c', 'memset.c', 'memmove.c'])

0 commit comments

Comments
 (0)