C
Candida Ferreira
Guest
Hello Everyone,
I'm building a 3-mux grammar in Verilog and just realized that it is not
giving the expeted results. For instance, the code below generated using
only AND, OR, and NOT, is a solution to the Majority(x,y,z) function.
---
module gepModel (d, result);
input [0:2] d;
output result;
reg result;
reg [0:1] gene;
initial begin
d[0] = 1'b1;
d[1] = 1'b0;
d[2] = 1'b1;
fork : geneEvaluation
gene[0] = ((d[2] & d[1]) | (d[0] & d[2]));
gene[1] = (d[0] & d[1]);
join
result = (gene[0] | gene[1]);
end
endmodule
---
The following code is a straightforward translation of this code to a Mux
grammar, but curiously it is no longer a solution to the majority function:
---
module gepModel (d, result);
input [0:2] d;
output result;
reg result;
reg [0:1] gene;
initial begin
d[0] = 1'b1;
d[1] = 1'b0;
d[2] = 1'b1;
fork : geneEvaluation
gene[0] =
gepMux(gepMux(d[2],d[2],d[1]),gepMux(d[0],d[0],d[2]),gepMux(d[2],d[2],d[1]));
gene[1] = gepMux(d[0],d[0],d[1]);
join
result = gepMux(gene[0],gene[1],gene[0]);
end
function gepMux;
input x, y, z;
begin
gepMux = (((~(x)) & y) | (x & z));
end
endfunction
endmodule
---
The most interesting is that a similar Mux grammar in VHDL behaves exactly
as expected and gives the correct answer:
library IEEE;
use IEEE.std_logic_1164.all;
entity gepModel is
port (d: in bit_vector (0 to 2);
result: out bit);
end gepModel;
architecture gepGeneratedCode of gepModel is
function gepMux(x, y, z: bit) return bit is
begin
return (((not(x)) and y) or (x and z));
end gepMux;
signal gene: bit_vector (0 to 1);
begin
gene(0) <=
gepMux(gepMux(d(2),d(2),d(1)),gepMux(d(0),d(0),d(2)),gepMux(d(2),d(2),d(1)));
gene(1) <= gepMux(d(0),d(0),d(1));
result <= gepMux(gene(0),gene(1),gene(0));
end architecture gepGeneratedCode;
---
Any ideas why this is happening in Verilog? Am I doing something wrong? This
happens fairly frequently and so far I've been unable to understand the
reason for this.
Many thanks.
Candida
---
Candida Ferreira, Ph.D.
Chief Scientist, Gepsoft
http://www.gene-expression-programming.com/author.asp
GEP: Mathematical Modeling by an Artificial Intelligence
(Springer Verlag edition 2006)
http://www.gene-expression-programming.com/Books/index.asp
Online Version:
http://www.gene-expression-programming.com/GepBook/Introduction.htm
Modeling Software:
http://www.gepsoft.com/
I'm building a 3-mux grammar in Verilog and just realized that it is not
giving the expeted results. For instance, the code below generated using
only AND, OR, and NOT, is a solution to the Majority(x,y,z) function.
---
module gepModel (d, result);
input [0:2] d;
output result;
reg result;
reg [0:1] gene;
initial begin
d[0] = 1'b1;
d[1] = 1'b0;
d[2] = 1'b1;
fork : geneEvaluation
gene[0] = ((d[2] & d[1]) | (d[0] & d[2]));
gene[1] = (d[0] & d[1]);
join
result = (gene[0] | gene[1]);
end
endmodule
---
The following code is a straightforward translation of this code to a Mux
grammar, but curiously it is no longer a solution to the majority function:
---
module gepModel (d, result);
input [0:2] d;
output result;
reg result;
reg [0:1] gene;
initial begin
d[0] = 1'b1;
d[1] = 1'b0;
d[2] = 1'b1;
fork : geneEvaluation
gene[0] =
gepMux(gepMux(d[2],d[2],d[1]),gepMux(d[0],d[0],d[2]),gepMux(d[2],d[2],d[1]));
gene[1] = gepMux(d[0],d[0],d[1]);
join
result = gepMux(gene[0],gene[1],gene[0]);
end
function gepMux;
input x, y, z;
begin
gepMux = (((~(x)) & y) | (x & z));
end
endfunction
endmodule
---
The most interesting is that a similar Mux grammar in VHDL behaves exactly
as expected and gives the correct answer:
library IEEE;
use IEEE.std_logic_1164.all;
entity gepModel is
port (d: in bit_vector (0 to 2);
result: out bit);
end gepModel;
architecture gepGeneratedCode of gepModel is
function gepMux(x, y, z: bit) return bit is
begin
return (((not(x)) and y) or (x and z));
end gepMux;
signal gene: bit_vector (0 to 1);
begin
gene(0) <=
gepMux(gepMux(d(2),d(2),d(1)),gepMux(d(0),d(0),d(2)),gepMux(d(2),d(2),d(1)));
gene(1) <= gepMux(d(0),d(0),d(1));
result <= gepMux(gene(0),gene(1),gene(0));
end architecture gepGeneratedCode;
---
Any ideas why this is happening in Verilog? Am I doing something wrong? This
happens fairly frequently and so far I've been unable to understand the
reason for this.
Many thanks.
Candida
---
Candida Ferreira, Ph.D.
Chief Scientist, Gepsoft
http://www.gene-expression-programming.com/author.asp
GEP: Mathematical Modeling by an Artificial Intelligence
(Springer Verlag edition 2006)
http://www.gene-expression-programming.com/Books/index.asp
Online Version:
http://www.gene-expression-programming.com/GepBook/Introduction.htm
Modeling Software:
http://www.gepsoft.com/