QUDA
v1.1.0
A library for QCD on GPUs
quda
include
externals
trove
static_gcd.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2013, NVIDIA Corporation
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
7
* Redistributions of source code must retain the above copyright
8
notice, this list of conditions and the following disclaimer.
9
* Redistributions in binary form must reproduce the above copyright
10
notice, this list of conditions and the following disclaimer in the
11
documentation and/or other materials provided with the distribution.
12
* Neither the name of the <organization> nor the
13
names of its contributors may be used to endorse or promote products
14
derived from this software without specific prior written permission.
15
16
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#pragma once
29
namespace
trove
{
30
31
template
<
int
u,
int
v>
32
struct
static_gcd;
33
34
namespace
detail
{
35
36
template
<
bool
u_odd,
bool
v_odd,
int
u,
int
v>
37
struct
static_gcd_helper
{
38
static
const
int
value
=
static_gcd
<(u>>1), (v>>1)>
::value
<< 1;
39
};
40
41
template
<
int
u,
int
v>
42
struct
static_gcd_helper
<false, true, u, v> {
43
static
const
int
value
=
static_gcd
<(u>>1), v>::
value
;
44
};
45
46
template
<
int
u,
int
v>
47
struct
static_gcd_helper
<true, false, u, v> {
48
static
const
int
value
=
static_gcd
<u, (v>>1)>::
value
;
49
};
50
51
template
<
int
u,
int
v>
52
struct
static_gcd_helper
<true, true, u, v> {
53
static
const
int
reduced_u = (u > v) ? ((u - v) >> 1) : ((v - u) >> 1);
54
static
const
int
reduced_v = (u > v) ? v : u;
55
static
const
int
value
=
static_gcd<reduced_u, reduced_v>::value
;
56
};
57
}
58
59
template
<
int
u,
int
v>
60
struct
static_gcd
{
61
static
const
bool
u_odd
= (u & 0x1) == 1;
62
static
const
bool
v_odd
= (v & 0x1) == 1;
63
static
const
bool
equal
= u == v;
64
static
const
int
value
=
equal
? u :
detail::static_gcd_helper<u_odd, v_odd, u, v>::value
;
65
};
66
67
template
<
int
v>
68
struct
static_gcd
<0, v> {
69
static
const
bool
value
= v;
70
};
71
72
template
<
int
u>
73
struct
static_gcd
<u, 0> {
74
static
const
bool
value
= u;
75
};
76
77
}
detail
Definition:
alias.h:4
trove
Definition:
aos.h:38
trove::detail::static_gcd_helper
Definition:
static_gcd.h:37
trove::detail::static_gcd_helper::value
static const int value
Definition:
static_gcd.h:38
trove::static_gcd
Definition:
static_gcd.h:60
trove::static_gcd::equal
static const bool equal
Definition:
static_gcd.h:63
trove::static_gcd::u_odd
static const bool u_odd
Definition:
static_gcd.h:61
trove::static_gcd::v_odd
static const bool v_odd
Definition:
static_gcd.h:62
trove::static_gcd::value
static const int value
Definition:
static_gcd.h:64
Generated on Thu Oct 28 2021 16:10:26 for QUDA by
1.9.1