We shouldn't question the OP's intentions: the OP may need the q_next to take some look-ahead decision.
Anyway; the original 28 LUTs can be reduced to 17 by rewriting the source code slightly:
module register8 (
clk,
clken,
reset_n,
data,
load,
cnt_en,
updown,
q,
q_next
);
input clk;
input clken;
input reset_n;
input data;
input load;
input cnt_en;
input updown;
output q, q_next;
reg addsub;
always @(*)
if ( updown )
addsub = - 8'd1;
else
addsub = 8'd1;
// asynchronous 'next' value. This is used extensively for flags
reg q, q_next;
always @(*)
q_next = q + addsub;
always @(posedge clk or negedge reset_n )
if ( !reset_n )
q <= 8'd0;
else if ( clken & (load | cnt_en))
if (load )
q <= data;
else
q <= q_next;
endmodule
This produces an (almost?) beautiful RTL schematic:
https://alteraforum.com/forum/attachment.php?attachmentid=14923&stc=1 Oops, I did change the functionality after all ...
Here is the corrected source code:
module register8 ( clk,
clken,
reset_n,
data,
load,
cnt_en,
updown,
q,
q_next
);
input clk;
input clken;
input reset_n;
input data;
input load;
input cnt_en;
input updown;
output q, q_next;
reg addsub;
always @(*)
if ( updown )
addsub = - 8'd1;
else
addsub = 8'd1;
// asynchronous 'next' value. This is used extensively for flags
reg q, q_next;
always @(*)
if (load)
q_next = data;
else
q_next = q + addsub;
always @(posedge clk or negedge reset_n )
if ( !reset_n )
q <= 8'd0;
else if ( clken & cnt_en)
q <= q_next;
endmodule
and the corresponding (beautiful!) RTL schematic:
https://alteraforum.com/forum/attachment.php?attachmentid=14924&stc=1 And still only 17 LEs!
But it is still different from the original ...
Three times is a charm ...
module register8 ( clk,
clken,
reset_n,
data,
load,
cnt_en,
updown,
q,
q_next
);
input clk;
input clken;
input reset_n;
input data;
input load;
input cnt_en;
input updown;
output q, q_next;
reg addsub;
always @(*)
if ( cnt_en)
if (updown )
addsub = - 8'd1;
else
addsub = 8'd1;
else
addsub = 0;
// asynchronous 'next' value. This is used extensively for flags
reg q, q_next;
always @(*)
if (load)
q_next = data;
else
q_next = q + addsub;
always @(posedge clk or negedge reset_n )
if ( !reset_n )
q <= 8'd0;
else if ( clken )
q <= q_next;
endmodule
https://alteraforum.com/forum/attachment.php?attachmentid=14925&stc=1 And, I am lucky! Still only 17 LE. I must admit this starts looking obscure, so I will not get any brownie points :)