Skip to content
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

Optimizations #98

Merged
merged 35 commits into from Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4b7c3c0
Define Instruction Set.
pepyakin Jun 12, 2018
48e4704
WIP
pepyakin Jun 12, 2018
81b832f
WIP 2
pepyakin Jun 13, 2018
5dd56d6
Tests
pepyakin Jun 13, 2018
40d73f2
Working
pepyakin Jun 13, 2018
875f73e
Bunch of other tests.
pepyakin Jun 13, 2018
0d59364
WIP
pepyakin Jun 13, 2018
029b052
WIP
pepyakin Jun 14, 2018
77a836f
Use Vec instead of VecDeque.
pepyakin Jun 14, 2018
ae8c834
Calibrate the limits.
pepyakin Jun 14, 2018
259c59f
Clean
pepyakin Jun 14, 2018
15ec33e
Clean
pepyakin Jun 14, 2018
7f07c1c
Another round of cleaning.
pepyakin Jun 14, 2018
bf80ad7
Ignore traces.
pepyakin Jun 14, 2018
c5b8591
Optimize value stack
pepyakin Jun 14, 2018
583bb63
Optimize a bit more.
pepyakin Jun 14, 2018
bdbf10b
Cache memory index.
pepyakin Jun 14, 2018
a16e757
Inline always instruction dispatch function.
pepyakin Jun 14, 2018
d8814fa
Comments.
pepyakin Jun 15, 2018
b16feab
Clean
pepyakin Jun 15, 2018
4e9f394
Clean
pepyakin Jun 15, 2018
3f10ba6
Use vector to keep unresolved references.
pepyakin Jun 15, 2018
bcc426c
Estimate resulting size.
pepyakin Jun 15, 2018
b2b9d62
do refactoring
pepyakin Jun 15, 2018
0f6da82
Validate the locals count in the begging
pepyakin Jun 16, 2018
2900215
Introduce Keep and DropKeep structs in isa
pepyakin Jun 18, 2018
6506705
Rename/Split Validator into Reader
pepyakin Jun 18, 2018
c384da2
Document stack layout
pepyakin Jun 18, 2018
76f6d0e
Remove println!
pepyakin Jun 18, 2018
26ff4c5
Fix typo.
pepyakin Jun 20, 2018
6647bc4
Use .last / .last_mut in stack
pepyakin Jun 20, 2018
4ea0aee
Update docs for BrTable.
pepyakin Jun 21, 2018
b94f9f2
Review fixes.
pepyakin Jun 25, 2018
856a34c
Merge.
pepyakin Jun 29, 2018
b7fff03
Add an assert that stack is empty after the exec
pepyakin Jun 29, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions benches/.gitignore
@@ -1 +1,3 @@
/target
*.trace

3 changes: 3 additions & 0 deletions benches/Cargo.toml
Expand Up @@ -7,3 +7,6 @@ authors = ["Sergey Pepyakin <s.pepyakin@gmail.com>"]
wasmi = { path = ".." }
assert_matches = "1.2"
wabt = "0.3"

[profile.bench]
debug = true
Copy link
Contributor

@NikVolf NikVolf Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cachegrind, although this probably shouldn't be committed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, or Instruments in my case : )

37 changes: 1 addition & 36 deletions src/common/mod.rs
@@ -1,4 +1,3 @@
use parity_wasm::elements::BlockType;

pub mod stack;

Expand All @@ -7,38 +6,4 @@ pub const DEFAULT_MEMORY_INDEX: u32 = 0;
/// Index of default table.
pub const DEFAULT_TABLE_INDEX: u32 = 0;

/// Control stack frame.
#[derive(Debug, Clone)]
pub struct BlockFrame {
/// Frame type.
pub frame_type: BlockFrameType,
/// A signature, which is a block signature type indicating the number and types of result values of the region.
pub block_type: BlockType,
/// A label for reference to block instruction.
pub begin_position: usize,
/// A label for reference from branch instructions.
pub branch_position: usize,
/// A label for reference from end instructions.
pub end_position: usize,
/// A limit integer value, which is an index into the value stack indicating where to reset it to on a branch to that label.
pub value_stack_len: usize,
/// Boolean which signals whether value stack became polymorphic. Value stack starts in non-polymorphic state and
/// becomes polymorphic only after an instruction that never passes control further is executed,
/// i.e. `unreachable`, `br` (but not `br_if`!), etc.
pub polymorphic_stack: bool,
}

/// Type of block frame.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BlockFrameType {
/// Function frame.
Function,
/// Usual block frame.
Block,
/// Loop frame (branching to the beginning of block).
Loop,
/// True-subblock of if expression.
IfTrue,
/// False-subblock of if expression.
IfFalse,
}
// TODO: Move BlockFrame under validation.
17 changes: 6 additions & 11 deletions src/common/stack.rs
@@ -1,5 +1,4 @@

use std::collections::VecDeque;
use std::error;
use std::fmt;

Expand All @@ -22,15 +21,15 @@ impl error::Error for Error {
#[derive(Debug)]
pub struct StackWithLimit<T> where T: Clone {
/// Stack values.
values: VecDeque<T>,
values: Vec<T>,
/// Stack limit (maximal stack len).
limit: usize,
}

impl<T> StackWithLimit<T> where T: Clone {
pub fn with_limit(limit: usize) -> Self {
StackWithLimit {
values: VecDeque::new(),
values: Vec::new(),
limit: limit
}
}
Expand All @@ -43,19 +42,15 @@ impl<T> StackWithLimit<T> where T: Clone {
self.values.len()
}

pub fn limit(&self) -> usize {
self.limit
}

pub fn top(&self) -> Result<&T, Error> {
self.values
.back()
.last()
.ok_or_else(|| Error("non-empty stack expected".into()))
}

pub fn top_mut(&mut self) -> Result<&mut T, Error> {
self.values
.back_mut()
.last_mut()
.ok_or_else(|| Error("non-empty stack expected".into()))
}

Expand All @@ -72,13 +67,13 @@ impl<T> StackWithLimit<T> where T: Clone {
return Err(Error(format!("exceeded stack limit {}", self.limit)));
}

self.values.push_back(value);
self.values.push(value);
Ok(())
}

pub fn pop(&mut self) -> Result<T, Error> {
self.values
.pop_back()
.pop()
.ok_or_else(|| Error("non-empty stack expected".into()))
}

Expand Down
7 changes: 3 additions & 4 deletions src/func.rs
@@ -1,12 +1,12 @@
use std::rc::{Rc, Weak};
use std::fmt;
use std::collections::HashMap;
use parity_wasm::elements::{Local, Instructions};
use parity_wasm::elements::Local;
use {Trap, TrapKind, Signature};
use host::Externals;
use runner::{check_function_args, Interpreter};
use value::RuntimeValue;
use module::ModuleInstance;
use isa;

/// Reference to a function (See [`FuncInstance`] for details).
///
Expand Down Expand Up @@ -158,6 +158,5 @@ impl FuncInstance {
#[derive(Clone, Debug)]
pub struct FuncBody {
pub locals: Vec<Local>,
pub instructions: Instructions,
pub labels: HashMap<usize, usize>,
pub code: isa::Instructions,
}