2022-11-12 01:44:30 -05:00
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2022-11-13 18:03:55 -05:00
|
|
|
#include <vector>
|
2022-11-12 01:44:30 -05:00
|
|
|
#include <limits>
|
2022-11-13 18:03:55 -05:00
|
|
|
#include <random>
|
2022-11-12 01:44:30 -05:00
|
|
|
|
|
|
|
using V = int64_t;
|
|
|
|
constexpr V V_min = std::numeric_limits<V>::min();
|
|
|
|
|
2022-11-13 18:03:55 -05:00
|
|
|
class Transfer {
|
|
|
|
std::default_random_engine generator;
|
|
|
|
std::normal_distribution<> dist;
|
|
|
|
double scale;
|
|
|
|
double m;
|
|
|
|
double b;
|
|
|
|
|
|
|
|
double sample() {return scale*dist(generator);}
|
|
|
|
|
|
|
|
public:
|
|
|
|
Transfer(double scale, double mean, double dev, double m, double b, int seed)
|
|
|
|
: scale{scale}, dist{mean,dev}, generator{}, m{m}, b{b} {
|
|
|
|
if (seed < 0) {
|
|
|
|
std::random_device rd;
|
|
|
|
generator.seed(rd());
|
|
|
|
} else {
|
|
|
|
generator.seed(seed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t val(double x) {
|
|
|
|
return m*x + b + sample();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
V mulsat(V x, V y, unsigned siz, unsigned discard);
|
|
|
|
|
2022-11-12 01:44:30 -05:00
|
|
|
struct fixed_point {
|
|
|
|
V val;
|
|
|
|
unsigned whole_len;
|
|
|
|
unsigned frac_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string fxp_to_string(const struct fixed_point &fxp);
|
2022-11-13 18:03:55 -05:00
|
|
|
// V asr(V x, unsigned len);
|
|
|
|
V sign_extend(V x, unsigned len);
|