`include "macros.v"
-module outbox_core(clk,
- instr_r, instr_a_, instr_d,
- fabric_in_r, fabric_in_a_, fabric_in_d,
- fabric_out_r_, fabric_out_a, fabric_out_d_,
- ship_r, ship_a_, ship_d);
+module outboxcore(clk,
+ instr_r, instr_a_, instr_d,
+ fabric_in_r, fabric_in_a_, fabric_in_d,
+ fabric_out_r_, fabric_out_a, fabric_out_d_,
+ ship_r, ship_a_, ship_d,
+ kill_r, kill_a_, kill_d,
+ recycle_r_, recycle_a, recycle_d_
+ );
input clk;
reg have_instruction;
reg have_token;
reg have_data;
reg send_token;
reg send_data;
+ reg parse_instruction;
+ reg do_recycle;
+ reg [(`COUNT_BITS-1):0] kill_count;
reg [(`INSTRUCTION_WIDTH-1):0] instruction;
- `input(ship_r, ship_a, ship_a_, [(`DATAWIDTH-1):0], ship_d)
`input(instr_r, instr_a, instr_a_, [(`INSTRUCTION_WIDTH-1):0], instr_d)
`input(fabric_in_r, fabric_in_a, fabric_in_a_, [(`PACKET_WIDTH-1):0], fabric_in_d)
`output(fabric_out_r, fabric_out_r_, fabric_out_a, [(`PACKET_WIDTH-1):0], fabric_out_d_)
- `defreg(fabric_out_d_, [(`PACKET_WIDTH-1):0], fabric_out_d)
+ `defreg(fabric_out_d_, [(`PACKET_WIDTH-1):0], fabric_out_d)
+ `input(ship_r, ship_a, ship_a_, [(`DATAWIDTH-1):0], ship_d)
+ `input(kill_r, kill_a, kill_a_, [(`COUNT_WIDTH-1):0], kill_d)
+ `output(recycle_r, recycle_r_, recycle_a, [(`INSTRUCTION_WIDTH-1):0], recycle_d_)
+ assign recycle_d_ = instruction;
always @(posedge clk) begin
- if (!have_instruction) begin
- `onread(instr_r, instr_a)
- instruction = instr_d;
- have_instruction = 1;
+
+ if (do_recycle) begin
+ `onwrite(recycle_r, recycle_a)
+ do_recycle = 0;
+ end
+
+ end else begin
+
+ if (!have_instruction && !parse_instruction) begin
+ `onread(instr_r, instr_a)
+ instruction = instr_d;
+ parse_instruction = 1;
+ end
+ end
+
+ /*
+ // FIXME: actually don't want to kill partway through an instruction
+ `onread(kill_r, kill_a)
+ kill_count = kill_d;
+ end
+
+ if (have_instruction && (kill_count > 0)) begin
+ kill_count = kill_count - 1;
+ have_instruction = 0;
+ end
+ */
+
+ if (parse_instruction) begin
have_token = !`instruction_bit_tokenin(instruction);
have_data = !`instruction_bit_datain(instruction);
- `packet_dest(fabric_out_d) = `instruction_bit_dest(instruction);
+ `packet_dest(fabric_out_d) = `instruction_bit_dest(instruction);
send_data = !`instruction_bit_dataout(instruction);
send_token = !`instruction_bit_tokenout(instruction);
+ have_instruction = 1;
+ parse_instruction = 0;
end
- end
- if (have_instruction && !have_token) begin
- `onread(fabric_in_r, fabric_in_a)
- have_token = 1;
+ if (have_instruction && !have_token) begin
+ `onread(fabric_in_r, fabric_in_a)
+ have_token = 1;
+ end
end
- end
-
- if (have_instruction && !have_data) begin
- `onread(ship_r, ship_a)
- if (`instruction_bit_latch(instruction)) begin
- `packet_data(fabric_out_d) = ship_d;
+
+ if (have_instruction && !have_data) begin
+ `onread(ship_r, ship_a)
+ if (`instruction_bit_latch(instruction)) begin
+ `packet_data(fabric_out_d) = ship_d;
+ end
+ have_data = 1;
end
- have_data = 1;
end
- end
- if (have_instruction && have_data && have_token) begin
- if (!send_data || !send_token) begin
- `onwrite(fabric_out_r, fabric_out_a)
- send_data = 1;
- send_token = 1;
+ if (have_instruction && have_data && have_token) begin
+ if (!send_data || !send_token) begin
+ `onwrite(fabric_out_r, fabric_out_a)
+ send_data = 1;
+ send_token = 1;
+ end
end
end
- end
- if (have_instruction && have_data && have_token && send_data && send_token) begin
- have_instruction = 0;
+ if (have_instruction && have_data && have_token && send_data && send_token) begin
+ if (`instruction_count(instruction)==1) begin
+ have_instruction = 0;
+ end else begin
+ have_instruction = 0;
+ if (`instruction_count(instruction)>0) begin
+ `instruction_count(instruction) = `instruction_count(instruction) - 1;
+ end
+ if (`instruction_bit_recycle(instruction)) begin
+ have_instruction = 0;
+ do_recycle = 1;
+ end else begin
+ parse_instruction = 1;
+ end
+ end
+ end
end
-
- end
-
+ end
endmodule
+