Giter VIP home page Giter VIP logo

metallic's Introduction

Metallic

A try to build a C runtime library for WebAssembly

This name is from Gary Bernhardt "The Birth & Death of JavaScript", where a world of metal web applications is conceived. This library is aimed to be a building block of early metal applications, whose performance is near native.

To achieve this goal, this library is written from scratch, including math functions. The math functions, especially float ones, take advantage of modern architectures to achieve both speed and accuracy. Most of them produce faithfully rounded results (error < 1 ulp) in reasonable time.

Dependencies

Compiler requirements

Currently only clang meet these requirements.

  • WebAssembly backend
  • GCC-compatible builtins
  • ILP32 or LP64 data model

Internal dependency

  • dlmalloc - Doug Lea's malloc with other memory management routines

metallic's People

Contributors

jdh8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

lygstate neotim

metallic's Issues

Approx 1 ulp imprecise in rem_pio2

Example:

sin(1e90 * M_PI);

Expect: 0.7352269418766969
Actual: 0.7352269418766968

I guess it comes from right_ helper. If shifter decrease by 1 result will be correct (or correct just compare to musl/libc?)

Btw I checked this argument in Julia which also used similar approach for argument reduction:
Julia playground

println(sin(1e90 * pi))
> 0.7352269418766968

So I'm wondering which result is correct

WASM Module

Could you publish the wasm binary module?

Status, scope, and goals of project?

I recall attending Gary's talk at strangeloop. it was the best conference presentation I have ever had the pleasure of experiencing and I am even more convinced today that It's an idea so crazy it might just work :-)

In the talk Gary Bernhardt talks about process isolation overhead, virtual memory boundaries, ring 0, sys calls, etc.

I'm curious how close to the talk are you trying to get? Does this project address process isolation overhead in the kernel?

Also I was curious if this overhead is even a thing today and there are new capabilities in modern chips with memory protection keys (MPKs) which can be used to drastically reduce this overhead. https://vahldiek.github.io/project/erim/

lld: No such triple

[email protected] ~/W/T/wasm $ /usr/local/opt/llvm/bin/clang --target=wasm32-unknown-unknown-wasm -pipe -O3 -Wall -flto -fno-builtin-memcpy -I $METALLIC_DIR/include/ $METALLIC_DIR/metallic.bc test.cpp -o test.wasm -nostdlib -v
clang version 7.0.1 (tags/RELEASE_701/final)
Target: wasm32-unknown-unknown-wasm
Thread model: single
InstalledDir: /usr/local/opt/llvm/bin
 "/usr/local/Cellar/llvm/7.0.1/bin/clang-7" -cc1 -triple wasm32-unknown-unknown-wasm -emit-llvm-bc -flto -flto-unit -disable-free -disable-llvm-verifier -discard-value-names -main-file-name metallic.bc -mrelocation-model static -mthread-model single -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu generic -fvisibility hidden -dwarf-column-info -debugger-tuning=gdb -target-linker-version 409.12 -momit-leaf-frame-pointer -v -resource-dir /usr/local/Cellar/llvm/7.0.1/lib/clang/7.0.1 -O3 -Wall -fdebug-compilation-dir /Users/Ingwie/Work/Triage/wasm -ferror-limit 19 -fmessage-length 204 -fno-builtin-memcpy -fobjc-runtime=gnustep -fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/kz/l3s2fpd51ln9_p9ymvqbyshm0000gn/T/metallic-4c5ec7.o -x ir /Users/Ingwie/Work/git/metallic/metallic.bc
clang -cc1 version 7.0.1 based upon LLVM 7.0.1 default target x86_64-apple-darwin18.2.0
 "/usr/local/Cellar/llvm/7.0.1/bin/clang-7" -cc1 -triple wasm32-unknown-unknown-wasm -emit-llvm-bc -flto -flto-unit -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mthread-model single -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu generic -fvisibility hidden -dwarf-column-info -debugger-tuning=gdb -target-linker-version 409.12 -momit-leaf-frame-pointer -v -resource-dir /usr/local/Cellar/llvm/7.0.1/lib/clang/7.0.1 -I /Users/Ingwie/Work/git/metallic/include/ -internal-isystem /include/c++/v1 -internal-isystem /include -O3 -Wall -fdeprecated-macro -fdebug-compilation-dir /Users/Ingwie/Work/Triage/wasm -ferror-limit 19 -fmessage-length 204 -fno-builtin-memcpy -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/kz/l3s2fpd51ln9_p9ymvqbyshm0000gn/T/test-2b894b.o -x c++ test.cpp
clang -cc1 version 7.0.1 based upon LLVM 7.0.1 default target x86_64-apple-darwin18.2.0
ignoring nonexistent directory "/include/c++/v1"
ignoring nonexistent directory "/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /Users/Ingwie/Work/git/metallic/include
 /usr/local/include
 /usr/local/Cellar/llvm/7.0.1/lib/clang/7.0.1/include
End of search list.
 "/usr/local/opt/llvm/bin/lld" -flavor wasm -L/lib /var/folders/kz/l3s2fpd51ln9_p9ymvqbyshm0000gn/T/metallic-4c5ec7.o /var/folders/kz/l3s2fpd51ln9_p9ymvqbyshm0000gn/T/test-2b894b.o -o test.wasm
lld: error: No available targets are compatible with this triple.
clang-7: error: lld command failed with exit code 1 (use -v to see invocation)
[email protected] ~/W/T/wasm $ cat test.cpp
#include <stdio.h>

int main(int argc, char** argv) {
  printf("Hello");
  return 0;
}

I copied crt1.o into my local folder as well. Previously, this had worked just fine... Any idea what I did wrong here?

How do I run the test suite?

I had to patch the Makefile a little bit to get it to use my LLVM 7 setup on OS X - but after that, it built successfuly! Now... I would like to run the test suite to see if this actually works. How can I do that?

Also, what I did was:

[email protected] ~/W/g/metallic $ git diff
diff --git a/Makefile b/Makefile
index 7867f1a..e36045a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,14 @@
 override CPPFLAGS += -MMD -MP -MQ $@
 override CFLAGS += -pipe -O3 -Wall -flto
 
-WACC = clang --target=wasm32-unknown-unknown-wasm
+WACC =  /usr/local/opt/llvm/bin/clang --target=wasm32-unknown-unknown-wasm
 LDFLAGS = -lm
 
 metallic.bc: CC = $(WACC)
 metallic.bc: CPPFLAGS += -I include
 metallic.bc: CFLAGS += -fno-builtin-memcpy
 metallic.bc: $(patsubst %.c, %.o, $(wildcard src/*/*.c src/*/*/*.c))
-       llvm-link -o $@ $^
+       /usr/local/opt/llvm/bin/llvm-link -o $@ $^
 
 check: $(patsubst %.c, %.out, $(wildcard test/wasm/*/*.c test/wasm/*/*/*.c)) \
        $(patsubst %.c, %.exe, $(wildcard test/native/*/*.c test/native/*/*/*.c))

I hope to use this soon! Because a simple hello-world program easily blows up the resulting filesize by quite a margin...

Incomplete floating-point formatted output

Current implementation of %f in src/stdio/vfprintf.c is incomplete, and %e and %g are not yet implemented. However, it took me too much time. I am going to work on other issues for now. Any help is greatly appreciated.

Now printf and friends work with %a and non-floats.

parsefloat_ / strtod can't pass special tests

I added extra tests in test/native/stdlib/strtod.c which unfortunately fail:

assert(parsefloat_(".2470328229206232720882843964341106861825299013071623822127928412503377536351044e-323", (void*)0) == 0x1p-1074);
// FAIL, actual: 0

assert(parsefloat_(".7410984687618698162648531893023320585475897039214871466383785237510132609053131e-323", (void*)0) == 0x1p-1074);
// FAIL, actual: 0

assert(parsefloat_(
"17976931348623158079372897140530341507993413271003782693617377898044 \
49682927647509466490179775872070963302864166928879109465555478519404 \
02630657488671505820681908902000708383676273854845817711531764475730 \
27006985557136695962284291481986083493647529271907416844436551070434 \
2711559699508093042880177904174497792", (void*)0) == INFINITY);
// FAIL, actual: 1.7976931348623157e+308

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.