inst_res.hh revision 12107
112107SRekai.GonzalezAlberquilla@arm.com/* 212107SRekai.GonzalezAlberquilla@arm.com * Copyright (c) 2016 ARM Limited 312107SRekai.GonzalezAlberquilla@arm.com * All rights reserved 412107SRekai.GonzalezAlberquilla@arm.com * 512107SRekai.GonzalezAlberquilla@arm.com * The license below extends only to copyright in the software and shall 612107SRekai.GonzalezAlberquilla@arm.com * not be construed as granting a license to any other intellectual 712107SRekai.GonzalezAlberquilla@arm.com * property including but not limited to intellectual property relating 812107SRekai.GonzalezAlberquilla@arm.com * to a hardware implementation of the functionality of the software 912107SRekai.GonzalezAlberquilla@arm.com * licensed hereunder. You may use the software subject to the license 1012107SRekai.GonzalezAlberquilla@arm.com * terms below provided that you ensure that this notice is replicated 1112107SRekai.GonzalezAlberquilla@arm.com * unmodified and in its entirety in all distributions of the software, 1212107SRekai.GonzalezAlberquilla@arm.com * modified or unmodified, in source code or in binary form. 1312107SRekai.GonzalezAlberquilla@arm.com * 1412107SRekai.GonzalezAlberquilla@arm.com * Redistribution and use in source and binary forms, with or without 1512107SRekai.GonzalezAlberquilla@arm.com * modification, are permitted provided that the following conditions are 1612107SRekai.GonzalezAlberquilla@arm.com * met: redistributions of source code must retain the above copyright 1712107SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer; 1812107SRekai.GonzalezAlberquilla@arm.com * redistributions in binary form must reproduce the above copyright 1912107SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer in the 2012107SRekai.GonzalezAlberquilla@arm.com * documentation and/or other materials provided with the distribution; 2112107SRekai.GonzalezAlberquilla@arm.com * neither the name of the copyright holders nor the names of its 2212107SRekai.GonzalezAlberquilla@arm.com * contributors may be used to endorse or promote products derived from 2312107SRekai.GonzalezAlberquilla@arm.com * this software without specific prior written permission. 2412107SRekai.GonzalezAlberquilla@arm.com * 2512107SRekai.GonzalezAlberquilla@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2612107SRekai.GonzalezAlberquilla@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2712107SRekai.GonzalezAlberquilla@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2812107SRekai.GonzalezAlberquilla@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2912107SRekai.GonzalezAlberquilla@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3012107SRekai.GonzalezAlberquilla@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3112107SRekai.GonzalezAlberquilla@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3212107SRekai.GonzalezAlberquilla@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3312107SRekai.GonzalezAlberquilla@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3412107SRekai.GonzalezAlberquilla@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3512107SRekai.GonzalezAlberquilla@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3612107SRekai.GonzalezAlberquilla@arm.com * 3712107SRekai.GonzalezAlberquilla@arm.com * Authors: Nathanael Premillieu 3812107SRekai.GonzalezAlberquilla@arm.com */ 3912107SRekai.GonzalezAlberquilla@arm.com 4012107SRekai.GonzalezAlberquilla@arm.com#ifndef __CPU_INST_RES_HH__ 4112107SRekai.GonzalezAlberquilla@arm.com#define __CPU_INST_RES_HH__ 4212107SRekai.GonzalezAlberquilla@arm.com 4312107SRekai.GonzalezAlberquilla@arm.com#include <type_traits> 4412107SRekai.GonzalezAlberquilla@arm.com 4512107SRekai.GonzalezAlberquilla@arm.com#include "arch/generic/types.hh" 4612107SRekai.GonzalezAlberquilla@arm.com 4712107SRekai.GonzalezAlberquilla@arm.comclass InstResult { 4812107SRekai.GonzalezAlberquilla@arm.com public: 4912107SRekai.GonzalezAlberquilla@arm.com union MultiResult { 5012107SRekai.GonzalezAlberquilla@arm.com uint64_t integer; 5112107SRekai.GonzalezAlberquilla@arm.com double dbl; 5212107SRekai.GonzalezAlberquilla@arm.com MultiResult() {} 5312107SRekai.GonzalezAlberquilla@arm.com }; 5412107SRekai.GonzalezAlberquilla@arm.com 5512107SRekai.GonzalezAlberquilla@arm.com enum class ResultType { 5612107SRekai.GonzalezAlberquilla@arm.com Scalar, 5712107SRekai.GonzalezAlberquilla@arm.com NumResultTypes, 5812107SRekai.GonzalezAlberquilla@arm.com Invalid 5912107SRekai.GonzalezAlberquilla@arm.com }; 6012107SRekai.GonzalezAlberquilla@arm.com 6112107SRekai.GonzalezAlberquilla@arm.com private: 6212107SRekai.GonzalezAlberquilla@arm.com MultiResult result; 6312107SRekai.GonzalezAlberquilla@arm.com ResultType type; 6412107SRekai.GonzalezAlberquilla@arm.com 6512107SRekai.GonzalezAlberquilla@arm.com public: 6612107SRekai.GonzalezAlberquilla@arm.com /** Default constructor creates an invalid result. */ 6712107SRekai.GonzalezAlberquilla@arm.com InstResult() : type(ResultType::Invalid) { } 6812107SRekai.GonzalezAlberquilla@arm.com /** Scalar result from scalar. */ 6912107SRekai.GonzalezAlberquilla@arm.com template<typename T> 7012107SRekai.GonzalezAlberquilla@arm.com explicit InstResult(T i, const ResultType& t) : type(t) { 7112107SRekai.GonzalezAlberquilla@arm.com static_assert(std::is_integral<T>::value ^ 7212107SRekai.GonzalezAlberquilla@arm.com std::is_floating_point<T>::value, 7312107SRekai.GonzalezAlberquilla@arm.com "Parameter type is neither integral nor fp, or it is both"); 7412107SRekai.GonzalezAlberquilla@arm.com if (std::is_integral<T>::value) { 7512107SRekai.GonzalezAlberquilla@arm.com result.integer = i; 7612107SRekai.GonzalezAlberquilla@arm.com } else if (std::is_floating_point<T>::value) { 7712107SRekai.GonzalezAlberquilla@arm.com result.dbl = i; 7812107SRekai.GonzalezAlberquilla@arm.com } 7912107SRekai.GonzalezAlberquilla@arm.com } 8012107SRekai.GonzalezAlberquilla@arm.com 8112107SRekai.GonzalezAlberquilla@arm.com /** 8212107SRekai.GonzalezAlberquilla@arm.com * Result comparison 8312107SRekai.GonzalezAlberquilla@arm.com * Two invalid results always differ. 8412107SRekai.GonzalezAlberquilla@arm.com */ 8512107SRekai.GonzalezAlberquilla@arm.com bool operator==(const InstResult& that) const { 8612107SRekai.GonzalezAlberquilla@arm.com if (this->type != that.type) 8712107SRekai.GonzalezAlberquilla@arm.com return false; 8812107SRekai.GonzalezAlberquilla@arm.com switch (type) { 8912107SRekai.GonzalezAlberquilla@arm.com case ResultType::Scalar: 9012107SRekai.GonzalezAlberquilla@arm.com return result.integer == that.result.integer; 9112107SRekai.GonzalezAlberquilla@arm.com case ResultType::Invalid: 9212107SRekai.GonzalezAlberquilla@arm.com return false; 9312107SRekai.GonzalezAlberquilla@arm.com default: 9412107SRekai.GonzalezAlberquilla@arm.com panic("Unknown type of result: %d\n", (int)type); 9512107SRekai.GonzalezAlberquilla@arm.com } 9612107SRekai.GonzalezAlberquilla@arm.com } 9712107SRekai.GonzalezAlberquilla@arm.com 9812107SRekai.GonzalezAlberquilla@arm.com bool operator!=(const InstResult& that) const { 9912107SRekai.GonzalezAlberquilla@arm.com return !operator==(that); 10012107SRekai.GonzalezAlberquilla@arm.com } 10112107SRekai.GonzalezAlberquilla@arm.com 10212107SRekai.GonzalezAlberquilla@arm.com /** Checks */ 10312107SRekai.GonzalezAlberquilla@arm.com /** @{ */ 10412107SRekai.GonzalezAlberquilla@arm.com /** Is this a scalar result?. */ 10512107SRekai.GonzalezAlberquilla@arm.com bool isScalar() const { return type == ResultType::Scalar; } 10612107SRekai.GonzalezAlberquilla@arm.com /** Is this a valid result?. */ 10712107SRekai.GonzalezAlberquilla@arm.com bool isValid() const { return type != ResultType::Invalid; } 10812107SRekai.GonzalezAlberquilla@arm.com /** @} */ 10912107SRekai.GonzalezAlberquilla@arm.com 11012107SRekai.GonzalezAlberquilla@arm.com /** Explicit cast-like operations. */ 11112107SRekai.GonzalezAlberquilla@arm.com /** @{ */ 11212107SRekai.GonzalezAlberquilla@arm.com const uint64_t& 11312107SRekai.GonzalezAlberquilla@arm.com asInteger() const 11412107SRekai.GonzalezAlberquilla@arm.com { 11512107SRekai.GonzalezAlberquilla@arm.com assert(isScalar()); 11612107SRekai.GonzalezAlberquilla@arm.com return result.integer; 11712107SRekai.GonzalezAlberquilla@arm.com } 11812107SRekai.GonzalezAlberquilla@arm.com 11912107SRekai.GonzalezAlberquilla@arm.com /** Cast to integer without checking type. 12012107SRekai.GonzalezAlberquilla@arm.com * This is required to have the o3 cpu checker happy, as it 12112107SRekai.GonzalezAlberquilla@arm.com * compares results as integers without being fully aware of 12212107SRekai.GonzalezAlberquilla@arm.com * their nature. */ 12312107SRekai.GonzalezAlberquilla@arm.com const uint64_t& 12412107SRekai.GonzalezAlberquilla@arm.com asIntegerNoAssert() const 12512107SRekai.GonzalezAlberquilla@arm.com { 12612107SRekai.GonzalezAlberquilla@arm.com return result.integer; 12712107SRekai.GonzalezAlberquilla@arm.com } 12812107SRekai.GonzalezAlberquilla@arm.com /** @} */ 12912107SRekai.GonzalezAlberquilla@arm.com}; 13012107SRekai.GonzalezAlberquilla@arm.com 13112107SRekai.GonzalezAlberquilla@arm.com#endif // __CPU_INST_RES_HH__ 132