Skip to content

Commit

Permalink
Silence Wignored-attributes in user code
Browse files Browse the repository at this point in the history
Users of Vc shouldn't have to compile with -Wno-ignored-attributes. So
the Vc headers may not produce any unnecessary noise. (GCC 6 produces
tons of warnings - by default - that are irrelevant.)

Disable ignored-attributes in global.h and reset it at the bottom of
vector.h. This should catch almost all uses of Vc. The few remaining
corner cases are not supported anyway and will only lose the
Wignored-attributes warning in their code.

Additionally, use much less attributes by only adding the alignment
attribute on Vector::EntryType when really necessary (i.e. if sizeof(T)
!= alignof(T), which is the case on 32-bit x86 for double).

Ignore the warning in the types.cpp test, where intrinsic types are
compared with std::is_same

Signed-off-by: Matthias Kretz <[email protected]>
  • Loading branch information
mattkretz committed May 2, 2017
1 parent 2a2dbf1 commit 71f831c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 12 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ if(Vc_COMPILER_IS_GCC)
list(APPEND disabled_targets
example_scaling_scalar
)
elseif(Vc_GCC_VERSION VERSION_GREATER "5.99")
AddCompilerFlag(-Wno-ignored-attributes)
endif()
elseif(Vc_COMPILER_IS_MSVC)
if(MSVC_VERSION LESS 1700)
Expand Down
2 changes: 1 addition & 1 deletion avx/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ template <typename T> class Vector<T, VectorAbi::Avx>

Vc_FREE_STORE_OPERATORS_ALIGNED(alignof(VectorType));

Vc_ALIGNED_TYPEDEF(sizeof(T), T, EntryType);
using EntryType = typename Common::ensure_alignment_equals_sizeof<T>::type;
using value_type = EntryType;
typedef EntryType VectorEntryType;
static constexpr size_t Size = sizeof(VectorType) / sizeof(EntryType);
Expand Down
13 changes: 13 additions & 0 deletions common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,19 @@ template <std::size_t Size, typename F> Vc_INTRINSIC void for_all_vector_entries
unrolled_loop<std::size_t, 0u, Size>(std::forward<F>(f));
}

/**\internal
* The member type `type` is either `T` or `T` with alignment increased to sizeof(T) if
* alignof(T) < sizeof(T).
*/
template <class T, std::size_t Size = sizeof(T), std::size_t Alignment = alignof(T)>
struct ensure_alignment_equals_sizeof {
Vc_ALIGNED_TYPEDEF(Size, T, type);
};
template <class T, std::size_t Size>
struct ensure_alignment_equals_sizeof<T, Size, Size> {
using type = T;
};

} // namespace Common
} // namespace Vc

Expand Down
8 changes: 8 additions & 0 deletions include/Vc/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define Vc_UNSUPPORTED_COMPILER 1
#endif

#if defined Vc_GCC && Vc_GCC >= 0x60000
#define Vc_RESET_DIAGNOSTICS _Pragma("GCC diagnostic pop")
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-attributes"
#else
#define Vc_RESET_DIAGNOSTICS
#endif

#if __cplusplus < 201103 && (!defined Vc_MSVC || _MSC_VER < 1900)
# error "Vc requires support for C++11."
#elif __cplusplus >= 201402L
Expand Down
2 changes: 2 additions & 0 deletions include/Vc/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,6 @@ namespace std
} // namespace std
#endif

Vc_RESET_DIAGNOSTICS

#endif // VC_VECTOR_H_
2 changes: 1 addition & 1 deletion mic/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Vector<T, VectorAbi::Mic> : public MIC::StoreMixin<MIC::Vector<T>, T>
Vc_FREE_STORE_OPERATORS_ALIGNED(64);
typedef typename MIC::VectorTypeHelper<T>::Type VectorType;
using vector_type = VectorType;
Vc_ALIGNED_TYPEDEF(sizeof(T), T, EntryType);
using EntryType = typename Common::ensure_alignment_equals_sizeof<T>::type;
using value_type = EntryType;
typedef typename MIC::DetermineVectorEntryType<T>::Type VectorEntryType;
static constexpr size_t Size = sizeof(VectorType) / sizeof(VectorEntryType);
Expand Down
2 changes: 1 addition & 1 deletion scalar/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ template <typename T> class Vector<T, VectorAbi::Scalar>

public:
using abi = VectorAbi::Scalar;
Vc_ALIGNED_TYPEDEF(sizeof(T), T, EntryType);
using EntryType = typename Common::ensure_alignment_equals_sizeof<T>::type;
using VectorEntryType = EntryType;
using value_type = EntryType;
using VectorType = EntryType;
Expand Down
9 changes: 3 additions & 6 deletions src/trigonometric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ Vc::float_v Trigonometric<Vc::Detail::TrigonometricImplementation<
Vc::CurrentImplementation::current()>>::asin(const Vc::float_v &_x)
{
typedef Vc::float_v V;
typedef V::EntryType T;
typedef Const<T, V::abi> C;
typedef Const<float, V::abi> C;
typedef V::Mask M;

const M &negative = _x < V::Zero();
Expand Down Expand Up @@ -358,8 +357,7 @@ Vc::float_v Trigonometric<Vc::Detail::TrigonometricImplementation<
Vc::CurrentImplementation::current()>>::atan(const Vc::float_v &_x)
{
using V = Vc::float_v;
typedef V::EntryType T;
typedef Const<T, V::abi> C;
typedef Const<float, V::abi> C;
typedef V::Mask M;
V x = abs(_x);
const M &gt_tan_3pi_8 = x > C::atanThrsHi();
Expand Down Expand Up @@ -416,8 +414,7 @@ Vc::float_v Trigonometric<Vc::Detail::TrigonometricImplementation<
const Vc::float_v &x)
{
using V = Vc::float_v;
typedef V::EntryType T;
typedef Const<T, V::abi> C;
typedef Const<float, V::abi> C;
typedef V::Mask M;

const M xZero = x == V::Zero();
Expand Down
2 changes: 1 addition & 1 deletion sse/intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ template <typename T> struct DetermineGatherMask
template <typename T> struct VectorTraits
{
typedef typename VectorTypeHelper<T>::Type VectorType;
Vc_ALIGNED_TYPEDEF(sizeof(T), T, EntryType);
using EntryType = typename Common::ensure_alignment_equals_sizeof<T>::type;
static constexpr size_t Size = sizeof(VectorType) / sizeof(EntryType);
enum Constants { HasVectorDivision = !std::is_integral<T>::value };
typedef Mask<T> MaskType;
Expand Down
4 changes: 4 additions & 0 deletions tests/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

#include "unittest.h"

#if defined Vc_GCC && Vc_GCC >= 0x60000
#pragma GCC diagnostic ignored "-Wignored-attributes"
#endif

#define ALL_TYPES (ALL_VECTORS, SIMD_ARRAYS(32))

TEST_TYPES(V, check_EntryType, ALL_TYPES)
Expand Down

1 comment on commit 71f831c

@mattkretz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.