Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wasmx/fizzy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0ba721731c4f99bcaddf70c51c9903b5cf3b9f1d
Choose a base ref
..
head repository: wasmx/fizzy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ff0b51a6d6865635aaa858c39bee75c417c89b4c
Choose a head ref
Showing with 65 additions and 36 deletions.
  1. +41 −6 lib/fizzy/instantiate.hpp
  2. +24 −30 test/testfloat/CMakeLists.txt
47 changes: 41 additions & 6 deletions lib/fizzy/instantiate.hpp
Original file line number Diff line number Diff line change
@@ -107,20 +107,37 @@ using bytes_ptr = std::unique_ptr<bytes, void (*)(bytes*)>;
/// The module instance.
struct Instance
{
/// Module of this instance.
std::unique_ptr<const Module> module;
// Memory is either allocated and owned by the instance or imported as already allocated bytes
// and owned externally.
// For these cases unique_ptr would either have a normal deleter or noop deleter respectively

/// Instance memory.
/// Memory is either allocated and owned by the instance or imported as already allocated bytes
/// and owned externally.
/// For these cases unique_ptr would either have a normal deleter or no-op deleter respectively
bytes_ptr memory = {nullptr, [](bytes*) {}};

/// Memory limits.
Limits memory_limits;
// Hard limit for memory growth in pages, checked when memory is defined as unbounded in module

/// Hard limit for memory growth in pages, checked when memory is defined as unbounded in
/// module.
uint32_t memory_pages_limit = 0;
// Table is either allocated and owned by the instance or imported and owned externally.
// For these cases unique_ptr would either have a normal deleter or noop deleter respectively.

/// Instance table.
/// Table is either allocated and owned by the instance or imported and owned externally.
/// For these cases unique_ptr would either have a normal deleter or no-op deleter respectively.
table_ptr table = {nullptr, [](table_elements*) {}};

/// Table limits.
Limits table_limits;

/// Instance globals (excluding imported globals).
std::vector<Value> globals;

/// Imported functions.
std::vector<ExternalFunction> imported_functions;

/// Imported globals.
std::vector<ExternalGlobal> imported_globals;

Instance(std::unique_ptr<const Module> _module, bytes_ptr _memory, Limits _memory_limits,
@@ -150,10 +167,19 @@ std::unique_ptr<Instance> instantiate(std::unique_ptr<const Module> module,
/// Function that should be used by instantiate as import, identified by module and function name.
struct ImportedFunction
{
/// Module name.
std::string module;

/// Function name.
std::string name;

/// Array of input types.
std::vector<ValType> inputs;

/// Output type or empty optional if function has void return type.
std::optional<ValType> output;

/// Function object, which will be called to execute the function.
ExecuteFunction function;
};

@@ -166,10 +192,19 @@ std::vector<ExternalFunction> resolve_imported_functions(
/// Global that should be used by instantiate as import, identified by module and global name.
struct ImportedGlobal
{
/// Module name.
std::string module;

/// Global name.
std::string name;

/// Pointer to global value.
Value* value = nullptr;

/// Value type of global.
ValType type = ValType::i32;

/// Mutability of global.
bool is_mutable = false;
};

54 changes: 24 additions & 30 deletions test/testfloat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -30,48 +30,47 @@ if(TESTFLOAT_GEN)

set(ROUNDING_MODES near_even minMag min max)

set(
ROUNDING_DEPENDENT_FUNCTIONS
# Arithmetic functions: sensitive to rounding and NaNs.
set(ARITHMETIC_FUNCTIONS
f32_sqrt f64_sqrt
f32_add f64_add
f32_sub f64_sub
f32_mul f64_mul
f32_div f64_div
f32_div f64_div)

i32_to_f32 ui32_to_f32 i64_to_f32 ui64_to_f32 i64_to_f64 ui64_to_f64
f64_to_f32
)
# Comparison functions: insensitive to rounding and NaNs.
set(COMPARISON_FUNCTIONS
f32_eq f64_eq f32_lt f64_lt f32_le f64_le)

set(
ROUNDING_INDEPENDENT_FUNCTIONS
f32_eq f64_eq f32_lt f64_lt f32_le f64_le
# Conversion functions sensitive to rounding.
set(INEXACT_CONVERSION_FUNCTIONS
i32_to_f32 ui32_to_f32 i64_to_f32 ui64_to_f32 i64_to_f64 ui64_to_f64
f64_to_f32)

# Always exact -> no rounding
# Conversion functions which are always exact -> no rounding.
set(EXACT_CONVERSION_FUNCTIONS
i32_to_f64 ui32_to_f64
f32_to_f64
)
f32_to_f64)

set(
TRUNC_FUNCTIONS
f32_trunc_to_i32 f32_trunc_to_ui32 f32_trunc_to_i64 f32_trunc_to_ui64 f64_trunc_to_i32 f64_trunc_to_ui32 f64_trunc_to_i64 f64_trunc_to_ui64
)
# Truncate conversion functions - the minMag rounding mode is forced.
set(TRUNC_FUNCTIONS
f32_trunc_to_i32 f32_trunc_to_ui32 f32_trunc_to_i64 f32_trunc_to_ui64
f64_trunc_to_i32 f64_trunc_to_ui32 f64_trunc_to_i64 f64_trunc_to_ui64)

# Here we need to map Wasm function to testfloat_gen arguments as Wasm has multiple functions
# with non-sticky rounding direction while testfloat_gen has single function and rounding
# direction options.
#
# TODO: NaNs are ignored for these as Fizzy always return nan:canonical.
set(
ROUND_TO_INT_FUNCTIONS
set(ROUND_TO_INT_FUNCTIONS
"f32_ceil\;-rmax f32_roundToInt"
"f32_floor\;-rmin f32_roundToInt"
"f32_trunc\;-rminMag f32_roundToInt"
"f32_nearest\;-rnear_even f32_roundToInt"
"f64_ceil\;-rmax f64_roundToInt"
"f64_floor\;-rmin f64_roundToInt"
"f64_trunc\;-rminMag f64_roundToInt"
"f64_nearest\;-rnear_even f64_roundToInt"
)
"f64_nearest\;-rnear_even f64_roundToInt")


macro(add_testfloat_test NAME TESTFLOAT_GEN_ARGS FIZZY_TESTFLOAT_ARGS)
@@ -88,13 +87,15 @@ if(TESTFLOAT_GEN)
endif()
endmacro()

foreach(FUNCTION ${ROUNDING_DEPENDENT_FUNCTIONS})
# Rounding sensitive functions - rounding mode must agree.
foreach(FUNCTION ${ARITHMETIC_FUNCTIONS} ${INEXACT_CONVERSION_FUNCTIONS})
foreach(ROUNDING_MODE ${ROUNDING_MODES})
add_testfloat_test(${FUNCTION}/${ROUNDING_MODE} "-r${ROUNDING_MODE} ${FUNCTION}" "-r${ROUNDING_MODE} ${FUNCTION}")
endforeach()
endforeach()

foreach(FUNCTION ${ROUNDING_INDEPENDENT_FUNCTIONS})
# Rounding insensitive functions - testfloat_gen generates rounding-independent test cases.
foreach(FUNCTION ${COMPARISON_FUNCTIONS} ${EXACT_CONVERSION_FUNCTIONS})
foreach(ROUNDING_MODE ${ROUNDING_MODES})
add_testfloat_test(${FUNCTION}/${ROUNDING_MODE} "${FUNCTION}" "-r${ROUNDING_MODE} ${FUNCTION}")
endforeach()
@@ -123,16 +124,9 @@ endif()
# fizzy-testfloat selftests

function(add_testfloat_selftest NAME ARGS INPUT EXPECTED_ERROR)
if(INPUT)
set(command sh -c "echo ${INPUT} | $<TARGET_FILE:fizzy-testfloat> ${ARGS}")
else()
separate_arguments(ARGS)
set(command $<TARGET_FILE:fizzy-testfloat> ${ARGS})
endif()

add_test(
NAME fizzy/testfloat/selftest/${NAME}
COMMAND ${command}
COMMAND sh -c "$<$<BOOL:${INPUT}>:echo ${INPUT} | >$<TARGET_FILE:fizzy-testfloat> ${ARGS}"
)

if(EXPECTED_ERROR)