wrote:
>>But this may be not the final solution. In line 49 you compare two
>>vectors, but the length of the vectors is variable. What would that be
>>in hardware? I guess /several/ comparators - one for every vector width.
>>(Ignore ressource sharing at the moment.) I don't expect, that a
>>synthesis tool is capable of computing how many of such comparators are
>>needed - because at the moment I do not. Do you know it? 
>
> The number of comparators is fixed. Since we always compare two numbers
> of size w bits (so number of comarators = w). It is only the position
> of these numbers in the two arrays that changes as per the 'pick'
> value. The position can not be known before hand because the arrays can
> have randomly any value.
Ok, then you gave yourself the answer: Model a w-bit wide comparator and
several multiplexers to select the appropriate data.
Synthesis complains about style like sig(x downto y) where x and y are
some not-fixed integers, because then the synthesis tool assumes, that x
and y are independend. You have to model such a selection descriping are
strong dependency between the two limits like sig(x+8 downto x).
Sometimes a suitable way of modelling can be found using a for-loop.
It may be a good idea to split the description of the comparator from
the one of the mux. This makes it often more clear what exactly must be
the desired hardware. Furthermore the mux should be described carefully
using every detail you know.
Some details: If I look at the following pieces of code
> 42 for i in 0 to ((2*n)-1) loop
....
> 54 sorted_array((((i+1)*w)-1) downto (i*w))<= ...
then the obviously the limits of the selected part of the array are
fixed, but I guess it will be much easier for the synthesis tool, if you
model this for
sorted_array(1*w-1 dowto 0*w)<=...
sorted_array(2*w-1 dowto 1*w)<=...
....
Furthermore you should seperate all these statements into several
processes. To avoid a lot of typing you may use a for-generate
statement, but I would do this later, if everything is clear.
If you separate all these partial vectors you have to model the
selectors in your code (x1, x2, pick1, pick2...) in a different way, but
I guess this approach leads to a more clean desription of the desired
hardware.
> What I don't know is which input to feed in these
> caomparators. That is decided by the 'pick' value.
Yes, I see.
My comments ignore the behavior of the algorithm. (I have to say, that I
did not even think about it.) I have just looked at the code and tried
to see the related hardware, that is described. At the moment I do not
know it, because the code is complex.
But I think if you can decribe the selectors of the muxes in a very
clean way (this means, that you have to know it for yourself and you
have to model it in a way, that can be understood by the synthesis tool)
you have the solution. And this:
> Is there a known hardware architecture for this last step of
> merge-sort?
is exactly the point. If I am not wrong we have figured out three main
parts of this architecture: the comparators, the muxes and the
mux-selectors (controlled by something we do not know at the moment).
I suggest to follow this top-down approach: Model every known component
in an explicit way and then the unknown parts will be more visible.
Ralf