113219Sodanrc@yahoo.com.br/*
213219Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria
313219Sodanrc@yahoo.com.br * Copyright (c) 2012-2014,2017 ARM Limited
413219Sodanrc@yahoo.com.br * All rights reserved.
513219Sodanrc@yahoo.com.br *
613219Sodanrc@yahoo.com.br * The license below extends only to copyright in the software and shall
713219Sodanrc@yahoo.com.br * not be construed as granting a license to any other intellectual
813219Sodanrc@yahoo.com.br * property including but not limited to intellectual property relating
913219Sodanrc@yahoo.com.br * to a hardware implementation of the functionality of the software
1013219Sodanrc@yahoo.com.br * licensed hereunder.  You may use the software subject to the license
1113219Sodanrc@yahoo.com.br * terms below provided that you ensure that this notice is replicated
1213219Sodanrc@yahoo.com.br * unmodified and in its entirety in all distributions of the software,
1313219Sodanrc@yahoo.com.br * modified or unmodified, in source code or in binary form.
1413219Sodanrc@yahoo.com.br *
1513219Sodanrc@yahoo.com.br * Copyright (c) 2003-2005,2014 The Regents of The University of Michigan
1613219Sodanrc@yahoo.com.br * All rights reserved.
1713219Sodanrc@yahoo.com.br *
1813219Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without
1913219Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are
2013219Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright
2113219Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer;
2213219Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright
2313219Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the
2413219Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution;
2513219Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its
2613219Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from
2713219Sodanrc@yahoo.com.br * this software without specific prior written permission.
2813219Sodanrc@yahoo.com.br *
2913219Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3013219Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3113219Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3213219Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3313219Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3413219Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3513219Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3613219Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3713219Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3813219Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3913219Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4013219Sodanrc@yahoo.com.br *
4113219Sodanrc@yahoo.com.br * Authors: Daniel Carvalho
4213219Sodanrc@yahoo.com.br *          Erik Hallnor
4313219Sodanrc@yahoo.com.br */
4413219Sodanrc@yahoo.com.br
4513219Sodanrc@yahoo.com.br/**
4613219Sodanrc@yahoo.com.br * @file
4713219Sodanrc@yahoo.com.br * Declaration of a common framework for indexing policies.
4813219Sodanrc@yahoo.com.br */
4913219Sodanrc@yahoo.com.br
5013219Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_INDEXING_POLICIES_BASE_HH__
5113219Sodanrc@yahoo.com.br#define __MEM_CACHE_INDEXING_POLICIES_BASE_HH__
5213219Sodanrc@yahoo.com.br
5313219Sodanrc@yahoo.com.br#include <vector>
5413219Sodanrc@yahoo.com.br
5513219Sodanrc@yahoo.com.br#include "params/BaseIndexingPolicy.hh"
5613219Sodanrc@yahoo.com.br#include "sim/sim_object.hh"
5713219Sodanrc@yahoo.com.br
5813219Sodanrc@yahoo.com.brclass ReplaceableEntry;
5913219Sodanrc@yahoo.com.br
6013219Sodanrc@yahoo.com.br/**
6113219Sodanrc@yahoo.com.br * A common base class for indexing table locations. Classes that inherit
6213219Sodanrc@yahoo.com.br * from it determine hash functions that should be applied based on the set
6313219Sodanrc@yahoo.com.br * and way. These functions are then applied to re-map the original values.
6413219Sodanrc@yahoo.com.br * @sa  \ref gem5MemorySystem "gem5 Memory System"
6513219Sodanrc@yahoo.com.br */
6613219Sodanrc@yahoo.com.brclass BaseIndexingPolicy : public SimObject
6713219Sodanrc@yahoo.com.br{
6813219Sodanrc@yahoo.com.br  protected:
6913219Sodanrc@yahoo.com.br    /**
7013219Sodanrc@yahoo.com.br     * The associativity.
7113219Sodanrc@yahoo.com.br     */
7213219Sodanrc@yahoo.com.br    const unsigned assoc;
7313219Sodanrc@yahoo.com.br
7413219Sodanrc@yahoo.com.br    /**
7513219Sodanrc@yahoo.com.br     * The number of sets in the cache.
7613219Sodanrc@yahoo.com.br     */
7713219Sodanrc@yahoo.com.br    const uint32_t numSets;
7813219Sodanrc@yahoo.com.br
7913219Sodanrc@yahoo.com.br    /**
8013219Sodanrc@yahoo.com.br     * The amount to shift the address to get the set.
8113219Sodanrc@yahoo.com.br     */
8213219Sodanrc@yahoo.com.br    const int setShift;
8313219Sodanrc@yahoo.com.br
8413219Sodanrc@yahoo.com.br    /**
8513219Sodanrc@yahoo.com.br     * Mask out all bits that aren't part of the set index.
8613219Sodanrc@yahoo.com.br     */
8713219Sodanrc@yahoo.com.br    const unsigned setMask;
8813219Sodanrc@yahoo.com.br
8913219Sodanrc@yahoo.com.br    /**
9013219Sodanrc@yahoo.com.br     * The cache sets.
9113219Sodanrc@yahoo.com.br     */
9213219Sodanrc@yahoo.com.br    std::vector<std::vector<ReplaceableEntry*>> sets;
9313219Sodanrc@yahoo.com.br
9413219Sodanrc@yahoo.com.br    /**
9513219Sodanrc@yahoo.com.br     * The amount to shift the address to get the tag.
9613219Sodanrc@yahoo.com.br     */
9713219Sodanrc@yahoo.com.br    const int tagShift;
9813219Sodanrc@yahoo.com.br
9913219Sodanrc@yahoo.com.br  public:
10013219Sodanrc@yahoo.com.br    /**
10113219Sodanrc@yahoo.com.br     * Convenience typedef.
10213219Sodanrc@yahoo.com.br     */
10313219Sodanrc@yahoo.com.br    typedef BaseIndexingPolicyParams Params;
10413219Sodanrc@yahoo.com.br
10513219Sodanrc@yahoo.com.br    /**
10613219Sodanrc@yahoo.com.br     * Construct and initialize this policy.
10713219Sodanrc@yahoo.com.br     */
10813219Sodanrc@yahoo.com.br    BaseIndexingPolicy(const Params *p);
10913219Sodanrc@yahoo.com.br
11013219Sodanrc@yahoo.com.br    /**
11113219Sodanrc@yahoo.com.br     * Destructor.
11213219Sodanrc@yahoo.com.br     */
11313219Sodanrc@yahoo.com.br    ~BaseIndexingPolicy() {};
11413219Sodanrc@yahoo.com.br
11513219Sodanrc@yahoo.com.br    /**
11613219Sodanrc@yahoo.com.br     * Associate a pointer to an entry to its physical counterpart.
11713219Sodanrc@yahoo.com.br     *
11813219Sodanrc@yahoo.com.br     * @param entry The entry pointer.
11913219Sodanrc@yahoo.com.br     * @param index An unique index for the entry.
12013219Sodanrc@yahoo.com.br     */
12113219Sodanrc@yahoo.com.br    void setEntry(ReplaceableEntry* entry, const uint64_t index);
12213219Sodanrc@yahoo.com.br
12313219Sodanrc@yahoo.com.br    /**
12413219Sodanrc@yahoo.com.br     * Get an entry based on its set and way. All entries must have been set
12513219Sodanrc@yahoo.com.br     * already before calling this function.
12613219Sodanrc@yahoo.com.br     *
12713219Sodanrc@yahoo.com.br     * @param set The set of the desired entry.
12813219Sodanrc@yahoo.com.br     * @param way The way of the desired entry.
12913219Sodanrc@yahoo.com.br     * @return entry The entry pointer.
13013219Sodanrc@yahoo.com.br     */
13113219Sodanrc@yahoo.com.br    ReplaceableEntry* getEntry(const uint32_t set, const uint32_t way) const;
13213219Sodanrc@yahoo.com.br
13313219Sodanrc@yahoo.com.br    /**
13413219Sodanrc@yahoo.com.br     * Generate the tag from the given address.
13513219Sodanrc@yahoo.com.br     *
13613219Sodanrc@yahoo.com.br     * @param addr The address to get the tag from.
13713219Sodanrc@yahoo.com.br     * @return The tag of the address.
13813219Sodanrc@yahoo.com.br     */
13913219Sodanrc@yahoo.com.br    Addr extractTag(const Addr addr) const;
14013219Sodanrc@yahoo.com.br
14113219Sodanrc@yahoo.com.br    /**
14213219Sodanrc@yahoo.com.br     * Find all possible entries for insertion and replacement of an address.
14313219Sodanrc@yahoo.com.br     * Should be called immediately before ReplacementPolicy's findVictim()
14413219Sodanrc@yahoo.com.br     * not to break cache resizing.
14513219Sodanrc@yahoo.com.br     *
14613219Sodanrc@yahoo.com.br     * @param addr The addr to a find possible entries for.
14713219Sodanrc@yahoo.com.br     * @return The possible entries.
14813219Sodanrc@yahoo.com.br     */
14913219Sodanrc@yahoo.com.br    virtual std::vector<ReplaceableEntry*> getPossibleEntries(const Addr addr)
15013219Sodanrc@yahoo.com.br                                                                    const = 0;
15113219Sodanrc@yahoo.com.br
15213219Sodanrc@yahoo.com.br    /**
15313219Sodanrc@yahoo.com.br     * Regenerate an entry's address from its tag and assigned indexing bits.
15413219Sodanrc@yahoo.com.br     *
15513219Sodanrc@yahoo.com.br     * @param tag The tag bits.
15613219Sodanrc@yahoo.com.br     * @param entry The entry.
15713219Sodanrc@yahoo.com.br     * @return the entry's original address.
15813219Sodanrc@yahoo.com.br     */
15913219Sodanrc@yahoo.com.br    virtual Addr regenerateAddr(const Addr tag, const ReplaceableEntry* entry)
16013219Sodanrc@yahoo.com.br                                                                    const = 0;
16113219Sodanrc@yahoo.com.br};
16213219Sodanrc@yahoo.com.br
16313219Sodanrc@yahoo.com.br#endif //__MEM_CACHE_INDEXING_POLICIES_BASE_HH__
164