mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
Is it a strawberry, see boyanio/wasm-wheel#2
This commit is contained in:
15
examples/i64-polyfill/README.md
Normal file
15
examples/i64-polyfill/README.md
Normal file
@ -0,0 +1,15 @@
|
||||
i64 polyfill
|
||||
============
|
||||
|
||||
An AssemblyScript example.
|
||||
|
||||
Instructions
|
||||
------------
|
||||
|
||||
To build `assembly/i64.ts` to `i64.wasm`, run:
|
||||
|
||||
```
|
||||
$> npm run build
|
||||
```
|
||||
|
||||
Afterwards, `require` the node module as usual (entry point is `index.js`).
|
1057
examples/i64-polyfill/assembly/i64.optimized.wast
Normal file
1057
examples/i64-polyfill/assembly/i64.optimized.wast
Normal file
File diff suppressed because it is too large
Load Diff
189
examples/i64-polyfill/assembly/i64.ts
Normal file
189
examples/i64-polyfill/assembly/i64.ts
Normal file
@ -0,0 +1,189 @@
|
||||
let lo: u32;
|
||||
let hi: u32;
|
||||
|
||||
export function getLo(): u32 {
|
||||
return lo;
|
||||
}
|
||||
|
||||
export function getHi(): u32 {
|
||||
return hi;
|
||||
}
|
||||
|
||||
function clz_(loLeft: u32, hiLeft: u32): void {
|
||||
const ret: u64 = clz<u64>(<u64>loLeft | <u64>hiLeft << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
export { clz_ as clz };
|
||||
|
||||
function ctz_(loLeft: u32, hiLeft: u32): void {
|
||||
const ret: u64 = ctz<u64>(<u64>loLeft | <u64>hiLeft << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
export { ctz_ as ctz };
|
||||
|
||||
function popcnt_(loLeft: u32, hiLeft: u32): void {
|
||||
const ret: u64 = popcnt<u64>(<u64>loLeft | <u64>hiLeft << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
export { popcnt_ as popcnt };
|
||||
|
||||
export function eqz(loLeft: u32, hiLeft: u32): void {
|
||||
const ret: bool = !(<u64>loLeft | <u64>hiLeft << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function add(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) + (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >> 32);
|
||||
}
|
||||
|
||||
export function sub(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) - (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >> 32);
|
||||
}
|
||||
|
||||
export function mul(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) * (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >> 32);
|
||||
}
|
||||
|
||||
export function div_s(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = <u64>(<i64>(<u64>loLeft | <u64>hiLeft << 32) / <i64>(<u64>loRight | <u64>hiRight << 32));
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >> 32);
|
||||
}
|
||||
|
||||
export function div_u(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) / (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >> 32);
|
||||
}
|
||||
|
||||
export function rem_s(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = <u64>(<i64>(<u64>loLeft | <u64>hiLeft << 32) % <i64>(<u64>loRight | <u64>hiRight << 32));
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >> 32);
|
||||
}
|
||||
|
||||
export function rem_u(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) % (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
|
||||
export function and(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) & (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
|
||||
export function or(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) | (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
|
||||
export function xor(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) ^ (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
|
||||
export function shl(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) << (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
|
||||
export function shr_s(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = <u64>(<i64>(<u64>loLeft | <u64>hiLeft << 32) >> <i64>(<u64>loRight | <u64>hiRight << 32));
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
|
||||
export function shr_u(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = (<u64>loLeft | <u64>hiLeft << 32) >> (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
|
||||
function rotl_(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = rotl<u64>(<u64>loLeft | <u64>hiLeft << 32, <u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
export { rotl_ as rotl };
|
||||
|
||||
function rotr_(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: u64 = rotr<u64>(<u64>loLeft | <u64>hiLeft << 32, <u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = <u32>(ret >>> 32);
|
||||
}
|
||||
export { rotr_ as rotr };
|
||||
|
||||
export function eq(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = (<u64>loLeft | <u64>hiLeft << 32) == (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function ne(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = (<u64>loLeft | <u64>hiLeft << 32) != (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function lt_s(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = <i64>(<u64>loLeft | <u64>hiLeft << 32) < <i64>(<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function lt_u(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = (<u64>loLeft | <u64>hiLeft << 32) < (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function le_s(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = <i64>(<u64>loLeft | <u64>hiLeft << 32) <= <i64>(<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function le_u(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = (<u64>loLeft | <u64>hiLeft << 32) <= (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function gt_s(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = <i64>(<u64>loLeft | <u64>hiLeft << 32) > <i64>(<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function gt_u(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = (<u64>loLeft | <u64>hiLeft << 32) > (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function ge_s(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = <i64>(<u64>loLeft | <u64>hiLeft << 32) >= <i64>(<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
||||
|
||||
export function ge_u(loLeft: u32, hiLeft: u32, loRight: u32, hiRight: u32): void {
|
||||
const ret: bool = (<u64>loLeft | <u64>hiLeft << 32) >= (<u64>loRight | <u64>hiRight << 32);
|
||||
lo = <u32>ret;
|
||||
hi = 0;
|
||||
}
|
1191
examples/i64-polyfill/assembly/i64.wast
Normal file
1191
examples/i64-polyfill/assembly/i64.wast
Normal file
File diff suppressed because it is too large
Load Diff
6
examples/i64-polyfill/assembly/tsconfig.json
Normal file
6
examples/i64-polyfill/assembly/tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../../../std/assembly.json",
|
||||
"include": [
|
||||
"./**/*.ts"
|
||||
]
|
||||
}
|
8
examples/i64-polyfill/index.js
Normal file
8
examples/i64-polyfill/index.js
Normal file
@ -0,0 +1,8 @@
|
||||
var fs = require("fs");
|
||||
|
||||
// Instantiate the module
|
||||
var mod = new WebAssembly.Module(fs.readFileSync(__dirname + "/i64.wasm"));
|
||||
var ins = new WebAssembly.Instance(mod, { /* no imports */ });
|
||||
|
||||
// Export its exports
|
||||
module.exports = ins.exports;
|
8
examples/i64-polyfill/package.json
Normal file
8
examples/i64-polyfill/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@assemblyscript/i64-polyfill-example",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "asc assembly/i64.ts -t assembly/i64.wast -c && asc assembly/i64.ts -b i64.wasm -t assembly/i64.optimized.wast -O -c"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user