File: main.cpp

package info (click to toggle)
vc 1.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,552 kB
  • sloc: cpp: 19,220; ansic: 15,669; sh: 453; xml: 186; makefile: 30
file content (79 lines) | stat: -rw-r--r-- 2,380 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*{{{
    Copyright (C) 2013 Matthias Kretz <kretz@kde.org>

    Permission to use, copy, modify, and distribute this software
    and its documentation for any purpose and without fee is hereby
    granted, provided that the above copyright notice appear in all
    copies and that both that the copyright notice and this
    permission notice and warranty disclaimer appear in supporting
    documentation, and that the name of the author not be used in
    advertising or publicity pertaining to distribution of the
    software without specific, written prior permission.

    The author disclaim all warranties with regard to this
    software, including all implied warranties of merchantability
    and fitness.  In no event shall the author be liable for any
    special, indirect or consequential damages or any damages
    whatsoever resulting from loss of use, data or profits, whether
    in an action of contract, negligence or other tortious action,
    arising out of or in connection with the use or performance of
    this software.

}}}*/

#include <Vc/Vc>

#include <array>
#include <algorithm>

#include "../tsc.h"

using Vc::double_v;
using Vc::double_m;

constexpr size_t ArraySize = 10240;

using Point = std::array<double_v, 3>;
using PointArray = std::array<Point, ArraySize / double_v::Size>;

static const std::array<double_v, 3> origin  = {{ 0.2, 0.3, 0.4 }};
static const std::array<double_v, 3> boxsize = {{ 0.5, 0.3, 0.1 }};

double_m contains(const Point &point)
{
    double_m inside[3];
    for (int dir = 0; dir < 3; ++dir) {
        inside[dir] = abs(point[dir] - origin[dir]) < boxsize[dir];
    }
    return inside[0] && inside[1] && inside[2];
}

std::array<bool, ArraySize> contains(const PointArray &points)
{
    std::array<bool, ArraySize> inside;
    auto storeIt = inside.begin();
    for (const auto &p : points) {
        contains(p).store(&*storeIt);
        storeIt += double_v::Size;
    }
    return inside;
}

std::array<bool, ArraySize> g_inside;

int Vc_CDECL main()
{
    PointArray points;
    std::generate(points.begin(), points.end(), []() -> Point {
        return {{ double_v::Random(), double_v::Random(), double_v::Random() }};
    });

    TimeStampCounter tsc;
    tsc.start();
    const auto &tmp = contains(points);
    tsc.stop();
    g_inside = tmp;
    std::cout << tsc.cycles() << std::endl;

    return 0;
}