reg_class.hh revision 9918
12SN/A/* 21762SN/A * Copyright (c) 2013 Advanced Micro Devices, Inc. 32SN/A * All rights reserved 42SN/A *. 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A * 282665SN/A * Authors: Steve Reinhardt 292665SN/A */ 302SN/A 312SN/A#ifndef __CPU__REG_CLASS_HH__ 322SN/A#define __CPU__REG_CLASS_HH__ 332SN/A 342SN/A#include <cassert> 352SN/A#include <cstddef> 3611263Sandreas.sandberg@arm.com 3711263Sandreas.sandberg@arm.com#include "arch/registers.hh" 382SN/A#include "config/the_isa.hh" 396216SN/A 40572SN/A/// Enumerate the classes of registers. 412SN/Aenum RegClass { 422SN/A IntRegClass, ///< Integer register 436214SN/A FloatRegClass, ///< Floating-point register 4410905SN/A MiscRegClass ///< Control (misc) register 45837SN/A}; 462SN/A 472SN/A/// Number of register classes. This value is not part of the enum, 482SN/A/// because putting it there makes the compiler complain about 4910469SN/A/// unhandled cases in some switch statements. 502SN/Aconst int NumRegClasses = MiscRegClass + 1; 512SN/A 5211701Smichael.lebeane@amd.com/** 532007SN/A * Map a 'unified' architectural register index to its register class. 542007SN/A * The unified architectural register index space is used to represent 552SN/A * all architectural register identifiers in a single contiguous 562007SN/A * index space. See http://gem5.org/Register_Indexing. 5711701Smichael.lebeane@amd.com * 5811701Smichael.lebeane@amd.com * @param reg_idx Unified-space register index 592007SN/A * @param rel_reg_idx Optional output param pointer; if non-NULL, location 606227SN/A * will be written with the relative register index for reg_idx 612SN/A * 6211701Smichael.lebeane@amd.com * @return Register class of reg_idx 6311701Smichael.lebeane@amd.com */ 6411701Smichael.lebeane@amd.cominline 6511701Smichael.lebeane@amd.comRegClass regIdxToClass(TheISA::RegIndex reg_idx, 6611701Smichael.lebeane@amd.com TheISA::RegIndex *rel_reg_idx = NULL) 6711701Smichael.lebeane@amd.com{ 6811701Smichael.lebeane@amd.com assert(reg_idx < TheISA::Max_Reg_Index); 6911701Smichael.lebeane@amd.com RegClass cl; 7011701Smichael.lebeane@amd.com int offset; 715483SN/A 7211701Smichael.lebeane@amd.com if (reg_idx < TheISA::FP_Reg_Base) { 734981SN/A cl = IntRegClass; 744981SN/A offset = 0; 756227SN/A } else if (reg_idx < TheISA::Misc_Reg_Base) { 7611701Smichael.lebeane@amd.com cl = FloatRegClass; 774981SN/A offset = TheISA::FP_Reg_Base; 784981SN/A } else { 792566SN/A cl = MiscRegClass; 80228SN/A offset = TheISA::Misc_Reg_Base; 8110905SN/A } 8210905SN/A 832SN/A if (rel_reg_idx) 842SN/A *rel_reg_idx = reg_idx - offset; 8510469SN/A return cl; 862SN/A} 8711263Sandreas.sandberg@arm.com 88/// Map enum values to strings for debugging 89extern const char *RegClassStrings[]; 90 91 92#endif // __CPU__REG_CLASS_HH__ 93