Austin Schuh | 9a24b37 | 2018-01-28 16:12:29 -0800 | [diff] [blame^] | 1 | /************************************************************************************************** |
| 2 | * * |
| 3 | * This file is part of BLASFEO. * |
| 4 | * * |
| 5 | * BLASFEO -- BLAS For Embedded Optimization. * |
| 6 | * Copyright (C) 2016-2017 by Gianluca Frison. * |
| 7 | * Developed at IMTEK (University of Freiburg) under the supervision of Moritz Diehl. * |
| 8 | * All rights reserved. * |
| 9 | * * |
| 10 | * HPMPC is free software; you can redistribute it and/or * |
| 11 | * modify it under the terms of the GNU Lesser General Public * |
| 12 | * License as published by the Free Software Foundation; either * |
| 13 | * version 2.1 of the License, or (at your option) any later version. * |
| 14 | * * |
| 15 | * HPMPC is distributed in the hope that it will be useful, * |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
| 18 | * See the GNU Lesser General Public License for more details. * |
| 19 | * * |
| 20 | * You should have received a copy of the GNU Lesser General Public * |
| 21 | * License along with HPMPC; if not, write to the Free Software * |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 23 | * * |
| 24 | * Author: Gianluca Frison, giaf (at) dtu.dk * |
| 25 | * gianluca.frison (at) imtek.uni-freiburg.de * |
| 26 | * * |
| 27 | **************************************************************************************************/ |
| 28 | |
| 29 | #include <stdlib.h> |
| 30 | #include <stdio.h> |
| 31 | |
| 32 | #include "../include/blasfeo_common.h" |
| 33 | #include "../include/blasfeo_s_kernel.h" |
| 34 | |
| 35 | |
| 36 | |
| 37 | #if defined(LA_HIGH_PERFORMANCE) |
| 38 | |
| 39 | |
| 40 | |
| 41 | // z = y + alpha*x, with increments equal to 1 |
| 42 | void saxpy_libstr(int m, float alpha, struct s_strvec *sx, int xi, struct s_strvec *sy, int yi, struct s_strvec *sz, int zi) |
| 43 | { |
| 44 | float *x = sx->pa + xi; |
| 45 | float *y = sy->pa + yi; |
| 46 | float *z = sz->pa + zi; |
| 47 | int ii; |
| 48 | ii = 0; |
| 49 | for( ; ii<m-3; ii+=4) |
| 50 | { |
| 51 | z[ii+0] = y[ii+0] + alpha*x[ii+0]; |
| 52 | z[ii+1] = y[ii+1] + alpha*x[ii+1]; |
| 53 | z[ii+2] = y[ii+2] + alpha*x[ii+2]; |
| 54 | z[ii+3] = y[ii+3] + alpha*x[ii+3]; |
| 55 | } |
| 56 | for( ; ii<m; ii++) |
| 57 | { |
| 58 | z[ii+0] = y[ii+0] + alpha*x[ii+0]; |
| 59 | } |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | |
| 65 | void saxpy_bkp_libstr(int m, float alpha, struct s_strvec *sx, int xi, struct s_strvec *sy, int yi, struct s_strvec *sz, int zi) |
| 66 | { |
| 67 | float *x = sx->pa + xi; |
| 68 | float *y = sy->pa + yi; |
| 69 | float *z = sz->pa + zi; |
| 70 | int ii; |
| 71 | ii = 0; |
| 72 | for( ; ii<m-3; ii+=4) |
| 73 | { |
| 74 | z[ii+0] = y[ii+0]; |
| 75 | y[ii+0] = y[ii+0] + alpha*x[ii+0]; |
| 76 | z[ii+1] = y[ii+1]; |
| 77 | y[ii+1] = y[ii+1] + alpha*x[ii+1]; |
| 78 | z[ii+2] = y[ii+2]; |
| 79 | y[ii+2] = y[ii+2] + alpha*x[ii+2]; |
| 80 | z[ii+3] = y[ii+3]; |
| 81 | y[ii+3] = y[ii+3] + alpha*x[ii+3]; |
| 82 | } |
| 83 | for( ; ii<m; ii++) |
| 84 | { |
| 85 | z[ii+0] = y[ii+0]; |
| 86 | y[ii+0] = y[ii+0] + alpha*x[ii+0]; |
| 87 | } |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | |
| 93 | // multiply two vectors and compute dot product |
| 94 | float svecmuldot_libstr(int m, struct s_strvec *sx, int xi, struct s_strvec *sy, int yi, struct s_strvec *sz, int zi) |
| 95 | { |
| 96 | |
| 97 | if(m<=0) |
| 98 | return 0.0; |
| 99 | |
| 100 | float *x = sx->pa + xi; |
| 101 | float *y = sy->pa + yi; |
| 102 | float *z = sz->pa + zi; |
| 103 | int ii; |
| 104 | float dot = 0.0; |
| 105 | |
| 106 | ii = 0; |
| 107 | |
| 108 | for(; ii<m; ii++) |
| 109 | { |
| 110 | z[ii+0] = x[ii+0] * y[ii+0]; |
| 111 | dot += z[ii+0]; |
| 112 | } |
| 113 | return dot; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | |
| 118 | #else |
| 119 | |
| 120 | #error : wrong LA choice |
| 121 | |
| 122 | #endif |
| 123 | |