Skip to content

Instantly share code, notes, and snippets.

@roblabla
Created March 1, 2020 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roblabla/52a271375a2c0cfee7a664fb2a548344 to your computer and use it in GitHub Desktop.
Save roblabla/52a271375a2c0cfee7a664fb2a548344 to your computer and use it in GitHub Desktop.
//! ```cargo
//! [package]
//! edition = "2018"
//!
//! [dependencies]
//!
//! bitfield = "0.13.2"
//! ```
use bitfield::bitfield;
#[derive(Debug, Clone, Copy)]
pub enum ReductionOperation {
ADD,
MIN,
MAX,
INCREMENT,
DECREMENT,
AND,
OR,
XOR,
Unknown(u32)
}
impl From<ReductionOperation> for u32 {
fn from(mode: ReductionOperation) -> u32 {
match mode {
ReductionOperation::ADD => 0,
ReductionOperation::MIN => 1,
ReductionOperation::MAX => 2,
ReductionOperation::INCREMENT => 3,
ReductionOperation::DECREMENT => 4,
ReductionOperation::AND => 5,
ReductionOperation::OR => 6,
ReductionOperation::XOR => 7,
ReductionOperation::Unknown(val) => val,
}
}
}
impl From<u32> for ReductionOperation {
fn from(mode: u32) -> ReductionOperation {
match mode {
0 => ReductionOperation::ADD,
1 => ReductionOperation::MIN,
2 => ReductionOperation::MAX,
3 => ReductionOperation::INCREMENT,
4 => ReductionOperation::DECREMENT,
5 => ReductionOperation::AND,
6 => ReductionOperation::OR,
7 => ReductionOperation::XOR,
val => ReductionOperation::Unknown(val),
}
}
}
bitfield! {
pub struct ReportControl(u32);
impl Debug;
#[inline]
pub operation, set_operation: 1, 0;
#[inline]
pub flush_disable, set_flush_disable: 2;
#[inline]
pub reduction_enable, set_reduction_enable: 3;
// ???
#[inline]
pub fence_enable, set_fence_enable: 4;
pub from into ReductionOperation, reduction_operation, set_reduction_operation: 11, 9;
#[inline]
pub counter_type, set_counter_type: 27, 23;
#[inline]
pub is_one_word, set_one_word: 28;
}
fn main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment