Skip to content

Commit

Permalink
Started soft float tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larryk85 committed Mar 15, 2018
1 parent 71e801c commit 83a4a26
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 2 deletions.
1 change: 1 addition & 0 deletions contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/*")

Expand Down
27 changes: 27 additions & 0 deletions contracts/eosiolib/datastream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions contracts/floattest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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}
)

21 changes: 21 additions & 0 deletions contracts/floattest/floattest.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"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": []
}
9 changes: 9 additions & 0 deletions contracts/floattest/floattest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <floattest/floattest.hpp>

namespace floattest {
extern "C" {
void apply( uint64_t code, uint64_t action ) {
eosio::dispatch<floattest, floattest::f32add>(code, action);
}
}
}
37 changes: 37 additions & 0 deletions contracts/floattest/floattest.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @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
19 changes: 17 additions & 2 deletions libraries/chain/include/eosio/chain/wasm_eosio_injection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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;
};
Expand All @@ -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>;
Expand Down Expand Up @@ -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>;
Expand Down

0 comments on commit 83a4a26

Please sign in to comment.