Skip to content

Commit

Permalink
Legalizer: Read splitter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMightyDuckOfDoom committed Sep 4, 2023
1 parent c1f23fa commit adb009b
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 174 deletions.
337 changes: 163 additions & 174 deletions src/backend/src/idma_legalizer.sv.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ ${database[p]['max_beats_per_burst']} * StrbWidth > ${database[p]['page_size']}\
logic w_tf_ena;

// page boundaries
% if no_read_bursting or has_page_read_bursting:
page_len_t r_page_num_bytes_to_pb;
% endif
% for read_protocol in used_read_protocols:
% if database[read_protocol]['bursts'] == 'only_pow2':
page_len_t r_${database[read_protocol]['prefix']}_num_bytes_to_pb;
% endif
% endfor
page_len_t r_num_bytes_to_pb;
page_len_t w_num_bytes_to_pb;
page_len_t c_num_bytes_to_pb;
Expand All @@ -163,111 +171,187 @@ ${database[p]['max_beats_per_burst']} * StrbWidth > ${database[p]['page_size']}\
//--------------------------------------
// read boundary check
//--------------------------------------
% if one_read_port:
% if database[used_read_protocols[0]]['bursts'] == 'not_supported':
% if no_read_bursting or has_page_read_bursting:
idma_legalizer_page_splitter #(
.OffsetWidth ( OffsetWidth ),
.PageAddrWidth ( PageSize ),
.addr_t ( addr_t ),
.page_len_t ( page_len_t ),
.page_addr_t ( page_addr_t )
) i_read_page_splitter (
.not_bursting_i ( 1'b1 ),
% if no_read_bursting:
.not_bursting_i ( 1'b1 ),
% elif len(used_non_bursting_read_protocols) == 0:
.not_bursting_i ( 1'b0 ),
% else:
.not_bursting_i ( opt_tf_q.src_protocol inside {\
% for index, protocol in enumerate(used_non_bursting_read_protocols):
idma_pkg::${database[protocol]['protocol_enum']}\
% if index != len(used_non_bursting_read_protocols)-1:
,\
% endif
% endfor
} ),
% endif

.reduce_len_i ( opt_tf_q.src_reduce_len ),
.max_llen_i ( opt_tf_q.src_max_llen ),

.addr_i ( r_tf_q.addr ),
.num_bytes_to_pb_o ( r_num_bytes_to_pb )
.num_bytes_to_pb_o ( r_page_num_bytes_to_pb )
);
% elif database[used_read_protocols[0]]['bursts'] == 'split_at_page_boundary':
idma_legalizer_page_splitter #(

% endif
% for read_protocol in used_read_protocols:
% if database[read_protocol]['bursts'] == 'only_pow2':
idma_legalizer_pow2_splitter #(
.PageAddrWidth ( $clog2(${database[read_protocol]['page_size']}) ),
.OffsetWidth ( OffsetWidth ),
.PageAddrWidth ( $clog2((${database[used_read_protocols[0]]['max_beats_per_burst']} * StrbWidth\
> ${database[used_read_protocols[0]]['page_size']}) ?\
${database[used_read_protocols[0]]['page_size']} :\
${database[used_read_protocols[0]]['max_beats_per_burst']} * StrbWidth) ),
.addr_t ( addr_t ),
.page_len_t ( page_len_t ),
.page_addr_t ( page_addr_t )
) i_read_page_splitter (
.not_bursting_i ( 1'b0 ),
.reduce_len_i ( opt_tf_q.src_reduce_len ),
.max_llen_i ( opt_tf_q.src_max_llen ),

.addr_i ( r_tf_q.addr ),
.num_bytes_to_pb_o ( r_num_bytes_to_pb )
);
% elif database[used_read_protocols[0]]['bursts'] == 'only_pow2':
idma_legalizer_pow2_splitter #(
.PageAddrWidth ( $clog2(${database[used_read_protocols[0]]['page_size']}) ),
.OffsetWidth ( OffsetWidth ),
.addr_t ( addr_t ),
.len_t ( page_len_t )
.len_t ( page_len_t )
) i_read_pow2_splitter (
.addr_i ( r_tf_q.addr ),
.addr_i ( r_tf_q.addr ),
.length_i ( \
% if database[used_read_protocols[0]]['tltoaxi4_compatibility_mode'] == "true":
|r_tf_q.length[$bits(r_tf_q.length)-1:PageAddrWidth] ? page_len_t'('d${database[used_read_protocols[0]]['page_size']} - r_tf_q.addr[PageAddrWidth-1:0]) : r_tf_q.length[PageAddrWidth:0] ),
% if database[read_protocol]['tltoaxi4_compatibility_mode'] == "true":
|r_tf_q.length[$bits(r_tf_q.length)-1:PageAddrWidth] ? page_len_t'('d${database[read_protocol]['page_size']} - r_tf_q.addr[PageAddrWidth-1:0]) : r_tf_q.length[PageAddrWidth:0] ),
.length_larger_i ( 1'b0 ),
% else:
% else:
r_tf_q.length[PageAddrWidth:0] ),
.length_larger_i ( |r_tf_q.length[$bits(r_tf_q.length)-1:PageAddrWidth+1] ),
% endif
.bytes_to_transfer_o ( r_num_bytes_to_pb )
% endif
.bytes_to_transfer_o ( r_${database[read_protocol]['prefix']}_num_bytes_to_pb )
);

% endif
% endfor
% if no_read_bursting:
assign r_num_bytes_to_pb = r_page_num_bytes_to_pb;
% elif one_read_port:
% if has_pow2_read_bursting:
assign r_num_bytes_to_pb = r_${database[used_read_protocols[0]]['prefix']}_num_bytes_to_pb;
% else:
`IDMA_NONSYNTH_BLOCK(
initial begin
$fatal(1, "bursts value '${database[used_read_protocols[0]]['bursts']}' for read protocol ${database[used_read_protocols[0]]['full_name']} not implemented in template!");
end
)
assign r_page_addr_width = '0;
assign r_num_bytes_to_pb = r_page_num_bytes_to_pb;
% endif
% elif no_read_bursting:
idma_legalizer_page_splitter #(
.OffsetWidth ( OffsetWidth ),
.PageAddrWidth ( PageSize ),
.addr_t ( addr_t ),
.page_len_t ( page_len_t ),
.page_addr_t ( page_addr_t )
) i_read_page_splitter (
.not_bursting_i ( 1'b1 ),

.reduce_len_i ( opt_tf_q.src_reduce_len ),
.max_llen_i ( opt_tf_q.src_max_llen ),

.addr_i ( r_tf_q.addr ),
.num_bytes_to_pb_o ( r_num_bytes_to_pb )
);
% else:
idma_legalizer_page_splitter #(
.OffsetWidth ( OffsetWidth ),
.PageAddrWidth ( PageSize ),
.addr_t ( addr_t ),
.page_len_t ( page_len_t ),
.page_addr_t ( page_addr_t )
) i_read_page_splitter (
%if len(used_non_bursting_read_protocols) == 0:
.not_bursting_i ( 1'b0 ),
%else:
.not_bursting_i ( opt_tf_q.src_protocol inside {\
% for index, protocol in enumerate(used_non_bursting_read_protocols):
idma_pkg::${database[protocol]['protocol_enum']}\
% if index != len(used_non_bursting_read_protocols)-1:
,\
always_comb begin : gen_read_num_bytes_to_pb_logic
case (opt_tf_q.src_protocol)
% for read_protocol in used_read_protocols:
idma_pkg::${database[read_protocol]['protocol_enum']}: \
% if database[read_protocol]['bursts'] == 'only_pow2':
r_num_bytes_to_pb = r_${database[read_protocol]['prefix']}_num_bytes_to_pb;
% else:
r_num_bytes_to_pb = r_page_num_bytes_to_pb;
% endif
% endfor
} ),
% endif
% endfor
default: r_num_bytes_to_pb = '0;
endcase
end
% endif

.reduce_len_i ( opt_tf_q.src_reduce_len ),
.max_llen_i ( opt_tf_q.src_max_llen ),
##% if one_read_port:
## % if database[used_read_protocols[0]]['bursts'] == 'not_supported':
## idma_legalizer_page_splitter #(
## .OffsetWidth ( OffsetWidth ),
## .PageAddrWidth ( PageSize ),
## .addr_t ( addr_t ),
## .page_len_t ( page_len_t ),
## .page_addr_t ( page_addr_t )
## ) i_read_page_splitter (
## .not_bursting_i ( 1'b1 ),

## .reduce_len_i ( opt_tf_q.src_reduce_len ),
## .max_llen_i ( opt_tf_q.src_max_llen ),

.addr_i ( r_tf_q.addr ),
.num_bytes_to_pb_o ( r_num_bytes_to_pb )
);
% endif
## .addr_i ( r_tf_q.addr ),
## .num_bytes_to_pb_o ( r_num_bytes_to_pb )
## );
## % elif database[used_read_protocols[0]]['bursts'] == 'split_at_page_boundary':
## idma_legalizer_page_splitter #(
## .OffsetWidth ( OffsetWidth ),
## .PageAddrWidth ( $clog2((${database[used_read_protocols[0]]['max_beats_per_burst']} * StrbWidth\
## > ${database[used_read_protocols[0]]['page_size']}) ?\
## ${database[used_read_protocols[0]]['page_size']} :\
## ${database[used_read_protocols[0]]['max_beats_per_burst']} * StrbWidth) ),
## .addr_t ( addr_t ),
## .page_len_t ( page_len_t ),
## .page_addr_t ( page_addr_t )
## ) i_read_page_splitter (
## .not_bursting_i ( 1'b0 ),
## .reduce_len_i ( opt_tf_q.src_reduce_len ),
## .max_llen_i ( opt_tf_q.src_max_llen ),

## .addr_i ( r_tf_q.addr ),
## .num_bytes_to_pb_o ( r_num_bytes_to_pb )
## );
## % elif database[used_read_protocols[0]]['bursts'] == 'only_pow2':
## idma_legalizer_pow2_splitter #(
## .PageAddrWidth ( $clog2(${database[used_read_protocols[0]]['page_size']}) ),
## .OffsetWidth ( OffsetWidth ),
## .addr_t ( addr_t ),
## .len_t ( page_len_t )
## ) i_read_pow2_splitter (
## .addr_i ( r_tf_q.addr ),
## .length_i ( \
##% if database[used_read_protocols[0]]['tltoaxi4_compatibility_mode'] == "true":
##|r_tf_q.length[$bits(r_tf_q.length)-1:PageAddrWidth] ? page_len_t'('d${database[used_read_protocols[0]]['page_size']} - r_tf_q.addr[PageAddrWidth-1:0]) : r_tf_q.length[PageAddrWidth:0] ),
## .length_larger_i ( 1'b0 ),
##% else:
##r_tf_q.length[PageAddrWidth:0] ),
## .length_larger_i ( |r_tf_q.length[$bits(r_tf_q.length)-1:PageAddrWidth+1] ),
##% endif
## .bytes_to_transfer_o ( r_num_bytes_to_pb )
## );
## % else:
## `IDMA_NONSYNTH_BLOCK(
## initial begin
## $fatal(1, "bursts value '${database[used_read_protocols[0]]['bursts']}' for read protocol ${database[used_read_protocols[0]]['full_name']} not implemented in template!");
## end
## )
## % endif
##% elif no_read_bursting:
## idma_legalizer_page_splitter #(
## .OffsetWidth ( OffsetWidth ),
## .PageAddrWidth ( PageSize ),
## .addr_t ( addr_t ),
## .page_len_t ( page_len_t ),
## .page_addr_t ( page_addr_t )
## ) i_read_page_splitter (
## .not_bursting_i ( 1'b1 ),

## .reduce_len_i ( opt_tf_q.src_reduce_len ),
## .max_llen_i ( opt_tf_q.src_max_llen ),

## .addr_i ( r_tf_q.addr ),
## .num_bytes_to_pb_o ( r_num_bytes_to_pb )
## );
##% else:
## idma_legalizer_page_splitter #(
## .OffsetWidth ( OffsetWidth ),
## .PageAddrWidth ( PageSize ),
## .addr_t ( addr_t ),
## .page_len_t ( page_len_t ),
## .page_addr_t ( page_addr_t )
## ) i_read_page_splitter (
## %if len(used_non_bursting_read_protocols) == 0:
## .not_bursting_i ( 1'b0 ),
## %else:
## .not_bursting_i ( opt_tf_q.src_protocol inside {\
## % for index, protocol in enumerate(used_non_bursting_read_protocols):
## idma_pkg::${database[protocol]['protocol_enum']}\
## % if index != len(used_non_bursting_read_protocols)-1:
##,\
## % endif
## % endfor
##} ),
## % endif

## .reduce_len_i ( opt_tf_q.src_reduce_len ),
## .max_llen_i ( opt_tf_q.src_max_llen ),

## .addr_i ( r_tf_q.addr ),
## .num_bytes_to_pb_o ( r_num_bytes_to_pb )
## );
##% endif

//--------------------------------------
// write boundary check
Expand Down Expand Up @@ -336,7 +420,6 @@ w_tf_q.length[PageAddrWidth:0] ),
$fatal(1, "bursts value '${database[used_write_protocols[0]]['bursts']}' for write protocol ${database[used_write_protocols[0]]['full_name']} not implemented in template!");
end
)
assign w_page_addr_width = '0;
% endif
% elif no_write_bursting:
idma_legalizer_page_splitter #(
Expand Down Expand Up @@ -391,100 +474,6 @@ w_tf_q.length[PageAddrWidth:0] ),
//--------------------------------------
// Synchronized R/W process
//--------------------------------------
## if 1R1W
## if no_read_bursting or no_write_bursting or tilelink
## -> decouple both
## else
## -> optional decouple
## else // Multiport
## if no_bursting
## -> optional decouple
## else if only_write_bursts:
## -> optional decouple write and force if non_bursting_write_protocol
## else if only_read_bursts:
## -> optional decouple read and force if non_bursting_read_protocol
## else: // Both can burst
## -> optional decouple both and force if non_bursting_protocol
##
##
##% if one_read_port and one_write_port:
## % if (no_read_bursting or no_write_bursting) or ('tilelink' in used_protocols):
## assign r_num_bytes_possible = r_num_bytes_to_pb;
## assign w_num_bytes_possible = w_num_bytes_to_pb;
## % else:
## assign r_num_bytes_possible = opt_tf_q.decouple_rw ?
## r_num_bytes_to_pb : c_num_bytes_to_pb;
## assign w_num_bytes_possible = opt_tf_q.decouple_rw ?
## w_num_bytes_to_pb : c_num_bytes_to_pb;
## % endif
##% else:
## % if no_read_bursting and no_write_bursting:
## // No Bursting at all
## assign r_num_bytes_possible = opt_tf_q.decouple_rw ?
## r_num_bytes_to_pb : c_num_bytes_to_pb;
## assign w_num_bytes_possible = opt_tf_q.decouple_rw ?
## w_num_bytes_to_pb : c_num_bytes_to_pb;
## % elif no_read_bursting and (not no_write_bursting):
## // Only write bursts possible
## assign r_num_bytes_possible = r_num_bytes_to_pb;
## assign w_num_bytes_possible = (opt_tf_q.decouple_rw || (opt_tf_q.dst_protocol inside {\
## % for index, protocol in enumerate(used_non_bursting_write_protocols):
## idma_pkg::${database[protocol]['protocol_enum']}\
## % if index != len(used_non_bursting_write_protocols)-1:
##,\
## % endif
## % endfor
## })) ?
## w_num_bytes_to_pb : c_num_bytes_to_pb;
## % elif (not no_read_bursting) and no_write_bursting:
## // Only read bursts possible
## assign w_num_bytes_possible = w_num_bytes_to_pb;
## assign r_num_bytes_possible = (opt_tf_q.decouple_rw || (opt_tf_q.src_protocol inside {\
## % for index, protocol in enumerate(used_non_bursting_read_protocols):
## idma_pkg::${database[protocol]['protocol_enum']}\
## % if index != len(used_non_bursting_read_protocols)-1:
##,\
## % endif
## % endfor
## })) ?
## r_num_bytes_to_pb : c_num_bytes_to_pb;
## % else:
## // Both read and write bursts possible
## always_comb begin
## r_num_bytes_possible = c_num_bytes_to_pb;
## w_num_bytes_possible = c_num_bytes_to_pb;

## if ( opt_tf_q.decouple_rw\
## % if len(used_non_bursting_read_protocols) != 0:

## || (opt_tf_q.src_protocol inside {\
## % for index, protocol in enumerate(used_non_bursting_read_protocols):
## idma_pkg::${database[protocol]['protocol_enum']}\
## % if index != len(used_non_bursting_read_protocols)-1:
##,\
## % endif
## % endfor
## })\
## % endif
## % if len(used_non_bursting_write_protocols) != 0:

## || (opt_tf_q.dst_protocol inside {\
## % for index, protocol in enumerate(used_non_bursting_write_protocols):
## idma_pkg::${database[protocol]['protocol_enum']}\
## % if index != len(used_non_bursting_write_protocols)-1:
##,\
## % endif
## % endfor
## })\
## % endif

## ) begin
## r_num_bytes_possible = r_num_bytes_to_pb;
## w_num_bytes_possible = w_num_bytes_to_pb;
## end
## end
## % endif
##% endif
always_comb begin : proc_num_bytes_possible
// Default: Coupled
r_num_bytes_possible = c_num_bytes_to_pb;
Expand Down
Loading

0 comments on commit adb009b

Please sign in to comment.