Skip to content

Commit d4aa30f

Browse files
authored
Update side table format to support OpenSK (#928)
1 parent 02be2f8 commit d4aa30f

File tree

24 files changed

+45
-38
lines changed

24 files changed

+45
-38
lines changed

crates/cli-tools/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@
9898

9999
## 0.1.0
100100

101-
<!-- Increment to skip CHANGELOG.md test: 1 -->
101+
<!-- Increment to skip CHANGELOG.md test: 2 -->

crates/cli-tools/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli-tools/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ serialport = { version = "4.7.3", default-features = false, optional = true }
3030
tar = { version = "0.4.44", default-features = false }
3131
toml = { version = "0.9.5", default-features = false, features = ["display", "parse", "serde"] }
3232
wasefire-common = { version = "0.1.1-git", path = "../common", optional = true }
33-
wasefire-interpreter = { version = "0.4.1-git", path = "../interpreter", optional = true }
33+
wasefire-interpreter = { version = "0.5.0-git", path = "../interpreter", optional = true }
3434
wasefire-wire = { version = "0.1.3-git", path = "../wire", optional = true }
3535

3636
[dependencies.clap]

crates/cli/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@
8282

8383
## 0.1.0
8484

85-
<!-- Increment to skip CHANGELOG.md test: 2 -->
85+
<!-- Increment to skip CHANGELOG.md test: 3 -->

crates/cli/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/interpreter/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Changelog
22

3-
## 0.4.1-git
3+
## 0.5.0-git
4+
5+
### Major
6+
7+
- Update side table format to support the OpenSK example applet
48

59
### Minor
610

11+
- Increase supported number of locals from 100 to 1000
712
- Add `Store::memory()` to access the memory of a given instance
813

914
### Patch

crates/interpreter/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/interpreter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wasefire-interpreter"
3-
version = "0.4.1-git"
3+
version = "0.5.0-git"
44
authors = ["Julien Cretin <[email protected]>"]
55
license = "Apache-2.0"
66
publish = true

crates/interpreter/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ impl<'m, M: Mode> Parser<'m, M> {
653653

654654
/// Maximum number of locals (must be less than 2^32).
655655
// NOTE: This should be configurable.
656-
const MAX_LOCALS: u32 = 100;
656+
const MAX_LOCALS: u32 = 1000;
657657

658658
fn check_eq<M: Mode, T: Eq>(x: T, y: T) -> MResult<(), M> {
659659
M::check(|| x == y)

crates/interpreter/src/side_table.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,44 +101,49 @@ pub fn serialize(side_table: &[MetadataEntry]) -> Result<Vec<u8>, Error> {
101101

102102
#[derive(Copy, Clone, Debug)]
103103
#[repr(transparent)]
104-
pub struct BranchTableEntry([u8; 6]);
104+
pub struct BranchTableEntry([u8; 6]); // 48 bits
105105

106106
#[derive(Debug)]
107107
pub struct BranchTableEntryView {
108108
/// The amount to adjust the instruction pointer by if the branch is taken.
109-
pub delta_ip: i32,
109+
pub delta_ip: i32, // 19 bits
110110
/// The amount to adjust the side-table pointer by if the branch is taken.
111-
pub delta_stp: i32,
111+
pub delta_stp: i32, // 13 bits
112112
/// The number of values that will be copied if the branch is taken.
113-
pub val_cnt: u32,
113+
pub val_cnt: u32, // 4 bits
114114
/// The number of values that will be popped if the branch is taken.
115-
pub pop_cnt: u32,
115+
pub pop_cnt: u32, // 12 bits
116116
}
117117

118118
impl BranchTableEntry {
119119
pub fn new(view: BranchTableEntryView) -> Result<Self, Error> {
120-
debug_assert!((i16::MIN as i32 .. i16::MAX as i32).contains(&view.delta_ip));
121-
debug_assert!((i16::MIN as i32 .. i16::MAX as i32).contains(&view.delta_stp));
120+
debug_assert!([0, -1].contains(&(view.delta_ip >> 18)), "{view:?}");
121+
debug_assert!([0, -1].contains(&(view.delta_stp >> 12)), "{view:?}");
122122
debug_assert!(view.val_cnt <= 0xf);
123123
debug_assert!(view.pop_cnt <= 0xfff);
124-
let delta_ip_bytes = (view.delta_ip as u16).to_le_bytes();
124+
let delta_ip_bytes = view.delta_ip.to_le_bytes();
125125
let delta_stp_bytes = (view.delta_stp as u16).to_le_bytes();
126126
let pop_val_counts_bytes = (((view.pop_cnt << 4) | view.val_cnt) as u16).to_le_bytes();
127127
Ok(BranchTableEntry([
128128
delta_ip_bytes[0],
129129
delta_ip_bytes[1],
130130
delta_stp_bytes[0],
131-
delta_stp_bytes[1],
131+
(delta_stp_bytes[1] & 0x1f) | (delta_ip_bytes[2] << 5),
132132
pop_val_counts_bytes[0],
133133
pop_val_counts_bytes[1],
134134
]))
135135
}
136136

137137
pub fn view<M: Mode>(self) -> MResult<BranchTableEntryView, M> {
138+
let mut delta_ip = parse_u16::<M>(&self.0, 0)? as u32;
139+
let delta_stp = parse_u16::<M>(&self.0, 2)?;
138140
let pop_val_counts = parse_u16::<M>(&self.0, 4)?;
141+
delta_ip |= (delta_stp as u32 & 0xe000) << 3;
142+
let delta_ip = ((delta_ip << 13) as i32) >> 13;
143+
let delta_stp = (((delta_stp << 3) as i16) >> 3) as i32;
139144
Ok(BranchTableEntryView {
140-
delta_ip: (parse_u16::<M>(&self.0, 0)? as i16) as i32,
141-
delta_stp: (parse_u16::<M>(&self.0, 2)? as i16) as i32,
145+
delta_ip,
146+
delta_stp,
142147
val_cnt: (pop_val_counts & 0xf) as u32,
143148
pop_cnt: (pop_val_counts >> 4) as u32,
144149
})

0 commit comments

Comments
 (0)