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 set associative indexing policy.
4813219Sodanrc@yahoo.com.br */
4913219Sodanrc@yahoo.com.br
5013219Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_INDEXING_POLICIES_SET_ASSOCIATIVE_HH__
5113219Sodanrc@yahoo.com.br#define __MEM_CACHE_INDEXING_POLICIES_SET_ASSOCIATIVE_HH__
5213219Sodanrc@yahoo.com.br
5313219Sodanrc@yahoo.com.br#include <vector>
5413219Sodanrc@yahoo.com.br
5513219Sodanrc@yahoo.com.br#include "mem/cache/tags/indexing_policies/base.hh"
5613219Sodanrc@yahoo.com.br#include "params/SetAssociative.hh"
5713219Sodanrc@yahoo.com.br
5813219Sodanrc@yahoo.com.brclass ReplaceableEntry;
5913219Sodanrc@yahoo.com.br
6013219Sodanrc@yahoo.com.br/**
6113219Sodanrc@yahoo.com.br * A set associative indexing policy.
6213219Sodanrc@yahoo.com.br * @sa  \ref gem5MemorySystem "gem5 Memory System"
6313219Sodanrc@yahoo.com.br *
6413219Sodanrc@yahoo.com.br * The set associative indexing policy has an immutable/identity mapping, so a
6513219Sodanrc@yahoo.com.br * value x is always mapped to set x, independent of the way, that is,
6613219Sodanrc@yahoo.com.br * Hash(A, 0) = Hash(A, 1) = Hash(A, N-1), where N is the number of ways.
6713219Sodanrc@yahoo.com.br *
6813219Sodanrc@yahoo.com.br * For example, let's assume address A maps to set 3 on way 0. This policy
6913219Sodanrc@yahoo.com.br * makes so that A is also mappable to set 3 on every other way. Visually, the
7013219Sodanrc@yahoo.com.br * possible locations of A are, for a table with 4 ways and 8 sets:
7113219Sodanrc@yahoo.com.br *    Way 0   1   2   3
7213219Sodanrc@yahoo.com.br *  Set   _   _   _   _
7313219Sodanrc@yahoo.com.br *    0  |_| |_| |_| |_|
7413219Sodanrc@yahoo.com.br *    1  |_| |_| |_| |_|
7513219Sodanrc@yahoo.com.br *    2  |_| |_| |_| |_|
7613219Sodanrc@yahoo.com.br *    3  |X| |X| |X| |X|
7713219Sodanrc@yahoo.com.br *    4  |_| |_| |_| |_|
7813219Sodanrc@yahoo.com.br *    5  |_| |_| |_| |_|
7913219Sodanrc@yahoo.com.br *    6  |_| |_| |_| |_|
8013219Sodanrc@yahoo.com.br *    7  |_| |_| |_| |_|
8113219Sodanrc@yahoo.com.br */
8213219Sodanrc@yahoo.com.brclass SetAssociative : public BaseIndexingPolicy
8313219Sodanrc@yahoo.com.br{
8413219Sodanrc@yahoo.com.br  private:
8513219Sodanrc@yahoo.com.br    /**
8613219Sodanrc@yahoo.com.br     * Apply a hash function to calculate address set.
8713219Sodanrc@yahoo.com.br     *
8813219Sodanrc@yahoo.com.br     * @param addr The address to calculate the set for.
8913219Sodanrc@yahoo.com.br     * @return The set index for given combination of address and way.
9013219Sodanrc@yahoo.com.br     */
9113219Sodanrc@yahoo.com.br    uint32_t extractSet(const Addr addr) const;
9213219Sodanrc@yahoo.com.br
9313219Sodanrc@yahoo.com.br  public:
9413219Sodanrc@yahoo.com.br    /**
9513219Sodanrc@yahoo.com.br     * Convenience typedef.
9613219Sodanrc@yahoo.com.br     */
9713219Sodanrc@yahoo.com.br    typedef SetAssociativeParams Params;
9813219Sodanrc@yahoo.com.br
9913219Sodanrc@yahoo.com.br    /**
10013219Sodanrc@yahoo.com.br     * Construct and initialize this policy.
10113219Sodanrc@yahoo.com.br     */
10213219Sodanrc@yahoo.com.br    SetAssociative(const Params *p);
10313219Sodanrc@yahoo.com.br
10413219Sodanrc@yahoo.com.br    /**
10513219Sodanrc@yahoo.com.br     * Destructor.
10613219Sodanrc@yahoo.com.br     */
10713219Sodanrc@yahoo.com.br    ~SetAssociative() {};
10813219Sodanrc@yahoo.com.br
10913219Sodanrc@yahoo.com.br    /**
11013219Sodanrc@yahoo.com.br     * Find all possible entries for insertion and replacement of an address.
11113219Sodanrc@yahoo.com.br     * Should be called immediately before ReplacementPolicy's findVictim()
11213219Sodanrc@yahoo.com.br     * not to break cache resizing.
11313219Sodanrc@yahoo.com.br     * Returns entries in all ways belonging to the set of the address.
11413219Sodanrc@yahoo.com.br     *
11513219Sodanrc@yahoo.com.br     * @param addr The addr to a find possible entries for.
11613219Sodanrc@yahoo.com.br     * @return The possible entries.
11713219Sodanrc@yahoo.com.br     */
11813219Sodanrc@yahoo.com.br    std::vector<ReplaceableEntry*> getPossibleEntries(const Addr addr) const
11913219Sodanrc@yahoo.com.br                                                                     override;
12013219Sodanrc@yahoo.com.br
12113219Sodanrc@yahoo.com.br    /**
12213219Sodanrc@yahoo.com.br     * Regenerate an entry's address from its tag and assigned set and way.
12313219Sodanrc@yahoo.com.br     *
12413219Sodanrc@yahoo.com.br     * @param tag The tag bits.
12513219Sodanrc@yahoo.com.br     * @param entry The entry.
12613219Sodanrc@yahoo.com.br     * @return the entry's original addr value.
12713219Sodanrc@yahoo.com.br     */
12813219Sodanrc@yahoo.com.br    Addr regenerateAddr(const Addr tag, const ReplaceableEntry* entry) const
12913219Sodanrc@yahoo.com.br                                                                   override;
13013219Sodanrc@yahoo.com.br};
13113219Sodanrc@yahoo.com.br
13213219Sodanrc@yahoo.com.br#endif //__MEM_CACHE_INDEXING_POLICIES_SET_ASSOCIATIVE_HH__
133