-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.rs
48 lines (42 loc) · 1.27 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::env;
use std::fs::File;
use std::io::Write;
use std::mem;
use std::path::Path;
fn log2(x: usize) -> usize {
mem::size_of::<usize>() * 8 - (x.leading_zeros() as usize) - 1
}
const SBLOCK_WIDTH: usize = 64;
const MAX_CODE_SIZE: usize = 48;
fn main() {
let mut combination = vec![vec![0u64; SBLOCK_WIDTH + 1]; SBLOCK_WIDTH + 1];
for n in 0..=SBLOCK_WIDTH {
combination[n][0] = 1;
for r in 1..=n {
combination[n][r] = combination[n - 1][r - 1] + combination[n - 1][r];
}
}
let mut code_size = vec![0; SBLOCK_WIDTH + 1];
code_size[0] = 0;
code_size[SBLOCK_WIDTH] = 0;
for n in 1..SBLOCK_WIDTH {
let size = log2((combination[SBLOCK_WIDTH][n] - 1) as usize) + 1;
code_size[n] = if size <= MAX_CODE_SIZE {
size
} else {
SBLOCK_WIDTH
};
}
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir).join("const.rs");
let mut f = File::create(&out_path).unwrap();
f.write_all(
format!(
"const COMBINATION: [[u64; {size}]; {size}] = {:?};
const CODE_SIZE: [u64; {size}] = {:?};",
combination,
code_size,
size = SBLOCK_WIDTH + 1
).as_bytes(),
).unwrap();
}