Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
calc.cpp File Reference
#include <stdio.h>
#include <sstream>
#include <map>
#include "xbyak/xbyak.h"
#include <boost/spirit/include/classic_file_iterator.hpp>
#include <boost/spirit/include/classic_core.hpp>
#include <boost/bind.hpp>
Include dependency graph for calc.cpp:

Go to the source code of this file.

Classes

class  FuncGen
 
struct  Grammar
 
struct  Grammar::definition< ScannerT >
 

Macros

#define XBYAK_NO_OP_NAMES
 

Enumerations

enum  Error { UNDEFINED_VARIABLE = 1 }
 

Functions

void put (const std::vector< double > &x)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ XBYAK_NO_OP_NAMES

#define XBYAK_NO_OP_NAMES

Definition at line 13 of file calc.cpp.

Enumeration Type Documentation

◆ Error

enum Error
Enumerator
UNDEFINED_VARIABLE 

Definition at line 23 of file calc.cpp.

23 {
25};
@ UNDEFINED_VARIABLE
Definition calc.cpp:24

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 164 of file calc.cpp.

165{
166 if (argc <= 2) {
167 fprintf(stderr, "calc \"var1 var2 ...\" \"function of var\"\n");
168 fprintf(stderr, "eg. calc x \"x*x\"\n");
169 fprintf(stderr, "eg. calc \"x y z\" \"x*x + y - z\"\n");
170 return 1;
171 }
172 const char *poly = argv[2];
173 try {
174 std::vector<std::string> varTbl;
175
176 // get varTbl from argv[1]
177 {
178 std::istringstream is(argv[1]);
179 int i = 0;
180 printf("varTbl = { ");
181 while (is) {
182 std::string var;
183 is >> var;
184 if (var.empty()) break;
185 printf("%s:%d, ", var.c_str(), i);
186 varTbl.push_back(var);
187 i++;
188 }
189 printf("}\n");
190 }
191 FuncGen funcGen(varTbl);
192 Grammar calc(funcGen);
193 boost::spirit::classic::parse_info<> r = parse(poly, calc, boost::spirit::classic::space_p);
194 if (!r.full) {
195 printf("err poly=%s\n", poly);
196 return 1;
197 }
198 funcGen.complete();
199 std::vector<double> valTbl;
200 valTbl.resize(varTbl.size());
201#ifdef XBYAK32
202 puts("32bit mode");
203 void (*func)(double *ret, const double *valTbl) = funcGen.getCode<void (*)(double *, const double*)>();
204#else
205 puts("64bit mode");
206 double (*func)(const double *valTbl) = funcGen.getCode<double (*)(const double*)>();
207#endif
208 for (int i = 0; i < 10; i++) {
209 for (size_t j = 0, n = valTbl.size(); j < n; j++) {
210 valTbl[j] = rand() % 7;
211 }
212 double y;
213#ifdef XBYAK32
214 func(&y, &valTbl[0]);
215#else
216 y = func(&valTbl[0]);
217#endif
218 printf("f("); put(valTbl); printf(")=%f\n", y);
219 }
220 } catch (std::exception& e) {
221 printf("ERR:%s\n", e.what());
222 } catch (Error err) {
223 printf("ERR:%d\n", err);
224 } catch (...) {
225 printf("unknown error\n");
226 }
227
228 return 0;
229}
const mie::Vuint & r
Definition bn.cpp:28
Error
Definition calc.cpp:23
void put()
Definition gen_code.cpp:234
char ** argv
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
uint64_t y
Definition sha3.cpp:34
void calc(void const *src, size_t bytelength, unsigned char *hash)
Calculate a SHA1 hash.
Definition sha1.hpp:127
CK_RV ret
uint16_t j
Here is the call graph for this function:

◆ put()

void put ( const std::vector< double > & x)

Definition at line 156 of file calc.cpp.

157{
158 printf("%f", x[0]);
159 for (size_t i = 1, n = x.size(); i < n; i++) {
160 printf(", %f", x[i]);
161 }
162}