Appearing further below is the atoi_it from the solution to Homework 2. (a) Show the hardware inferred for an atoi_it module instantiated with r=14 (yes, radix 14) and n=3.
Problem 2: Appearing further below is the atoi_it from the solution to Homework 2.
(a) Show the hardware inferred for an atoi_it module instantiated with r=14 (yes, radix 14) and
n=3.
Show atoi1, mult_by_c, and add instances as modules, do not show what is inside.
Show the hardware inferred for the operators, such as && and ?:.
Do not confuse parameters and ports.
Omit hardware that does not belong, such as "hardware" to compute values needed at elaboration time.
Be sure to show the inferred logic. Remember that generate statements describe what hap- pens at elaboration time, not what happens at simulation time nor does it describe operations performed by the hardware.
(b) Show the hardware inferred for an atoi_it module instantiated with r=16 (hexadecimal this time) and n=3, and show the hardware after optimization. Consider the impact of optimization on the mult_by_c and add modules, which should be considerable since r is a power of 2.
3
module atoi_it
#( int r = 11, n = 5, wv = $clog2( r**n ), wd = $clog2(n+1) )
( output logic [wv-1:0] val, output logic [wd-1:0] nd, input uwire [7:0] str [n-1:0] );
uwire [wv-1:0] vali[n-1:-1]; uwire is_valid[n-1:-1]; uwire [wd-1:0] ndi[n-1:-1]; assign is_valid[-1] = 1; assign ndi[-1] = 0;
assign vali[-1] = 0; assign nd = ndi[n-1]; assign val = vali[n-1];
localparam int wcv = $clog2(r); for ( genvar i=0; i<n; i++ ) begin // Find Value of Digit i // uwire [wcv-1:0] valdr; uwire is_digit;
atoi1 #(r,wcv) a( valdr, is_digit, str[i] );
// Determine if this digit continues a sequence of valid digits // starting at str[0].
//
assign is_valid[i] = is_digit && is_valid[i-1];
// Replace value with zero if str[i] is not a digit, or if the // string of valid digits has already ended.
//
uwire [wcv-1:0] vald = is_valid[i] ? valdr : 0;
// Multiply (scale) the digit value based on its position in the number. //
uwire [wv-1:0] vals;
mult_by_c #( .w_in(wcv), .c(r**i), .w_out(wv) ) mc( vals, vald );
// Add the scaled digit to the value accumulated so far. //
add #(wv) a1( vali[i], vali[i-1], vals );
// Update the number of digits so far.
//
assign ndi[i] = is_valid[i] ? i+1 : ndi[i-1];
end
endmodule
Trending now
This is a popular solution!
Step by step
Solved in 2 steps