anchor.diff:  
         // Source priority 
         else if (addr_offset < 'h1000) begin
  -	 Bit #(10) source_id = addr_offset [11:2];
  -	 if ((0 < source_id) && (source_id < fromInteger (n_sources)))
  +	 Bit #(T_wd_source_id)  source_id = truncate (addr_offset [11:2]);
  +	 if ((0 < source_id) && (source_id <= fromInteger (n_sources - 1)))
   	    vrg_source_prio [source_id] <= changeWidth (wdata32);
         end
   
         // Source IPs (interrupt pending).
         // Read-only, so ignore write; just check that addr ok.
         else if (('h1000 <= addr_offset) && (addr_offset < 'h2000)) begin
  -	 Bit #(15) source_id_base = { addr_offset [11:0], 3'h0 };
  -
  -	 if (source_id_base >= fromInteger (n_sources))
  +	 Bit #(T_wd_source_id)  source_id_base = truncate ({ addr_offset [11:0], 5'h0 });
  +
  +	 if (! (source_id_base <= fromInteger (n_sources - 1)))
   	    bresp = axi4_resp_decerr;
         end
   
  
positive.code: 
        // Source priority 
        else if (addr_offset < 'h1000) begin
  	 Bit #(10) source_id = addr_offset [11:2];
  	 if ((0 < source_id) && (source_id < fromInteger (n_sources)))
  	    rdata = changeWidth (vrg_source_prio [source_id]);
        end
  
        // Source IPs (interrupt pending).
        // Return 32 consecutive IP bits starting with addr.
        else if (('h1000 <= addr_offset) && (addr_offset < 'h2000)) begin
  	 Bit #(15) source_id_base = { addr_offset [11:0], 3'h0 };
  
  	 function Bool fn_ip_source_id (Integer source_id_offset);
  	    let source_id = source_id_base + fromInteger (source_id_offset);
  	    Bool ip_source_id = False;
  	    if (source_id < fromInteger (n_sources))
  	       ip_source_id = vrg_source_ip [source_id];
  	    return ip_source_id;
  	 endfunction
  
  	 if (source_id_base < fromInteger (n_sources)) begin
  	    Bit #(32) v_ip = pack (genWith  (fn_ip_source_id));
  	    rdata = changeWidth (v_ip);
  	 end
        end
  
        // Source IEs (interrupt enables) for a target
        // Return 32 consecutive IE bits starting with addr.
        // Target 0 addrs: 2000-207F, Target 1 addrs: 2080-20FF, ...
        else if (('h2000 <= addr_offset) && (addr_offset < 'h3000)) begin
  	 Bit #(5)  target_id      = addr_offset [11:7];
  	 Bit #(10) source_id_base = { addr_offset [6:0], 3'h0 };
  
  	 function Bool fn_ie_source_id (Integer source_id_offset);
  	    let source_id = fromInteger (source_id_offset) + source_id_base;
  	    return (  (source_id < fromInteger (n_sources))
  		    ? vvrg_ie [target_id][source_id]
  		    : False);
  	 endfunction
  
  	 if (   (source_id_base < fromInteger (n_sources))
  	     && (target_id      < fromInteger (n_targets))) begin
  	    Bit #(32) v_ie = pack (genWith  (fn_ie_source_id));
  	    rdata = changeWidth (v_ie);
  	 end
        end
  
        // Target threshold
        else if ((addr_offset [31:0] & 32'hFFFF_0FFF) == 32'h0020_0000) begin
  	 Bit #(4) target_id = addr_offset [15:12];
  	 if (target_id < fromInteger (n_targets))
  	    rdata = changeWidth (vrg_target_threshold [target_id]);
        end
  
        // Interrupt service claim by target
        else if ((addr_offset [31:0] & 32'hFFFF_0FFF) == 32'h0020_0004) begin
  	 Bit #(4) target_id  = addr_offset [15:12];
  	 match { .eip, .max_id } = v_target_outputs [target_id];
  	 if (target_id < fromInteger (n_targets)) begin
  	    if (vrg_servicing_source [target_id] != 0) begin
  	       $display ("%0d: ERROR: PLIC: target %0d claiming without prior completion",
  			 cur_cycle, target_id);
  
negative.code: 
     // For each target: (interrupt pending, source)
     Vector #(t_n_targets,
  	    Tuple2 #(Bool, Bit #(TLog #(t_n_sources))))  v_target_outputs = genWith (fn_target_output);
  
     // ================================================================
     // Soft reset
  