Dataset Viewer
Auto-converted to Parquet Duplicate
signature
stringlengths
21
72
description
stringlengths
36
140
code
stringlengths
48
417
fn prefix_scan_eq(x: u32[8]) -> u3[8]
Iterates over an 8-element array and counts consecutive duplicate values. The counter resets to 0 immediately upon encountering a new value.
fn prefix_scan_eq(x: u32[8]) -> u3[8] { let (_, _, result) = for (i, elem): (u32, u32) in enumerate(x) { let (prior, count, current_result) = acc; let (to_place, new_count): (u3, u3) = match (i == u32:0, prior == elem) { (true, _) => (u3:0, u3:1), (false, true) => (count, count + u3:1), (false, false) => (u3:0, u3:1), ...
fn hello_xls(hello_string: u8[11])
Accepts an 11-byte array representing a string and outputs the value to standard error using the trace primitive.
fn hello_xls(hello_string: u8[11]) { trace!(hello_string); }
fn crc32_one_byte(byte: u8, polynomial: u32, crc: u32) -> u32
Calculates the CRC32 checksum update for a single input byte using a specific polynomial and the current CRC state.
fn crc32_one_byte(byte: u8, polynomial: u32, crc: u32) -> u32 { let crc = crc ^ (byte as u32); for (i, crc): (u32, u32) in range(u32:0, u32:8) { let mask = (-(crc as s1) as u32); (crc >> 1) ^ (mask & polynomial) }(crc) }
fn adler32(buf: u8[N]) -> u32
Computes the Adler-32 checksum for a fixed-size byte buffer by maintaining two 16-bit counters modulo 65521.
const MOD_ADLER = u32:65521; fn adler32<N: u32>(buf: u8[N]) -> u32 { let (s1, s2) = for (byte, (s1, s2)): (u8, (u32, u32)) in buf { let s1 = (s1 + (byte as u32)) % MOD_ADLER; let s2 = (s2 + s1) % MOD_ADLER; (s1, s2) }((u32:1, u32:0)); (s2 << 16) | s1 }
fn bit_count(x: u32) -> u32
Calculates the population count (Hamming weight) of a 32-bit integer by iterating through all bits and summing the ones.
fn bit_count(x: u32) -> u32 { for (i, count): (u32, u32) in range(u32:0, u32:32) { if ((x >> i) & u32:1) == u32:1 { count + u32:1 } else { count } }(u32:0) }
fn fibonacci(n: u32) -> u32
Computes the n-th Fibonacci number using an iterative loop that updates a tuple of the previous two numbers.
fn fibonacci(n: u32) -> u32 { let (curr, next) = for (_, (a, b)): (u32, (u32, u32)) in range(u32:0, n) { (b, a + b) }((u32:0, u32:1)); curr }
fn reverse_bits(x: u32) -> u32
Reverses the order of bits in a 32-bit integer.
fn reverse_bits(x: u32) -> u32 { for (i, res): (u32, u32) in range(u32:0, u32:32) { let bit = (x >> i) & u32:1; res | (bit << (u32:31 - i)) }(u32:0) }
fn is_even(x: u32) -> bool
Checks if a 32-bit unsigned integer is even by inspecting the least significant bit.
fn is_even(x: u32) -> bool { (x & u32:1) == u32:0 }
fn abs(x: s32) -> u32
Computes the absolute value of a signed 32-bit integer, casting the result to unsigned.
fn abs(x: s32) -> u32 { if x < s32:0 { (-x) as u32 } else { x as u32 } }
fn min(x: u32, y: u32) -> u32
Returns the smaller of two unsigned 32-bit integers.
fn min(x: u32, y: u32) -> u32 { if x < y { x } else { y } }
fn max(x: u32, y: u32) -> u32
Returns the larger of two unsigned 32-bit integers.
fn max(x: u32, y: u32) -> u32 { if x > y { x } else { y } }
fn clamp(x: u32, low: u32, high: u32) -> u32
Constrains a value x to be within the range [low, high].
fn clamp(x: u32, low: u32, high: u32) -> u32 { if x < low { low } else if x > high { high } else { x } }
fn lfsr_step(state: u16) -> u16
Performs a single step of a 16-bit Linear Feedback Shift Register using a standard tap configuration (taps at bits 11, 13, 14, 16).
fn lfsr_step(state: u16) -> u16 { let bit = ((state >> 0) ^ (state >> 2) ^ (state >> 3) ^ (state >> 5)) & u16:1; (state >> 1) | (bit << 15) }
fn one_hot_encode(index: u3, enable: bool) -> u8
Generates an 8-bit one-hot encoded value from a 3-bit index, or returns 0 if enable is false.
fn one_hot_encode(index: u3, enable: bool) -> u8 { if enable { u8:1 << index } else { u8:0 } }
fn decode_one_hot(one_hot: u8) -> (bool, u3)
Decodes an 8-bit one-hot value into a 3-bit index and a validity flag. Returns the index of the first set bit found.
fn decode_one_hot(one_hot: u8) -> (bool, u3) { for (i, (found, idx)): (u3, (bool, u3)) in range(u3:0, u3:8) { if !found && ((one_hot >> i) & u8:1) == u8:1 { (true, i) } else { (found, idx) } }((false, u3:0)) }
fn half_adder(a: u1, b: u1) -> (u1, u1)
Implements a simple half-adder, returning the sum and carry.
fn half_adder(a: u1, b: u1) -> (u1, u1) { let sum = a ^ b; let carry = a & b; (sum, carry) }
fn full_adder(a: u1, b: u1, cin: u1) -> (u1, u1)
Implements a full-adder logic taking two inputs and a carry-in, returning sum and carry-out.
fn full_adder(a: u1, b: u1, cin: u1) -> (u1, u1) { let sum = a ^ b ^ cin; let cout = (a & b) | (cin & (a ^ b)); (sum, cout) }
fn dot_product(a: u32[4], b: u32[4]) -> u32
Computes the scalar dot product of two 4-element vectors.
fn dot_product(a: u32[4], b: u32[4]) -> u32 { for (i, acc): (u32, u32) in range(u32:0, u32:4) { acc + (a[i] * b[i]) }(u32:0) }
fn matmul_2x2(a: u32[2][2], b: u32[2][2]) -> u32[2][2]
Multiplies two 2x2 integer matrices.
fn matmul_2x2(a: u32[2][2], b: u32[2][2]) -> u32[2][2] { for (i, rows): (u32, u32[2][2]) in range(u32:0, u32:2) { let row = for (j, cols): (u32, u32[2]) in range(u32:0, u32:2) { let dot = (a[i][0] * b[0][j]) + (a[i][1] * b[1][j]); update(cols, j, dot) }(rows[i]); update(rows, i, row) }(u32[2][2]:[[0,0],[0,0]]) }
fn complex_mul(a_re: s32, a_im: s32, b_re: s32, b_im: s32) -> (s32, s32)
Multiplies two complex numbers (a_re + ia_im) and (b_re + ib_im).
fn complex_mul(a_re: s32, a_im: s32, b_re: s32, b_im: s32) -> (s32, s32) { let real = (a_re * b_re) - (a_im * b_im); let imag = (a_re * b_im) + (a_im * b_re); (real, imag) }
fn fir_filter(sample: s32, history: s32[4], coeffs: s32[5]) -> s32
Computes a single output sample of a 5-tap FIR filter given the current sample, history, and coefficients.
fn fir_filter(sample: s32, history: s32[4], coeffs: s32[5]) -> s32 { let tap0 = sample * coeffs[0]; let tap1 = history[0] * coeffs[1]; let tap2 = history[1] * coeffs[2]; let tap3 = history[2] * coeffs[3]; let tap4 = history[3] * coeffs[4]; tap0 + tap1 + tap2 + tap3 + tap4 }
fn rgb_to_gray(r: u8, g: u8, b: u8) -> u8
Converts an RGB pixel to grayscale using fixed-point integer weights (approx: 0.3R + 0.59G + 0.11B).
fn rgb_to_gray(r: u8, g: u8, b: u8) -> u8 { let r_w = (r as u16) * u16:30; let g_w = (g as u16) * u16:59; let b_w = (b as u16) * u16:11; let sum = r_w + g_w + b_w; (sum / u16:100) as u8 }
fn hamming_dist(a: u32, b: u32) -> u32
Calculates the Hamming distance between two 32-bit integers (number of differing bits).
fn hamming_dist(a: u32, b: u32) -> u32 { let xor_val = a ^ b; for (i, c): (u32, u32) in range(u32:0, u32:32) { c + ((xor_val >> i) & u32:1) }(u32:0) }
fn rotate_left(x: u32, amount: u32) -> u32
Rotates the bits of a 32-bit integer to the left by the specified amount.
fn rotate_left(x: u32, amount: u32) -> u32 { let amount = amount % u32:32; (x << amount) | (x >> (u32:32 - amount)) }
fn sign_extend_8_to_32(x: u8) -> u32
Sign-extends an 8-bit integer to a 32-bit integer.
fn sign_extend_8_to_32(x: u8) -> u32 { (x as s8) as s32 as u32 }
fn find_first_set(x: u32) -> s32
Returns the index (0-31) of the least significant bit set to 1, or -1 if input is 0.
fn find_first_set(x: u32) -> s32 { for (i, result): (u32, s32) in range(u32:0, u32:32) { if result == s32:-1 && ((x >> i) & u32:1) == u32:1 { i as s32 } else { result } }(s32:-1) }
fn gcd(x: u32, y: u32) -> u32
Computes the Greatest Common Divisor using recursive logic (implied bounded for hardware synthesis).
fn gcd(x: u32, y: u32) -> u32 { if y == u32:0 { x } else { gcd(y, x % y) } }
fn gray_to_binary(gray: u32) -> u32
Converts a 32-bit Gray code value to its standard binary representation using XOR shifts.
fn gray_to_binary(gray: u32) -> u32 { let mask = gray >> 1; let bin = gray ^ mask; let mask = mask >> 1; let bin = bin ^ mask; let mask = mask >> 1; let bin = bin ^ mask; for (i, b): (u32, u32) in range(u32:0, u32:32) { b ^ (b >> 1) }(gray) }
fn demux_1_to_4(sel: u2, val: u8) -> u8[4]
Routes a single 8-bit input to one of 4 outputs based on a selector.
fn demux_1_to_4(sel: u2, val: u8) -> u8[4] { let out = u8[4]:[0, 0, 0, 0]; update(out, sel, val) }
fn majority_vote(a: u1, b: u1, c: u1) -> u1
Returns 1 if the majority of the three inputs are 1, otherwise 0.
fn majority_vote(a: u1, b: u1, c: u1) -> u1 { (a & b) | (b & c) | (a & c) }
fn swap(a: u32, b: u32) -> (u32, u32)
Swaps two values and returns them in reversed order.
fn swap(a: u32, b: u32) -> (u32, u32) { (b, a) }
fn sum_array(arr: u32[8]) -> u32
Calculates the sum of all elements in an 8-element array.
fn sum_array(arr: u32[8]) -> u32 { for (_, acc): (u32, u32) in arr { acc + acc } (u32:0) }
fn is_power_of_two(x: u32) -> bool
Determines if a number is a power of two.
fn is_power_of_two(x: u32) -> bool { x != u32:0 && (x & (x - u32:1)) == u32:0 }
fn toggle_bit(x: u32, pos: u32) -> u32
Toggles the bit at the specified position.
fn toggle_bit(x: u32, pos: u32) -> u32 { x ^ (u32:1 << pos) }
fn simple_alu(op: u2, a: u32, b: u32) -> u32
A basic Arithmetic Logic Unit supporting ADD, SUB, AND, OR based on opcode.
fn simple_alu(op: u2, a: u32, b: u32) -> u32 { match op { u2:0 => a + b, u2:1 => a - b, u2:2 => a & b, u2:3 => a | b, _ => u32:0 } }
fn parity(x: u32) -> u1
Computes the parity bit (1 if odd number of 1s, 0 otherwise).
fn parity(x: u32) -> u1 { let p = for (i, p): (u32, u1) in range(u32:0, u32:32) { p ^ ((x >> i) as u1) }(u1:0); p }
fn average(a: u32, b: u32) -> u32
Computes the integer average of two numbers without overflow.
fn average(a: u32, b: u32) -> u32 { (a & b) + ((a ^ b) >> 1) }
fn max_array(arr: u32[4]) -> u32
Finds the maximum value in a 4-element array.
fn max_array(arr: u32[4]) -> u32 { for (i, cur_max): (u32, u32) in enumerate(arr) { if i == u32:0 { arr[0] } else if acc > cur_max { acc } else { cur_max } }(u32:0) }
fn logical_shift_right(x: u32, n: u32) -> u32
Performs a logical right shift (padding with zeros).
fn logical_shift_right(x: u32, n: u32) -> u32 { x >> n }
fn arithmetic_shift_right(x: s32, n: u32) -> s32
Performs an arithmetic right shift (preserving sign bit).
fn arithmetic_shift_right(x: s32, n: u32) -> s32 { x >> n }
fn abs_diff(a: u32, b: u32) -> u32
Computes the absolute difference between two unsigned integers.
fn abs_diff(a: u32, b: u32) -> u32 { if a > b { a - b } else { b - a } }
README.md exists but content is empty.
Downloads last month
5