1

I am wondering if the VMIPS code that I have written is equivalent to the C code snippet below. The target vector machine has length 64, and all variables are double-precision.

for (i = 0; i < 35; i=i+1) {
    X[i] = A[i]*B[i]-C[i]*D[i];
    Y[i] = A[i]*D[i]+B[i]*C[i];
    Z[i] = X[i]*X[i]+Y[i]*Y[i];
}

VMIPS code:

L.D       R1, #35        #Load scalar  
MTC1      VLR, R1        #Set vector length to 35
LV        V1, Ra         #Load vector a
LV        V2, Rb         #Load vector b
LV        V3, Rc         #Load vector c
LV        V4, Rd         #Load vector d
MULVV.D   V5, V1, V2     #A*B
MULVV.D   V6, V3, V4     #C*D
MULVV.D   V7, V1, V3     #A*D
MULVV.D   V8, V2, V4     #B*C
SUBVV.D   V9, V5, V6     #X = A*B - C*D
ADDVV.D   V10, V7, V8    #Y = A*D + B*C
MULVV.D   V11, V9, V9    #X*X
MULVV.D   V12, V10, V10  #Y*Y
ADDVV.D   V13, V11, V12  #Z = X*X + Y*Y
SV        Rx, V9         #Store X
SV        Ry, V10        #Store Y
SV        Rz, V13        #Store Z

I apologise in advance if there are any big mistakes in my answer. I am new to the topic! :)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
maffffff
  • 11
  • 1
  • Have you tried it for some sample input, compared against a C compiler's code-gen? – Peter Cordes Jan 23 '23 at 13:18
  • I've never worked with SIMD or vectors before, but are you actually looping or just doing it once? It looks like the latter. But as far as the actual arithmetic goes, I don't see any issues. – puppydrum64 Jan 30 '23 at 18:34

0 Answers0