113667Sjavier.bueno@metempsy.com/**
213667Sjavier.bueno@metempsy.com * Copyright (c) 2018 Metempsy Technology Consulting
313667Sjavier.bueno@metempsy.com * All rights reserved.
413667Sjavier.bueno@metempsy.com *
513667Sjavier.bueno@metempsy.com * Redistribution and use in source and binary forms, with or without
613667Sjavier.bueno@metempsy.com * modification, are permitted provided that the following conditions are
713667Sjavier.bueno@metempsy.com * met: redistributions of source code must retain the above copyright
813667Sjavier.bueno@metempsy.com * notice, this list of conditions and the following disclaimer;
913667Sjavier.bueno@metempsy.com * redistributions in binary form must reproduce the above copyright
1013667Sjavier.bueno@metempsy.com * notice, this list of conditions and the following disclaimer in the
1113667Sjavier.bueno@metempsy.com * documentation and/or other materials provided with the distribution;
1213667Sjavier.bueno@metempsy.com * neither the name of the copyright holders nor the names of its
1313667Sjavier.bueno@metempsy.com * contributors may be used to endorse or promote products derived from
1413667Sjavier.bueno@metempsy.com * this software without specific prior written permission.
1513667Sjavier.bueno@metempsy.com *
1613667Sjavier.bueno@metempsy.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713667Sjavier.bueno@metempsy.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813667Sjavier.bueno@metempsy.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913667Sjavier.bueno@metempsy.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013667Sjavier.bueno@metempsy.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113667Sjavier.bueno@metempsy.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213667Sjavier.bueno@metempsy.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313667Sjavier.bueno@metempsy.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413667Sjavier.bueno@metempsy.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513667Sjavier.bueno@metempsy.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613667Sjavier.bueno@metempsy.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713667Sjavier.bueno@metempsy.com *
2813667Sjavier.bueno@metempsy.com * Authors: Javier Bueno
2913667Sjavier.bueno@metempsy.com */
3013667Sjavier.bueno@metempsy.com
3113667Sjavier.bueno@metempsy.com#ifndef __MEM_CACHE_PREFETCH_DELTA_CORRELATING_PREDICTION_TABLES_HH_
3213667Sjavier.bueno@metempsy.com#define __MEM_CACHE_PREFETCH_DELTA_CORRELATING_PREDICTION_TABLES_HH_
3313667Sjavier.bueno@metempsy.com
3413667Sjavier.bueno@metempsy.com#include "mem/cache/prefetch/associative_set.hh"
3513667Sjavier.bueno@metempsy.com#include "mem/cache/prefetch/queued.hh"
3613667Sjavier.bueno@metempsy.com
3713667Sjavier.bueno@metempsy.comstruct DeltaCorrelatingPredictionTablesParams;
3813667Sjavier.bueno@metempsy.com
3913667Sjavier.bueno@metempsy.com/**
4013667Sjavier.bueno@metempsy.com * Delta Correlating Prediction Tables Prefetcher
4113667Sjavier.bueno@metempsy.com * References:
4213667Sjavier.bueno@metempsy.com *   Multi-level hardware prefetching using low complexity delta correlating
4313667Sjavier.bueno@metempsy.com *   prediction tables with partial matching.
4413667Sjavier.bueno@metempsy.com *   Marius Grannaes, Magnus Jahre, and Lasse Natvig. 2010.
4513667Sjavier.bueno@metempsy.com *   In Proceedings of the 5th international conference on High Performance
4613667Sjavier.bueno@metempsy.com *   Embedded Architectures and Compilers (HiPEAC'10)
4713667Sjavier.bueno@metempsy.com *
4813667Sjavier.bueno@metempsy.com * The filter feature is not implemented as gem5 already drops redundant
4913667Sjavier.bueno@metempsy.com * prefetches.
5013667Sjavier.bueno@metempsy.com * The main prefetcher logic is implemented on a separate SimObject as there
5113667Sjavier.bueno@metempsy.com * are other prefetcher that can rehuse this component.
5213667Sjavier.bueno@metempsy.com */
5313667Sjavier.bueno@metempsy.com
5413667Sjavier.bueno@metempsy.comclass DeltaCorrelatingPredictionTables : public SimObject
5513667Sjavier.bueno@metempsy.com{
5613667Sjavier.bueno@metempsy.com    /** Number of bits of each delta */
5713667Sjavier.bueno@metempsy.com    const unsigned int deltaBits;
5813667Sjavier.bueno@metempsy.com    /** Number of lower bits to ignore from the deltas */
5913667Sjavier.bueno@metempsy.com    const unsigned int deltaMaskBits;
6013667Sjavier.bueno@metempsy.com
6113667Sjavier.bueno@metempsy.com    /** DCPT Table entry datatype */
6213667Sjavier.bueno@metempsy.com    struct DCPTEntry : public TaggedEntry
6313667Sjavier.bueno@metempsy.com    {
6413667Sjavier.bueno@metempsy.com        /** Last accessed address */
6513667Sjavier.bueno@metempsy.com        Addr lastAddress;
6613667Sjavier.bueno@metempsy.com        /**
6713667Sjavier.bueno@metempsy.com        * Position of the first free entry, or the oldest element, if it is
6813667Sjavier.bueno@metempsy.com        * full
6913667Sjavier.bueno@metempsy.com        */
7013667Sjavier.bueno@metempsy.com        unsigned int deltaPointer;
7113667Sjavier.bueno@metempsy.com        /** Stored deltas */
7213667Sjavier.bueno@metempsy.com        std::vector<Addr> deltas;
7313667Sjavier.bueno@metempsy.com
7413667Sjavier.bueno@metempsy.com        /**
7513667Sjavier.bueno@metempsy.com         * Constructor
7613667Sjavier.bueno@metempsy.com         * @param num_deltas number of deltas stored in the entry
7713667Sjavier.bueno@metempsy.com         */
7813667Sjavier.bueno@metempsy.com        DCPTEntry(unsigned int num_deltas) : lastAddress(0), deltaPointer(0),
7913667Sjavier.bueno@metempsy.com            deltas(num_deltas)
8013667Sjavier.bueno@metempsy.com        {}
8113667Sjavier.bueno@metempsy.com
8213667Sjavier.bueno@metempsy.com        /** Reset callback called when invalidating the entry */
8313667Sjavier.bueno@metempsy.com        void reset() override;
8413667Sjavier.bueno@metempsy.com
8513667Sjavier.bueno@metempsy.com        /**
8613667Sjavier.bueno@metempsy.com         * Adds an address to the entry, if the entry already existed, a delta
8713667Sjavier.bueno@metempsy.com         * will be generated
8813667Sjavier.bueno@metempsy.com         * @param address address to add
8913667Sjavier.bueno@metempsy.com         * @param delta_num_bits number of bits of the delta
9013667Sjavier.bueno@metempsy.com         */
9113667Sjavier.bueno@metempsy.com        void addAddress(Addr address, unsigned int delta_num_bits);
9213667Sjavier.bueno@metempsy.com
9313667Sjavier.bueno@metempsy.com        /**
9413667Sjavier.bueno@metempsy.com         * Attempt to generate prefetch candidates using the two most recent
9513667Sjavier.bueno@metempsy.com         * deltas. Prefetch candidates are added to the provided vector.
9613667Sjavier.bueno@metempsy.com         * @param pfs reference to a vector where candidates will be added
9713667Sjavier.bueno@metempsy.com         * @param mask_bits the number of lower bits that should be masked
9813667Sjavier.bueno@metempsy.com         *        (ignored) when comparing deltas
9913667Sjavier.bueno@metempsy.com         */
10013667Sjavier.bueno@metempsy.com        void getCandidates(std::vector<QueuedPrefetcher::AddrPriority> &pfs,
10113667Sjavier.bueno@metempsy.com                           unsigned int mask_bits) const;
10213667Sjavier.bueno@metempsy.com
10313667Sjavier.bueno@metempsy.com    };
10413667Sjavier.bueno@metempsy.com    /** The main table */
10513667Sjavier.bueno@metempsy.com    AssociativeSet<DCPTEntry> table;
10613667Sjavier.bueno@metempsy.com
10713667Sjavier.bueno@metempsy.com  public:
10813667Sjavier.bueno@metempsy.com    DeltaCorrelatingPredictionTables(
10913667Sjavier.bueno@metempsy.com        DeltaCorrelatingPredictionTablesParams *p);
11013667Sjavier.bueno@metempsy.com    ~DeltaCorrelatingPredictionTables()
11113667Sjavier.bueno@metempsy.com    {}
11213667Sjavier.bueno@metempsy.com
11313667Sjavier.bueno@metempsy.com    /**
11413667Sjavier.bueno@metempsy.com     * Computes the prefetch candidates given a prefetch event.
11513667Sjavier.bueno@metempsy.com     * @param pfi The prefetch event information
11613667Sjavier.bueno@metempsy.com     * @param addresses prefetch candidates generated
11713667Sjavier.bueno@metempsy.com     */
11813667Sjavier.bueno@metempsy.com    void calculatePrefetch(const BasePrefetcher::PrefetchInfo &pfi,
11913667Sjavier.bueno@metempsy.com        std::vector<QueuedPrefetcher::AddrPriority> &addresses);
12013667Sjavier.bueno@metempsy.com
12113667Sjavier.bueno@metempsy.com};
12213667Sjavier.bueno@metempsy.com
12313667Sjavier.bueno@metempsy.comstruct DCPTPrefetcherParams;
12413667Sjavier.bueno@metempsy.com
12513667Sjavier.bueno@metempsy.com/** The prefetcher object using the DCPT */
12613667Sjavier.bueno@metempsy.comclass DCPTPrefetcher : public QueuedPrefetcher
12713667Sjavier.bueno@metempsy.com{
12813667Sjavier.bueno@metempsy.com    /** DCPT object */
12913667Sjavier.bueno@metempsy.com    DeltaCorrelatingPredictionTables &dcpt;
13013667Sjavier.bueno@metempsy.com  public:
13113667Sjavier.bueno@metempsy.com    DCPTPrefetcher(const DCPTPrefetcherParams *p);
13213667Sjavier.bueno@metempsy.com    ~DCPTPrefetcher()
13313667Sjavier.bueno@metempsy.com    {}
13413667Sjavier.bueno@metempsy.com    void calculatePrefetch(const PrefetchInfo &pfi,
13513667Sjavier.bueno@metempsy.com        std::vector<AddrPriority> &addresses) override;
13613667Sjavier.bueno@metempsy.com};
13713667Sjavier.bueno@metempsy.com#endif//__MEM_CACHE_PREFETCH_DELTA_CORRELATING_PREDICTION_TABLES_HH_
138