Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8500 from EOSIO/wavm_plat_intrin_removal
Browse files Browse the repository at this point in the history
remove old WAVM Platform files and WAVM intrinsics
  • Loading branch information
spoonincode authored Feb 14, 2020
2 parents 0637a70 + 9a04e87 commit 9eb7fd4
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 1,228 deletions.
2 changes: 0 additions & 2 deletions CMakeModules/EosioTester.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ find_library(libwasm WASM @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/li
find_library(libwast WAST @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libwabt wabt @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libir IR @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libplatform Platform @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(liblogging Logging @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libruntime Runtime @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libsoftfloat softfloat @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
Expand Down Expand Up @@ -93,7 +92,6 @@ macro(add_eosio_test_executable test_name)
${libwasm}
${libwabt}
${libruntime}
${libplatform}
${libir}
${libsoftfloat}
${liboscrypto}
Expand Down
2 changes: 0 additions & 2 deletions CMakeModules/EosioTesterBuild.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ find_library(libwasm WASM @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/WASM NO_D
find_library(libwast WAST @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/WAST NO_DEFAULT_PATH)
find_library(libir IR @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/IR NO_DEFAULT_PATH)
find_library(libwabt wabt @CMAKE_BINARY_DIR@/libraries/wabt NO_DEFAULT_PATH)
find_library(libplatform Platform @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/Platform NO_DEFAULT_PATH)
find_library(liblogging Logging @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/Logging NO_DEFAULT_PATH)
find_library(libruntime Runtime @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/Runtime NO_DEFAULT_PATH)
find_library(libsoftfloat softfloat @CMAKE_BINARY_DIR@/libraries/softfloat NO_DEFAULT_PATH)
Expand Down Expand Up @@ -92,7 +91,6 @@ macro(add_eosio_test_executable test_name)
${libwasm}
${libwabt}
${libruntime}
${libplatform}
${libir}
${libsoftfloat}
${liboscrypto}
Expand Down
1 change: 0 additions & 1 deletion libraries/wasm-jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ add_subdirectory(Include/Inline)

add_subdirectory(Source/IR)
add_subdirectory(Source/Logging)
add_subdirectory(Source/Platform)
add_subdirectory(Source/Runtime)
add_subdirectory(Source/WASM)
add_subdirectory(Source/WAST)
Expand Down
176 changes: 12 additions & 164 deletions libraries/wasm-jit/Include/Platform/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@
#include "Inline/BasicTypes.h"
#include "Inline/Errors.h"

#ifdef _WIN32
#define THREAD_LOCAL thread_local
#define DLL_EXPORT __declspec(dllexport)
#define DLL_IMPORT __declspec(dllimport)
#define FORCEINLINE __forceinline
#define SUPPRESS_UNUSED(variable) (void)(variable);
#include <intrin.h>
#define PACKED_STRUCT(definition) __pragma(pack(push, 1)) definition; __pragma(pack(pop))
#else
// Use __thread instead of the C++11 thread_local because Apple's clang doesn't support thread_local yet.
#define THREAD_LOCAL __thread
#define DLL_EXPORT
#define DLL_IMPORT
#define FORCEINLINE inline __attribute__((always_inline))
#define SUPPRESS_UNUSED(variable) (void)(variable);
#define PACKED_STRUCT(definition) definition __attribute__((packed));
#endif
// Use __thread instead of the C++11 thread_local because Apple's clang doesn't support thread_local yet.
#define THREAD_LOCAL __thread
#define DLL_EXPORT
#define DLL_IMPORT
#define FORCEINLINE inline __attribute__((always_inline))
#define SUPPRESS_UNUSED(variable) (void)(variable);
#define PACKED_STRUCT(definition) definition __attribute__((packed));

#ifndef PLATFORM_API
#define PLATFORM_API DLL_IMPORT
Expand All @@ -31,155 +21,13 @@
namespace Platform
{
// countLeadingZeroes/countTrailingZeroes returns the number of leading/trailing zeroes, or the bit width of the input if no bits are set.
#ifdef _WIN32
// BitScanReverse/BitScanForward return 0 if the input is 0.
inline U32 countLeadingZeroes(U32 value) { unsigned long result; return _BitScanReverse(&result,value) ? (31 - result) : 32; }
inline U32 countTrailingZeroes(U32 value) { unsigned long result; return _BitScanForward(&result,value) ? result : 32; }

#ifdef _WIN64
inline U64 countLeadingZeroes(U64 value) { unsigned long result; return _BitScanReverse64(&result,value) ? (63 - result) : 64; }
inline U64 countTrailingZeroes(U64 value) { unsigned long result; return _BitScanForward64(&result,value) ? result : 64; }
#else
inline U64 countLeadingZeroes(U64 value) { throw; }
inline U64 countTrailingZeroes(U64 value) { throw; }
#endif
#else
// __builtin_clz/__builtin_ctz are undefined if the input is 0.
inline U64 countLeadingZeroes(U64 value) { return value == 0 ? 64 : __builtin_clzll(value); }
inline U32 countLeadingZeroes(U32 value) { return value == 0 ? 32 : __builtin_clz(value); }
inline U64 countTrailingZeroes(U64 value) { return value == 0 ? 64 : __builtin_ctzll(value); }
inline U32 countTrailingZeroes(U32 value) { return value == 0 ? 32 : __builtin_ctz(value); }
#endif
// __builtin_clz/__builtin_ctz are undefined if the input is 0.
inline U64 countLeadingZeroes(U64 value) { return value == 0 ? 64 : __builtin_clzll(value); }
inline U32 countLeadingZeroes(U32 value) { return value == 0 ? 32 : __builtin_clz(value); }
inline U64 countTrailingZeroes(U64 value) { return value == 0 ? 64 : __builtin_ctzll(value); }
inline U32 countTrailingZeroes(U32 value) { return value == 0 ? 32 : __builtin_ctz(value); }
inline U64 floorLogTwo(U64 value) { return value <= 1 ? 0 : 63 - countLeadingZeroes(value); }
inline U32 floorLogTwo(U32 value) { return value <= 1 ? 0 : 31 - countLeadingZeroes(value); }
inline U64 ceilLogTwo(U64 value) { return floorLogTwo(value * 2 - 1); }
inline U32 ceilLogTwo(U32 value) { return floorLogTwo(value * 2 - 1); }

//
// Memory
//

// Describes allowed memory accesses.
enum class MemoryAccess
{
None,
ReadOnly,
ReadWrite,
Execute,
ReadWriteExecute
};

// Returns the base 2 logarithm of the smallest virtual page size.
PLATFORM_API Uptr getPageSizeLog2();

// Allocates virtual addresses without commiting physical pages to them.
// Returns the base virtual address of the allocated addresses, or nullptr if the virtual address space has been exhausted.
PLATFORM_API U8* allocateVirtualPages(Uptr numPages);

// Commits physical memory to the specified virtual pages.
// baseVirtualAddress must be a multiple of the preferred page size.
// Return true if successful, or false if physical memory has been exhausted.
PLATFORM_API bool commitVirtualPages(U8* baseVirtualAddress,Uptr numPages,MemoryAccess access = MemoryAccess::ReadWrite);

// Changes the allowed access to the specified virtual pages.
// baseVirtualAddress must be a multiple of the preferred page size.
// Return true if successful, or false if the access-level could not be set.
PLATFORM_API bool setVirtualPageAccess(U8* baseVirtualAddress,Uptr numPages,MemoryAccess access);

// Decommits the physical memory that was committed to the specified virtual pages.
// baseVirtualAddress must be a multiple of the preferred page size.
PLATFORM_API void decommitVirtualPages(U8* baseVirtualAddress,Uptr numPages);

// Frees virtual addresses. Any physical memory committed to the addresses must have already been decommitted.
// baseVirtualAddress must be a multiple of the preferred page size.
PLATFORM_API void freeVirtualPages(U8* baseVirtualAddress,Uptr numPages);

//
// Call stack and exceptions
//

// Describes a call stack.
struct CallStack
{
struct Frame
{
Uptr ip;
};
std::vector<Frame> stackFrames;
};

// Captures the execution context of the caller.
PLATFORM_API CallStack captureCallStack(Uptr numOmittedFramesFromTop = 0);

// Describes an instruction pointer.
PLATFORM_API bool describeInstructionPointer(Uptr ip,std::string& outDescription);

#ifdef _WIN64
// Registers/deregisters the data used by Windows SEH to unwind stack frames.
PLATFORM_API void registerSEHUnwindInfo(Uptr imageLoadAddress,Uptr pdataAddress,Uptr pdataNumBytes);
PLATFORM_API void deregisterSEHUnwindInfo(Uptr pdataAddress);
#endif

// Calls a thunk, and if it causes any of some specific hardware traps, returns true.
// If a trap was caught, the outCause, outContext, and outOperand parameters are set to describe the trap.
enum HardwareTrapType
{
none,
accessViolation,
stackOverflow,
intDivideByZeroOrOverflow
};
PLATFORM_API HardwareTrapType catchHardwareTraps(
CallStack& outTrapCallStack,
Uptr& outTrapOperand,
const std::function<void()>& thunk
);
PLATFORM_API [[noreturn]] void immediately_exit(std::exception_ptr except);

//
// Threading
//

// Returns the current value of a clock that may be used as an absolute time for wait timeouts.
// The resolution is microseconds, and the origin is arbitrary.
PLATFORM_API U64 getMonotonicClock();

// Platform-independent mutexes.
struct Mutex;
PLATFORM_API Mutex* createMutex();
PLATFORM_API void destroyMutex(Mutex* mutex);
PLATFORM_API void lockMutex(Mutex* mutex);
PLATFORM_API void unlockMutex(Mutex* mutex);

// RAII-style lock for Mutex.
struct Lock
{
Lock(Mutex* inMutex) : mutex(inMutex) { lockMutex(mutex); }
~Lock() { unlockMutex(mutex); }

void release()
{
if(mutex)
{
unlockMutex(mutex);
}
mutex = nullptr;
}

void detach()
{
WAVM_ASSERT_THROW(mutex);
mutex = nullptr;
}

private:
Mutex* mutex;
};

// Platform-independent events.
struct Event;
PLATFORM_API Event* createEvent();
PLATFORM_API void destroyEvent(Event* event);
PLATFORM_API bool waitForEvent(Event* event,U64 untilClock);
PLATFORM_API void signalEvent(Event* event);
}
1 change: 0 additions & 1 deletion libraries/wasm-jit/Source/Logging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ include_directories(${WAVM_INCLUDE_DIR}/Logging)
add_definitions(-DLOGGING_API=DLL_EXPORT)

add_library(Logging STATIC ${Sources} ${PublicHeaders})
target_link_libraries(Logging Platform)

# Link with dl on Linux for dladdr.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
Expand Down
4 changes: 0 additions & 4 deletions libraries/wasm-jit/Source/Logging/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Log
{
static Platform::Mutex* categoryEnabledMutex = Platform::createMutex();
static bool categoryEnabled[(Uptr)Category::num] =
{
true, // error
Expand All @@ -20,19 +19,16 @@ namespace Log
};
void setCategoryEnabled(Category category,bool enable)
{
Platform::Lock lock(categoryEnabledMutex);
WAVM_ASSERT_THROW(category < Category::num);
categoryEnabled[(Uptr)category] = enable;
}
bool isCategoryEnabled(Category category)
{
Platform::Lock lock(categoryEnabledMutex);
WAVM_ASSERT_THROW(category < Category::num);
return categoryEnabled[(Uptr)category];
}
void printf(Category category,const char* format,...)
{
Platform::Lock lock(categoryEnabledMutex);
if(categoryEnabled[(Uptr)category])
{
va_list varArgs;
Expand Down
20 changes: 0 additions & 20 deletions libraries/wasm-jit/Source/Platform/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 9eb7fd4

Please sign in to comment.