Commit df5c7c53 authored by Tom Almeida's avatar Tom Almeida
Browse files

Merge branch 'master' into 'master'

Fix `buffer::pop`

See merge request !1
parents 74faa301 8f0cfcf9
...@@ -40,8 +40,8 @@ impl State { ...@@ -40,8 +40,8 @@ impl State {
// The pointer to the current bytes. // The pointer to the current bytes.
let mut ptr = buf.as_ptr(); let mut ptr = buf.as_ptr();
/// The end of the "main segment", i.e. the biggest buffer s.t. the length is divisible // The end of the "main segment", i.e. the biggest buffer s.t. the length is divisible
/// by 32. // by 32.
let end_ptr = buf.as_ptr().offset(buf.len() as isize & !0x1F); let end_ptr = buf.as_ptr().offset(buf.len() as isize & !0x1F);
while end_ptr > ptr { while end_ptr > ptr {
...@@ -174,10 +174,8 @@ impl State { ...@@ -174,10 +174,8 @@ impl State {
/// Write another 64-bit integer into the state. /// Write another 64-bit integer into the state.
pub fn push(&mut self, x: u64) { pub fn push(&mut self, x: u64) {
let mut a = self.a;
// Mix `x` into `a`. // Mix `x` into `a`.
a = helper::diffuse(a ^ x); let a = helper::diffuse(self.a ^ x);
// Rotate around. // Rotate around.
// _______________________ // _______________________
...@@ -196,22 +194,20 @@ impl State { ...@@ -196,22 +194,20 @@ impl State {
/// ///
/// Given the value of the most recently written u64 `last`, remove it from the state. /// Given the value of the most recently written u64 `last`, remove it from the state.
pub fn pop(&mut self, last: u64) { pub fn pop(&mut self, last: u64) {
// Decrese the written bytes counter. // Un-mix `last` from `d`. Removes the recently written data.
self.written -= 8; let d = helper::undiffuse(self.d) ^ last;
// Remove the recently written data.
self.d = helper::undiffuse(self.d) ^ last;
let mut a = self.a;
// Rotate back. // Rotate back.
// _______________________ // _______________________
// v | // v |
// a ----> b ----> c ----> d // a ----> b ----> c ----> d
self.a = self.d;
self.b = a;
self.c = self.b;
self.d = self.c; self.d = self.c;
self.c = self.b;
self.b = self.a;
self.a = d;
// Decrese the written bytes counter.
self.written -= 8;
} }
/// Finalize the state. /// Finalize the state.
......
...@@ -60,7 +60,7 @@ pub unsafe fn read_u64(ptr: *const u8) -> u64 { ...@@ -60,7 +60,7 @@ pub unsafe fn read_u64(ptr: *const u8) -> u64 {
{ {
// We cannot be sure about the memory layout of a potentially emulated 64-bit integer, so // We cannot be sure about the memory layout of a potentially emulated 64-bit integer, so
// we read it manually. If possible, the compiler should emit proper instructions. // we read it manually. If possible, the compiler should emit proper instructions.
(*(ptr as *const u32)).to_le() as u64 | ((*(ptr as *const u32)).to_le() as u64) << 32 (*(ptr as *const u32)).to_le() as u64 | ((*(ptr.offset(4) as *const u32)).to_le() as u64) << 32
} }
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment