#NEWLINE# def __init__( s , nreqs ) : #NEWLINE# #INDENT# nreqsX2 = ( nreqs * 2 ) #NEWLINE# s . reqs = InPort ( nreqs ) #NEWLINE# s . grants = OutPort ( nreqs ) #NEWLINE# s . priority_en = Wire ( 1 ) #NEWLINE# s . priority_reg = m = RegEnRst ( nreqs , reset_value = 1 ) #NEWLINE# s . connect_dict ( { #NEWLINE# #INDENT# m . en : s . priority_en , #NEWLINE# m . in_ [ 1 : s ] : s . grants [ 0 : ( nreqs - 1 ) ] , #NEWLINE# m . in_ [ 0 ] : s . grants [ ( nreqs - 1 ) ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# s . kills = Wire ( ( ( 2 * nreqs ) + 1 ) ) #NEWLINE# s . priority_int = Wire ( ( 2 * nreqs ) ) #NEWLINE# s . reqs_int = Wire ( ( 2 * nreqs ) ) #NEWLINE# s . grants_int = Wire ( ( 2 * nreqs ) ) #NEWLINE# @ s . combinational #NEWLINE# def comb( ) : #NEWLINE# #INDENT# s . kills [ 0 ] . value = 1 #NEWLINE# s . priority_int [ 0 : nreqs ] . value = s . priority_reg . out #NEWLINE# s . priority_int [ nreqs : nreqsX2 ] . value = 0 #NEWLINE# s . reqs_int [ 0 : nreqs ] . value = s . reqs #NEWLINE# s . reqs_int [ nreqs : nreqsX2 ] . value = s . reqs #NEWLINE# for i in range ( nreqsX2 ) : #NEWLINE# #INDENT# if s . priority_int [ i ] . value : #NEWLINE# #INDENT# s . grants_int [ i ] . value = s . reqs_int [ i ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s . grants_int [ i ] . value = ( ( ~ s . kills [ i ] ) & s . reqs_int [ i ] ) #NEWLINE# #UNINDENT# if s . priority_int [ i ] . value : #NEWLINE# #INDENT# s . kills [ ( i + 1 ) ] . value = s . grants_int [ i ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s . kills [ ( i + 1 ) ] . value = ( s . kills [ i ] | s . grants_int [ i ] ) #NEWLINE# #UNINDENT# #UNINDENT# for i in range ( nreqs ) : #NEWLINE# #INDENT# s . grants [ i ] . value = ( s . grants_int [ i ] | s . grants_int [ ( nreqs + i ) ] ) #NEWLINE# #UNINDENT# s . priority_en . value = ( s . grants != 0 )