2011-06-16 03:19:09 +08:00
|
|
|
//===- llvm/unittest/ADT/PackedVectorTest.cpp - PackedVector tests --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// BitVectorTest tests fail on PowerPC for unknown reasons, so disable this
|
|
|
|
// as well since it depends on a BitVector.
|
[PowerPC] Improve consistency in use of __ppc__, __powerpc__, etc.
Both GCC and LLVM will implicitly define __ppc__ and __powerpc__ for
all PowerPC targets, whether 32- or 64-bit. They will both implicitly
define __ppc64__ and __powerpc64__ for 64-bit PowerPC targets, and not
for 32-bit targets. We cannot be sure that all other possible
compilers used to compile Clang/LLVM define both __ppc__ and
__powerpc__, for example, so it is best to check for both when relying
on either inside the Clang/LLVM code base.
This patch makes sure we always check for both variants. In addition,
it fixes one unnecessary check in lib/Target/PowerPC/PPCJITInfo.cpp.
(At least one of __ppc__ and __powerpc__ should always be defined when
compiling for a PowerPC target, no matter which compiler is used, so
testing for them is unnecessary.)
There are some places in the compiler that check for other variants,
like __POWERPC__ and _POWER, and I have left those in place. There is
no need to add them elsewhere. This seems to be in Apple-specific
code, and I won't take a chance on breaking it.
There is no intended change in behavior; thus, no test cases are
added.
llvm-svn: 187248
2013-07-27 05:39:15 +08:00
|
|
|
#if !defined(__ppc__) && !defined(__powerpc__)
|
2011-06-16 03:19:09 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/PackedVector.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
TEST(PackedVectorTest, Operation) {
|
|
|
|
PackedVector<unsigned, 2> Vec;
|
|
|
|
EXPECT_EQ(0U, Vec.size());
|
|
|
|
EXPECT_TRUE(Vec.empty());
|
|
|
|
|
|
|
|
Vec.resize(5);
|
|
|
|
EXPECT_EQ(5U, Vec.size());
|
|
|
|
EXPECT_FALSE(Vec.empty());
|
|
|
|
|
|
|
|
Vec.resize(11);
|
|
|
|
EXPECT_EQ(11U, Vec.size());
|
|
|
|
EXPECT_FALSE(Vec.empty());
|
|
|
|
|
|
|
|
PackedVector<unsigned, 2> Vec2(3);
|
|
|
|
EXPECT_EQ(3U, Vec2.size());
|
|
|
|
EXPECT_FALSE(Vec2.empty());
|
|
|
|
|
|
|
|
Vec.clear();
|
|
|
|
EXPECT_EQ(0U, Vec.size());
|
|
|
|
EXPECT_TRUE(Vec.empty());
|
|
|
|
|
|
|
|
Vec.push_back(2);
|
|
|
|
Vec.push_back(0);
|
|
|
|
Vec.push_back(1);
|
|
|
|
Vec.push_back(3);
|
|
|
|
|
|
|
|
EXPECT_EQ(2U, Vec[0]);
|
|
|
|
EXPECT_EQ(0U, Vec[1]);
|
|
|
|
EXPECT_EQ(1U, Vec[2]);
|
|
|
|
EXPECT_EQ(3U, Vec[3]);
|
|
|
|
|
|
|
|
EXPECT_FALSE(Vec == Vec2);
|
|
|
|
EXPECT_TRUE(Vec != Vec2);
|
|
|
|
|
|
|
|
Vec2.swap(Vec);
|
|
|
|
EXPECT_EQ(3U, Vec.size());
|
|
|
|
EXPECT_FALSE(Vec.empty());
|
|
|
|
EXPECT_EQ(0U, Vec[0]);
|
|
|
|
EXPECT_EQ(0U, Vec[1]);
|
|
|
|
EXPECT_EQ(0U, Vec[2]);
|
|
|
|
|
|
|
|
EXPECT_EQ(2U, Vec2[0]);
|
|
|
|
EXPECT_EQ(0U, Vec2[1]);
|
|
|
|
EXPECT_EQ(1U, Vec2[2]);
|
|
|
|
EXPECT_EQ(3U, Vec2[3]);
|
|
|
|
|
|
|
|
Vec = Vec2;
|
|
|
|
EXPECT_TRUE(Vec == Vec2);
|
|
|
|
EXPECT_FALSE(Vec != Vec2);
|
|
|
|
|
|
|
|
Vec[1] = 1;
|
|
|
|
Vec2[1] = 2;
|
|
|
|
Vec |= Vec2;
|
|
|
|
EXPECT_EQ(3U, Vec[1]);
|
|
|
|
}
|
|
|
|
|
2011-06-16 04:39:05 +08:00
|
|
|
#ifdef EXPECT_DEBUG_DEATH
|
|
|
|
|
2011-06-16 03:19:09 +08:00
|
|
|
TEST(PackedVectorTest, UnsignedValues) {
|
|
|
|
PackedVector<unsigned, 2> Vec(1);
|
|
|
|
Vec[0] = 0;
|
|
|
|
Vec[0] = 1;
|
|
|
|
Vec[0] = 2;
|
|
|
|
Vec[0] = 3;
|
|
|
|
EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big");
|
|
|
|
EXPECT_DEBUG_DEATH(Vec[0] = -1, "value is too big");
|
|
|
|
EXPECT_DEBUG_DEATH(Vec[0] = 0x100, "value is too big");
|
|
|
|
|
|
|
|
PackedVector<unsigned, 3> Vec2(1);
|
|
|
|
Vec2[0] = 0;
|
|
|
|
Vec2[0] = 7;
|
|
|
|
EXPECT_DEBUG_DEATH(Vec[0] = 8, "value is too big");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PackedVectorTest, SignedValues) {
|
|
|
|
PackedVector<signed, 2> Vec(1);
|
|
|
|
Vec[0] = -2;
|
|
|
|
Vec[0] = -1;
|
|
|
|
Vec[0] = 0;
|
|
|
|
Vec[0] = 1;
|
|
|
|
EXPECT_DEBUG_DEATH(Vec[0] = -3, "value is too big");
|
|
|
|
EXPECT_DEBUG_DEATH(Vec[0] = 2, "value is too big");
|
|
|
|
|
|
|
|
PackedVector<signed, 3> Vec2(1);
|
|
|
|
Vec2[0] = -4;
|
|
|
|
Vec2[0] = 3;
|
|
|
|
EXPECT_DEBUG_DEATH(Vec[0] = -5, "value is too big");
|
|
|
|
EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big");
|
|
|
|
}
|
|
|
|
|
2011-06-16 04:39:05 +08:00
|
|
|
#endif
|
|
|
|
|
2011-06-16 03:19:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|