[NFCI] Add StackOffset class and base classes for ElementCount, TypeSize.
This patch adds a linear polynomial base class, called LinearPolyBase, which
serves as a base class for StackOffset. It tries to represent a linear
polynomial like:
c0 * scale0 + c1 * scale1 + ... + cK * scaleK
where the scale is implicit, meaning that only the coefficients are
encoded.
This patch also adds a univariate linear polynomial, which serves as
a base class for ElementCount and TypeSize. This tries to represent a
linear polynomial where only one dimension can be set at any one time,
i.e. a TypeSize is either fixed-sized, or scalable-sized, but cannot be
a combination of the two.
class LinearPolyBase
^
|
+---- class StackOffset (dimensions = 2 (fixed/scalable), type = int64_t)
class UnivariateLinearPolyBase
|
|
+---- class LinearPolySize (dimensions = 2 (fixed/scalable))
^
|
+-------- class ElementCount (type = unsigned)
|
|
+-------- class TypeSize (type = uint64_t)
Reviewed By: ctetreau, david-arm
Differential Revision: https://reviews.llvm.org/D88982
2020-11-03 05:32:57 +08:00
|
|
|
//===- TestPoly3D.cpp - Poly3D unit tests------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/TypeSize.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
class Poly3D;
|
2020-11-03 23:55:12 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
template <> struct LinearPolyBaseTypeTraits<Poly3D> {
|
[NFCI] Add StackOffset class and base classes for ElementCount, TypeSize.
This patch adds a linear polynomial base class, called LinearPolyBase, which
serves as a base class for StackOffset. It tries to represent a linear
polynomial like:
c0 * scale0 + c1 * scale1 + ... + cK * scaleK
where the scale is implicit, meaning that only the coefficients are
encoded.
This patch also adds a univariate linear polynomial, which serves as
a base class for ElementCount and TypeSize. This tries to represent a
linear polynomial where only one dimension can be set at any one time,
i.e. a TypeSize is either fixed-sized, or scalable-sized, but cannot be
a combination of the two.
class LinearPolyBase
^
|
+---- class StackOffset (dimensions = 2 (fixed/scalable), type = int64_t)
class UnivariateLinearPolyBase
|
|
+---- class LinearPolySize (dimensions = 2 (fixed/scalable))
^
|
+-------- class ElementCount (type = unsigned)
|
|
+-------- class TypeSize (type = uint64_t)
Reviewed By: ctetreau, david-arm
Differential Revision: https://reviews.llvm.org/D88982
2020-11-03 05:32:57 +08:00
|
|
|
using ScalarTy = int64_t;
|
|
|
|
static const unsigned Dimensions = 3;
|
|
|
|
};
|
2020-11-03 23:55:12 +08:00
|
|
|
}
|
[NFCI] Add StackOffset class and base classes for ElementCount, TypeSize.
This patch adds a linear polynomial base class, called LinearPolyBase, which
serves as a base class for StackOffset. It tries to represent a linear
polynomial like:
c0 * scale0 + c1 * scale1 + ... + cK * scaleK
where the scale is implicit, meaning that only the coefficients are
encoded.
This patch also adds a univariate linear polynomial, which serves as
a base class for ElementCount and TypeSize. This tries to represent a
linear polynomial where only one dimension can be set at any one time,
i.e. a TypeSize is either fixed-sized, or scalable-sized, but cannot be
a combination of the two.
class LinearPolyBase
^
|
+---- class StackOffset (dimensions = 2 (fixed/scalable), type = int64_t)
class UnivariateLinearPolyBase
|
|
+---- class LinearPolySize (dimensions = 2 (fixed/scalable))
^
|
+-------- class ElementCount (type = unsigned)
|
|
+-------- class TypeSize (type = uint64_t)
Reviewed By: ctetreau, david-arm
Differential Revision: https://reviews.llvm.org/D88982
2020-11-03 05:32:57 +08:00
|
|
|
|
|
|
|
using Poly3DBase = LinearPolyBase<Poly3D>;
|
|
|
|
class Poly3D : public Poly3DBase {
|
|
|
|
public:
|
|
|
|
using ScalarTy = Poly3DBase::ScalarTy;
|
|
|
|
Poly3D(ScalarTy x, ScalarTy y, ScalarTy z) : Poly3DBase({x, y, z}) {}
|
|
|
|
Poly3D(const Poly3DBase &Convert) : Poly3DBase(Convert) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(LinearPolyBase, Poly3D_isZero) {
|
|
|
|
EXPECT_TRUE(Poly3D(0, 0, 0).isZero());
|
|
|
|
EXPECT_TRUE(Poly3D(0, 0, 1).isNonZero());
|
|
|
|
EXPECT_TRUE(Poly3D(0, 0, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LinearPolyBase, Poly3D_Equality) {
|
|
|
|
EXPECT_EQ(Poly3D(1, 2, 3), Poly3D(1, 2, 3));
|
|
|
|
EXPECT_NE(Poly3D(1, 2, 3), Poly3D(1, 2, 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LinearPolyBase, Poly3D_GetValue) {
|
|
|
|
EXPECT_EQ(Poly3D(1, 2, 3).getValue(0), 1);
|
|
|
|
EXPECT_EQ(Poly3D(1, 2, 3).getValue(1), 2);
|
|
|
|
EXPECT_EQ(Poly3D(1, 2, 3).getValue(2), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LinearPolyBase, Poly3D_Add) {
|
|
|
|
// Test operator+
|
|
|
|
EXPECT_EQ(Poly3D(42, 0, 0) + Poly3D(0, 42, 0) + Poly3D(0, 0, 42),
|
|
|
|
Poly3D(42, 42, 42));
|
|
|
|
|
|
|
|
// Test operator+=
|
|
|
|
Poly3D X(42, 0, 0);
|
|
|
|
X += Poly3D(0, 42, 0);
|
|
|
|
X += Poly3D(0, 0, 42);
|
|
|
|
EXPECT_EQ(X, Poly3D(42, 42, 42));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LinearPolyBase, Poly3D_Sub) {
|
|
|
|
// Test operator-
|
|
|
|
EXPECT_EQ(Poly3D(42, 42, 42) - Poly3D(42, 0, 0) - Poly3D(0, 42, 0) -
|
|
|
|
Poly3D(0, 0, 42),
|
|
|
|
Poly3D(0, 0, 0));
|
|
|
|
|
|
|
|
// Test operator-=
|
|
|
|
Poly3D X(42, 42, 42);
|
|
|
|
X -= Poly3D(42, 0, 0);
|
|
|
|
X -= Poly3D(0, 42, 0);
|
|
|
|
X -= Poly3D(0, 0, 42);
|
|
|
|
EXPECT_EQ(X, Poly3D(0, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LinearPolyBase, Poly3D_Scale) {
|
|
|
|
// Test operator*
|
|
|
|
EXPECT_EQ(Poly3D(1, 2, 4) * 2, Poly3D(2, 4, 8));
|
|
|
|
EXPECT_EQ(Poly3D(1, 2, 4) * -2, Poly3D(-2, -4, -8));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LinearPolyBase, Poly3D_Invert) {
|
|
|
|
// Test operator-
|
|
|
|
EXPECT_EQ(-Poly3D(2, 4, 8), Poly3D(-2, -4, -8));
|
|
|
|
}
|
|
|
|
|
|
|
|
class Univariate3D;
|
2020-11-03 23:55:12 +08:00
|
|
|
namespace llvm {
|
|
|
|
template <> struct LinearPolyBaseTypeTraits<Univariate3D> {
|
[NFCI] Add StackOffset class and base classes for ElementCount, TypeSize.
This patch adds a linear polynomial base class, called LinearPolyBase, which
serves as a base class for StackOffset. It tries to represent a linear
polynomial like:
c0 * scale0 + c1 * scale1 + ... + cK * scaleK
where the scale is implicit, meaning that only the coefficients are
encoded.
This patch also adds a univariate linear polynomial, which serves as
a base class for ElementCount and TypeSize. This tries to represent a
linear polynomial where only one dimension can be set at any one time,
i.e. a TypeSize is either fixed-sized, or scalable-sized, but cannot be
a combination of the two.
class LinearPolyBase
^
|
+---- class StackOffset (dimensions = 2 (fixed/scalable), type = int64_t)
class UnivariateLinearPolyBase
|
|
+---- class LinearPolySize (dimensions = 2 (fixed/scalable))
^
|
+-------- class ElementCount (type = unsigned)
|
|
+-------- class TypeSize (type = uint64_t)
Reviewed By: ctetreau, david-arm
Differential Revision: https://reviews.llvm.org/D88982
2020-11-03 05:32:57 +08:00
|
|
|
using ScalarTy = int64_t;
|
|
|
|
static const unsigned Dimensions = 3;
|
|
|
|
};
|
2020-11-03 23:55:12 +08:00
|
|
|
}
|
[NFCI] Add StackOffset class and base classes for ElementCount, TypeSize.
This patch adds a linear polynomial base class, called LinearPolyBase, which
serves as a base class for StackOffset. It tries to represent a linear
polynomial like:
c0 * scale0 + c1 * scale1 + ... + cK * scaleK
where the scale is implicit, meaning that only the coefficients are
encoded.
This patch also adds a univariate linear polynomial, which serves as
a base class for ElementCount and TypeSize. This tries to represent a
linear polynomial where only one dimension can be set at any one time,
i.e. a TypeSize is either fixed-sized, or scalable-sized, but cannot be
a combination of the two.
class LinearPolyBase
^
|
+---- class StackOffset (dimensions = 2 (fixed/scalable), type = int64_t)
class UnivariateLinearPolyBase
|
|
+---- class LinearPolySize (dimensions = 2 (fixed/scalable))
^
|
+-------- class ElementCount (type = unsigned)
|
|
+-------- class TypeSize (type = uint64_t)
Reviewed By: ctetreau, david-arm
Differential Revision: https://reviews.llvm.org/D88982
2020-11-03 05:32:57 +08:00
|
|
|
|
|
|
|
using Univariate3DBase = UnivariateLinearPolyBase<Univariate3D>;
|
|
|
|
class Univariate3D : public Univariate3DBase {
|
|
|
|
public:
|
|
|
|
using ScalarTy = Univariate3DBase::ScalarTy;
|
|
|
|
Univariate3D(ScalarTy x, unsigned Dim) : Univariate3DBase(x, Dim) {}
|
|
|
|
Univariate3D(const Univariate3DBase &Convert) : Univariate3DBase(Convert) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(UnivariateLinearPolyBase, Univariate3D_isZero) {
|
|
|
|
EXPECT_TRUE(Univariate3D(0, 0).isZero());
|
|
|
|
EXPECT_TRUE(Univariate3D(0, 1).isZero());
|
|
|
|
EXPECT_TRUE(Univariate3D(0, 2).isZero());
|
|
|
|
EXPECT_TRUE(Univariate3D(1, 0).isNonZero());
|
|
|
|
EXPECT_TRUE(Univariate3D(1, 1).isNonZero());
|
|
|
|
EXPECT_TRUE(Univariate3D(1, 2).isNonZero());
|
|
|
|
EXPECT_TRUE(Univariate3D(1, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(UnivariateLinearPolyBase, Univariate3D_Equality) {
|
|
|
|
EXPECT_EQ(Univariate3D(1, 0), Univariate3D(1, 0));
|
|
|
|
EXPECT_NE(Univariate3D(1, 0), Univariate3D(1, 2));
|
|
|
|
EXPECT_NE(Univariate3D(1, 0), Univariate3D(1, 1));
|
|
|
|
EXPECT_NE(Univariate3D(1, 0), Univariate3D(2, 0));
|
|
|
|
EXPECT_NE(Univariate3D(1, 0), Univariate3D(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(UnivariateLinearPolyBase, Univariate3D_GetValue) {
|
|
|
|
EXPECT_EQ(Univariate3D(42, 0).getValue(0), 42);
|
|
|
|
EXPECT_EQ(Univariate3D(42, 0).getValue(1), 0);
|
|
|
|
EXPECT_EQ(Univariate3D(42, 0).getValue(2), 0);
|
|
|
|
|
|
|
|
EXPECT_EQ(Univariate3D(42, 1).getValue(0), 0);
|
|
|
|
EXPECT_EQ(Univariate3D(42, 1).getValue(1), 42);
|
|
|
|
EXPECT_EQ(Univariate3D(42, 1).getValue(2), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(UnivariateLinearPolyBase, Univariate3D_Add) {
|
|
|
|
// Test operator+
|
|
|
|
EXPECT_EQ(Univariate3D(42, 0) + Univariate3D(42, 0), Univariate3D(84, 0));
|
|
|
|
EXPECT_EQ(Univariate3D(42, 1) + Univariate3D(42, 1), Univariate3D(84, 1));
|
|
|
|
EXPECT_DEBUG_DEATH(Univariate3D(42, 0) + Univariate3D(42, 1),
|
|
|
|
"Invalid dimensions");
|
|
|
|
|
|
|
|
// Test operator+=
|
|
|
|
Univariate3D X(42, 0);
|
|
|
|
X += Univariate3D(42, 0);
|
|
|
|
EXPECT_EQ(X, Univariate3D(84, 0));
|
2020-11-06 15:56:55 +08:00
|
|
|
|
|
|
|
// Test 'getWithIncrement' method
|
|
|
|
EXPECT_EQ(Univariate3D(42, 0).getWithIncrement(1), Univariate3D(43, 0));
|
|
|
|
EXPECT_EQ(Univariate3D(42, 1).getWithIncrement(2), Univariate3D(44, 1));
|
|
|
|
EXPECT_EQ(Univariate3D(42, 2).getWithIncrement(3), Univariate3D(45, 2));
|
[NFCI] Add StackOffset class and base classes for ElementCount, TypeSize.
This patch adds a linear polynomial base class, called LinearPolyBase, which
serves as a base class for StackOffset. It tries to represent a linear
polynomial like:
c0 * scale0 + c1 * scale1 + ... + cK * scaleK
where the scale is implicit, meaning that only the coefficients are
encoded.
This patch also adds a univariate linear polynomial, which serves as
a base class for ElementCount and TypeSize. This tries to represent a
linear polynomial where only one dimension can be set at any one time,
i.e. a TypeSize is either fixed-sized, or scalable-sized, but cannot be
a combination of the two.
class LinearPolyBase
^
|
+---- class StackOffset (dimensions = 2 (fixed/scalable), type = int64_t)
class UnivariateLinearPolyBase
|
|
+---- class LinearPolySize (dimensions = 2 (fixed/scalable))
^
|
+-------- class ElementCount (type = unsigned)
|
|
+-------- class TypeSize (type = uint64_t)
Reviewed By: ctetreau, david-arm
Differential Revision: https://reviews.llvm.org/D88982
2020-11-03 05:32:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(UnivariateLinearPolyBase, Univariate3D_Sub) {
|
|
|
|
// Test operator+
|
|
|
|
EXPECT_EQ(Univariate3D(84, 0) - Univariate3D(42, 0), Univariate3D(42, 0));
|
|
|
|
EXPECT_EQ(Univariate3D(84, 1) - Univariate3D(42, 1), Univariate3D(42, 1));
|
|
|
|
EXPECT_DEBUG_DEATH(Univariate3D(84, 0) - Univariate3D(42, 1),
|
|
|
|
"Invalid dimensions");
|
|
|
|
|
|
|
|
// Test operator+=
|
|
|
|
Univariate3D X(84, 0);
|
|
|
|
X -= Univariate3D(42, 0);
|
|
|
|
EXPECT_EQ(X, Univariate3D(42, 0));
|
2020-11-06 15:56:55 +08:00
|
|
|
|
|
|
|
// Test 'getWithDecrement' method
|
|
|
|
EXPECT_EQ(Univariate3D(43, 0).getWithDecrement(1), Univariate3D(42, 0));
|
|
|
|
EXPECT_EQ(Univariate3D(44, 1).getWithDecrement(2), Univariate3D(42, 1));
|
|
|
|
EXPECT_EQ(Univariate3D(45, 2).getWithDecrement(3), Univariate3D(42, 2));
|
[NFCI] Add StackOffset class and base classes for ElementCount, TypeSize.
This patch adds a linear polynomial base class, called LinearPolyBase, which
serves as a base class for StackOffset. It tries to represent a linear
polynomial like:
c0 * scale0 + c1 * scale1 + ... + cK * scaleK
where the scale is implicit, meaning that only the coefficients are
encoded.
This patch also adds a univariate linear polynomial, which serves as
a base class for ElementCount and TypeSize. This tries to represent a
linear polynomial where only one dimension can be set at any one time,
i.e. a TypeSize is either fixed-sized, or scalable-sized, but cannot be
a combination of the two.
class LinearPolyBase
^
|
+---- class StackOffset (dimensions = 2 (fixed/scalable), type = int64_t)
class UnivariateLinearPolyBase
|
|
+---- class LinearPolySize (dimensions = 2 (fixed/scalable))
^
|
+-------- class ElementCount (type = unsigned)
|
|
+-------- class TypeSize (type = uint64_t)
Reviewed By: ctetreau, david-arm
Differential Revision: https://reviews.llvm.org/D88982
2020-11-03 05:32:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(UnivariateLinearPolyBase, Univariate3D_Scale) {
|
|
|
|
// Test operator*
|
|
|
|
EXPECT_EQ(Univariate3D(4, 0) * 2, Univariate3D(8, 0));
|
|
|
|
EXPECT_EQ(Univariate3D(4, 1) * -2, Univariate3D(-8, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(UnivariateLinearPolyBase, Univariate3D_Invert) {
|
|
|
|
// Test operator-
|
|
|
|
EXPECT_EQ(-Univariate3D(4, 0), Univariate3D(-4, 0));
|
|
|
|
EXPECT_EQ(-Univariate3D(4, 1), Univariate3D(-4, 1));
|
|
|
|
}
|
|
|
|
|