I encountered something weird in a Verilog code, and I have doubts about it.
Someone used a function in Verilog in the following way:
Pipe #(.W($bits(Data))) MetaO (Clock, MyFunc(DataIn, I0, I1), DataOut);
function [DATA_SIZE-1:0] MyFunc (input [DATA_SIZE-1:0] DataIn, input I0, input I1);
MyFunc = DataIn;
MyFunc[1] = X;
if(I0) begin
MyFunc[2] = Y;
MyFunc[3] = K;
MyFunc[4] = I1;
end endfunction
So, what he tried to do here is to pipe DataIn to DataOut,
but to manipulate DataIn bits before the pipe, so he used function as the input to the Input port of the pipe.
My doubts are in the function itself.
He first of all kind of initialized MyFunc with DataIn,
and then in the following lines, assigns different values in the other bits depending on some stuff.
Because it's eventually combinatorial logic, I ask myself if it's a correct way to write Verilog.
Doesn't it create a race condition on some of these bits?
Can it make timing issues eventually?
What is another better way to write the same combinatorial logic?