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 numbern. 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?

## Task - Investigating the Collatz conjecture

The Collatz Conjecture states:Take any natural number

n. Ifnis even, divide it by 2 to getn/ 2. Ifnis 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:

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.

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)

1213742556871683919106111412913914171517164171218201920207217221523152410252326102711128182918301831106325332634133513362137213821393440841109428432944164516461647104481149245024