1 /**************************************************************************************************
2 *                                                                                                 *
3 * This file is part of BLASFEO.                                                                   *
4 *                                                                                                 *
5 * BLASFEO -- BLAS For Embedded Optimization.                                                      *
6 * Copyright (C) 2019 by Gianluca Frison.                                                          *
7 * Developed at IMTEK (University of Freiburg) under the supervision of Moritz Diehl.              *
8 * All rights reserved.                                                                            *
9 *                                                                                                 *
10 * The 2-Clause BSD License                                                                        *
11 *                                                                                                 *
12 * Redistribution and use in source and binary forms, with or without                              *
13 * modification, are permitted provided that the following conditions are met:                     *
14 *                                                                                                 *
15 * 1. Redistributions of source code must retain the above copyright notice, this                  *
16 *    list of conditions and the following disclaimer.                                             *
17 * 2. Redistributions in binary form must reproduce the above copyright notice,                    *
18 *    this list of conditions and the following disclaimer in the documentation                    *
19 *    and/or other materials provided with the distribution.                                       *
20 *                                                                                                 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND                 *
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED                   *
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE                          *
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR                 *
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES                  *
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;                    *
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND                     *
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT                      *
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS                   *
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                    *
31 *                                                                                                 *
32 * Author: Gianluca Frison, gianluca.frison (at) imtek.uni-freiburg.de                             *
33 *                                                                                                 *
34 **************************************************************************************************/
35 
36 #include <stdlib.h>
37 #include <stdio.h>
38 
39 #include "../include/blasfeo_stdlib.h"
40 #include "../include/blasfeo_v_aux_ext_dep.h"
41 
42 #if 0
43 #include <malloc.h>
44 #endif
45 
46 
47 /* creates a zero matrix given the size in bytes */
v_zeros(void ** ptrA,int size)48 void v_zeros(void **ptrA, int size)
49 	{
50 	// allocate memory
51 	*ptrA = (void *) malloc(size);
52 	// zero memory
53 	int i;
54 	double *dA = (double *) *ptrA;
55 	for(i=0; i<size/8; i++) dA[i] = 0.0;
56 	char *cA = (char *) dA;
57 	i *= 8;
58 	for(; i<size; i++) cA[i] = 0;
59 	return;
60 	}
61 
62 
63 /* creates a zero matrix aligned to a cache line given the size in bytes */
v_zeros_align(void ** ptrA,int size)64 void v_zeros_align(void **ptrA, int size)
65 	{
66 	// allocate memory
67 	blasfeo_malloc_align(ptrA, size);
68 	// zero allocated memory
69 	int i;
70 	double *dA = (double *) *ptrA;
71 	for(i=0; i<size/8; i++) dA[i] = 0.0;
72 	char *cA = (char *) dA;
73 	i *= 8;
74 	for(; i<size; i++) cA[i] = 0;
75 	return;
76 	}
77 
78 
79 /* frees matrix */
v_free(void * pA)80 void v_free(void *pA)
81 	{
82 	free( pA );
83 	}
84 
85 
86 /* frees aligned matrix */
v_free_align(void * pA)87 void v_free_align(void *pA)
88 	{
89 	blasfeo_free_align(pA);
90 	}
91 
92 
93 /* creates a zero matrix given the size in bytes */
c_zeros(char ** ptrA,int size)94 void c_zeros(char **ptrA, int size)
95 	{
96 	// allocate memory
97 	*ptrA = (char *)malloc(size);
98 	// zero memory
99 	int i;
100 	double *dA = (double *) *ptrA;
101 	for(i=0; i<size/8; i++) dA[i] = 0.0;
102 	char *cA = (char *) dA;
103 	i *= 8;
104 	for(; i<size; i++) cA[i] = 0;
105 	return;
106 	}
107 
108 
109 /* creates a zero matrix aligned to a cache line given the size in bytes */
c_zeros_align(char ** ptrA,int size)110 void c_zeros_align(char **ptrA, int size)
111 	{
112 	// allocate memory
113 	blasfeo_malloc_align((void **) ptrA, size);
114 	// zero allocated memory
115 	int i;
116 	double *dA = (double *) *ptrA;
117 	for(i=0; i<size/8; i++) dA[i] = 0.0;
118 	char *cA = (char *) dA;
119 	i *= 8;
120 	for(; i<size; i++) cA[i] = 0;
121 	return;
122 	}
123 
124 
125 /* frees matrix */
c_free(char * pA)126 void c_free(char *pA)
127 	{
128 	free( pA );
129 	}
130 
131 
132 /* frees aligned matrix */
c_free_align(char * pA)133 void c_free_align(char *pA)
134 	{
135 	blasfeo_free_align(pA);
136 	}
137