Fast double

Two days ago we looked at the first Idea I had to write an algorithm for duplicating each bit in a file. However, this turned out not to actually be that fast, and a friend of mine wrote a much faster algorithm. The goal of this challenge is simply to implement the rust function below to run as fast as possible. There are 3 implementations to compare to: A naive SISD implementation, an optimized SISD implementation, and an optimized SIMD implementation.

The function should insert a copy of each bit next to itself. An example of what the function should do is provided bellow:

let input = vec![0b11111111, 0b00000100, 0b11000101]; let output = double_array_user(&input); assert_eq!(output, vec![ 0b11111111, 0b11111111, 0b00000000, 0b00110000, 0b11110000, 0b00110011, ]);

Solution:

Oh also just to make things more fun you don't have access to std. We reimplemented print line using assert so you can print but only once per run ;).

pub fn double_array_user(array: &Vec<u8>) -> Vec<u8> { }

Since this question requires compiled code it uses a server to run the code. Please shoot me a DM if it breaks


Output:



Need a hint? Click below:

Split the bits first then copy them.

More hints? Click below:

Divide and conquer.

Final hint? Click below:

Can you efficiently move multiple bits at once? What is the minimum number of groups of bits you need to shift?