Update: bug has been fixed as of commit number 2024-6-26
In short, Im building a Nary tree to meet timing for some basic operations. &, |, and ^
Im using some `defines and `undefine statements to make the code reusable for each operations. (a.k.a a little hard to read and follow, but much easier to cut and paste)
I have wrote and tested the recursion functions, and can now calculate all the information needed to build the tree.
but when I try to use the value returned by the function, I get an error in my simulator(iVerilog), but not Gowin FPGA designer( no simulator.)
Error code can be found here
https://github.com/Adivinedude/FPGA-toolbox/blob/refactor_counter/math_pipelined.vline # 132
generate
// loop through each unit and assign the in and outs
for( unit_index = 0; unit_index < CMP_VECTOR_SIZE; unit_index = unit_index + 1) begin : CMP_unit_loop
// make the input wires for this unit
/*129*/ wire [f_NaryRecursionGetUnitWidth(CHUNK_COUNT, CMP_LUT_WIDTH, unit_index)-1:0] unit_inputs;
// assign the inputs to their proper place, unused inputs should be optimized away when set properly
for( input_index = 0; input_index != CMP_LUT_WIDTH; input_index = input_index+1 ) begin : CMP_input_loop
/*132*/ if( f_NaryRecursionGetUnitInputAddress(CHUNK_COUNT, CMP_LUT_WIDTH, unit_index, input_index) != ~0 )
assign unit_inputs[input_index] = r_cmp[f_NaryRecursionGetUnitInputAddress(CHUNK_COUNT, CMP_LUT_WIDTH, unit_index, input_index)];
end
// perform the function and store the output
always @( posedge clk ) r_cmp[CHUNK_COUNT+unit_index] <= & unit_inputs; // edit operation here
end
`undef OPERATION
endgenerate
unit_index, input_index, and idx are defined at genvar in line 69-71
the functions are defined here
https://github.com/Adivinedude/FPGA-toolbox/blob/refactor_counter/recursion_iterators.v#213 // f_NaryRecursionGetUnitWidth - Returns the total number of inputs for unit requested
#297 // f_NaryRecursionGetUnitInputAddress - Returns the index for the base bit requested. returns ~0 is input is request is invalid
error message
Starting Testbench with iVerilog
././toolbox/recursion_iterators.v:222: error: A function invoked by a constant function must be a constant function local to the current module.
././toolbox/recursion_iterators.v:322: error: A function invoked by a constant function must be a constant function local to the current module.
././toolbox/recursion_iterators.v:309: error: A function invoked by a constant function must be a constant function local to the current module.
c:\Users\adivi\Desktop\fpga_projects\Tang_Nano_9K_blink\src\uart\toolbox\math_pipelined.v:132: error: `f_NaryRecursionGetUnitInputAddress' is not a constant function.
c:\Users\adivi\Desktop\fpga_projects\Tang_Nano_9K_blink\src\uart\toolbox\math_pipelined.v:132: error: Cannot evaluate genvar conditional expression: (f_NaryRecursionGetUnitInputAddress(CHUNK_COUNT, CMP_LUT_WIDTH, unit_index, input_index))!=(~('sd0))
...(last two lines repeat many times
the obvious question is, How do I do this?
but line #129 also requires a constant value, but does not throw an error.
so now i'm questing my understanding of what a constant function is, I have read many google post about it, but none state where the official definition is located. I would love to read it myself.
Im stumped as to what to try next.
This seams simple enough but just doesn't work. its been a real pain in the @$$ for the last few hours.