arm: Add a unit test for some aspects of the aapcs64 ABI.
authorGabe Black <gabeblack@google.com>
Mon, 27 Apr 2020 20:46:42 +0000 (13:46 -0700)
committerGabe Black <gabeblack@google.com>
Wed, 29 Apr 2020 11:30:58 +0000 (11:30 +0000)
This test covers the templates which attempt to classify types, but not the
actual gathering of arguments of distribution of return values. As before, we
can't really use standard C++ to accurately test for HFAs and HVAs, so we stick
with approximating them by detecting arrays of the right types.

For example, I think technically we should also accept a struct with only 4
float members, but c++ templates aren't able to match against types in that way
as far as I know.

Change-Id: I1d7756a964a86c0c5ea13e068a5fc74603e14e30
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28268
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/arch/arm/SConscript
src/arch/arm/aapcs64.test.cc [new file with mode: 0644]

index e51437e49c2e608efd9270b9beb06999931ff111..73ebcacf200d1e9267b8ed1f9e3f0cb5eebf6542 100644 (file)
@@ -44,6 +44,8 @@ if env['TARGET_ISA'] == 'arm':
 # Workaround for bug in SCons version > 0.97d20071212
 # Scons bug id: 2006 M5 Bug id: 308
     Dir('isa/formats')
+
+    GTest('aapcs64.test', 'aapcs64.test.cc')
     Source('decoder.cc')
     Source('faults.cc')
     Source('insts/branch.cc')
diff --git a/src/arch/arm/aapcs64.test.cc b/src/arch/arm/aapcs64.test.cc
new file mode 100644 (file)
index 0000000..69bbb83
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2020 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "arch/arm/aapcs64.hh"
+
+TEST(Aapcs64, IsAapcs64ShortVector)
+{
+    using Scalar = uint64_t;
+    using TooShort = uint8_t[2];
+    using TooLong = uint16_t[32];
+    using TooLongFloat = double[4];
+    using EightLong = uint32_t[2];
+    using SixteenLong = uint64_t[2];
+    using EightLongFloat = float[2];
+    using SixteenLongFloat = double[2];
+
+    EXPECT_FALSE(GuestABI::IsAapcs64ShortVector<Scalar>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64ShortVector<TooShort>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64ShortVector<TooLong>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64ShortVector<TooLongFloat>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64ShortVector<void>::value);
+
+    EXPECT_TRUE(GuestABI::IsAapcs64ShortVector<EightLong>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64ShortVector<SixteenLong>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64ShortVector<EightLongFloat>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64ShortVector<SixteenLongFloat>::value);
+}
+
+TEST(Aapcs64, IsAapcs64Hfa)
+{
+    // Accept floating point arrays with up to 4 members.
+    EXPECT_TRUE(GuestABI::IsAapcs64Hfa<float[1]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hfa<float[2]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hfa<float[3]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hfa<float[4]>::value);
+
+    EXPECT_TRUE(GuestABI::IsAapcs64Hfa<double[1]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hfa<double[2]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hfa<double[3]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hfa<double[4]>::value);
+
+    // Too many members.
+    EXPECT_FALSE(GuestABI::IsAapcs64Hfa<float[5]>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hfa<double[5]>::value);
+
+    // Wrong type of members, or not arrays.
+    EXPECT_FALSE(GuestABI::IsAapcs64Hfa<int32_t[3]>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hfa<float>::value);
+    struct Struct {};
+    EXPECT_FALSE(GuestABI::IsAapcs64Hfa<Struct>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hfa<void>::value);
+}
+
+TEST(Aapcs64, IsAapcs64Hva)
+{
+    using SvaInt = uint32_t[2];
+    using SvaTiny = uint8_t[16];
+    using SvaFloat = float[2];
+
+    EXPECT_TRUE(GuestABI::IsAapcs64Hva<SvaInt[3]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hva<SvaInt[4]>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hva<SvaInt[5]>::value);
+
+    EXPECT_TRUE(GuestABI::IsAapcs64Hva<SvaFloat[3]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hva<SvaFloat[4]>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hva<SvaFloat[5]>::value);
+
+    EXPECT_TRUE(GuestABI::IsAapcs64Hva<SvaTiny[3]>::value);
+    EXPECT_TRUE(GuestABI::IsAapcs64Hva<SvaTiny[4]>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hva<SvaTiny[5]>::value);
+
+    EXPECT_FALSE(GuestABI::IsAapcs64Hva<uint64_t>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hva<uint64_t[1]>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hva<SvaTiny>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hva<void>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hva<float>::value);
+}
+
+TEST(Aapcs64, IsAapcs64Hxa)
+{
+    using SvaInt = uint32_t[2];
+
+    EXPECT_TRUE(GuestABI::IsAapcs64Hxa<SvaInt[4]>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hxa<SvaInt[5]>::value);
+
+    EXPECT_TRUE(GuestABI::IsAapcs64Hxa<float[4]>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hxa<float[5]>::value);
+
+    EXPECT_FALSE(GuestABI::IsAapcs64Hxa<SvaInt>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hxa<uint64_t>::value);
+    EXPECT_FALSE(GuestABI::IsAapcs64Hxa<void>::value);
+}