forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request emscripten-core#4075 from juj/simd_intrinsics_fixes
Simd intrinsics fixes
- Loading branch information
Showing
14 changed files
with
810 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include <emscripten/vector.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <inttypes.h> | ||
|
||
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include <emscripten/vector.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <inttypes.h> | ||
|
||
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"); | ||
} |
Oops, something went wrong.