diff --git a/emscripten.py b/emscripten.py index 5932f295852ad..a26cecf203bcb 100755 --- a/emscripten.py +++ b/emscripten.py @@ -483,15 +483,24 @@ def make_emulated_param(i): 'select', 'swizzle', 'shuffle', 'load', 'store', 'load1', 'store1', 'load2', 'store2', 'load3', 'store3'] simdintboolfuncs = ['and', 'xor', 'or', 'not'] + if metadata['simdUint8x16']: + simdinttypes += ['Uint8x16'] + simdintfloatfuncs += ['fromUint8x16Bits'] if metadata['simdInt8x16']: - simdinttypes += ['Int8x16', 'Uint8x16'] - simdintfloatfuncs += ['fromInt8x16Bits', 'fromUint8x16Bits'] + simdinttypes += ['Int8x16'] + simdintfloatfuncs += ['fromInt8x16Bits'] + if metadata['simdUint16x8']: + simdinttypes += ['Uint16x8'] + simdintfloatfuncs += ['fromUint16x8Bits'] if metadata['simdInt16x8']: - simdinttypes += ['Int16x8', 'Uint16x8'] - simdintfloatfuncs += ['fromInt16x8Bits', 'fromUint16x8Bits'] + simdinttypes += ['Int16x8'] + simdintfloatfuncs += ['fromInt16x8Bits'] + if metadata['simdUint32x4']: + simdinttypes += ['Uint32x4'] + simdintfloatfuncs += ['fromUint32x4', 'fromUint32x4Bits'] if metadata['simdInt32x4']: - simdinttypes += ['Int32x4', 'Uint32x4'] - simdintfloatfuncs += ['fromInt32x4', 'fromInt32x4Bits', 'fromUint32x4Bits'] + simdinttypes += ['Int32x4'] + simdintfloatfuncs += ['fromInt32x4', 'fromInt32x4Bits'] if metadata['simdFloat32x4']: simdfloattypes += ['Float32x4'] simdintfloatfuncs += ['fromFloat32x4', 'fromFloat32x4Bits'] @@ -508,8 +517,8 @@ def make_emulated_param(i): simdbooltypes += ['Bool64x2'] simdfloatfuncs = simdfuncs + simdintfloatfuncs + ['div', 'min', 'max', 'minNum', 'maxNum', 'sqrt', - 'abs', 'reciprocalApproximation', 'reciprocalSqrtApproximation']; - simdintfuncs = simdfuncs + simdintfloatfuncs + simdintboolfuncs + ['shiftLeftByScalar', 'shiftRightByScalar']; + 'abs', 'reciprocalApproximation', 'reciprocalSqrtApproximation'] + simdintfuncs = simdfuncs + simdintfloatfuncs + simdintboolfuncs + ['shiftLeftByScalar', 'shiftRightByScalar', 'addSaturate', 'subSaturate'] simdboolfuncs = simdfuncs + simdintboolfuncs + ['anyTrue', 'allTrue'] simdtypes = simdfloattypes + simdinttypes + simdbooltypes @@ -735,7 +744,10 @@ def string_contains_any(s, str_list): if sub in s: return True return False - nonexisting_simd_symbols = ['Int8x16_fromInt8x16', 'Int16x8_fromInt16x8', 'Int32x4_fromInt32x4', 'Float32x4_fromFloat32x4', 'Float64x2_fromFloat64x2'] + nonexisting_simd_symbols = ['Int8x16_fromInt8x16', 'Uint8x16_fromUint8x16', 'Int16x8_fromInt16x8', 'Uint16x8_fromUint16x8', 'Int32x4_fromInt32x4', 'Uint32x4_fromUint32x4', 'Float32x4_fromFloat32x4', 'Float64x2_fromFloat64x2'] + nonexisting_simd_symbols += ['Int32x4_addSaturate', 'Int32x4_subSaturate', 'Uint32x4_addSaturate', 'Uint32x4_subSaturate'] + nonexisting_simd_symbols += [(x + '_' + y) for x in ['Int8x16', 'Uint8x16', 'Int16x8', 'Uint16x8', 'Float64x2'] for y in ['load2', 'load3', 'store2', 'store3']] + nonexisting_simd_symbols += [(x + '_' + y) for x in ['Int8x16', 'Uint8x16', 'Int16x8', 'Uint16x8'] for y in ['load1', 'load1']] asm_global_funcs += ''.join([' var SIMD_' + ty + '=global' + access_quote('SIMD') + access_quote(ty) + ';\n' for ty in simdtypes]) diff --git a/src/ecmascript_simd.js b/src/ecmascript_simd.js index 4af343e223f62..81efacadaec72 100644 --- a/src/ecmascript_simd.js +++ b/src/ecmascript_simd.js @@ -878,6 +878,11 @@ if (typeof simdPhase2 !== 'undefined') { "load", "store"], } + // XXX Emscripten: Need these functions for intrinsics, see https://github.com/tc39/ecmascript_simd/issues/316. + float64x2.fns.push("load1"); + float64x2.fns.push("store1"); + // XXX Emscripten + var bool64x2 = { name: "Bool64x2", fn: SIMD.Bool64x2, diff --git a/system/include/emscripten/vector.h b/system/include/emscripten/vector.h index 63b48792f0d65..2385eba4cdb8c 100644 --- a/system/include/emscripten/vector.h +++ b/system/include/emscripten/vector.h @@ -67,8 +67,8 @@ float64x2 emscripten_float64x2_select(bool64x2 __a, float64x2 __b, float64x2 __c // n.b. No emscripten_float64x2_subSaturate, only defined on 8-bit and 16-bit integer SIMD types. // n.b. No emscripten_float64x2_shiftLeftByScalar, only defined on integer SIMD types. // n.b. No emscripten_float64x2_shiftRightByScalar, only defined on integer SIMD types. -inline float emscripten_float64x2_extractLane(float64x2 __a, int __lane) __attribute__((__nothrow__, __const__)) { return __a[__lane]; } -inline float64x2 emscripten_float64x2_replaceLane(float64x2 __a, int __lane, float __s) __attribute__((__nothrow__, __const__)) { __a[__lane] = __s; return __a; } +inline double emscripten_float64x2_extractLane(float64x2 __a, int __lane) __attribute__((__nothrow__, __const__)) { return __a[__lane]; } +inline float64x2 emscripten_float64x2_replaceLane(float64x2 __a, int __lane, double __s) __attribute__((__nothrow__, __const__)) { __a[__lane] = __s; return __a; } void emscripten_float64x2_store(const void *__p, float64x2 __a) __attribute__((__nothrow__)); void emscripten_float64x2_store1(const void *__p, float64x2 __a) __attribute__((__nothrow__)); float64x2 emscripten_float64x2_load(const void *__p) __attribute__((__nothrow__, __pure__)); @@ -450,20 +450,20 @@ uint8x16 emscripten_uint8x16_swizzle(uint8x16 __a, int __lane0, int __lane1, int uint8x16 emscripten_uint8x16_shuffle(uint8x16 __a, uint8x16 __b, int __lane0, int __lane1, int __lane2, int __lane3, int __lane4, int __lane5, int __lane6, int __lane7, int __lane8, int __lane9, int __lane10, int __lane11, int __lane12, int __lane13, int __lane14, int __lane15) __attribute__((__nothrow__, __const__)); // Bool64x2 -bool emscripten_bool64x2_anyTrue(bool64x2 __a, bool64x2 __b) __attribute__((__nothrow__, __const__)); -bool emscripten_bool64x2_allTrue(bool64x2 __a, bool64x2 __b) __attribute__((__nothrow__, __const__)); +int emscripten_bool64x2_anyTrue(bool64x2 __a) __attribute__((__nothrow__, __const__)); +int emscripten_bool64x2_allTrue(bool64x2 __a) __attribute__((__nothrow__, __const__)); // Bool32x4 -bool emscripten_bool32x4_anyTrue(bool32x4 __a, bool32x4 __b) __attribute__((__nothrow__, __const__)); -bool emscripten_bool32x4_allTrue(bool32x4 __a, bool32x4 __b) __attribute__((__nothrow__, __const__)); +int emscripten_bool32x4_anyTrue(bool32x4 __a) __attribute__((__nothrow__, __const__)); +int emscripten_bool32x4_allTrue(bool32x4 __a) __attribute__((__nothrow__, __const__)); // Bool16x8 -bool emscripten_bool16x8_anyTrue(bool16x8 __a, bool16x8 __b) __attribute__((__nothrow__, __const__)); -bool emscripten_bool16x8_allTrue(bool16x8 __a, bool16x8 __b) __attribute__((__nothrow__, __const__)); +int emscripten_bool16x8_anyTrue(bool16x8 __a) __attribute__((__nothrow__, __const__)); +int emscripten_bool16x8_allTrue(bool16x8 __a) __attribute__((__nothrow__, __const__)); // Bool8x16 -bool emscripten_bool8x16_anyTrue(bool8x16 __a, bool8x16 __b) __attribute__((__nothrow__, __const__)); -bool emscripten_bool8x16_allTrue(bool8x16 __a, bool8x16 __b) __attribute__((__nothrow__, __const__)); +int emscripten_bool8x16_anyTrue(bool8x16 __a) __attribute__((__nothrow__, __const__)); +int emscripten_bool8x16_allTrue(bool8x16 __a) __attribute__((__nothrow__, __const__)); #ifdef __cplusplus } diff --git a/tests/core/test_simd_float32x4.c b/tests/core/test_simd_float32x4.c new file mode 100644 index 0000000000000..d1c53092f82bd --- /dev/null +++ b/tests/core/test_simd_float32x4.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include + +void dump(const char *name, float32x4 vec) +{ + printf("%s: %f %f %f %f\n", name, emscripten_float32x4_extractLane(vec, 0), emscripten_float32x4_extractLane(vec, 1), emscripten_float32x4_extractLane(vec, 2), emscripten_float32x4_extractLane(vec, 3)); +} +#define DUMP(V) dump(#V, (V)) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + float32x4 v = emscripten_float32x4_set(-1.f, 0.f, 1.f, 3.5f); + DUMP(v); + float32x4 w = emscripten_float32x4_splat(2.f); + DUMP(w); + DUMP(emscripten_float32x4_add(v, w)); + DUMP(emscripten_float32x4_sub(v, w)); + DUMP(emscripten_float32x4_mul(v, w)); + DUMP(emscripten_float32x4_div(v, w)); + DUMP(emscripten_float32x4_max(v, w)); + DUMP(emscripten_float32x4_min(v, w)); + DUMP(emscripten_float32x4_maxNum(v, w)); + DUMP(emscripten_float32x4_minNum(v, w)); + DUMP(emscripten_float32x4_neg(v)); + DUMP(emscripten_float32x4_sqrt(v)); + DUMP(emscripten_float32x4_reciprocalApproximation(v)); + DUMP(emscripten_float32x4_reciprocalSqrtApproximation(v)); + DUMP(emscripten_float32x4_abs(v)); + DUMP(emscripten_float32x4_and(v, w)); + DUMP(emscripten_float32x4_xor(v, w)); + DUMP(emscripten_float32x4_or(v, w)); + DUMP(emscripten_float32x4_not(v)); + DUMP(emscripten_float32x4_lessThan(v, w)); + DUMP(emscripten_float32x4_lessThanOrEqual(v, w)); + DUMP(emscripten_float32x4_greaterThan(v, w)); + DUMP(emscripten_float32x4_greaterThanOrEqual(v, w)); + DUMP(emscripten_float32x4_equal(v, w)); + DUMP(emscripten_float32x4_notEqual(v, w)); + bool32x4 b = emscripten_int32x4_set(0, -1, 0, -1); + DUMP(emscripten_float32x4_select(b, v, w)); + DUMP(emscripten_float32x4_replaceLane(v, 0, 9.f)); + DUMP(emscripten_float32x4_replaceLane(v, 1, -3.f)); + DUMP(emscripten_float32x4_replaceLane(v, 2, 0.f)); + DUMP(emscripten_float32x4_replaceLane(v, 3, -0.f)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float32x4_store(bytes, v); + DUMPBYTES("emscripten_float32x4_store", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float32x4_store1(bytes, v); + DUMPBYTES("emscripten_float32x4_store1", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float32x4_store2(bytes, v); + DUMPBYTES("emscripten_float32x4_store2", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float32x4_store3(bytes, v); + DUMPBYTES("emscripten_float32x4_store3", bytes); + + emscripten_float32x4_store(bytes, v); + DUMP(emscripten_float32x4_load(bytes)); + DUMP(emscripten_float32x4_load1(bytes)); + DUMP(emscripten_float32x4_load2(bytes)); + DUMP(emscripten_float32x4_load3(bytes)); + // TODO: emscripten_float32x4_fromFloat64x2Bits + // TODO: emscripten_float32x4_fromInt32x4Bits + // TODO: emscripten_float32x4_fromUint32x4Bits + // TODO: emscripten_float32x4_fromInt16x8Bits + // TODO: emscripten_float32x4_fromUint16x8Bits + // TODO: emscripten_float32x4_fromInt8x16Bits + // TODO: emscripten_float32x4_fromUint8x16Bits + // TODO: emscripten_float32x4_fromInt32x4 + // TODO: emscripten_float32x4_fromUint32x4 + DUMP(emscripten_float32x4_swizzle(v, 0, 1, 2, 3)); + DUMP(emscripten_float32x4_swizzle(v, 3, 2, 1, 0)); + DUMP(emscripten_float32x4_swizzle(v, 0, 0, 0, 0)); + DUMP(emscripten_float32x4_swizzle(v, 0, 3, 0, 3)); + DUMP(emscripten_float32x4_swizzle(v, 3, 3, 3, 3)); + float32x4 z = emscripten_float32x4_set(-5.f, 20.f, 14.f, 9.f); + DUMP(z); + DUMP(emscripten_float32x4_shuffle(v, z, 0, 0, 0, 0)); + DUMP(emscripten_float32x4_shuffle(v, z, 4, 4, 4, 4)); + DUMP(emscripten_float32x4_shuffle(v, z, 7, 7, 7, 7)); + DUMP(emscripten_float32x4_shuffle(v, z, 0, 2, 4, 6)); + DUMP(emscripten_float32x4_shuffle(v, z, 7, 0, 3, 5)); + + printf("Done!\n"); +} diff --git a/tests/core/test_simd_float32x4.out b/tests/core/test_simd_float32x4.out new file mode 100644 index 0000000000000..8748af42f3b26 --- /dev/null +++ b/tests/core/test_simd_float32x4.out @@ -0,0 +1,50 @@ +v: -1.000000 0.000000 1.000000 3.500000 +w: 2.000000 2.000000 2.000000 2.000000 +emscripten_float32x4_add(v, w): 1.000000 2.000000 3.000000 5.500000 +emscripten_float32x4_sub(v, w): -3.000000 -2.000000 -1.000000 1.500000 +emscripten_float32x4_mul(v, w): -2.000000 0.000000 2.000000 7.000000 +emscripten_float32x4_div(v, w): -0.500000 0.000000 0.500000 1.750000 +emscripten_float32x4_max(v, w): 2.000000 2.000000 2.000000 3.500000 +emscripten_float32x4_min(v, w): -1.000000 0.000000 1.000000 2.000000 +emscripten_float32x4_maxNum(v, w): 2.000000 2.000000 2.000000 3.500000 +emscripten_float32x4_minNum(v, w): -1.000000 0.000000 1.000000 2.000000 +emscripten_float32x4_neg(v): 1.000000 -0.000000 -1.000000 -3.500000 +emscripten_float32x4_sqrt(v): nan 0.000000 1.000000 1.870829 +emscripten_float32x4_reciprocalApproximation(v): -1.000000 inf 1.000000 0.285714 +emscripten_float32x4_reciprocalSqrtApproximation(v): nan inf 1.000000 0.534522 +emscripten_float32x4_abs(v): 1.000000 0.000000 1.000000 3.500000 +emscripten_float32x4_and(v, w): 0.000000 0.000000 0.000000 2.000000 +emscripten_float32x4_xor(v, w): -inf 2.000000 inf 0.000000 +emscripten_float32x4_or(v, w): -inf 2.000000 inf 3.500000 +emscripten_float32x4_not(v): 4.000000 nan -4.000000 -1.250000 +emscripten_float32x4_lessThan(v, w): nan nan nan 0.000000 +emscripten_float32x4_lessThanOrEqual(v, w): nan nan nan 0.000000 +emscripten_float32x4_greaterThan(v, w): 0.000000 0.000000 0.000000 nan +emscripten_float32x4_greaterThanOrEqual(v, w): 0.000000 0.000000 0.000000 nan +emscripten_float32x4_equal(v, w): 0.000000 0.000000 0.000000 0.000000 +emscripten_float32x4_notEqual(v, w): nan nan nan nan +emscripten_float32x4_select(b, v, w): 2.000000 0.000000 2.000000 3.500000 +emscripten_float32x4_replaceLane(v, 0, 9.f): 9.000000 0.000000 1.000000 3.500000 +emscripten_float32x4_replaceLane(v, 1, -3.f): -1.000000 -3.000000 1.000000 3.500000 +emscripten_float32x4_replaceLane(v, 2, 0.f): -1.000000 0.000000 0.000000 3.500000 +emscripten_float32x4_replaceLane(v, 3, -0.f): -1.000000 0.000000 1.000000 -0.000000 +emscripten_float32x4_store: 00 00 80 BF 00 00 00 00 00 00 80 3F 00 00 60 40 +emscripten_float32x4_store1: 00 00 80 BF FF FF FF FF FF FF FF FF FF FF FF FF +emscripten_float32x4_store2: 00 00 80 BF 00 00 00 00 FF FF FF FF FF FF FF FF +emscripten_float32x4_store3: 00 00 80 BF 00 00 00 00 00 00 80 3F FF FF FF FF +emscripten_float32x4_load(bytes): -1.000000 0.000000 1.000000 3.500000 +emscripten_float32x4_load1(bytes): -1.000000 0.000000 0.000000 0.000000 +emscripten_float32x4_load2(bytes): -1.000000 0.000000 0.000000 0.000000 +emscripten_float32x4_load3(bytes): -1.000000 0.000000 1.000000 0.000000 +emscripten_float32x4_swizzle(v, 0, 1, 2, 3): -1.000000 0.000000 1.000000 3.500000 +emscripten_float32x4_swizzle(v, 3, 2, 1, 0): 3.500000 1.000000 0.000000 -1.000000 +emscripten_float32x4_swizzle(v, 0, 0, 0, 0): -1.000000 -1.000000 -1.000000 -1.000000 +emscripten_float32x4_swizzle(v, 0, 3, 0, 3): -1.000000 3.500000 -1.000000 3.500000 +emscripten_float32x4_swizzle(v, 3, 3, 3, 3): 3.500000 3.500000 3.500000 3.500000 +z: -5.000000 20.000000 14.000000 9.000000 +emscripten_float32x4_shuffle(v, z, 0, 0, 0, 0): -1.000000 -1.000000 -1.000000 -1.000000 +emscripten_float32x4_shuffle(v, z, 4, 4, 4, 4): -5.000000 -5.000000 -5.000000 -5.000000 +emscripten_float32x4_shuffle(v, z, 7, 7, 7, 7): 9.000000 9.000000 9.000000 9.000000 +emscripten_float32x4_shuffle(v, z, 0, 2, 4, 6): -1.000000 1.000000 -5.000000 14.000000 +emscripten_float32x4_shuffle(v, z, 7, 0, 3, 5): 9.000000 -1.000000 3.500000 20.000000 +Done! \ No newline at end of file diff --git a/tests/core/test_simd_float64x2.c b/tests/core/test_simd_float64x2.c new file mode 100644 index 0000000000000..14b6a9952db29 --- /dev/null +++ b/tests/core/test_simd_float64x2.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include + +void dump(const char *name, float64x2 vec) +{ + printf("%s: %f %f\n", name, emscripten_float64x2_extractLane(vec, 0), emscripten_float64x2_extractLane(vec, 1)); +} +#define DUMP(V) dump(#V, (V)) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + float64x2 v = emscripten_float64x2_set(-1.5f, 2.5f); + DUMP(v); + float64x2 w = emscripten_float64x2_splat(1.5f); + DUMP(w); + DUMP(emscripten_float64x2_add(v, w)); + DUMP(emscripten_float64x2_sub(v, w)); + DUMP(emscripten_float64x2_mul(v, w)); + DUMP(emscripten_float64x2_div(v, w)); + DUMP(emscripten_float64x2_max(v, w)); + DUMP(emscripten_float64x2_min(v, w)); + DUMP(emscripten_float64x2_maxNum(v, w)); + DUMP(emscripten_float64x2_minNum(v, w)); + DUMP(emscripten_float64x2_neg(v)); + DUMP(emscripten_float64x2_sqrt(v)); + DUMP(emscripten_float64x2_reciprocalApproximation(v)); + DUMP(emscripten_float64x2_reciprocalSqrtApproximation(v)); + DUMP(emscripten_float64x2_abs(v)); + DUMP(emscripten_float64x2_and(v, w)); + DUMP(emscripten_float64x2_xor(v, w)); + DUMP(emscripten_float64x2_or(v, w)); + DUMP(emscripten_float64x2_not(v)); + DUMP(emscripten_float64x2_lessThan(v, w)); + DUMP(emscripten_float64x2_lessThanOrEqual(v, w)); + DUMP(emscripten_float64x2_greaterThan(v, w)); + DUMP(emscripten_float64x2_greaterThanOrEqual(v, w)); + DUMP(emscripten_float64x2_equal(v, w)); + DUMP(emscripten_float64x2_notEqual(v, w)); + //bool64x2 b = emscripten_int64x2_set(0, -1); // TODO: Can't yet use this form, no int64x2. + //DUMP(emscripten_float64x2_select(b, v, w)); + DUMP(emscripten_float64x2_replaceLane(v, 0, 9.f)); + DUMP(emscripten_float64x2_replaceLane(v, 1, -3.f)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float64x2_store(bytes, v); + DUMPBYTES("emscripten_float64x2_store", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_float64x2_store1(bytes, v); + DUMPBYTES("emscripten_float64x2_store1", bytes); + + emscripten_float64x2_store(bytes, v); + DUMP(emscripten_float64x2_load(bytes)); + DUMP(emscripten_float64x2_load1(bytes)); + // TODO: emscripten_float64x2_fromFloat64x2Bits + // TODO: emscripten_float64x2_fromInt64x2Bits + // TODO: emscripten_float64x2_fromUint64x2Bits + // TODO: emscripten_float64x2_fromInt16x8Bits + // TODO: emscripten_float64x2_fromUint16x8Bits + // TODO: emscripten_float64x2_fromInt8x16Bits + // TODO: emscripten_float64x2_fromUint8x16Bits + // TODO: emscripten_float64x2_fromInt64x2 + // TODO: emscripten_float64x2_fromUint64x2 + DUMP(emscripten_float64x2_swizzle(v, 0, 1)); + DUMP(emscripten_float64x2_swizzle(v, 1, 0)); + DUMP(emscripten_float64x2_swizzle(v, 0, 0)); + DUMP(emscripten_float64x2_swizzle(v, 1, 1)); + float64x2 z = emscripten_float64x2_set(-5.5f, 20.5f); + DUMP(z); + DUMP(emscripten_float64x2_shuffle(v, z, 0, 0)); + DUMP(emscripten_float64x2_shuffle(v, z, 2, 2)); + DUMP(emscripten_float64x2_shuffle(v, z, 3, 3)); + DUMP(emscripten_float64x2_shuffle(v, z, 0, 2)); + DUMP(emscripten_float64x2_shuffle(v, z, 3, 1)); + + printf("Done!\n"); +} diff --git a/tests/core/test_simd_float64x2.out b/tests/core/test_simd_float64x2.out new file mode 100644 index 0000000000000..b127fd9275046 --- /dev/null +++ b/tests/core/test_simd_float64x2.out @@ -0,0 +1,42 @@ +v: -1.500000 2.500000 +w: 1.500000 1.500000 +emscripten_float64x2_add(v, w): 0.000000 4.000000 +emscripten_float64x2_sub(v, w): -3.000000 1.000000 +emscripten_float64x2_mul(v, w): -2.250000 3.750000 +emscripten_float64x2_div(v, w): -1.000000 1.666667 +emscripten_float64x2_max(v, w): 1.500000 2.500000 +emscripten_float64x2_min(v, w): -1.500000 1.500000 +emscripten_float64x2_maxNum(v, w): 1.500000 2.500000 +emscripten_float64x2_minNum(v, w): -1.500000 1.500000 +emscripten_float64x2_neg(v): 1.500000 -2.500000 +emscripten_float64x2_sqrt(v): nan 1.581139 +emscripten_float64x2_reciprocalApproximation(v): -0.666667 0.400000 +emscripten_float64x2_reciprocalSqrtApproximation(v): nan 0.632456 +emscripten_float64x2_abs(v): 1.500000 2.500000 +emscripten_float64x2_and(v, w): 1.500000 0.000000 +emscripten_float64x2_xor(v, w): -0.000000 nan +emscripten_float64x2_or(v, w): -1.500000 nan +emscripten_float64x2_not(v): 3.000000 -1.750000 +emscripten_float64x2_lessThan(v, w): nan 0.000000 +emscripten_float64x2_lessThanOrEqual(v, w): nan 0.000000 +emscripten_float64x2_greaterThan(v, w): 0.000000 nan +emscripten_float64x2_greaterThanOrEqual(v, w): 0.000000 nan +emscripten_float64x2_equal(v, w): 0.000000 0.000000 +emscripten_float64x2_notEqual(v, w): nan nan +emscripten_float64x2_replaceLane(v, 0, 9.f): 9.000000 2.500000 +emscripten_float64x2_replaceLane(v, 1, -3.f): -1.500000 -3.000000 +emscripten_float64x2_store: 00 00 00 00 00 00 F8 BF 00 00 00 00 00 00 04 40 +emscripten_float64x2_store1: 00 00 00 00 00 00 F8 BF FF FF FF FF FF FF FF FF +emscripten_float64x2_load(bytes): -1.500000 2.500000 +emscripten_float64x2_load1(bytes): -1.500000 0.000000 +emscripten_float64x2_swizzle(v, 0, 1): -1.500000 2.500000 +emscripten_float64x2_swizzle(v, 1, 0): 2.500000 -1.500000 +emscripten_float64x2_swizzle(v, 0, 0): -1.500000 -1.500000 +emscripten_float64x2_swizzle(v, 1, 1): 2.500000 2.500000 +z: -5.500000 20.500000 +emscripten_float64x2_shuffle(v, z, 0, 0): -1.500000 -1.500000 +emscripten_float64x2_shuffle(v, z, 2, 2): -5.500000 -5.500000 +emscripten_float64x2_shuffle(v, z, 3, 3): 20.500000 20.500000 +emscripten_float64x2_shuffle(v, z, 0, 2): -1.500000 -5.500000 +emscripten_float64x2_shuffle(v, z, 3, 1): 20.500000 2.500000 +Done! \ No newline at end of file diff --git a/tests/core/test_simd_int16x8.c b/tests/core/test_simd_int16x8.c new file mode 100644 index 0000000000000..d22e0697f8fa9 --- /dev/null +++ b/tests/core/test_simd_int16x8.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include + +void dump(const char *name, int16x8 vec) +{ + printf("%s: %d %d %d %d %d %d %d %d\n", name, emscripten_int16x8_extractLane(vec, 0), emscripten_int16x8_extractLane(vec, 1), emscripten_int16x8_extractLane(vec, 2), emscripten_int16x8_extractLane(vec, 3), + emscripten_int16x8_extractLane(vec, 4), emscripten_int16x8_extractLane(vec, 5), emscripten_int16x8_extractLane(vec, 6), emscripten_int16x8_extractLane(vec, 7)); +} +#define DUMP(V) dump(#V, (V)) +#define DUMPINT(V) printf("%s: %d\n", #V, V) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + int16x8 v = emscripten_int16x8_set(1, 0, 1, 32767, -2, 9, 13, -32768); + DUMP(v); + int16x8 w = emscripten_int16x8_splat(2); + DUMP(w); + DUMP(emscripten_int16x8_add(v, w)); + DUMP(emscripten_int16x8_sub(v, w)); + DUMP(emscripten_int16x8_mul(v, w)); + DUMP(emscripten_int16x8_neg(v)); + DUMP(emscripten_int16x8_and(v, w)); + DUMP(emscripten_int16x8_xor(v, w)); + DUMP(emscripten_int16x8_or(v, w)); + DUMP(emscripten_int16x8_not(v)); + DUMP(emscripten_int16x8_lessThan(v, w)); + DUMP(emscripten_int16x8_lessThanOrEqual(v, w)); + DUMP(emscripten_int16x8_greaterThan(v, w)); + DUMP(emscripten_int16x8_greaterThanOrEqual(v, w)); + DUMP(emscripten_int16x8_equal(v, w)); + DUMP(emscripten_int16x8_notEqual(v, w)); +// DUMPINT(emscripten_int16x8_anyTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int16x8->bool16x8 and enable this, or remove if this doesn't make sense. +// DUMPINT(emscripten_int16x8_allTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int16x8->bool16x8 and enable this, or remove if this doesn't make sense. + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 0)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 1)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 2)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 16)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 32)); + DUMP(emscripten_int16x8_shiftLeftByScalar(v, 48)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 0)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 1)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 2)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 16)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 32)); + DUMP(emscripten_int16x8_shiftRightByScalar(v, 48)); + bool32x4 b = emscripten_int16x8_set(0, -1, 0, -1, 0, -1, 0, -1); + DUMP(emscripten_int16x8_select(b, v, w)); + DUMP(emscripten_int16x8_addSaturate(v, w)); + DUMP(emscripten_int16x8_subSaturate(v, w)); + DUMP(emscripten_int16x8_replaceLane(v, 0, 9)); + DUMP(emscripten_int16x8_replaceLane(v, 1, 3)); + DUMP(emscripten_int16x8_replaceLane(v, 2, 0)); + DUMP(emscripten_int16x8_replaceLane(v, 3, 91)); + DUMP(emscripten_int16x8_replaceLane(v, 4, 32767)); + DUMP(emscripten_int16x8_replaceLane(v, 5, 100)); + DUMP(emscripten_int16x8_replaceLane(v, 6, -100)); + DUMP(emscripten_int16x8_replaceLane(v, 7, -32768)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int16x8_store(bytes, v); + DUMPBYTES("emscripten_int16x8_store", bytes); + DUMP(emscripten_int16x8_load(bytes)); + // TODO: emscripten_int16x8_fromFloat64x2Bits + // TODO: emscripten_int16x8_fromint16x8Bits + // TODO: emscripten_int16x8_fromUint16x8Bits + // TODO: emscripten_int16x8_fromInt16x8Bits + // TODO: emscripten_int16x8_fromUint16x8Bits + // TODO: emscripten_int16x8_fromInt8x16Bits + // TODO: emscripten_int16x8_fromUint8x16Bits + // TODO: emscripten_int16x8_fromint16x8 + // TODO: emscripten_int16x8_fromUint16x8 + DUMP(emscripten_int16x8_swizzle(v, 0, 1, 2, 3, 4, 5, 6, 7)); + DUMP(emscripten_int16x8_swizzle(v, 7, 6, 5, 4, 3, 2, 1, 0)); + DUMP(emscripten_int16x8_swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0)); + DUMP(emscripten_int16x8_swizzle(v, 0, 3, 0, 3, 7, 1, 2, 6)); + DUMP(emscripten_int16x8_swizzle(v, 3, 3, 3, 3, 3, 3, 3, 3)); + int16x8 z = emscripten_int16x8_set(-5, 20, 14, 9, 0, 11, 32764, -32750); + DUMP(z); + DUMP(emscripten_int16x8_shuffle(v, z, 0, 0, 0, 0, 0, 0, 0, 0)); + DUMP(emscripten_int16x8_shuffle(v, z, 4, 4, 4, 4, 4, 4, 4, 4)); + DUMP(emscripten_int16x8_shuffle(v, z, 15, 15, 15, 15, 7, 7, 7, 7)); + DUMP(emscripten_int16x8_shuffle(v, z, 0, 2, 4, 6, 8, 10, 12, 14)); + DUMP(emscripten_int16x8_shuffle(v, z, 7, 0, 3, 5, 9, 11, 1, 4)); + printf("Done!\n"); +} diff --git a/tests/core/test_simd_int16x8.out b/tests/core/test_simd_int16x8.out new file mode 100644 index 0000000000000..2493a0a122ca9 --- /dev/null +++ b/tests/core/test_simd_int16x8.out @@ -0,0 +1,53 @@ +v: 1 0 1 32767 -2 9 13 -32768 +w: 2 2 2 2 2 2 2 2 +emscripten_int16x8_add(v, w): 3 2 3 -32767 0 11 15 -32766 +emscripten_int16x8_sub(v, w): -1 -2 -1 32765 -4 7 11 32766 +emscripten_int16x8_mul(v, w): 2 0 2 -2 -4 18 26 0 +emscripten_int16x8_neg(v): -1 0 -1 -32767 2 -9 -13 -32768 +emscripten_int16x8_and(v, w): 0 0 0 2 2 0 0 0 +emscripten_int16x8_xor(v, w): 3 2 3 32765 -4 11 15 -32766 +emscripten_int16x8_or(v, w): 3 2 3 32767 -2 11 15 -32766 +emscripten_int16x8_not(v): -2 -1 -2 -32768 1 -10 -14 32767 +emscripten_int16x8_lessThan(v, w): -1 -1 -1 0 -1 0 0 -1 +emscripten_int16x8_lessThanOrEqual(v, w): -1 -1 -1 0 -1 0 0 -1 +emscripten_int16x8_greaterThan(v, w): 0 0 0 -1 0 -1 -1 0 +emscripten_int16x8_greaterThanOrEqual(v, w): 0 0 0 -1 0 -1 -1 0 +emscripten_int16x8_equal(v, w): 0 0 0 0 0 0 0 0 +emscripten_int16x8_notEqual(v, w): -1 -1 -1 -1 -1 -1 -1 -1 +emscripten_int16x8_shiftLeftByScalar(v, 0): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftLeftByScalar(v, 1): 2 0 2 -2 -4 18 26 0 +emscripten_int16x8_shiftLeftByScalar(v, 2): 4 0 4 -4 -8 36 52 0 +emscripten_int16x8_shiftLeftByScalar(v, 16): 0 0 0 0 0 0 0 0 +emscripten_int16x8_shiftLeftByScalar(v, 32): 0 0 0 0 0 0 0 0 +emscripten_int16x8_shiftLeftByScalar(v, 48): 0 0 0 0 0 0 0 0 +emscripten_int16x8_shiftRightByScalar(v, 0): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_shiftRightByScalar(v, 1): 0 0 0 16383 -1 4 6 -16384 +emscripten_int16x8_shiftRightByScalar(v, 2): 0 0 0 8191 -1 2 3 -8192 +emscripten_int16x8_shiftRightByScalar(v, 16): 0 0 0 0 -1 0 0 -1 +emscripten_int16x8_shiftRightByScalar(v, 32): 0 0 0 0 -1 0 0 -1 +emscripten_int16x8_shiftRightByScalar(v, 48): 0 0 0 0 -1 0 0 -1 +emscripten_int16x8_select(b, v, w): 2 0 2 32767 2 9 2 -32768 +emscripten_int16x8_addSaturate(v, w): 3 2 3 32767 0 11 15 -32766 +emscripten_int16x8_subSaturate(v, w): -1 -2 -1 32765 -4 7 11 -32768 +emscripten_int16x8_replaceLane(v, 0, 9): 9 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_replaceLane(v, 1, 3): 1 3 1 32767 -2 9 13 -32768 +emscripten_int16x8_replaceLane(v, 2, 0): 1 0 0 32767 -2 9 13 -32768 +emscripten_int16x8_replaceLane(v, 3, 91): 1 0 1 91 -2 9 13 -32768 +emscripten_int16x8_replaceLane(v, 4, 32767): 1 0 1 32767 32767 9 13 -32768 +emscripten_int16x8_replaceLane(v, 5, 100): 1 0 1 32767 -2 100 13 -32768 +emscripten_int16x8_replaceLane(v, 6, -100): 1 0 1 32767 -2 9 -100 -32768 +emscripten_int16x8_replaceLane(v, 7, -32768): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_store: 01 00 00 00 01 00 FF 7F FE FF 09 00 0D 00 00 80 +emscripten_int16x8_load(bytes): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_swizzle(v, 0, 1, 2, 3, 4, 5, 6, 7): 1 0 1 32767 -2 9 13 -32768 +emscripten_int16x8_swizzle(v, 7, 6, 5, 4, 3, 2, 1, 0): -32768 13 9 -2 32767 1 0 1 +emscripten_int16x8_swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0): 1 1 1 1 1 1 1 1 +emscripten_int16x8_swizzle(v, 0, 3, 0, 3, 7, 1, 2, 6): 1 32767 1 32767 -32768 0 1 13 +emscripten_int16x8_swizzle(v, 3, 3, 3, 3, 3, 3, 3, 3): 32767 32767 32767 32767 32767 32767 32767 32767 +z: -5 20 14 9 0 11 32764 -32750 +emscripten_int16x8_shuffle(v, z, 0, 0, 0, 0, 0, 0, 0, 0): 1 1 1 1 1 1 1 1 +emscripten_int16x8_shuffle(v, z, 4, 4, 4, 4, 4, 4, 4, 4): -2 -2 -2 -2 -2 -2 -2 -2 +emscripten_int16x8_shuffle(v, z, 15, 15, 15, 15, 7, 7, 7, 7): -32750 -32750 -32750 -32750 -32768 -32768 -32768 -32768 +emscripten_int16x8_shuffle(v, z, 0, 2, 4, 6, 8, 10, 12, 14): 1 1 -2 13 -5 14 0 32764 +emscripten_int16x8_shuffle(v, z, 7, 0, 3, 5, 9, 11, 1, 4): -32768 1 32767 9 20 9 0 -2 +Done! \ No newline at end of file diff --git a/tests/core/test_simd_int32x4.c b/tests/core/test_simd_int32x4.c new file mode 100644 index 0000000000000..cc18205b741fd --- /dev/null +++ b/tests/core/test_simd_int32x4.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include + +void dump(const char *name, int32x4 vec) +{ + printf("%s: %d %d %d %d\n", name, emscripten_int32x4_extractLane(vec, 0), emscripten_int32x4_extractLane(vec, 1), emscripten_int32x4_extractLane(vec, 2), emscripten_int32x4_extractLane(vec, 3)); +} +#define DUMP(V) dump(#V, (V)) +#define DUMPINT(V) printf("%s: %d\n", #V, V) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + int32x4 v = emscripten_int32x4_set(1, 0, 1, 4); + DUMP(v); + int32x4 w = emscripten_int32x4_splat(2); + DUMP(w); + DUMP(emscripten_int32x4_add(v, w)); + DUMP(emscripten_int32x4_sub(v, w)); + DUMP(emscripten_int32x4_mul(v, w)); + DUMP(emscripten_int32x4_neg(v)); + DUMP(emscripten_int32x4_and(v, w)); + DUMP(emscripten_int32x4_xor(v, w)); + DUMP(emscripten_int32x4_or(v, w)); + DUMP(emscripten_int32x4_not(v)); + DUMP(emscripten_int32x4_lessThan(v, w)); + DUMP(emscripten_int32x4_lessThanOrEqual(v, w)); + DUMP(emscripten_int32x4_greaterThan(v, w)); + DUMP(emscripten_int32x4_greaterThanOrEqual(v, w)); + DUMP(emscripten_int32x4_equal(v, w)); + DUMP(emscripten_int32x4_notEqual(v, w)); +// DUMPINT(emscripten_int32x4_anyTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int32x4->bool32x4 and enable this, or remove if this doesn't make sense. +// DUMPINT(emscripten_int32x4_allTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int32x4->bool32x4 and enable this, or remove if this doesn't make sense. + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 0)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 1)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 2)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 16)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 32)); + DUMP(emscripten_int32x4_shiftLeftByScalar(v, 48)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 0)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 1)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 2)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 16)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 32)); + DUMP(emscripten_int32x4_shiftRightByScalar(v, 48)); + bool32x4 b = emscripten_int32x4_set(0, -1, 0, -1); + DUMP(emscripten_int32x4_select(b, v, w)); + DUMP(emscripten_int32x4_replaceLane(v, 0, 9)); + DUMP(emscripten_int32x4_replaceLane(v, 1, 3)); + DUMP(emscripten_int32x4_replaceLane(v, 2, 0)); + DUMP(emscripten_int32x4_replaceLane(v, 3, 91)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int32x4_store(bytes, v); + DUMPBYTES("emscripten_int32x4_store", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int32x4_store1(bytes, v); + DUMPBYTES("emscripten_int32x4_store1", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int32x4_store2(bytes, v); + DUMPBYTES("emscripten_int32x4_store2", bytes); + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int32x4_store3(bytes, v); + DUMPBYTES("emscripten_int32x4_store3", bytes); + + emscripten_int32x4_store(bytes, v); + DUMP(emscripten_int32x4_load(bytes)); + DUMP(emscripten_int32x4_load1(bytes)); + DUMP(emscripten_int32x4_load2(bytes)); + DUMP(emscripten_int32x4_load3(bytes)); + // TODO: emscripten_int32x4_fromFloat64x2Bits + // TODO: emscripten_int32x4_fromInt32x4Bits + // TODO: emscripten_int32x4_fromUint32x4Bits + // TODO: emscripten_int32x4_fromInt16x8Bits + // TODO: emscripten_int32x4_fromUint16x8Bits + // TODO: emscripten_int32x4_fromInt8x16Bits + // TODO: emscripten_int32x4_fromUint8x16Bits + // TODO: emscripten_int32x4_fromInt32x4 + // TODO: emscripten_int32x4_fromUint32x4 + DUMP(emscripten_int32x4_swizzle(v, 0, 1, 2, 3)); + DUMP(emscripten_int32x4_swizzle(v, 3, 2, 1, 0)); + DUMP(emscripten_int32x4_swizzle(v, 0, 0, 0, 0)); + DUMP(emscripten_int32x4_swizzle(v, 0, 3, 0, 3)); + DUMP(emscripten_int32x4_swizzle(v, 3, 3, 3, 3)); + int32x4 z = emscripten_int32x4_set(-5, 20, 14, 9); + DUMP(z); + DUMP(emscripten_int32x4_shuffle(v, z, 0, 0, 0, 0)); + DUMP(emscripten_int32x4_shuffle(v, z, 4, 4, 4, 4)); + DUMP(emscripten_int32x4_shuffle(v, z, 7, 7, 7, 7)); + DUMP(emscripten_int32x4_shuffle(v, z, 0, 2, 4, 6)); + DUMP(emscripten_int32x4_shuffle(v, z, 7, 0, 3, 5)); + printf("Done!\n"); +} diff --git a/tests/core/test_simd_int32x4.out b/tests/core/test_simd_int32x4.out new file mode 100644 index 0000000000000..471de66e1189a --- /dev/null +++ b/tests/core/test_simd_int32x4.out @@ -0,0 +1,53 @@ +v: 1 0 1 4 +w: 2 2 2 2 +emscripten_int32x4_add(v, w): 3 2 3 6 +emscripten_int32x4_sub(v, w): -1 -2 -1 2 +emscripten_int32x4_mul(v, w): 2 0 2 8 +emscripten_int32x4_neg(v): -1 0 -1 -4 +emscripten_int32x4_and(v, w): 0 0 0 0 +emscripten_int32x4_xor(v, w): 3 2 3 6 +emscripten_int32x4_or(v, w): 3 2 3 6 +emscripten_int32x4_not(v): -2 -1 -2 -5 +emscripten_int32x4_lessThan(v, w): -1 -1 -1 0 +emscripten_int32x4_lessThanOrEqual(v, w): -1 -1 -1 0 +emscripten_int32x4_greaterThan(v, w): 0 0 0 -1 +emscripten_int32x4_greaterThanOrEqual(v, w): 0 0 0 -1 +emscripten_int32x4_equal(v, w): 0 0 0 0 +emscripten_int32x4_notEqual(v, w): -1 -1 -1 -1 +emscripten_int32x4_shiftLeftByScalar(v, 0): 1 0 1 4 +emscripten_int32x4_shiftLeftByScalar(v, 1): 2 0 2 8 +emscripten_int32x4_shiftLeftByScalar(v, 2): 4 0 4 16 +emscripten_int32x4_shiftLeftByScalar(v, 16): 65536 0 65536 262144 +emscripten_int32x4_shiftLeftByScalar(v, 32): 0 0 0 0 +emscripten_int32x4_shiftLeftByScalar(v, 48): 0 0 0 0 +emscripten_int32x4_shiftRightByScalar(v, 0): 1 0 1 4 +emscripten_int32x4_shiftRightByScalar(v, 1): 0 0 0 2 +emscripten_int32x4_shiftRightByScalar(v, 2): 0 0 0 1 +emscripten_int32x4_shiftRightByScalar(v, 16): 0 0 0 0 +emscripten_int32x4_shiftRightByScalar(v, 32): 0 0 0 0 +emscripten_int32x4_shiftRightByScalar(v, 48): 0 0 0 0 +emscripten_int32x4_select(b, v, w): 2 0 2 4 +emscripten_int32x4_replaceLane(v, 0, 9): 9 0 1 4 +emscripten_int32x4_replaceLane(v, 1, 3): 1 3 1 4 +emscripten_int32x4_replaceLane(v, 2, 0): 1 0 0 4 +emscripten_int32x4_replaceLane(v, 3, 91): 1 0 1 91 +emscripten_int32x4_store: 01 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 +emscripten_int32x4_store1: 01 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF +emscripten_int32x4_store2: 01 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF +emscripten_int32x4_store3: 01 00 00 00 00 00 00 00 01 00 00 00 FF FF FF FF +emscripten_int32x4_load(bytes): 1 0 1 4 +emscripten_int32x4_load1(bytes): 1 0 0 0 +emscripten_int32x4_load2(bytes): 1 0 0 0 +emscripten_int32x4_load3(bytes): 1 0 1 0 +emscripten_int32x4_swizzle(v, 0, 1, 2, 3): 1 0 1 4 +emscripten_int32x4_swizzle(v, 3, 2, 1, 0): 4 1 0 1 +emscripten_int32x4_swizzle(v, 0, 0, 0, 0): 1 1 1 1 +emscripten_int32x4_swizzle(v, 0, 3, 0, 3): 1 4 1 4 +emscripten_int32x4_swizzle(v, 3, 3, 3, 3): 4 4 4 4 +z: -5 20 14 9 +emscripten_int32x4_shuffle(v, z, 0, 0, 0, 0): 1 1 1 1 +emscripten_int32x4_shuffle(v, z, 4, 4, 4, 4): -5 -5 -5 -5 +emscripten_int32x4_shuffle(v, z, 7, 7, 7, 7): 9 9 9 9 +emscripten_int32x4_shuffle(v, z, 0, 2, 4, 6): 1 1 -5 14 +emscripten_int32x4_shuffle(v, z, 7, 0, 3, 5): 9 1 4 20 +Done! \ No newline at end of file diff --git a/tests/core/test_simd_int8x16.c b/tests/core/test_simd_int8x16.c new file mode 100644 index 0000000000000..009746f295246 --- /dev/null +++ b/tests/core/test_simd_int8x16.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include + +void dump(const char *name, int8x16 vec) +{ + printf("%s: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", name, emscripten_int8x16_extractLane(vec, 0), emscripten_int8x16_extractLane(vec, 1), emscripten_int8x16_extractLane(vec, 2), emscripten_int8x16_extractLane(vec, 3), + emscripten_int8x16_extractLane(vec, 4), emscripten_int8x16_extractLane(vec, 5), emscripten_int8x16_extractLane(vec, 6), emscripten_int8x16_extractLane(vec, 7), + emscripten_int8x16_extractLane(vec, 8), emscripten_int8x16_extractLane(vec, 9), emscripten_int8x16_extractLane(vec, 10), emscripten_int8x16_extractLane(vec, 11), + emscripten_int8x16_extractLane(vec, 12), emscripten_int8x16_extractLane(vec, 13), emscripten_int8x16_extractLane(vec, 14), emscripten_int8x16_extractLane(vec, 15)); +} +#define DUMP(V) dump(#V, (V)) +#define DUMPINT(V) printf("%s: %d\n", #V, V) + +void dumpBytes(const char *name, const void *bytes, int n) +{ + printf("%s:", name); + for(int i = 0; i < n; ++i) + printf(" %02X", ((uint8_t*)bytes)[i]); + printf("\n"); +} +#define DUMPBYTES(name, bytes) dumpBytes(name, bytes, sizeof(bytes)) + +int main() +{ + int8x16 v = emscripten_int8x16_set(1, 0, 1, 127, -2, 9, 13, -128, 3, 19, 73, -53, 42, 66, 10, 100); + DUMP(v); + int8x16 w = emscripten_int8x16_splat(2); + DUMP(w); + DUMP(emscripten_int8x16_add(v, w)); + DUMP(emscripten_int8x16_sub(v, w)); + DUMP(emscripten_int8x16_mul(v, w)); + DUMP(emscripten_int8x16_neg(v)); + DUMP(emscripten_int8x16_and(v, w)); + DUMP(emscripten_int8x16_xor(v, w)); + DUMP(emscripten_int8x16_or(v, w)); + DUMP(emscripten_int8x16_not(v)); + DUMP(emscripten_int8x16_lessThan(v, w)); + DUMP(emscripten_int8x16_lessThanOrEqual(v, w)); + DUMP(emscripten_int8x16_greaterThan(v, w)); + DUMP(emscripten_int8x16_greaterThanOrEqual(v, w)); + DUMP(emscripten_int8x16_equal(v, w)); + DUMP(emscripten_int8x16_notEqual(v, w)); +// DUMPINT(emscripten_int8x16_anyTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int8x16->bool8x16 and enable this, or remove if this doesn't make sense. +// DUMPINT(emscripten_int8x16_allTrue(v)); // XXX TODO: Figure out if there is a no-op cast from int8x16->bool8x16 and enable this, or remove if this doesn't make sense. + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 0)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 1)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 2)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 16)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 32)); + DUMP(emscripten_int8x16_shiftLeftByScalar(v, 48)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 0)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 1)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 2)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 16)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 32)); + DUMP(emscripten_int8x16_shiftRightByScalar(v, 48)); + bool32x4 b = emscripten_int8x16_set(0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1); + DUMP(emscripten_int8x16_select(b, v, w)); + DUMP(emscripten_int8x16_addSaturate(v, w)); + DUMP(emscripten_int8x16_subSaturate(v, w)); + DUMP(emscripten_int8x16_replaceLane(v, 0, 9)); + DUMP(emscripten_int8x16_replaceLane(v, 1, 3)); + DUMP(emscripten_int8x16_replaceLane(v, 2, 0)); + DUMP(emscripten_int8x16_replaceLane(v, 3, 91)); + DUMP(emscripten_int8x16_replaceLane(v, 4, 127)); + DUMP(emscripten_int8x16_replaceLane(v, 5, 100)); + DUMP(emscripten_int8x16_replaceLane(v, 6, -100)); + DUMP(emscripten_int8x16_replaceLane(v, 7, -128)); + DUMP(emscripten_int8x16_replaceLane(v, 8, 9)); + DUMP(emscripten_int8x16_replaceLane(v, 9, 3)); + DUMP(emscripten_int8x16_replaceLane(v, 10, 0)); + DUMP(emscripten_int8x16_replaceLane(v, 11, 91)); + DUMP(emscripten_int8x16_replaceLane(v, 12, 127)); + DUMP(emscripten_int8x16_replaceLane(v, 13, 100)); + DUMP(emscripten_int8x16_replaceLane(v, 14, -100)); + DUMP(emscripten_int8x16_replaceLane(v, 15, -128)); + uint8_t bytes[16]; + memset(bytes, 0xFF, sizeof(bytes)); + emscripten_int8x16_store(bytes, v); + DUMPBYTES("emscripten_int8x16_store", bytes); + DUMP(emscripten_int8x16_load(bytes)); + // TODO: emscripten_int8x16_fromFloat64x2Bits + // TODO: emscripten_int8x16_fromint8x16Bits + // TODO: emscripten_int8x16_fromUint8x16Bits + // TODO: emscripten_int8x16_fromInt8x16Bits + // TODO: emscripten_int8x16_fromUint8x16Bits + // TODO: emscripten_int8x16_fromInt8x16Bits + // TODO: emscripten_int8x16_fromUint8x16Bits + // TODO: emscripten_int8x16_fromint8x16 + // TODO: emscripten_int8x16_fromUint8x16 + DUMP(emscripten_int8x16_swizzle(v, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)); + DUMP(emscripten_int8x16_swizzle(v, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)); + DUMP(emscripten_int8x16_swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + DUMP(emscripten_int8x16_swizzle(v, 0, 3, 0, 3, 7, 1, 2, 6, 9, 14, 5, 12, 15, 4, 10, 2)); + DUMP(emscripten_int8x16_swizzle(v, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)); + int8x16 z = emscripten_int8x16_set(-5, 20, 14, 9, 0, 11, 120, -120, 40, 50, 60, 70, 80, 90, 100, 110); + DUMP(z); + DUMP(emscripten_int8x16_shuffle(v, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + DUMP(emscripten_int8x16_shuffle(v, z, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)); + DUMP(emscripten_int8x16_shuffle(v, z, 15, 15, 15, 15, 7, 7, 7, 7, 31, 31, 31, 31, 15, 14, 13, 12)); + DUMP(emscripten_int8x16_shuffle(v, z, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30)); + DUMP(emscripten_int8x16_shuffle(v, z, 7, 0, 3, 5, 9, 11, 1, 4, 6, 12, 19, 4, 9, 0, 2, 3)); + printf("Done!\n"); +} diff --git a/tests/core/test_simd_int8x16.out b/tests/core/test_simd_int8x16.out new file mode 100644 index 0000000000000..f56a2e7163e98 --- /dev/null +++ b/tests/core/test_simd_int8x16.out @@ -0,0 +1,61 @@ +v: 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +w: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 +emscripten_int8x16_add(v, w): 3 2 3 -127 0 11 15 -126 5 21 75 -51 44 68 12 102 +emscripten_int8x16_sub(v, w): -1 -2 -1 125 -4 7 11 126 1 17 71 -55 40 64 8 98 +emscripten_int8x16_mul(v, w): 2 0 2 -2 -4 18 26 0 6 38 -110 -106 84 -124 20 -56 +emscripten_int8x16_neg(v): -1 0 -1 -127 2 -9 -13 -128 -3 -19 -73 53 -42 -66 -10 -100 +emscripten_int8x16_and(v, w): 0 0 0 2 2 0 0 0 2 2 0 2 2 2 2 0 +emscripten_int8x16_xor(v, w): 3 2 3 125 -4 11 15 -126 1 17 75 -55 40 64 8 102 +emscripten_int8x16_or(v, w): 3 2 3 127 -2 11 15 -126 3 19 75 -53 42 66 10 102 +emscripten_int8x16_not(v): -2 -1 -2 -128 1 -10 -14 127 -4 -20 -74 52 -43 -67 -11 -101 +emscripten_int8x16_lessThan(v, w): -1 -1 -1 0 -1 0 0 -1 0 0 0 -1 0 0 0 0 +emscripten_int8x16_lessThanOrEqual(v, w): -1 -1 -1 0 -1 0 0 -1 0 0 0 -1 0 0 0 0 +emscripten_int8x16_greaterThan(v, w): 0 0 0 -1 0 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 +emscripten_int8x16_greaterThanOrEqual(v, w): 0 0 0 -1 0 -1 -1 0 -1 -1 -1 0 -1 -1 -1 -1 +emscripten_int8x16_equal(v, w): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +emscripten_int8x16_notEqual(v, w): -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 +emscripten_int8x16_shiftLeftByScalar(v, 0): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftLeftByScalar(v, 1): 2 0 2 -2 -4 18 26 0 6 38 -110 -106 84 -124 20 -56 +emscripten_int8x16_shiftLeftByScalar(v, 2): 4 0 4 -4 -8 36 52 0 12 76 36 44 -88 8 40 -112 +emscripten_int8x16_shiftLeftByScalar(v, 16): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +emscripten_int8x16_shiftLeftByScalar(v, 32): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +emscripten_int8x16_shiftLeftByScalar(v, 48): 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +emscripten_int8x16_shiftRightByScalar(v, 0): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_shiftRightByScalar(v, 1): 0 0 0 63 -1 4 6 -64 1 9 36 -27 21 33 5 50 +emscripten_int8x16_shiftRightByScalar(v, 2): 0 0 0 31 -1 2 3 -32 0 4 18 -14 10 16 2 25 +emscripten_int8x16_shiftRightByScalar(v, 16): 0 0 0 0 -1 0 0 -1 0 0 0 -1 0 0 0 0 +emscripten_int8x16_shiftRightByScalar(v, 32): 0 0 0 0 -1 0 0 -1 0 0 0 -1 0 0 0 0 +emscripten_int8x16_shiftRightByScalar(v, 48): 0 0 0 0 -1 0 0 -1 0 0 0 -1 0 0 0 0 +emscripten_int8x16_select(b, v, w): 2 0 2 127 2 9 2 -128 2 19 2 -53 2 66 2 100 +emscripten_int8x16_addSaturate(v, w): 3 2 3 127 0 11 15 -126 5 21 75 -51 44 68 12 102 +emscripten_int8x16_subSaturate(v, w): -1 -2 -1 125 -4 7 11 -128 1 17 71 -55 40 64 8 98 +emscripten_int8x16_replaceLane(v, 0, 9): 9 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 1, 3): 1 3 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 2, 0): 1 0 0 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 3, 91): 1 0 1 91 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 4, 127): 1 0 1 127 127 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 5, 100): 1 0 1 127 -2 100 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 6, -100): 1 0 1 127 -2 9 -100 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 7, -128): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 8, 9): 1 0 1 127 -2 9 13 -128 9 19 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 9, 3): 1 0 1 127 -2 9 13 -128 3 3 73 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 10, 0): 1 0 1 127 -2 9 13 -128 3 19 0 -53 42 66 10 100 +emscripten_int8x16_replaceLane(v, 11, 91): 1 0 1 127 -2 9 13 -128 3 19 73 91 42 66 10 100 +emscripten_int8x16_replaceLane(v, 12, 127): 1 0 1 127 -2 9 13 -128 3 19 73 -53 127 66 10 100 +emscripten_int8x16_replaceLane(v, 13, 100): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 100 10 100 +emscripten_int8x16_replaceLane(v, 14, -100): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 -100 100 +emscripten_int8x16_replaceLane(v, 15, -128): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 -128 +emscripten_int8x16_store: 01 00 01 7F FE 09 0D 80 03 13 49 CB 2A 42 0A 64 +emscripten_int8x16_load(bytes): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_swizzle(v, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15): 1 0 1 127 -2 9 13 -128 3 19 73 -53 42 66 10 100 +emscripten_int8x16_swizzle(v, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0): 100 10 66 42 -53 73 19 3 -128 13 9 -2 127 1 0 1 +emscripten_int8x16_swizzle(v, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0): 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +emscripten_int8x16_swizzle(v, 0, 3, 0, 3, 7, 1, 2, 6, 9, 14, 5, 12, 15, 4, 10, 2): 1 127 1 127 -128 0 1 13 19 10 9 42 100 -2 73 1 +emscripten_int8x16_swizzle(v, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3): 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 127 +z: -5 20 14 9 0 11 120 -120 40 50 60 70 80 90 100 110 +emscripten_int8x16_shuffle(v, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0): 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +emscripten_int8x16_shuffle(v, z, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4): -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 +emscripten_int8x16_shuffle(v, z, 15, 15, 15, 15, 7, 7, 7, 7, 31, 31, 31, 31, 15, 14, 13, 12): 100 100 100 100 -128 -128 -128 -128 110 110 110 110 100 10 66 42 +emscripten_int8x16_shuffle(v, z, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30): 1 1 -2 13 3 73 42 10 -5 14 0 120 40 60 80 100 +emscripten_int8x16_shuffle(v, z, 7, 0, 3, 5, 9, 11, 1, 4, 6, 12, 19, 4, 9, 0, 2, 3): -128 1 127 9 19 -53 0 -2 13 42 9 -2 19 1 1 127 +Done! \ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index ce00474c3f67a..5f301e98cbdce 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -5950,6 +5950,31 @@ def test_simd16(self): self.emcc_args = self.emcc_args + ['-msse', '-msse2'] self.do_run_from_file(src, output) + @SIMD + def test_simd_float64x2(self): + src, output = (path_from_root('tests', 'core', 'test_simd_float64x2') + s for s in ('.c', '.out')) + self.do_run_from_file(src, output) + + @SIMD + def test_simd_float32x4(self): + src, output = (path_from_root('tests', 'core', 'test_simd_float32x4') + s for s in ('.c', '.out')) + self.do_run_from_file(src, output) + + @SIMD + def test_simd_int32x4(self): + src, output = (path_from_root('tests', 'core', 'test_simd_int32x4') + s for s in ('.c', '.out')) + self.do_run_from_file(src, output) + + @SIMD + def test_simd_int16x8(self): + src, output = (path_from_root('tests', 'core', 'test_simd_int16x8') + s for s in ('.c', '.out')) + self.do_run_from_file(src, output) + + @SIMD + def test_simd_int8x16(self): + src, output = (path_from_root('tests', 'core', 'test_simd_int8x16') + s for s in ('.c', '.out')) + self.do_run_from_file(src, output) + @SIMD def test_simd_dyncall(self): test_path = path_from_root('tests', 'core', 'test_simd_dyncall')