Skip to content

Instantly share code, notes, and snippets.

View carlopi's full-sized avatar

Carlo Piovesan carlopi

View GitHub Profile
@carlopi
carlopi / _README.txt
Last active April 14, 2021 07:58
binaryheap.cpp compiled with Cheerp
wat2wasm cheerp_wasm.wat > cheerp_wasm.wasm
/path/to/d8 --module --harmony-top-level-await bench_cheerp.js
@carlopi
carlopi / Makefile
Created September 13, 2021 08:35
Wrapping Cheerp ES6 modules
all:
/opt/cheerp/bin/clang++ add.cpp -cheerp-make-module=es6 -o add.js -O3
@carlopi
carlopi / earcut_cheerp.js
Created December 22, 2021 09:52
Experiment with compiling earcut.hpp with Cheerp
"use strict";/*Compiled using Cheerp (R) by Leaning Technologies Ltd*/var a4=Math.imul;var a5=Math.fround;var oSlot=0;var nullArray=[null];var nullObj={d:nullArray,o:0};function bt(p){var b=null,f='function';if(typeof fetch===f)b=fetch(p).then(r=>r.arrayBuffer());else if(typeof require===f){p=require('path').join(__dirname, p);b=new Promise((y,n)=>{require('fs').readFile(p,(e,d)=>{if(e)n(e);else y(d);});});}else b=new Promise((y,n)=>{y(read(p,'binary'));});return b;}function a1(w,v){var u=null,k=null,l=0,j=0,g=0,h=0,t=-0.,i=0,s=0,o=0,p=null,q=0,m=null,n=0;u=ax();k=-64+u|0;ag(k);aN((w.length)>>>1);j=w.length;if((j|0)>0){h=0;g=0;while(1){t=+w[g];f[(h<<4)+(c[1049616>>2]|0)>>3]=t;t=+w[g+1|0];f[(h<<4)+8+(c[1049616>>2]|0)>>3]=t;g=g+2|0;if((g|0)<(j|0)){h=h+1|0;continue;}break;}}j=48+k|0;aL(j);if(v!==null){g=v.length;if((g|0)!==0){h=40+k|0;s=0;i=0;while(1){o=v[i];c[h>>2]=s;c[4+h>>2]=o;ao(j,h);i=i+1|0;if((i|0)!==(g|0)){s=o;continue;}break;}}else{o=0;}}else{o=0;}g=32+k|0;h=c[1049620>>2]|0;i=c[1049616>>2]|0;c[g>>2]=o;c[
@carlopi
carlopi / signBit.js
Last active February 2, 2022 08:18
signBit JavaScript implementation
function signBit(La){
var Lgh_u$pi=null,tmp1=0;
Lgh_u$pi={d:new DataView(new ArrayBuffer(8)),o:0};
Lgh_u$pi.d.setFloat64(Lgh_u$pi.o,La,true);
tmp1=Lgh_u$pi.d.getInt32(1*4+Lgh_u$pi.o,true)|0;
return ((tmp1|0)<0?1:0)|0;
}
//or way better perfromance wise, having the DataView being globally available (=created only once)
var Lgh_u$pi=new DataView(new ArrayBuffer(8));
@carlopi
carlopi / atobtoa.js
Created March 5, 2022 07:16
atob / btoa Cheerp optimized implementation
"use strict";/*Compiled using Cheerp (R) by Leaning Technologies Ltd*/var H=Math.imul;var I=Math.fround;var oSlot=0;var nullArray=[null];var nullObj={d:nullArray,o:0};function y(){r=new TextDecoder();}function E(G){var h=0,g=null,f=0,e=0,b=0,a=0,d=0,c=null,j=0;h=G.length;if(h>>>0<100){g=w();if((h|0)===0)return g;f=0;while(1){e=G.charCodeAt(f);if(e>>>0>255)return null;b=f+1|0;a=e<<4&48;if(h>>>0>b>>>0){b=G.charCodeAt(b);if(b>>>0>255)return null;a|=(b>>>4);b=b<<2&60;}else{b=64;}d=f+2|0;if(h>>>0>d>>>0){d=G.charCodeAt(d);if(d>>>0>255)return null;b|=(d>>>6);d&=63;}else{d=64;}c=String.fromCharCode(o[e>>>2]<<24>>24);g=g.concat(c);if((a|0)===64){a=61;}else{a=o[a]|0;}c=String.fromCharCode(a<<24>>24);g=g.concat(c);if((b|0)===64){b=61;}else{b=o[b]|0;}c=String.fromCharCode(b<<24>>24);g=g.concat(c);if((d|0)===64){e=61;}else{e=o[d]|0;}c=String.fromCharCode(e<<24>>24);g=g.concat(c);f=f+3|0;if(f>>>0<h>>>0)continue;break;}return g;}else{g=new Uint8Array((+(((h<<2)+20>>>0)/3>>>0)));e=0;f=0;while(1){b=G.charCodeAt(f);if(b>>>0>25
@carlopi
carlopi / googlebot.pretty.js
Last active May 3, 2022 11:58
googlebot robotstxt analyzer, from https://github.com/google/robotstxt
"use strict";
/*Compiled using Cheerp (R) by Leaning Technologies Ltd*/
var __imul=Math.imul;
var __fround=Math.fround;
var oSlot=0;var nullArray=[null];var nullObj={d:nullArray,o:0};
function __ZN9googlebot13RobotsMatcherD2Ev(Lthis){
var tmp0=null;
Lthis.a0=__ZTVN9googlebot13RobotsMatcherE;
tmp0=Lthis.a6;
if(tmp0!==null)tmp0.a0.a2(tmp0);
@carlopi
carlopi / README.md
Last active May 9, 2022 12:35
Random bits Cheerp

Compile from scratch /opt/cheerp/bin/clang++ randomBits.c -o randomBits.js -cheerp-pretty-code -O3 -target cheerp-wasm

wat -> wasm wat2wasm randomBits.wat -o randomBits.wasm

serve http-serve

Inspired by:

@carlopi
carlopi / Cheerp-WebPack
Last active May 9, 2022 14:54
WebPack -Cheerp example [to be reviewed]
Take this GIST: https://gist.github.com/carlopi/e06214ac66594d41cdfcbff7581ddd79, compile the files with this command line:
/opt/cheerp/bin/clang++ randomBits.c -o randomBits.js -O3 -cheerp-make-module=es6 -cheerp-pretty-code
Create a folder with the following structure:
webpack.config.js
package.json
src
|-- instatiation.js
|-- randomBits.js