Skip to content

Commit 5837734

Browse files
authored
Merge branch 'master' into feat/skip_fixed_commit_of_range_table
2 parents 386fca6 + 083b2d4 commit 5837734

File tree

7 files changed

+50
-65
lines changed

7 files changed

+50
-65
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ceno_host/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,15 @@ impl From<&CenoStdin> for Vec<u32> {
120120
}
121121

122122
impl CenoStdin {
123-
pub fn write_slice(&mut self, bytes: AlignedVec) {
123+
pub fn write_slice(&mut self, bytes: AlignedVec) -> &mut Self {
124124
self.items.push(bytes);
125+
self
125126
}
126127

127128
pub fn write(
128129
&mut self,
129130
item: &impl for<'a> Serialize<HighSerializer<AlignedVec, ArenaHandle<'a>, Error>>,
130-
) -> Result<(), Error> {
131+
) -> Result<&mut Self, Error> {
131132
to_bytes::<Error>(item).map(|bytes| self.write_slice(bytes))
132133
}
133134
}

ceno_host/tests/test_elf.rs

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use ceno_emul::{
77
};
88
use ceno_host::CenoStdin;
99
use itertools::{Itertools, enumerate, izip};
10+
use rand::{Rng, thread_rng};
1011
use tiny_keccak::keccakf;
1112

1213
#[test]
@@ -111,14 +112,15 @@ fn test_ceno_rt_io() -> Result<()> {
111112

112113
#[test]
113114
fn test_hints() -> Result<()> {
114-
let mut hints = CenoStdin::default();
115-
hints.write(&true)?;
116-
hints.write(&"This is my hint string.".to_string())?;
117-
hints.write(&1997_u32)?;
118-
hints.write(&1999_u32)?;
119-
120-
let all_messages =
121-
messages_to_strings(&ceno_host::run(CENO_PLATFORM, ceno_examples::hints, &hints));
115+
let all_messages = messages_to_strings(&ceno_host::run(
116+
CENO_PLATFORM,
117+
ceno_examples::hints,
118+
CenoStdin::default()
119+
.write(&true)?
120+
.write(&"This is my hint string.".to_string())?
121+
.write(&1997_u32)?
122+
.write(&1999_u32)?,
123+
));
122124
for (i, msg) in enumerate(&all_messages) {
123125
println!("{i}: {msg}");
124126
}
@@ -128,17 +130,12 @@ fn test_hints() -> Result<()> {
128130

129131
#[test]
130132
fn test_bubble_sorting() -> Result<()> {
131-
use rand::Rng;
132-
let mut hints = CenoStdin::default();
133-
let mut rng = rand::thread_rng();
134-
135-
// Provide some random numbers to sort.
136-
hints.write(&(0..1_000).map(|_| rng.gen::<u32>()).collect::<Vec<_>>())?;
137-
133+
let mut rng = thread_rng();
138134
let all_messages = messages_to_strings(&ceno_host::run(
139135
CENO_PLATFORM,
140-
ceno_examples::bubble_sorting,
141-
&hints,
136+
ceno_examples::quadratic_sorting,
137+
// Provide some random numbers to sort.
138+
CenoStdin::default().write(&(0..1_000).map(|_| rng.gen::<u32>()).collect::<Vec<_>>())?,
142139
));
143140
for msg in &all_messages {
144141
print!("{msg}");
@@ -147,17 +144,12 @@ fn test_bubble_sorting() -> Result<()> {
147144
}
148145
#[test]
149146
fn test_sorting() -> Result<()> {
150-
use rand::Rng;
151-
let mut hints = CenoStdin::default();
152-
let mut rng = rand::thread_rng();
153-
154-
// Provide some random numbers to sort.
155-
hints.write(&(0..1000).map(|_| rng.gen::<u32>()).collect::<Vec<_>>())?;
156-
147+
let mut rng = thread_rng();
157148
let all_messages = messages_to_strings(&ceno_host::run(
158149
CENO_PLATFORM,
159150
ceno_examples::sorting,
160-
&hints,
151+
// Provide some random numbers to sort.
152+
CenoStdin::default().write(&(0..1000).map(|_| rng.gen::<u32>()).collect::<Vec<_>>())?,
161153
));
162154
for (i, msg) in enumerate(&all_messages) {
163155
println!("{i}: {msg}");
@@ -167,9 +159,8 @@ fn test_sorting() -> Result<()> {
167159

168160
#[test]
169161
fn test_median() -> Result<()> {
170-
use rand::Rng;
171162
let mut hints = CenoStdin::default();
172-
let mut rng = rand::thread_rng();
163+
let mut rng = thread_rng();
173164

174165
// Provide some random numbers to find the median of.
175166
let mut nums = (0..1000).map(|_| rng.gen::<u32>()).collect::<Vec<_>>();
@@ -192,23 +183,22 @@ fn test_median() -> Result<()> {
192183
#[test]
193184
#[should_panic(expected = "Trap IllegalInstruction")]
194185
fn test_hashing_fail() {
195-
use rand::Rng;
196-
let mut hints = CenoStdin::default();
197-
let mut rng = rand::thread_rng();
186+
let mut rng = thread_rng();
198187

199188
let mut nums = (0..1_000).map(|_| rng.gen::<u32>()).collect::<Vec<_>>();
200189
// Add a duplicate number to make uniqueness check fail:
201190
nums[211] = nums[907];
202-
hints.write(&nums).unwrap();
203191

204-
let _ = ceno_host::run(CENO_PLATFORM, ceno_examples::hashing, &hints);
192+
let _ = ceno_host::run(
193+
CENO_PLATFORM,
194+
ceno_examples::hashing,
195+
CenoStdin::default().write(&nums).unwrap(),
196+
);
205197
}
206198

207199
#[test]
208200
fn test_hashing() -> Result<()> {
209-
use rand::Rng;
210-
let mut hints = CenoStdin::default();
211-
let mut rng = rand::thread_rng();
201+
let mut rng = thread_rng();
212202

213203
// Provide some unique random numbers to verify:
214204
let uniques: Vec<u32> = {
@@ -219,11 +209,10 @@ fn test_hashing() -> Result<()> {
219209
.collect::<Vec<_>>()
220210
};
221211

222-
hints.write(&uniques)?;
223212
let all_messages = messages_to_strings(&ceno_host::run(
224213
CENO_PLATFORM,
225214
ceno_examples::hashing,
226-
&hints,
215+
CenoStdin::default().write(&uniques)?,
227216
));
228217
assert!(!all_messages.is_empty());
229218
for (i, msg) in enumerate(&all_messages) {

ceno_zkvm/src/instructions/riscv/rv32im.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ use ceno_emul::{
2929
};
3030
use ecall::EcallDummy;
3131
use ff_ext::ExtensionField;
32-
use itertools::Itertools;
32+
use itertools::{Itertools, izip};
3333
use mul::{MulInstruction, MulhInstruction, MulhsuInstruction};
3434
use shift::SraInstruction;
3535
use slt::{SltInstruction, SltuInstruction};
3636
use slti::SltiuInstruction;
37-
use std::collections::{BTreeMap, BTreeSet};
37+
use std::{
38+
cmp::Reverse,
39+
collections::{BTreeMap, BTreeSet},
40+
};
3841
use strum::IntoEnumIterator;
3942

4043
use super::{
@@ -337,14 +340,10 @@ impl<E: ExtensionField> Rv32imConfig<E> {
337340
}
338341
});
339342

340-
for (insn_kind, (_, records)) in InsnKind::iter()
341-
.zip(all_records.iter())
342-
.sorted_by(|a, b| Ord::cmp(&a.1.1.len(), &b.1.1.len()))
343-
.rev()
343+
for (insn_kind, (_, records)) in
344+
izip!(InsnKind::iter(), &all_records).sorted_by_key(|(_, (_, a))| Reverse(a.len()))
344345
{
345-
if !records.is_empty() {
346-
tracing::info!("tracer generated {:?} {} records", insn_kind, records.len());
347-
}
346+
tracing::info!("tracer generated {:?} {} records", insn_kind, records.len());
348347
}
349348

350349
macro_rules! assign_opcode {

examples-builder/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ license.workspace = true
77
name = "ceno-examples"
88
repository.workspace = true
99
version.workspace = true
10+
11+
[build-dependencies]
12+
glob = "0.3"

examples-builder/build.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
1+
use glob::glob;
12
use std::{
23
fs::{File, read_dir},
34
io::{self, Write},
45
path::Path,
56
process::Command,
67
};
78

8-
/// Add each example to this list.
9-
///
10-
/// Contact Matthias, if your examples get complicated enough to need their own crates, instead of just being one file.
11-
const EXAMPLES: &[&str] = &[
12-
"ceno_rt_alloc",
13-
"ceno_rt_io",
14-
"ceno_rt_mem",
15-
"ceno_rt_mini",
16-
"ceno_rt_panic",
17-
"ceno_rt_keccak",
18-
"hints",
19-
"sorting",
20-
"median",
21-
"bubble_sorting",
22-
"hashing",
23-
];
249
const CARGO_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
2510

2611
fn rerun_all_but_target(dir: &Path) {
@@ -51,7 +36,12 @@ fn build_elfs() {
5136
io::stderr().write_all(&output.stderr).unwrap();
5237
panic!("cargo build of examples failed.");
5338
}
54-
for example in EXAMPLES {
39+
// Contact Matthias, if your examples get complicated enough to need their own crates, instead of just being one file.
40+
for example in glob("../examples/examples/*.rs")
41+
.unwrap()
42+
.map(Result::unwrap)
43+
{
44+
let example = example.file_stem().unwrap().to_str().unwrap();
5545
writeln!(
5646
dest,
5747
r#"#[allow(non_upper_case_globals)]

0 commit comments

Comments
 (0)