Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Multiplying Matrices in VHDL - Need to be able to shift rows

Status
Not open for further replies.

jerryt

Junior Member level 3
Joined
Jan 26, 2009
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,608
Hi, I am working on a school project. I need to be able to multiply two matrices together. The values in the matrices are all signed digits.

I need to multiply two matrices like this and add each value to an offset of [x0]:

X[1] [W1 W2 W3 W4] [x1] [x0]
X[2] [W2 W3 W4 W1] [x2] [x0]
X[3] = [W3 W4 W1 W2] * [x3] + [x0]
X[4] [W4 W1 W2 W3] [x4] [x0]



Here is how I formed the W matrix. For example:

type matrix4x4 is array (1 to 4, 1 to 4) of signed;
variable matrixA: matrix4x3 : ((W1,W2,W3,W4),(W2,W3,W4,W1),(W3,W4,W1,W2),(W4,W1,W2,W3));

You will notice that each row of the W matrix is just a cyclic shift of itself. Am I declaring the W matrix correctly? Can I call it signed? How could I just declare one row of the matrix [for instance row 1: [W1 W2 W3 W4] and then declare the next 3 rows of the matrix by shifting row 1 by one?

Thanks for everyone's help!
 

well here is where you need to learn some hardware tricks.

There is nothing wrong with what you already have. Assuming W1-4 are just inputs, you can just wire the inputs into your matrix4x4 type easily. If you need a generic size, you could easily write a function that did this for you using array attributes to loop through the values, but if its fixed at 4x4 its a bit of overkill. It is not going to use any logic at this stage, because you're just connecting a load of wires to a load of points (basically free). The array type is just a container to make it easier for you to understand in code (at the hardware level, its just a load of bits).

Would you like to see a function to do this for an unlimited size array (obviously in real hardware, you would limit the size to something sensible).

The matrix multiply you are suggesting is fairly straightforward to implement - you just need to pipeline the stages.
 
  • Like
Reactions: jerryt

    jerryt

    Points: 2
    Helpful Answer Positive Rating
Tricky I think I am going to design this module the structural way instead of the behavioral way as you suggested. I will be creating a new thread with the multiplier block I need to build with a shift register. Thanks for you help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top