-
Notifications
You must be signed in to change notification settings - Fork 29
Fixes FP rounding issue and adds tests #166
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
Open
jsturtevant
wants to merge
1
commit into
hyperlight-dev:main
Choose a base branch
from
jsturtevant:fp-rounding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use examples_common::get_wasm_module_path; | ||
use hyperlight_wasm::SandboxBuilder; | ||
|
||
use crate::bindings::example::runcomponent::Guest; | ||
|
||
extern crate alloc; | ||
mod bindings { | ||
hyperlight_component_macro::host_bindgen!( | ||
"../../src/wasmsamples/components/runcomponent-world.wasm" | ||
); | ||
} | ||
|
||
pub struct State {} | ||
impl State { | ||
pub fn new() -> Self { | ||
State {} | ||
} | ||
} | ||
|
||
impl Default for State { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl bindings::example::runcomponent::Host for State { | ||
fn r#get_time_since_boot_microsecond(&mut self) -> i64 { | ||
let res = std::time::SystemTime::now() | ||
.duration_since(std::time::SystemTime::UNIX_EPOCH) | ||
.unwrap() | ||
.as_micros(); | ||
i64::try_from(res).unwrap() | ||
} | ||
} | ||
|
||
impl bindings::example::runcomponent::RuncomponentImports for State { | ||
type Host = State; | ||
|
||
fn r#host(&mut self) -> impl ::core::borrow::BorrowMut<Self::Host> { | ||
self | ||
} | ||
} | ||
|
||
fn main() { | ||
let state = State::new(); | ||
let mut sandbox = SandboxBuilder::new() | ||
.with_guest_input_buffer_size(70000000) | ||
.with_guest_heap_size(200000000) | ||
.with_guest_stack_size(100000000) | ||
//.with_debugging_enabled(8080) | ||
.build() | ||
.unwrap(); | ||
let rt = bindings::register_host_functions(&mut sandbox, state); | ||
|
||
let sb = sandbox.load_runtime().unwrap(); | ||
|
||
let mod_path = get_wasm_module_path("runcomponent.aot").unwrap(); | ||
let sb = sb.load_module(mod_path).unwrap(); | ||
|
||
let mut wrapped = bindings::RuncomponentSandbox { sb, rt }; | ||
let instance = bindings::example::runcomponent::RuncomponentExports::guest(&mut wrapped); | ||
let echo = instance.echo("Hello World!".to_string()); | ||
println!("{}", echo); | ||
|
||
let result = instance.round_to_nearest_int(1.331, 24.0); | ||
println!("rounded result {}", result); | ||
assert_eq!(result, 32); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
#include "bindings/runcomponent.h" | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <math.h> | ||
|
||
void exports_example_runcomponent_guest_echo(runcomponent_string_t *msg, runcomponent_string_t *ret) | ||
{ | ||
ret->len = msg->len; | ||
ret->ptr = (uint8_t *) malloc(ret->len); | ||
memcpy(ret->ptr, msg->ptr, ret->len); | ||
runcomponent_string_free(msg); | ||
} | ||
|
||
int32_t exports_example_runcomponent_guest_round_to_nearest_int(float a, float b) | ||
{ | ||
float c = a*b; | ||
float r = lrintf(c); | ||
return r; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turning off soft-float might cause issues with
hyperlight-wasm/src/wasm_runtime/src/marshal.rs
Lines 353 to 354 in 7775121