(no commit message)
[libreriscv.git] / simple_v_extension / vector_ops.mdwn
index e45b9642fbab3d58f70be1b8e4fd488be49d39d2..394e5b24d3f477e86bd165615335afe1a9881c2d 100644 (file)
@@ -37,40 +37,14 @@ may also be run in either "vector" mode or "rotation" mode.  See [[discussion]]
 CORDIC can also be used for performing DCT.  See
 <https://arxiv.org/abs/1606.02424>
 
-vx, vy = CORDIC(vx, vy, coordinate\_mode, beta)
-
-     int i = 0;
-     int iterations = 0; // Number of times to run the algorithm
-     float arctanTable[iterations]; // in Radians
-     float K = 0.6073; // K
-     float v_x,v_y; // Vector v; x and y components
-
-     for(i=0; i < iterations; i++) {
-        arctanTable[i] = atan(pow(2,-i));
-     }
-
-     float vnew_x;   // To store the new value of x;
-     for(i = 0; i < iterations; i++) {
-         // If beta is negative, we need to do a counter-clockwise rotation:
-         if( beta < 0) {
-            vnew_x = v_x + (v_y*pow(2,-i)); 
-            v_y -= (v_x*pow(2,-i));  
-            beta += arctanTable[i]; 
-         }
-         // If beta is positive, we need to do a clockwise rotation:
-         else {
-            vnew_x = v_x - (v_y*pow(2,-i));
-            v_y += (v_x*pow(2,-i));
-            beta -= arctanTable[i];
-         }
-         v_x = vnew_x;
-     }
-     v_x *= K;
-     v_y *= K;
+CORDIC has several RADIX-4 papers for efficient pipelining.  Each stage requires its own ROM tables which can get costly.  Two combinatorial blocks may be chained together to double the RADIX and halve the pipeline depth, at the cost of doubling the latency.
+
+Also, to get good accuracy, particularly at the limits of CORDIC input range, requires double the bitwidth of the output in internal computations. This similar to how MUL requires double the bitwidth to compute.
 
 Links:
 
 * <http://www.myhdl.org/docs/examples/sinecomp/>
+* <https://www.atlantis-press.com/proceedings/jcis2006/232>
 
 ## Vector cross product
 
@@ -131,6 +105,16 @@ Pseudocode in c:
         return result;
     }
 
+## Vector Normalisation (not included)
+
+Vector normalisation may be performed through dot product, recip square root and multiplication:
+
+    fdot F3, F1, F1 # vector dot with self
+    rcpsqrta F3, F3
+    fscale,0 F2, F3, F1
+
+Or it may be performed through VLEN (Vector length) and division.
+
 ## Vector length
 
 * rd=scalar, vs1=vec (SUBVL=1)
@@ -144,6 +128,8 @@ The scalar length of a vector:
 
     sqrt(x[0]^2 + x[1]^2 + ...).
 
+One option is for this to be a macro op fusion sequence, with inverse-sqrt also being a second macro op sequence suitable for normalisation.
+
 ## Vector distance
 
 * VDIST rd, vs1, vs2
@@ -336,3 +322,7 @@ TODO
 * <http://lists.libre-riscv.org/pipermail/libre-riscv-dev/2019-September/002736.html>
 * <http://lists.libre-riscv.org/pipermail/libre-riscv-dev/2019-September/002733.html>
 * <http://bugs.libre-riscv.org/show_bug.cgi?id=142>
+
+Research Papers
+
+* <https://www.researchgate.net/publication/2938554_PLX_FP_An_Efficient_Floating-Point_Instruction_Set_for_3D_Graphics>