Skip to content

Commit

Permalink
fix bugs in codegen compact encoder (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
xermicus committed Feb 20, 2023
1 parent 4bb4747 commit 2d65da8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/codegen/encoding/scale_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn encode_compact(
let done = cfg.new_basic_block("done".into());
let fail = cfg.new_basic_block("fail".into());
let prepare = cfg.new_basic_block("prepare".into());
let cmp_val = Expression::NumberLiteral(Codegen, Uint(32), 0x40000000.into());
let cmp_val = Expression::NumberLiteral(Codegen, Uint(32), (0x40000000 - 1).into());
let compare = Expression::UnsignedMore(Codegen, expr.clone().into(), cmp_val.into());
cfg.add(
vartab,
Expand All @@ -92,7 +92,7 @@ fn encode_compact(
cfg.add(vartab, Instr::AssertFailure { encoded_args: None });

cfg.set_basic_block(prepare);
let cmp_val = Expression::NumberLiteral(Codegen, Uint(32), 0x40.into());
let cmp_val = Expression::NumberLiteral(Codegen, Uint(32), (0x40 - 1).into());
let compare = Expression::UnsignedMore(Codegen, expr.clone().into(), cmp_val.into());
cfg.add(
vartab,
Expand All @@ -104,7 +104,7 @@ fn encode_compact(
);

cfg.set_basic_block(medium_or_big);
let cmp_val = Expression::NumberLiteral(Codegen, Uint(32), 0x4000.into());
let cmp_val = Expression::NumberLiteral(Codegen, Uint(32), (0x4000 - 1).into());
let compare = Expression::UnsignedMore(Codegen, expr.clone().into(), cmp_val.into());
cfg.add(
vartab,
Expand All @@ -114,8 +114,8 @@ fn encode_compact(
false_block: medium,
},
);
vartab.new_dirty_tracker();
let size_variable = vartab.temp_anonymous(&Uint(32));
vartab.new_dirty_tracker();
let four = Expression::NumberLiteral(Codegen, Uint(32), 4.into()).into();
let mul = Expression::Multiply(Codegen, Uint(32), false, expr.clone().into(), four);

Expand All @@ -126,7 +126,7 @@ fn encode_compact(
Instr::WriteBuffer {
buf: buffer.clone(),
offset: offset.clone(),
value: mul.clone(),
value: Expression::Cast(Codegen, Uint(8), mul.clone().into()),
},
);
}
Expand All @@ -143,13 +143,13 @@ fn encode_compact(

cfg.set_basic_block(medium);
if let (Some(buffer), Some(offset)) = (buffer, offset) {
let mul2 = Expression::BitwiseOr(Codegen, Uint(32), mul.clone().into(), one.into());
let mul = Expression::BitwiseOr(Codegen, Uint(32), mul.clone().into(), one.into());
cfg.add(
vartab,
Instr::WriteBuffer {
buf: buffer.clone(),
offset: offset.clone(),
value: mul2,
value: Expression::Cast(Codegen, Uint(16), mul.clone().into()),
},
);
}
Expand All @@ -166,13 +166,12 @@ fn encode_compact(

cfg.set_basic_block(big);
if let (Some(buffer), Some(offset)) = (buffer, offset) {
let mul2 = Expression::BitwiseOr(Codegen, Uint(32), mul.into(), two.into());
cfg.add(
vartab,
Instr::WriteBuffer {
buf: buffer.clone(),
offset: offset.clone(),
value: mul2,
value: Expression::BitwiseOr(Codegen, Uint(32), mul.into(), two.into()),
},
);
}
Expand Down
Loading

0 comments on commit 2d65da8

Please sign in to comment.