Repository navigation
Replies: 13 comments 13 replies
|
I think the Integer performance. I don't see any reason that Have you looked at another discussion?
|
You shouldn't need to modify mhs to use the FFI, as long as you specify the header file and pass its directory to mhs (via the
Compiled packages should work out of the box. |
|
trying to build mhs + gmp with emscripten I ran into a couple of problems. the first is essy to fix, but I don't know the internals to fix the second. definition of
@konsumlamm I know FFI works when compiling, I'm wondering about the interactive interpreter. I guess I should try it again. @augustss thanks for the reminder, I had skimmed it but should reread more carefully small data point: Integer at around 1000-2000 bits with gmp is about 100x faster than otherwise with mhs interactive interpreter compiled for arm64 (mobile phone with Termux) |
|
yes ffi in mhs interactive is not working even when compiled package works fine: ERR: FFI unknown myFFIImport |
|
I'll add GMP on a 32 bit platform to the tests and fix the problems. |
|
re:
|
|
I believe GMP should work on 32 bit platforms now. |
|
yes thanks, got an mhs-gmp.js compiled. 10^1000 dropped from 1500ms with mhs.js to 65ms with mhs-gmp.js. will document the process later once I have reproducible instructions. will try customizing for extra FFI next |
|
I tried using MicroHs as a library but adding FFI does not work this way: mcabal install MicroHs mhs -o mhs-hello Main |
|
main = hello >> MicroHs.Main.main works, so I suspect deadcode removal? but in the repl the ffi action seems to be executed twice each time instead of once |
|
I think I'll use the |
emscripten and gmpinstall gmp for emscriptenexport EMPREFIX="${HOME}/opt/emscripten/pthreads-exceptions"
git clone https://code.mathr.co.uk/build-scripts.git
cd build-scripts
./BUILD.sh download "emsdk gmp"
./BUILD.sh emscripten gmppatch MicroHs
diff --git a/Makefile b/Makefile
index 87bf6d4c..e7af92ad 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,11 @@
# Define these 3 lines to use GMP for Integer.
-#MHSGMPCCFLAGS=-DWANT_GMP=1
-#MHSGMP=-ilib/gmp
-#MCABALGMP=-fgmp
+MHSGMPCCFLAGS=-DWANT_GMP=1
+MHSGMP=-ilib/gmp
+MCABALGMP=-fgmp
# AND, for MacOS with homebrew (after brew install gmp):
#MHSGMPCCLIBS= -L/opt/homebrew/lib -lgmp -I/opt/homebrew/include
# OR, for Ubuntu Linux (after apt-get install -y libgmp-dev):
-#MHSGMPCCLIBS=-lgmp
+MHSGMPCCLIBS=-lgmp
#
# installation prefix
PREFIX=/usr/local
@@ -134,6 +134,9 @@ generated/mcabal.c:
mhs.js: src/*/*.hs $(RTS)/*.h $(RTS)/*/*.h targets.conf
bin/mhs $(MHSINC) -temscripten $(MAINMODULE) -o mhs.js
+mhs-gmp.js: src/*/*.hs $(RTS)/*.h $(RTS)/*/*.h targets.conf
+ bin/mhs $(MHSINC) -temscriptengmp $(MAINMODULE) -o mhs-gmp.js
+
# Make sure boottrapping works
bootstrap: bin/mhs-stage2
@echo "*** copy stage2 to bin/mhs"
diff --git a/targets.conf.in b/targets.conf.in
index 4155a71d..a703fc7d 100644
--- a/targets.conf.in
+++ b/targets.conf.in
@@ -16,6 +16,12 @@ ccflags = "-O3 -sEXPORTED_RUNTIME_METHODS=stringToNewUTF8 -sALLOW_MEMORY_GROWTH
cclibs = "-lm"
conf = "unix"
+[emscriptengmp]
+cc = "emcc"
+ccflags = "-I${EMPREFIX}/include -DWANT_GMP=1 -O3 -sEXPORTED_RUNTIME_METHODS=stringToNewUTF8 -sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sNODERAWFS -sSINGLE_FILE -DUSE_SYSTEM_RAW -sEXIT_RUNTIME -Wno-address-of-packed-member"
+cclibs = "-L${EMPREFIX}/lib -lgmp -lm"
+conf = "unix"
+
[tcc]
cc = "tcc"
ccflags = "-D__TCC__=1"build mhs jsmake install
mcabal install
make mhs-gmp.js
make MHSGMP= mhs.js mhs interpreter with custom FFI |
|
So here is what I'm planning to add to
This way you can produce an @claudeha, will this be sufficient for you? You'd so something like |
Uh oh!
There was an error while loading. Please reload this page.
I want to compile mhs interactive interpreter with some libraries of mine to run in the web browser, to make it easier for people to try out.
A while ago I compiled mhs interpreter to run in web browser with tidal-core package as a proof of concept, so at least part of it is possible. That was all pure Haskell without extra FFI.
Ideally I would also have bindings to C libraries like MPFR and GMP for higher precision floating point numerics, I know how to compile and use them with Emscripten-based C and C++ code. The Haskell bindings need hsc2hs.
Alternatively how is the performance of Integer when compiled to web? (browser Javascript has BigInt, don't know about WASM). I am working on a arbitrary precision float library using Integer (which is mostly working, apart from Floating methods). Can mhs compiled with emscriptem use emscripten-compiled GMP?
Some questions:
All reactions