GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/PFunc/pfunc_utils.cpp Lines: 84 86 97.7 %
Date: 2024-09-10 03:06:26 Branches: 153 164 93.3 %

Line Branch Exec Source
1
/***************************************
2
	Auteur : Pierre Aubert
3
	Mail : pierre.aubert@lapp.in2p3.fr
4
	Licence : CeCILL-C
5
****************************************/
6
7
#include "string_function.h"
8
#include "string_lower_upper.h"
9
10
#include "pfunc_utils.h"
11
12
using namespace std;
13
14
///Get the licence in string
15
/**	@return licence in string
16
*/
17
5
std::string licenceSaveStr(){
18
5
	std::string body("");
19
5
	body += "/***************************************\n";
20
5
	body += "\tAuteur : Pierre Aubert\n";
21
5
	body += "\tMail : pierre.aubert@lapp.in2p3.fr\n";
22
5
	body += "\tLicence : CeCILL-C\n";
23
5
	body += "****************************************/\n\n\n";
24
5
	return body;
25
}
26
27
///Get the plib intrinsics name
28
/**	@param name : name of the intrinsics function
29
 * 	@return corresponding plib intrinsics name
30
*/
31
5358
std::string getPlibIntrinsicsfunction(const std::string & name){
32
16074
	std::string out(""), out2("");
33
5358
	replaceStrInStr(out, name, "_mm256", "plib");
34
5358
	replaceStrInStr(out2, out, "_mm512", "plib");
35
5358
	replaceStrInStr(out, out2, "_mm", "plib");
36
5358
	replaceStrInStr(out2, out, "_kshift", "plib_kshift");
37
5358
	replaceStrInStr(out, out2, "_unpackb", "plib_unpackb");
38
5358
	replaceStrInStr(out2, out, "_kunpackb", "plib_kunpackb");
39
5358
	replaceStrInStr(out, out2, "_store_mask", "plib_store_mask");
40
5358
	replaceStrInStr(out2, out, "_load_mask", "plib_load_mask");
41
5358
	replaceStrInStr(out, out2, "_cvtu32_mask", "plib_cvtu32_mask");
42
43

5358
	if(out == name && name != ""){
44
34
		out = "plib" + name;
45
	}
46
10716
	return out;
47
}
48
49
///Get the plib intrinsics name
50
/**	@param name : name of the intrinsics function
51
 * 	@return corresponding plib intrinsics name
52
*/
53
1046
std::string getPlibIntrinsicsMacro(const std::string & name){
54
3138
	std::string out(""), out2("");
55
1046
	replaceStrInStr(out, name, "_H_INCLUDED", "_H_INCLUDED_PLIB");
56
1046
	replaceStrInStr(out2, out, "# error", "#error");
57
1046
	replaceStrInStr(out, out2, "#error \"Never use", "//#error \"Never use");
58
2092
	return out;
59
}
60
61
///Save a function
62
/**	@param func : function to be saved
63
 * 	@return string of the function declaration
64
*/
65
3250
std::string saveFunction(const PFunc & func){
66

3250
	if(func.getMacro() != ""){
67
1046
		return getPlibIntrinsicsMacro(func.getMacro());
68
	}
69
70

6612
	std::string body(""), name(func.getName()), returnType(func.getReturnType());
71
72

2204
	body += "\n//Function "+returnType+" " + name + "(";
73
4408
	std::string vecParamStr("");
74
2204
	const PVecArg & vecArg = func.getVecArg();
75
2204
	bool isNotFirst(false);
76
8466
	for(PVecArg::const_iterator it(vecArg.begin()); it != vecArg.end(); ++it){
77
6262
		if(isNotFirst){
78
4058
			vecParamStr += ", ";
79
		}
80

6262
		vecParamStr += it->getType() + " " + it->getName();
81
6262
		isNotFirst = true;
82
	}
83
2204
	body += vecParamStr + ")";
84
2204
	body += "\n";
85
2204
	body += "inline ";
86
4408
	std::string functionName("");
87
2204
	if(func.getNoReplace()){
88
96
		functionName = "plib" + name;
89
	}else{
90
2108
		functionName = getPlibIntrinsicsfunction(name);
91
	}
92
93

2204
	body += returnType + " " + functionName + "(" + vecParamStr + "){";
94
2204
	if(returnType != "void"){
95
2101
		body += "return ";
96
	}
97
2204
	body += name + "(";
98
2204
	isNotFirst = false;
99
2204
	vecParamStr = "";
100
8466
	for(PVecArg::const_iterator it(vecArg.begin()); it != vecArg.end(); ++it){
101
6262
		if(isNotFirst){
102
4058
			vecParamStr += ", ";
103
		}
104
6262
		vecParamStr += it->getName();
105
6262
		isNotFirst = true;
106
	}
107
2204
	if(vecParamStr != "void"){
108
2182
		body += vecParamStr;
109
	}
110
2204
	body += ");";
111
112
2204
	body += "}\n";
113
2204
	return body;
114
}
115
116
///Save the PHeader
117
/**	@param header : header to be saved
118
 * 	@return true on success, false otherwise
119
*/
120
5
bool saveHeader(const PHeader & header){
121

15
	std::string macroFile("__" + strToUpper(replaceCharInStr(header.getName(), '.', "_")) + "__");
122

15
	std::string originalIntrinsicFileName(replaceStrInStr(header.getName(), "plib_", ""));
123
124
10
	std::string body("");
125
5
	body += licenceSaveStr();
126
5
	body += "#ifndef " + macroFile + "\n";
127
5
	body += "#define " + macroFile + "\n";
128
129
5
	body += "\n\n#include <immintrin.h>\n\n";
130
5
	body += "//Following functions come from "+originalIntrinsicFileName + "\n\n";
131
132
5
	const PVecFunc & vecFunc = header.getVecFunc();
133
3255
	for(PVecFunc::const_iterator it(vecFunc.begin()); it != vecFunc.end(); ++it){
134
3250
		body += saveFunction(*it);
135
	}
136
5
	body += "#endif\n\n";
137

5
	if(!saveFileContent(header.getName(), body)){
138
		cerr << "saveHeader : can't save header '"<<header.getName()<<"'" << endl;
139
		return false;
140
	}
141
5
	return true;
142
}
143
144
///Save the vector of PHeader
145
/**	@param vecHeader : vector of header
146
 * 	@return true on success, false otherwise
147
*/
148
1
bool saveHeaderVec(const PVecHeader & vecHeader){
149
1
	bool b(true);
150
6
	for(PVecHeader::const_iterator it(vecHeader.begin()); it != vecHeader.end(); ++it){
151
5
		b &= saveHeader(*it);
152
	}
153
1
	return b;
154
}
155
156