analogdevicesinc/hdl

[BUG] Possible bug in request_arb.v of axi_dmac core

catkira opened this issue · 2 comments

I am looking at this function and cant make sense of it:

function compare_id;
  input [ID_WIDTH-1:0] a;
  input [ID_WIDTH-1:0] b;
  begin
    compare_id = a[ID_WIDTH-1] == b[ID_WIDTH-1];  // compare MSB
    if (ID_WIDTH >= 2) begin
      if (a[ID_WIDTH-2] == b[ID_WIDTH-2]) begin //  compare 2nd MSB
        compare_id = 1'b1;
      end
    end
    if (ID_WIDTH >= 3) begin
      if (a[ID_WIDTH-3:0] != b[ID_WIDTH-3:0]) begin      // compare LSBs except 2 MSBs
        compare_id = 1'b1;
      end
    end
  end
endfunction

(code comments are added by me)

Why is it comparing in some cases "==" and in another case "!="?
That numbers that are compared are gray coded, maybe that helps to figure out the meaning of this function...
The code is taken from here.

@larsclausen I think You now the code best (judging by the commit history of the file)

It's standard logic for comparing gray code FIFO addresses.

To understand this maybe going through a simple example will help. Imagine a FIFO with 4 entries. The FIFO can be in 5 different states (0, 1, 2, 3, 4 elements used). So you need 3 bits. Draw the table of all 3 bit gray codes in the right order and then look at it to see the pattern when FIFO should be considered full.

thanks, that helped a lot!
I would maybe name the function something like "test_not_full" or so :)

Its the inverted version of this code from zipcpu

	assign	o_wfull  = (wgray[AW:AW-1] == ~wq2_rgray[AW:AW-1])
				&& (wgray[AW-2:0]==wq2_rgray[AW-2:0]);