Skip to content

Commit d8ec881

Browse files
committed
const folding: difftest with rustc const block
1 parent 33b0c09 commit d8ec881

File tree

8 files changed

+73
-14
lines changed

8 files changed

+73
-14
lines changed

tests/difftests/tests/Cargo.lock

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

tests/difftests/tests/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ members = [
2727
"lang/core/ops/matrix_ops/matrix_ops-rust",
2828
"lang/core/ops/matrix_ops/matrix_ops-wgsl",
2929
"lang/core/ops/bitwise_ops/bitwise_ops-rust",
30+
"lang/core/ops/const_fold_int/const-expr-cpu",
31+
"lang/core/ops/const_fold_int/const-expr-shader",
3032
"lang/core/ops/const_fold_int/const-fold-cpu",
3133
"lang/core/ops/const_fold_int/const-fold-shader",
3234
"lang/core/ops/const_fold_int/dynamic-values-cpu",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "const_fold_int-const-expr-cpu"
3+
edition.workspace = true
4+
5+
[lints]
6+
workspace = true
7+
8+
# GPU deps
9+
[dependencies]
10+
const_fold_int-const-fold-cpu = { path = "../const-fold-cpu" }
11+
12+
# CPU deps (for the test harness)
13+
[target.'cfg(not(target_arch = "spirv"))'.dependencies]
14+
difftest.workspace = true
15+
bytemuck.workspace = true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use const_fold_int_const_fold_cpu::Variants;
2+
3+
fn main() {
4+
const_fold_int_const_fold_cpu::cpu_driver::run(Variants::ConstExpr);
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "const_fold_int-const-expr-shader"
3+
edition.workspace = true
4+
5+
[lints]
6+
workspace = true
7+
8+
[lib]
9+
crate-type = ["dylib"]
10+
11+
# GPU deps
12+
[dependencies]
13+
const_fold_int-const-fold-cpu = { path = "../const-fold-cpu" }
14+
15+
# CPU deps (for the test harness)
16+
[target.'cfg(not(target_arch = "spirv"))'.dependencies]
17+
difftest.workspace = true
18+
bytemuck.workspace = true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![cfg_attr(target_arch = "spirv", no_std)]
2+
#![allow(arithmetic_overflow)]
3+
4+
pub use const_fold_int_const_fold_cpu::shader::main_cs;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use const_fold_int_const_fold_cpu::Variants;
2+
3+
fn main() {
4+
const_fold_int_const_fold_cpu::shader_driver::run(Variants::ConstExpr);
5+
}

tests/difftests/tests/lang/core/ops/const_fold_int/const-fold-cpu/src/lib.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ macro_rules! op_u {
1414
[
1515
($value << 0) as u32,
1616
($value << 1) as u32,
17-
($value << 2) as u32,
1817
($value << 30) as u32,
1918
($value << 31) as u32,
20-
($value << 32) as u32,
21-
($value << 33) as u32,
22-
($value << 34) as u32,
2319
($value >> 0) as u32,
2420
($value >> 1) as u32,
25-
($value >> 2) as u32,
2621
($value >> 30) as u32,
2722
($value >> 31) as u32,
28-
($value >> 32) as u32,
29-
($value >> 33) as u32,
30-
($value >> 34) as u32,
3123
]
3224
};
3325
}
@@ -66,21 +58,21 @@ pub const INTERESTING_PATTERNS: [u32; 8] = interesting_patterns!(identity);
6658
pub enum Variants {
6759
/// const folding in rust-gpu
6860
ConstFold,
69-
// /// `const {}` expr for const eval within rustc
70-
// ConstExpr,
61+
/// `const {}` expr for const eval within rustc
62+
ConstExpr,
7163
/// dynamic values from `input_patterns`
7264
DynamicValues,
7365
}
7466

75-
pub type EvalResult = [[[u32; 16]; 8]; 2];
67+
pub type EvalResult = [[[u32; 8]; 8]; 2];
7668

7769
impl Variants {
7870
pub fn eval(&self, input_patterns: &[u32; 8]) -> EvalResult {
7971
match self {
8072
Variants::ConstFold => [interesting_patterns!(op_u), interesting_patterns!(op_i)],
81-
// Variants::ConstExpr => {
82-
// const { [interesting_patterns!(op_u), interesting_patterns!(op_i)] }
83-
// }
73+
Variants::ConstExpr => {
74+
const { [interesting_patterns!(op_u), interesting_patterns!(op_i)] }
75+
}
8476
Variants::DynamicValues => [
8577
[
8678
op_u!(input_patterns[0]),

0 commit comments

Comments
 (0)