From f8926cd56f01e588b6306733880c6c2e64390b2b Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 27 Apr 2020 13:46:42 -0700 Subject: [PATCH] arm: Add a unit test for some aspects of the aapcs64 ABI. 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 Maintainer: Giacomo Travaglini Tested-by: kokoro --- src/arch/arm/SConscript | 2 + src/arch/arm/aapcs64.test.cc | 118 +++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 src/arch/arm/aapcs64.test.cc diff --git a/src/arch/arm/SConscript b/src/arch/arm/SConscript index e51437e49..73ebcacf2 100644 --- a/src/arch/arm/SConscript +++ b/src/arch/arm/SConscript @@ -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 index 000000000..69bbb837d --- /dev/null +++ b/src/arch/arm/aapcs64.test.cc @@ -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 + +#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::value); + EXPECT_FALSE(GuestABI::IsAapcs64ShortVector::value); + EXPECT_FALSE(GuestABI::IsAapcs64ShortVector::value); + EXPECT_FALSE(GuestABI::IsAapcs64ShortVector::value); + EXPECT_FALSE(GuestABI::IsAapcs64ShortVector::value); + + EXPECT_TRUE(GuestABI::IsAapcs64ShortVector::value); + EXPECT_TRUE(GuestABI::IsAapcs64ShortVector::value); + EXPECT_TRUE(GuestABI::IsAapcs64ShortVector::value); + EXPECT_TRUE(GuestABI::IsAapcs64ShortVector::value); +} + +TEST(Aapcs64, IsAapcs64Hfa) +{ + // Accept floating point arrays with up to 4 members. + EXPECT_TRUE(GuestABI::IsAapcs64Hfa::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hfa::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hfa::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hfa::value); + + EXPECT_TRUE(GuestABI::IsAapcs64Hfa::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hfa::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hfa::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hfa::value); + + // Too many members. + EXPECT_FALSE(GuestABI::IsAapcs64Hfa::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hfa::value); + + // Wrong type of members, or not arrays. + EXPECT_FALSE(GuestABI::IsAapcs64Hfa::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hfa::value); + struct Struct {}; + EXPECT_FALSE(GuestABI::IsAapcs64Hfa::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hfa::value); +} + +TEST(Aapcs64, IsAapcs64Hva) +{ + using SvaInt = uint32_t[2]; + using SvaTiny = uint8_t[16]; + using SvaFloat = float[2]; + + EXPECT_TRUE(GuestABI::IsAapcs64Hva::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hva::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hva::value); + + EXPECT_TRUE(GuestABI::IsAapcs64Hva::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hva::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hva::value); + + EXPECT_TRUE(GuestABI::IsAapcs64Hva::value); + EXPECT_TRUE(GuestABI::IsAapcs64Hva::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hva::value); + + EXPECT_FALSE(GuestABI::IsAapcs64Hva::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hva::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hva::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hva::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hva::value); +} + +TEST(Aapcs64, IsAapcs64Hxa) +{ + using SvaInt = uint32_t[2]; + + EXPECT_TRUE(GuestABI::IsAapcs64Hxa::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hxa::value); + + EXPECT_TRUE(GuestABI::IsAapcs64Hxa::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hxa::value); + + EXPECT_FALSE(GuestABI::IsAapcs64Hxa::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hxa::value); + EXPECT_FALSE(GuestABI::IsAapcs64Hxa::value); +} -- 2.30.2