vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use super::{valid_window, window_byte, ROLLING_BASE};
use crate::ir::{BufferDecl, DataType, Expr, Node, Program};

/// Build a polynomial rolling hash program with `window_size` baked into IR.
#[must_use]
pub fn rolling_hash_program(window_size: u32) -> Program {
    Program::new(
        vec![
            BufferDecl::read("input", 0, DataType::Bytes),
            BufferDecl::output("out", 1, DataType::U32),
        ],
        [1, 1, 1],
        vec![Node::loop_for(
            "start",
            Expr::u32(0),
            Expr::buf_len("input"),
            vec![Node::if_then(
                valid_window(window_size),
                vec![
                    Node::let_bind("hash", Expr::u32(0)),
                    Node::loop_for(
                        "offset",
                        Expr::u32(0),
                        Expr::u32(window_size),
                        vec![Node::assign(
                            "hash",
                            Expr::add(
                                Expr::mul(Expr::var("hash"), Expr::u32(ROLLING_BASE)),
                                window_byte(),
                            ),
                        )],
                    ),
                    Node::store("out", Expr::var("start"), Expr::var("hash")),
                ],
            )],
        )],
    )
}