summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2023-10-26 04:37:38 -0600
committerAlejandro Soto <alejandro@34project.org>2023-10-26 04:37:38 -0600
commitebd3ef9b8ebe6c19d0965c3d5ee741c725180f85 (patch)
treebdc7dc8eb43838cad86f6f4f1bd949beb447350a
parent4d10617bd697114ecdc748cb638a10bd8159aeaa (diff)
rtl/gfx: implement matrix transpose
-rw-r--r--gfx_hw.tcl1
-rw-r--r--rtl/gfx/mat_mat_mul.sv12
-rw-r--r--rtl/gfx/transpose.sv17
3 files changed, 27 insertions, 3 deletions
diff --git a/gfx_hw.tcl b/gfx_hw.tcl
index 570d948..5d56f44 100644
--- a/gfx_hw.tcl
+++ b/gfx_hw.tcl
@@ -51,6 +51,7 @@ add_fileset_file fold_flow.sv SYSTEM_VERILOG PATH rtl/gfx/fold_flow.sv
add_fileset_file skid_flow.sv SYSTEM_VERILOG PATH rtl/gfx/skid_flow.sv
add_fileset_file skid_buf.sv SYSTEM_VERILOG PATH rtl/gfx/skid_buf.sv
add_fileset_file vec_dot.sv SYSTEM_VERILOG PATH rtl/gfx/vec_dot.sv
+add_fileset_file transpose.sv SYSTEM_VERILOG PATH rtl/gfx/transpose.sv
#
diff --git a/rtl/gfx/mat_mat_mul.sv b/rtl/gfx/mat_mat_mul.sv
index cf4bd35..7c21249 100644
--- a/rtl/gfx/mat_mat_mul.sv
+++ b/rtl/gfx/mat_mat_mul.sv
@@ -15,7 +15,7 @@ module mat_mat_mul
out_valid
);
- mat4 a_hold, b_hold, q_hold, mul_b;
+ mat4 a_hold, b_hold, b_transpose, q_hold, mul_b;
vec4 mul_q;
logic mul_in_ready, mul_in_valid, mul_out_ready, mul_out_valid;
index4 in_index, out_index;
@@ -26,6 +26,12 @@ module mat_mat_mul
assign mul_in_valid = in_valid || in_index != `INDEX4_MIN;
assign mul_out_ready = out_ready || out_index != `INDEX4_MAX;
+ transpose transpose
+ (
+ .in(b),
+ .out(b_transpose)
+ );
+
mat_vec_mul mul
(
.a(in_index == `INDEX4_MIN ? a : a_hold),
@@ -40,7 +46,7 @@ module mat_mat_mul
always_comb begin
mul_b = b_hold;
- mul_b[0] = b[0];
+ mul_b[0] = b_transpose[0];
q = q_hold;
q[`VECS_PER_MAT - 1] = mul_q;
@@ -61,7 +67,7 @@ module mat_mat_mul
always_ff @(posedge clk) begin
if (in_ready) begin
a_hold <= a;
- b_hold <= b;
+ b_hold <= b_transpose;
end
if (mul_out_ready && mul_out_valid)
diff --git a/rtl/gfx/transpose.sv b/rtl/gfx/transpose.sv
new file mode 100644
index 0000000..1df68d5
--- /dev/null
+++ b/rtl/gfx/transpose.sv
@@ -0,0 +1,17 @@
+`include "gfx/gfx_defs.sv"
+
+module transpose
+(
+ input mat4 in,
+ output mat4 out
+);
+
+ integer i, j;
+
+ // Esto no tiene costo en hardware, es un renombramiento de seƱales
+ always_comb
+ for (i = 0; i < `VECS_PER_MAT; ++i)
+ for (j = 0; j < `FLOATS_PER_VEC; ++j)
+ out[i][j] = in[j][i];
+
+endmodule