Skip to content

Commit 2f1a6c4

Browse files
authored
Add SIMD prerequisites (AssemblyScript#469)
1 parent 7ce3296 commit 2f1a6c4

File tree

201 files changed

+1485
-1432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+1485
-1432
lines changed

cli/asc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
" sign-extension Enables sign-extension operations",
163163
" mutable-global Enables mutable global imports and exports",
164164
" bulk-memory Enables bulk memory operations",
165+
" simd Enables SIMD types and operations.",
165166
""
166167
],
167168
"type": "s"

src/builtins.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,7 +3513,7 @@ export function compileIterateRoots(compiler: Compiler): void {
35133513
? module.createI64(i64_low(value), i64_high(value))
35143514
: module.createI32(i64_low(value))
35153515
],
3516-
"iv"
3516+
"i_"
35173517
)
35183518
);
35193519
} else {
@@ -3526,7 +3526,7 @@ export function compileIterateRoots(compiler: Compiler): void {
35263526
compiler.options.nativeSizeType
35273527
)
35283528
],
3529-
"iv"
3529+
"i_"
35303530
)
35313531
);
35323532
}
@@ -3610,7 +3610,7 @@ export function ensureGCHook(
36103610
[
36113611
module.createGetLocal(0, nativeSizeType)
36123612
],
3613-
nativeSizeType == NativeType.I64 ? "Iv" : "iv"
3613+
nativeSizeType == NativeType.I64 ? "I_" : "i_"
36143614
)
36153615
);
36163616

src/compiler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ export const enum Feature {
235235
/** Mutable global imports and exports. */
236236
MUTABLE_GLOBAL = 1 << 1, // see: https://github.com/WebAssembly/mutable-global
237237
/** Bulk memory operations. */
238-
BULK_MEMORY = 1 << 2 // see: https://github.com/WebAssembly/bulk-memory-operations
238+
BULK_MEMORY = 1 << 2, // see: https://github.com/WebAssembly/bulk-memory-operations
239+
/** SIMD types and operations. */
240+
SIMD = 1 << 3 // see: https://github.com/WebAssembly/simd
239241
}
240242

241243
/** Indicates the desired kind of a conversion. */

src/decompiler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ function nativeTypeToType(type: NativeType): string {
880880
case NativeType.I64: return "i64";
881881
case NativeType.F32: return "f32";
882882
case NativeType.F64: return "f64";
883+
case NativeType.V128: return "v128";
883884
case NativeType.Unreachable: throw new Error("unreachable type");
884885
case NativeType.Auto: throw new Error("auto type");
885886
default: throw new Error("unexpected type");

src/definitions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ export class TSDBuilder extends ExportsWalker {
480480
case TypeKind.BOOL: return "bool";
481481
case TypeKind.F32: return "f32";
482482
case TypeKind.F64: return "f64";
483+
case TypeKind.V128: return "v128";
483484
case TypeKind.VOID: return "void";
484485
default: {
485486
assert(false);

src/glue/binaryen.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ declare function _BinaryenTypeInt32(): BinaryenType;
1818
declare function _BinaryenTypeInt64(): BinaryenType;
1919
declare function _BinaryenTypeFloat32(): BinaryenType;
2020
declare function _BinaryenTypeFloat64(): BinaryenType;
21+
declare function _BinaryenTypeVec128(): BinaryenType;
2122
declare function _BinaryenTypeUnreachable(): BinaryenType;
2223
declare function _BinaryenTypeAuto(): BinaryenType;
2324

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ export const FEATURE_SIGN_EXTENSION = Feature.SIGN_EXTENSION;
130130
export const FEATURE_MUTABLE_GLOBAL = Feature.MUTABLE_GLOBAL;
131131
/** Bulk memory operations. */
132132
export const FEATURE_BULK_MEMORY = Feature.BULK_MEMORY;
133+
/** SIMD types and operations. */
134+
export const FEATURE_SIMD = Feature.SIMD;
133135

134136
/** Enables a specific feature. */
135137
export function enableFeature(options: Options, feature: Feature): void {

src/module.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ export type RelooperRef = usize;
1818
export type RelooperBlockRef = usize;
1919
export type Index = u32;
2020

21-
export const enum NativeType {
22-
None = 0, // _BinaryenTypeNone(),
23-
I32 = 1, // _BinaryenTypeInt32(),
24-
I64 = 2, // _BinaryenTypeInt64(),
25-
F32 = 3, // _BinaryenTypeFloat32(),
26-
F64 = 4, // _BinaryenTypeFloat64(),
27-
Unreachable = 5, // _BinaryenTypeUnreachable(),
28-
Auto = -1 // _BinaryenTypeAuto()
21+
export enum NativeType {
22+
None = _BinaryenTypeNone(),
23+
I32 = _BinaryenTypeInt32(),
24+
I64 = _BinaryenTypeInt64(),
25+
F32 = _BinaryenTypeFloat32(),
26+
F64 = _BinaryenTypeFloat64(),
27+
V128 = _BinaryenTypeVec128(),
28+
Unreachable = _BinaryenTypeUnreachable(),
29+
Auto = _BinaryenTypeAuto()
2930
}
3031

3132
export enum ExpressionId {
@@ -442,6 +443,15 @@ export class Module {
442443
return _BinaryenConst(this.ref, out);
443444
}
444445

446+
createV128(bytes: Uint8Array): ExpressionRef {
447+
assert(bytes.length == 16);
448+
var out = this.lit;
449+
// FIXME: does this work or do we need to malloc?
450+
for (let i = 0; i < 16; ++i) store<u8>(out + i, bytes[i]);
451+
_BinaryenLiteralVec128(out, out);
452+
return _BinaryenConst(this.ref, out);
453+
}
454+
445455
// expressions
446456

447457
createUnary(

src/program.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ export class Program extends DiagnosticEmitter {
415415
["number", Type.f64],
416416
["boolean", Type.bool]
417417
]);
418+
if (options.hasFeature(Feature.SIMD)) this.typesLookup.set("v128", Type.v128);
418419

419420
// add compiler hints
420421
this.setConstantInteger("ASC_TARGET", Type.i32,
@@ -433,6 +434,10 @@ export class Program extends DiagnosticEmitter {
433434
i64_new(options.hasFeature(Feature.MUTABLE_GLOBAL) ? 1 : 0, 0));
434435
this.setConstantInteger("ASC_FEATURE_SIGN_EXTENSION", Type.bool,
435436
i64_new(options.hasFeature(Feature.SIGN_EXTENSION) ? 1 : 0, 0));
437+
this.setConstantInteger("ASC_FEATURE_BULK_MEMORY", Type.bool,
438+
i64_new(options.hasFeature(Feature.BULK_MEMORY) ? 1 : 0, 0));
439+
this.setConstantInteger("ASC_FEATURE_SIMD", Type.bool,
440+
i64_new(options.hasFeature(Feature.SIMD) ? 1 : 0, 0));
436441

437442
// remember deferred elements
438443
var queuedImports = new Array<QueuedImport>();
@@ -659,6 +664,7 @@ export class Program extends DiagnosticEmitter {
659664
this.registerBasicClass(TypeKind.BOOL, "Bool");
660665
this.registerBasicClass(TypeKind.F32, "F32");
661666
this.registerBasicClass(TypeKind.F64, "F64");
667+
if (options.hasFeature(Feature.SIMD)) this.registerBasicClass(TypeKind.V128, "V128");
662668

663669
// register 'start'
664670
{

src/resolver.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export class Resolver extends DiagnosticEmitter {
234234
case TypeKind.U64: return Type.u64;
235235
case TypeKind.F32: return Type.f32;
236236
case TypeKind.F64: return Type.f64;
237+
case TypeKind.V128: return Type.v128;
237238
case TypeKind.VOID: return Type.void;
238239
default: assert(false);
239240
}

0 commit comments

Comments
 (0)