JaviGr

Untitled

Jul 3rd, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Copyright (c) 2016 ARM Limited
  3.  * All rights reserved
  4.  *
  5.  * The license below extends only to copyright in the software and shall
  6.  * not be construed as granting a license to any other intellectual
  7.  * property including but not limited to intellectual property relating
  8.  * to a hardware implementation of the functionality of the software
  9.  * licensed hereunder. You may use the software subject to the license
  10.  * terms below provided that you ensure that this notice is replicated
  11.  * unmodified and in its entirety in all distributions of the software,
  12.  * modified or unmodified, in source code or in binary form.
  13.  *
  14.  * Copyright (c) 2004-2005 The Regents of The University of Michigan
  15.  * Copyright (c) 2013 Advanced Micro Devices, Inc.
  16.  * All rights reserved.
  17.  *
  18.  * Redistribution and use in source and binary forms, with or without
  19.  * modification, are permitted provided that the following conditions are
  20.  * met: redistributions of source code must retain the above copyright
  21.  * notice, this list of conditions and the following disclaimer;
  22.  * redistributions in binary form must reproduce the above copyright
  23.  * notice, this list of conditions and the following disclaimer in the
  24.  * documentation and/or other materials provided with the distribution;
  25.  * neither the name of the copyright holders nor the names of its
  26.  * contributors may be used to endorse or promote products derived from
  27.  * this software without specific prior written permission.
  28.  *
  29.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40.  *
  41.  * Authors: Kevin Lim
  42.  */
  43.  
  44. #include "cpu/o3/rename_map.hh"
  45.  
  46. #include <vector>
  47.  
  48. #include "cpu/reg_class_impl.hh"
  49. #include "debug/Rename.hh"
  50.  
  51. using namespace std;
  52.  
  53. /**** SimpleRenameMap methods ****/
  54.  
  55. static brojac=0;
  56.  
  57. SimpleRenameMap::SimpleRenameMap()
  58.     : freeList(NULL), zeroReg(IntRegClass,0)
  59. {
  60. }
  61.  
  62.  
  63. void
  64. SimpleRenameMap::init(unsigned size, SimpleFreeList *_freeList,
  65.                       RegIndex _zeroReg)
  66. {
  67.     assert(freeList == NULL);
  68.     assert(map.empty());
  69.  
  70.     map.resize(size);
  71.     freeList = _freeList;
  72.     zeroReg = RegId(IntRegClass, _zeroReg);
  73. }
  74.  
  75. SimpleRenameMap::RenameInfo
  76. SimpleRenameMap::rename(const RegId& arch_reg)
  77. {
  78.     PhysRegIdPtr renamed_reg;
  79.     // Record the current physical register that is renamed to the
  80.     // requested architected register.
  81.     PhysRegIdPtr prev_reg = map[arch_reg.index()];
  82.  
  83.     // If it's not referencing the zero register, then rename the
  84.     // register.
  85.     if (arch_reg != zeroReg) {
  86.     PhyRegIdPtr pom[256]= freeList->getReg();
  87.         renamed_reg = pom[brojac];
  88.     brojac++;
  89.  
  90.         map[arch_reg.index()] = renamed_reg;
  91.     } else {
  92.         // Otherwise return the zero register so nothing bad happens.
  93.         assert(prev_reg->isZeroReg());
  94.         renamed_reg = prev_reg;
  95.     }
  96.  
  97.     DPRINTF(Rename, "Renamed reg %d to physical reg %d (%d) old mapping was"
  98.             " %d (%d)\n",
  99.             arch_reg, renamed_reg->index(), renamed_reg->flatIndex(),
  100.             prev_reg->index(), prev_reg->flatIndex());
  101.  
  102.     return RenameInfo(renamed_reg, prev_reg);
  103. }
  104.  
  105.  
  106. /**** UnifiedRenameMap methods ****/
  107.  
  108. void
  109. UnifiedRenameMap::init(PhysRegFile *_regFile,
  110.                        RegIndex _intZeroReg,
  111.                        RegIndex _floatZeroReg,
  112.                        UnifiedFreeList *freeList,
  113.                        VecMode _mode)
  114. {
  115.     regFile = _regFile;
  116.     vecMode = _mode;
  117.  
  118.     intMap.init(TheISA::NumIntRegs, &(freeList->intList), _intZeroReg);
  119.  
  120.     floatMap.init(TheISA::NumFloatRegs, &(freeList->floatList), _floatZeroReg);
  121.  
  122.     vecMap.init(TheISA::NumVecRegs, &(freeList->vecList), (RegIndex)-1);
  123.  
  124.     vecElemMap.init(TheISA::NumVecRegs * NVecElems,
  125.             &(freeList->vecElemList), (RegIndex)-1);
  126.  
  127.     ccMap.init(TheISA::NumCCRegs, &(freeList->ccList), (RegIndex)-1);
  128.  
  129. }
  130.  
  131. void
  132. UnifiedRenameMap::switchMode(VecMode newVecMode, UnifiedFreeList* freeList)
  133. {
  134.     if (newVecMode == Enums::Elem && vecMode == Enums::Full) {
  135.         /* Switch to vector element rename mode. */
  136.         /* The free list should currently be tracking full registers. */
  137.         panic_if(freeList->hasFreeVecElems(),
  138.                 "The free list is already tracking Vec elems");
  139.         panic_if(freeList->numFreeVecRegs() !=
  140.                 regFile->numVecPhysRegs() - TheISA::NumVecRegs,
  141.                 "The free list has lost vector registers");
  142.         /* Split the mapping of each arch reg. */
  143.         int reg = 0;
  144.         for (auto &e: vecMap) {
  145.             PhysRegFile::IdRange range = this->regFile->getRegElemIds(e);
  146.             uint32_t i;
  147.             for (i = 0; range.first != range.second; i++, range.first++) {
  148.                 vecElemMap.setEntry(RegId(VecElemClass, reg, i),
  149.                                     &(*range.first));
  150.             }
  151.             panic_if(i != NVecElems,
  152.                 "Wrong name of elems: expecting %u, got %d\n",
  153.                 TheISA::NumVecElemPerVecReg, i);
  154.             reg++;
  155.         }
  156.         /* Split the free regs. */
  157.         while (freeList->hasFreeVecRegs()) {
  158.             auto vr = freeList->getVecReg();
  159.             auto range = this->regFile->getRegElemIds(vr);
  160.             freeList->addRegs(range.first, range.second);
  161.         }
  162.         vecMode = Enums::Elem;
  163.     } else if (newVecMode == Enums::Full && vecMode == Enums::Elem) {
  164.         /* Switch to full vector register rename mode. */
  165.         /* The free list should currently be tracking register elems. */
  166.         panic_if(freeList->hasFreeVecRegs(),
  167.                 "The free list is already tracking full Vec");
  168.         panic_if(freeList->numFreeVecRegs() !=
  169.                 regFile->numVecElemPhysRegs() - TheISA::NumFloatRegs,
  170.                 "The free list has lost vector register elements");
  171.         /* To rebuild the arch regs we take the easy road:
  172.          *  1.- Stitch the elems together into vectors.
  173.          *  2.- Replace the contents of the register file with the vectors
  174.          *  3.- Set the remaining registers as free
  175.          */
  176.         TheISA::VecRegContainer new_RF[TheISA::NumVecRegs];
  177.         for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) {
  178.             VecReg dst = new_RF[i].as<TheISA::VecElem>();
  179.             for (uint32_t l = 0; l < NVecElems; l++) {
  180.                 RegId s_rid(VecElemClass, i, l);
  181.                 PhysRegIdPtr s_prid = vecElemMap.lookup(s_rid);
  182.                 dst[l] = regFile->readVecElem(s_prid);
  183.             }
  184.         }
  185.  
  186.         for (uint32_t i = 0; i < TheISA::NumVecRegs; i++) {
  187.             PhysRegId pregId(VecRegClass, i, 0);
  188.             regFile->setVecReg(regFile->getTrueId(&pregId), new_RF[i]);
  189.         }
  190.  
  191.         auto range = regFile->getRegIds(VecRegClass);
  192.         freeList->addRegs(range.first + TheISA::NumVecRegs, range.second);
  193.  
  194.         /* We remove the elems from the free list. */
  195.         while (freeList->hasFreeVecElems())
  196.             freeList->getVecElem();
  197.         vecMode = Enums::Full;
  198.     }
  199. }
Add Comment
Please, Sign In to add comment