## 4 ML Instruction Set Architecture
### ML Core Operations  
ANN and CNN computations require efficient and generic vector operations crucial to implementing ML on microcontrollers, at least for model inference. The REXA VM provides a unified core set of vector operations that can be used for the iterative computation of ANN and CNN models. It is assumed that the integer data width of the models is \(N\)-bitand that there is 2N-bit arithmetic. In our case, we have 16-bit model data and 32-bit native integer arithmetic. The set of basic operations needed to implement ANN and CNN models and perform forward activation computations consists of the following:  
1. Element-wise vector operations, i.e., addition and multiplication, _vecmul: op1 vec op2 vec dstvec scalevc;_
2. Dot-product operations performing a sum of product data fusion (_vecprod: veza vech scale_\(\rightarrow\) number);
3. A folding operation for node layer computations (_vecfold: invec wgtvec outvec scalevc_);
4. A convolution operation for CNN computations (_vecconv: invec wgtvec outvec scale inwidth kwidth stride pad_);
5. A pooling operation for CNN computations reusing the _vecconv_ operation. The second argument combines the kernel height and a pooling function index (max, min, and so on) if the kernel width argument is negative (_vecconv: invec hieight + poolfun outvec scale inwidth -kwidth stride pad_);
6. A mapping operation applying a function elementwise (_vecmap: srcvec dstvec func solve_);
7. A reduction operation applying a function to all elements returning an aggregate value (_vecred: vec vecoff veclen op_) with the supported functions _min_, _max_, _sum_, and _average_;
8. A vector reshape operation shrinking or expanding a vector (_vecshape: srcvec dstvec scale_);
9. A generic scaling operation (_vecscale: srcvec dstvec scalevc_). Vector operations commonly operate on arrays embedded in code frames, as shown in Definition 1. Scaling is typically applied after an aggregation operation, e.g., after computing a vector dot product sum of products (using 2N arithmetic), to avoid overflow. Some operations use one scaling factor for all elements, as discussed in the following section. **Definition 1**. : _Initialized arrays embedded in place in code frames and non-initialized arrays stored at the end of the compiled code frame._ \begin{tabular}{|c|} \hline array x 100 \\ array y 2 \\ array z \{ 1 \\.3 4.. \} \\... \\... \\... \\ \hline \end{tabular}  \ \begin{tabular}{|c|} \hline hypercube.. \\... \\... \\... \\... \\... \\... \\ \hline \end{tabular} 
\begin{tabular}{|c|} \hline \(\ldots\) \\ \(\ldots\)  
Vector operations always operate on single data words (16 bit), but internally, 32-bit arithmetic is used to avoid over- and underflows. To scale to a signed 16 bit integer, some of the operations use a scale factor or scale factor vector (negative scale values reduce, positive expand the values by the scale factor) to avoid overflows or underflows in following computations, similar to scaled tensors in [7; 8]. Vector operations can access arrays stored in code frames or provided externally by the host application (e.g., a signal buffer). The computation of these operations is defined by the following formulas:  
\[