Skip to content

[Memory64] embind C++ changes for 64-bit #15226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions system/include/emscripten/val.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <emscripten/wire.h>
#include <array>
#include <vector>
#include <climits>


namespace emscripten {
Expand Down Expand Up @@ -189,10 +190,15 @@ namespace emscripten {
union {
unsigned u;
float f;
#if __ILP32__
const void* p;
#endif
} w[2];
double d;
uint64_t u;
#if __LP64__
const void* p;
#endif
};
static_assert(sizeof(GenericWireType) == 8, "GenericWireType must be 8 bytes");
static_assert(alignof(GenericWireType) == 8, "GenericWireType must be 8-byte-aligned");
Expand All @@ -219,14 +225,29 @@ namespace emscripten {

template<typename T>
void writeGenericWireType(GenericWireType*& cursor, T* wt) {
#if __ILP32__
cursor->w[0].p = wt;
#else
cursor->p = wt;
// FIXME: This requires the JS reading code to be audited to be compatible with it.
assert(false);
abort();
#endif
++cursor;
}

template<typename ElementType>
inline void writeGenericWireType(GenericWireType*& cursor, const memory_view<ElementType>& wt) {
cursor->w[0].u = wt.size;
#if __ILP32__
cursor->w[1].p = wt.data;
#else
// FIXME: need to change GenericWireType such that it can store a 64-bit pointer?
// This requires the JS reading code to be audited to be compatible with it.
cursor->w[1].u = 0;
assert(false);
abort();
#endif
++cursor;
}

Expand Down
3 changes: 2 additions & 1 deletion system/include/emscripten/wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ namespace emscripten {
return (std::is_floating_point<T>::value &&
(sizeof(T) == 4 || sizeof(T) == 8)) ||
(std::is_integral<T>::value &&
(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4));
(sizeof(T) == 1 || sizeof(T) == 2 ||
sizeof(T) == 4 || sizeof(T) == 8));
}
}

Expand Down
6 changes: 5 additions & 1 deletion system/lib/embind/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ enum TypedArrayIndex {
Uint32Array,
Float32Array,
Float64Array,
// Only available if WASM_BIGINT
Int64Array,
Uint64Array,
};

template <typename T> constexpr TypedArrayIndex getTypedArrayIndex() {
Expand All @@ -86,7 +89,8 @@ template <typename T> constexpr TypedArrayIndex getTypedArrayIndex() {
: (sizeof(T) == 1
? (std::is_signed<T>::value ? Int8Array : Uint8Array)
: (sizeof(T) == 2 ? (std::is_signed<T>::value ? Int16Array : Uint16Array)
: (std::is_signed<T>::value ? Int32Array : Uint32Array)));
: (sizeof(T) == 4 ? (std::is_signed<T>::value ? Int32Array : Uint32Array)
: (std::is_signed<T>::value ? Int64Array : Uint64Array))));
}

template <typename T> static void register_memory_view(const char* name) {
Expand Down