Skip to content

Commit

Permalink
CpuId: call init whenever a user includes Vc/cpuid.h
Browse files Browse the repository at this point in the history
Make sure it's called only once, though, and not from every single TU
that included Vc/cpuid.h.

Fixes: VcDevelgh-114
Signed-off-by: Matthias Kretz <kretz@kde.org>
  • Loading branch information
mattkretz committed Oct 13, 2016
1 parent c31207c commit 175ed0d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 0 additions & 1 deletion examples/cpuid/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
int Vc_CDECL main()
{
using Vc::CpuId;
CpuId::init();
std::cout << " cacheLineSize: " << CpuId::cacheLineSize() << '\n';
std::cout << " processorType: " << CpuId::processorType() << '\n';
std::cout << " processorFamily: " << CpuId::processorFamily() << '\n';
Expand Down
15 changes: 15 additions & 0 deletions include/Vc/cpuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ class CpuId
static bool s_noL2orL3;
};

#ifndef Vc_COMPILE_LIB
namespace detail
{
template <int = 0> struct RunCpuIdInit {
RunCpuIdInit() { CpuId::init(); }
static RunCpuIdInit tmp;
};
template <int N> RunCpuIdInit<N> RunCpuIdInit<N>::tmp;
namespace
{
static auto ctor = RunCpuIdInit<>::tmp;
} // unnamed namespace
} // namespace detail
#endif

}

#endif // VC_CPUID_H_
2 changes: 1 addition & 1 deletion tests/linkTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ int Vc_CDECL main()
{
float_v x = float_v::Random();
x = fooLib0A(fooLib0B(fooLib1A(fooLib1B(fooLib2(fooLib3(foo0(foo1(x))))))));
return static_cast<int>(x.sum());
return static_cast<int>(x.sum()) >> 8;
}
1 change: 1 addition & 0 deletions tests/linkTestLib0.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Vc/Vc>
#include <Vc/IO>
#include <Vc/support.h>

#define CAT(a, b) a##b
#define name(a, b) CAT(a, b)
Expand Down
1 change: 1 addition & 0 deletions tests/linkTestLib1.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Vc/Vc>
#include <Vc/IO>
#include <Vc/support.h>

#define CAT(a, b) a##b
#define name(a, b) CAT(a, b)
Expand Down

0 comments on commit 175ed0d

Please sign in to comment.