In the previous practical you only had to make a very simple Handel-C component. In this practical you will make hardware to solve a more complex problem.

Task - Investigating the Collatz conjecture

The Collatz Conjecture states:
Take any natural number n. If n is even, divide it by 2 to get n / 2. If n is odd, multiply it by 3 and add 1 to obtain 3n + 1. Repeat the process indefinitely. The conjecture is that no matter what number you start with, you will always eventually reach 1. (source Wikipedia)

Build a system that can evaluate how many steps it takes for each natural number to get back to 1. In order to be as fast as possible, the Microblaze will coordinate the actions of a set of parallel Collatz evaluation engines that are implemented in Handel-C.
Hints:
  • Build a Collatz evaluation function in Handel-C, this should be very simple. To test your function, you can find below a table of the first 50 Collatz numbers.
  • Divide by 2 can be implemented with a right shift, and if a number is even its least-significant bit is 0.
  • The Microblaze should report the calculated values, but don't worry about keeping them in order.

Once you have this working, extend the system so that it can evaluate multiple values in parallel. You will need to use channels and prialts.
  • A good way to organise your system is for your Collatz evaluation units to have their own input and output channels. They can read an integer from their input channel, calculate the Collatz number for it, and output the result over their output channel.
  • Your hardware can then use a prialt write to whichever evaluation unit is ready.

Time how long it takes your system to evaluate the first 50 Collatz values. Who can be the fastest?

Table of Collatz values (from here)

n
Steps
1
0
2
1
3
7
4
2
5
5
6
8
7
16
8
3
9
19
10
6
11
14
12
9
13
9
14
17
15
17
16
4
17
12
18
20
19
20
20
7
21
7
22
15
23
15
24
10
25
23
26
10
27
111
28
18
29
18
30
18
31
106
32
5
33
26
34
13
35
13
36
21
37
21
38
21
39
34
40
8
41
109
42
8
43
29
44
16
45
16
46
16
47
104
48
11
49
24
50
24