summaryrefslogtreecommitdiff
path: root/wasm2c/examples/fac/fac.c
Commit message (Collapse)AuthorAgeFilesLines
* wasm2c: harmonize bulk mem ops re: i32/i64 (#2506) + parametrize memchecks ↵HEADmainKeith Winstein2024-12-171-46/+93
| | | | | | | | | | | | | | | | | per-memory (#2507) The PR updates the bulk memory operations (memory.fill, memory.copy, table.fill, etc.) to support 64-bit addresses and counts. Previously these functions only took u32's, even with memory64 enabled. (#2506) This PR also allows "software-bounds-checked" memories and "guard-page-checked" memories to coexist in the same module. It creates two versions of every memory operation: an unrestricted version (that works with any memory) and a _default32 version (for memories with default page size and i32 indexing). (#2507) #2506 and #2507 have been squashed together to avoid a performance regression. This is a stepping stone to supporting custom-page-sizes (which will need to be software-bounds-checked) (#2508).
* wasm2c: Cleanup of handling of WASM_RT_USE_SEGUE macroShravan Narayan2024-10-141-27/+7
|
* wasm2c: Add segue option to make exclusive use of the segment registerShravan Narayan2024-09-181-17/+17
|
* wasm2c: Segue support for CPUs without wrgsbase instructionsShravan Narayan2024-09-061-24/+52
|
* wasm2c: Segue optimization for modules with a single unshared memory (#2395)Shravan Narayan2024-06-261-13/+58
|
* Update wasm2c examples (#2358)Keith Winstein2023-12-151-52/+45
|
* wasm2c: Cleanup/separate code for heap and stack signal handlersShravan Narayan2023-12-141-1/+1
|
* wasm2c: implement the tail-call proposal (#2272)Keith Winstein2023-10-241-4/+28
|
* [wasm2c] Use wasm_rt_memcpy everywhere in generated code (#2292)Sam Clegg2023-09-091-15/+15
|
* Share reading/validation code between elem exprs & other const exprs (#2288)Keith Winstein2023-09-061-5/+18
| | | | | | This continues the work from #1783 and reduces special handling of elem exprs, by treating them the same as other const expressions (init expressions).
* wasm2c: add link to clang bug on mips force read constraintShravan Narayan2023-07-301-0/+1
|
* wasm2c: ensure force read constraints compile for clang on mipsShravan Narayan2023-07-301-20/+28
|
* wasm2c: include simd128.h and wasm-rt-exceptions.h where necessary (#2236)Keith Winstein2023-05-121-121/+0
| | | Co-authored-by: Shravan Narayan <shravanrn@gmail.com>
* wasm2c: Enable exceptions and simd according to command line flagsShravan Narayan2023-05-021-1/+5
|
* wasm2c: Separate the macros for allocation and bounds checks strategiesShravan Narayan2023-04-121-1/+1
|
* wasm2c: multiple .c outputs (#2146)Yuhan Deng2023-04-051-21/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * wasm2c: multiple .c outputs This enables wasm2c to have multiple .c outputs, which allows parallel compilation of the wasm2c outputs. This is useful when the input WASM module is big. wasm2c takes the number of .c outputs as an argument to `--num-outputs` (defaulting to 1). If the number is equal to 1, the .c output does not change except for two new macro declarations and the ordering of declarations and definitions. If greater than 1, wasm2c outputs change in the following ways: 1) wasm2c outputs a [module-name]-impl.h that includes any module-wide declarations, including: * content of `WriteSourceTop()` * function type declarations * tag types * tag declarations * function declarations * data segments and elem segments declarations Any static declaration become extern in this header. 2) wasm2c outputs [module-name]_i.c for i = [0, ..., number of .c outputs - 1). Any module-wide material is written to [module-name]_0.c, including: * function types, tags, data segments, elem segments * imports and exports * module initialization, instantiation and free 3) For each function implementation, wasm2c assigns it to one output .c file by sorting the function names and partitioning into roughly equal buckets. Alternately, the caller can supply its own assignment function (helpful if it wants the assignments to be more stable in the face of function insertion or deletion).
* c-writer.cc: Add local symbol prefix. (#2171)Yuhan Deng2023-03-151-16/+16
| | | | | | Add kLocalSymbolPrefix which is used for names of params, locals and stack vars. This allows c-writer to not assign global_sym_map_ to local_sym_map_ for writing each individual function, since local names can't duplicate global names.
* wasm2c: prettify/change name mangling (#2142)Keith Winstein2023-02-231-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * wasm2c: prettify/change name-mangling This refactors the wasm2c name-mangling in two big ways: 1) Removing the `Z_` prefix and trying to make the names somewhat ergonomic/pretty. Previously the `factorial` export from a `fac` module looked like this: ``` u32 Z_facZ_factorial(Z_fac_instance_t*, u32); ``` After this commit, it looks like this: ``` u32 w2c_fac_factorial(w2c_fac*, u32); ``` Symbols defined by wasm2c itself (including instantiate, free, get_func_type and the imported memory limits) are now prefixed with `wasm2c_` to avoid conflicting with names defined by the module. 2) Using globally unique (module-prefixed) names for functions, types, segments, and tags, even though they are currently static (internal-linkage) symbols in the .c output. This is preparation for a future "multiple .c output" option where these symbols will need to have external linkage.
* wasm2c: add SIMD support (#2119)Willy R. Vasquez2023-01-291-0/+121
| | | This change incorporates [simd-everywhere](https://github.com/simd-everywhere/simde) into the wasm2c output, which maps wasm SIMD C intrinsics to any supported target architecture.
* Make wasm2c output UBSAN-clean (and run w2c CI w/ UBSAN) (#2080)Keith Winstein2023-01-281-2/+8
| | | | | | We had been running the GitHub UBSAN wasm2c tests with -fsanitize=undefined but without -fno-sanitize-recover, meaning some of the spec tests were printing UBSAN error messages but still returning 0, so we weren't seeing the test failures.
* wasm2c: serialize types at wasm2c-time (#2120)Keith Winstein2023-01-251-23/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | This makes wasm2c serialize each function type, rather than registering function types at module-initialization time. The serialized function type is the SHA-256 of the mangled param and result types (with a space between params and results). At runtime in call_indirect, a known (immediate) function type is compared against the function type stored in a funcref structure. For call_indirects to functions local to the module, or for any call_indirect when the toolchain merges string constants across compilation units (generally, GCC and clang), this can be done by comparing the pointers to each function type. Otherwise, the actual 32-byte values are compared. The function type IDs can be looked up at runtime with `Z_[modname]_get_func_type`, which matches the API from `wasm_rt_register_func_type`. A new `callback` example demos this. wasm2c does the SHA-256 either by linking against libcrypto or, if not available or if requested via `cmake -DUSE_INTERNAL_SHA256=ON`, by using a vendored (header-only) PicoSHA2. There is no runtime dependency on SHA-256 in the wasm2c runtime or generated modules. This eliminates the last of the per-module state, so this commit also removes the [modname]_init_module() function and the s_module_initialized bool.
* Update wasm2c examples to reflect new wasm_rt_allocate_memory() parameter ↵Keith Winstein2023-01-221-0/+11
| | | | (#2133)
* Update wasm2c fac.c example (#2067)Keith Winstein2022-11-151-4/+2
|
* Update testsuite (#2054)Sam Clegg2022-11-131-24/+25
| | | | | | | | | | | | | | | As well as the testsuite update there are two notable changes that come with it here. These can both be split out an landed first if it makes sense. 1. wasm2c now supports element sections containing externref. Currently only the null reference is supported. 2. element segments no longer use funcref as the default element type but instead, unless explicitly included in the binary, the element type defaults to the type of the table in which the segment is active. Fixes: #1612 #2022
* wasm2c: implement the reference-types proposal (#1887)Keith Winstein2022-10-031-43/+81
| | | | Restores current versions of all non-SIMD tests in the core testsuite and multi-memory and exception-handling proposals.
* wasm2c cleanup: eliminate unused initialization functions in output (#1999)Keith Winstein2022-09-211-24/+0
| | | | also: - cleanup handling of newlines - "init_memory"/"init_table" -> "init_memories"/"init_tables"
* wasm2c: implement the bulk memory operations proposal (#1877)Keith Winstein2022-09-211-9/+100
| | | Co-authored-by: Yuhan Deng <yhdeng@stanford.edu>
* wasm2c: support for module instancing (#1814)Yuhan Deng2022-09-161-19/+24
| | | Co-authored-by: Angela Montemayor <amontema@cs.stanford.edu>
* Simplify export declarations in wasm2c output. NFC (#1966)Sam Clegg2022-08-231-1/+2
| | | | | | | | | | | | | | | | | | | | | | This change avoids some confusing/redundant bracketing and makes the output a little easier to easy and more like regular C usage. Old: ``` wasm_rt_memory_t (*Z_test_hello_worldZ_memory); ... Z_test_hello_worldZ_memory = (&w2c_memory); Z_test_hello_worldZ__start = (&w2c__start) ``` New: ``` wasm_rt_memory_t* Z_test_hello_worldZ_memory; ... Z_test_hello_worldZ_memory = &w2c_memory; Z_test_hello_worldZ__start = &w2c__start; ```
* wasm2c: implement the exception-handling proposal (#1930)Keith Winstein2022-07-141-1/+10
| | | | | (The imports.txt and exports.txt tests require multi-table and are disabled until reference types is supported.)
* wasm2c: run tests with -O2 on non-Windows (#1939)Keith Winstein2022-07-111-0/+130
| | | | | | | | | Enable optimization when compiling the wasm2c output on non-Windows platforms (effectively GCC and clang). This required: - Preventing load instructions from being optimized away if their value is unused (using inline assembly with an input operand and empty code). This is necessary to force an OOB trap on platforms that use mprotect and the signal handler to detect OOB. - Disabling tail-call optimization in the compiler, to make sure that infinite recursion traps. (This required bumping the version of macOS in GitHub Actions to get a new-enough AppleClang. We should revert this back to 'macos-latest' as soon as that becomes the default.) - Using NaN-quieting versions of a bunch of FP ops that were previously only used on Windows, and adding floor/ceil and promotion/demotion. - Using the '-frounding-math' and '-fsignaling-nans' compiler flags to tell GCC and clang not to fold certain FP ops (e.g. subtracting zero, multiplying by 1). Fixes #1925.
* Format wasm2c templated code (#1942)Keith Winstein2022-07-081-90/+115
|
* wasm2c: export free() function to free module state (#1901)Keith Winstein2022-04-141-0/+3
| | | | | | This will be required by module instancing and bulk memory ops to avoid a memory leak detected by asan. Update README.md to reflect changes, including the `fac` walkthrough.
* wasm2c: Always use a module prefix and set one by default (#1897)Sam Clegg2022-04-141-3/+3
| | | | | | | | | | | | The module prefix is no longer optional and is now set by default to the name of the module as given in the name section, or taken from the name of the input file. A new `-n/--module-name` command line flag can also be used to override. The prefix used by the generated code is now fixed at wasm2c time which makes the output code easier to read and also avoid the symbol pasting in the C pre-processor which makes the source hard to understand. For example, it makes symbols hard to `grep` for.
* Fix spelling typo in wasm2c output. NFC (#1900)Sam Clegg2022-04-141-1/+1
|
* Remove signature mangling from wasm2c output (#1896)Sam Clegg2022-04-141-2/+2
| | | | | | | | | | | This effectively means that we no longer support imports that are overloaded by signature only. This is not something that we need to support in order to support the core wasm spec. This feature is available in the JS embedding but there is no good reason (AFAICT) to support it in wasm2c, and this simplifies the generated code. Fixes #1858
* wasm2c: use signal handler to detect stack exhaustion (#1875)Keith Winstein2022-04-041-16/+23
| | | | | | On MacOS, merge OOB and exhaustion traps. (Linux distinguishes these as SEGV_ACCERR vs. SEGV_MAPERR in the si_code, but MacOS seems to deliver a SEGV_ACCERR for both.) Add wasm_rt_init() and wasm_rt_free() functions to wasm-rt.h that the embedder must call to set up and clean up the runtime state. (If the embedder doesn't call these, OOB and exhaustion will result in an uncaught segfault.)
* Add windows implementation of wasm2c runtime (#1843)Sam Clegg2022-03-091-26/+101
| | | | | | | All tests are now passing with cl.exe under x64. With x86 there are some test failure that I believe relate the use of the x87 registers to pass floating point numbers. I suggest we look into fixing those as a followup. Split out from #1833
* Update wasm2c example output. NFC (#1851)Sam Clegg2022-03-071-73/+137
| | | | | Do we really want to have this output checked in like this? If so, we should probably automate its update ot at least add a check to avoid it getting out-of-date.
* [wasm2c] Add rot13 example (#1384)Ben Smith2020-04-141-2/+1
| | | | | | | | | | This example demonstrates how to use imported functions. The `rot13` program takes each command line argument, and rot13-encodes it. The exported `rot13` function has no arguments, and instead calls back into the program (via `fill_buf`) with a buffer to fill in. When the function finishes it calls `buf_done`. (rot13.wat is the same as in src/test-interp.cc.)
* More work on the wasm2c documentation (#835)Ben Smith2018-05-221-0/+203
* Described how to use it, and put it near the top of the doc * Added the sources and generated files