-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfma-loop.cc
More file actions
39 lines (33 loc) · 737 Bytes
/
Copy pathfma-loop.cc
File metadata and controls
39 lines (33 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdint>
// Y = aX+b
__attribute__((noinline))
auto reserving(const std::vector<uint16_t>& X, float a, float b)
{
std::vector<float> Y;
Y.reserve(X.size());
transform(
X.begin(), X.end(),
back_inserter(Y),
[=](uint16_t x) { return a*x + b; });
return Y;
}
__attribute__((noinline))
auto resizing(const std::vector<uint16_t>& X, float a, float b)
{
std::vector<float> Y;
Y.resize(X.size());
transform(
X.begin(), X.end(),
Y.begin(),
[=](uint16_t x) { return a*x + b; });
return Y;
}
int main()
{
std::vector<uint16_t> X(512);
iota(X.begin(), X.end(), 0);
return ! (reserving(X, 2.3, 4.5) == resizing(X, 2.3, 4.5));
}