提交 83a4a26a 编写于 作者: B Bucky Kittinger

Started soft float tests

上级 71e801c5
......@@ -28,6 +28,7 @@ add_subdirectory(simpledb)
#add_subdirectory(social)
add_subdirectory(test.system)
add_subdirectory(noop)
add_subdirectory(floattest)
file(GLOB SKELETONS RELATIVE ${CMAKE_SOURCE_DIR}/contracts "skeleton/*")
......
......@@ -154,6 +154,33 @@ inline datastream<Stream>& operator>>(datastream<Stream>& ds, key256& d) {
return ds;
}
/**
* Serialize a float into a stream
* @brief Serialize a float
* @param ds stream to write
* @param d value to serialize
*/
template<typename Stream>
inline datastream<Stream>& operator<<(datastream<Stream>& ds, float d) {
uint32_t val = *(uint32_t*)(&d);
ds.write( (const char*)&val, sizeof(val) );
return ds;
}
/**
* Deserialize a float from a stream
* @brief Deserialize a float
* @param ds stream to read
* @param d destination for deserialized value
*/
template<typename Stream>
inline datastream<Stream>& operator>>(datastream<Stream>& ds, float& d) {
uint32_t val = 0;
ds.read((char*)&val, sizeof(val) );
d = *(float*)(&val);
return ds;
}
/**
* Serialize a double into a stream
* @brief Serialize a double
......
file(GLOB ABI_FILES "*.abi")
configure_file("${ABI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
add_wast_executable(TARGET floattest
INCLUDE_FOLDERS "${STANDARD_INCLUDE_FOLDERS}"
LIBRARIES libc++ libc eosiolib
DESTINATION_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)
{
"types": [{
"new_type_name": "account_name",
"type": "name"
}
],
"structs": [{
"name": "f32add",
"base": "",
"fields": [
{ "name" : "test_output", "type" : "vector<float>" }
]
}
],
"actions": [{
"name":"f32add",
"type":"f32add"
}
],
"tables": []
}
#include <floattest/floattest.hpp>
namespace floattest {
extern "C" {
void apply( uint64_t code, uint64_t action ) {
eosio::dispatch<floattest, floattest::f32add>(code, action);
}
}
}
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#pragma once
#include <vector>
#include <eosiolib/eosio.hpp>
#include <eosiolib/dispatcher.hpp>
namespace floattest {
using std::string;
/**
noop contract
All it does is require sender authorization.
Actions: anyaction
*/
class floattest {
public:
ACTION(N(floattest), f32add) {
f32add() { }
f32add( std::vector<float> outs ) : outputs( outs ) {}
std::vector<float> outputs;
EOSLIB_SERIALIZE(f32add, (outputs))
};
static void on(const f32add& act)
{
prints("Hello\n");
}
};
} /// noop
......@@ -151,7 +151,6 @@ namespace eosio { namespace chain { namespace wasm_injections {
static constexpr bool post = true;
static void init() { checktime_idx = -1; }
static void accept( wasm_ops::instr* inst, wasm_ops::visitor_arg& arg ) {
#if 1
// first add the import for checktime
injector_utils::add_import<ResultType::none, ValueType::i32>( *(arg.module), u8"env", u8"checktime", checktime_idx );
......@@ -167,7 +166,6 @@ namespace eosio { namespace chain { namespace wasm_injections {
std::vector<U8> tmp = chktm.pack();
injected.insert( injected.end(), tmp.begin(), tmp.end() );
arg.new_code->insert( arg.new_code->end(), injected.begin(), injected.end() );
#endif
}
static int32_t checktime_idx;
};
......@@ -191,7 +189,22 @@ namespace eosio { namespace chain { namespace wasm_injections {
}
};
// float injections
struct f32_add_injector {
static constexpr bool kills = true;
static constexpr bool post = false;
static void init() {}
static void accept( wasm_ops::instr* inst, wasm_ops::visitor_arg& arg ) {
int32_t idx;
injector_utils::add_import<ResultType::f32, ValueType::f32, ValueType::f32>( *(arg.module), u8"env", u8"f32_add", idx );
wasm_ops::op_types<>::call_t f32add;
f32add.field = idx;
std::vector<U8> injected = f32add.pack();
arg.new_code->insert( arg.new_code->end(), injected.begin(), injected.end() );
}
};
struct pre_op_injectors : wasm_ops::op_types<pass_injector> {
using block_t = wasm_ops::block <instruction_counter, checktime_injector>;
using loop_t = wasm_ops::loop <instruction_counter, checktime_injector>;
......@@ -309,6 +322,8 @@ namespace eosio { namespace chain { namespace wasm_injections {
using i64_rotl_t = wasm_ops::i64_rotl <instruction_counter>;
using i64_rotr_t = wasm_ops::i64_rotr <instruction_counter>;
using f32_add_t = wasm_ops::f32_add <instruction_counter, f32_add_injector>;
using i32_wrap_i64_t = wasm_ops::i32_wrap_i64 <instruction_counter>;
using i64_extend_s_i32_t = wasm_ops::i64_extend_s_i32 <instruction_counter>;
using i64_extend_u_i32_t = wasm_ops::i64_extend_u_i32 <instruction_counter>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册