Skip to content

Commit

Permalink
ioreg: No need to read from write-only registers
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed Aug 28, 2014
1 parent a922996 commit 0d8d9c6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ioreg/builder/setter.rs
Expand Up @@ -122,14 +122,23 @@ fn build_drop<'a>(cx: &'a ExtCtxt, path: &Vec<String>,
}
}

// no need to read write-only registers
let wo_reg: bool = fields.iter().all(|f| f.access == node::WriteOnly);
let initial_value =
if wo_reg {
quote_expr!(cx, 0)
} else {
quote_expr!(cx, self.reg.value.get())
};

let item = quote_item!(cx,
#[unsafe_destructor]
#[doc = "This performs the register update"]
impl<'a> Drop for $setter_ty<'a> {
fn drop(&mut self) {
let clear_mask: $unpacked_ty = $clear as $unpacked_ty;
if self.mask != 0 {
let v: $unpacked_ty = self.reg.value.get() & ! clear_mask & ! self.mask;
let v: $unpacked_ty = $initial_value & ! clear_mask & ! self.mask;
self.reg.value.set(self.value | v);
}
}
Expand Down

0 comments on commit 0d8d9c6

Please sign in to comment.