110152Satgutier@umich.edu/*****************************************************************************
210152Satgutier@umich.edu *                                McPAT/CACTI
310152Satgutier@umich.edu *                      SOFTWARE LICENSE AGREEMENT
410152Satgutier@umich.edu *            Copyright 2012 Hewlett-Packard Development Company, L.P.
510234Syasuko.eckert@amd.com *            Copyright (c) 2010-2013 Advanced Micro Devices, Inc.
610152Satgutier@umich.edu *                          All Rights Reserved
710152Satgutier@umich.edu *
810152Satgutier@umich.edu * Redistribution and use in source and binary forms, with or without
910152Satgutier@umich.edu * modification, are permitted provided that the following conditions are
1010152Satgutier@umich.edu * met: redistributions of source code must retain the above copyright
1110152Satgutier@umich.edu * notice, this list of conditions and the following disclaimer;
1210152Satgutier@umich.edu * redistributions in binary form must reproduce the above copyright
1310152Satgutier@umich.edu * notice, this list of conditions and the following disclaimer in the
1410152Satgutier@umich.edu * documentation and/or other materials provided with the distribution;
1510152Satgutier@umich.edu * neither the name of the copyright holders nor the names of its
1610152Satgutier@umich.edu * contributors may be used to endorse or promote products derived from
1710152Satgutier@umich.edu * this software without specific prior written permission.
1810152Satgutier@umich.edu
1910152Satgutier@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2010152Satgutier@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2110152Satgutier@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2210152Satgutier@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2310152Satgutier@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2410152Satgutier@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2510152Satgutier@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2610152Satgutier@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2710152Satgutier@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2810152Satgutier@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2910234Syasuko.eckert@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3010152Satgutier@umich.edu *
3110152Satgutier@umich.edu ***************************************************************************/
3210152Satgutier@umich.edu
3310152Satgutier@umich.edu#include "arbiter.h"
3410152Satgutier@umich.edu
3510152Satgutier@umich.eduArbiter::Arbiter(
3610152Satgutier@umich.edu    double n_req,
3710152Satgutier@umich.edu    double flit_size_,
3810152Satgutier@umich.edu    double output_len,
3910152Satgutier@umich.edu    TechnologyParameter::DeviceType *dt
4010234Syasuko.eckert@amd.com    ): R(n_req), flit_size(flit_size_),
4110234Syasuko.eckert@amd.com       o_len (output_len), deviceType(dt) {
4210234Syasuko.eckert@amd.com    min_w_pmos = deviceType->n_to_p_eff_curr_drv_ratio * g_tp.min_w_nmos_;
4310234Syasuko.eckert@amd.com    Vdd = dt->Vdd;
4410234Syasuko.eckert@amd.com    double technology = g_ip->F_sz_um;
4510234Syasuko.eckert@amd.com    NTn1 = 13.5 * technology / 2;
4610234Syasuko.eckert@amd.com    PTn1 = 76 * technology / 2;
4710234Syasuko.eckert@amd.com    NTn2 = 13.5 * technology / 2;
4810234Syasuko.eckert@amd.com    PTn2 = 76 * technology / 2;
4910234Syasuko.eckert@amd.com    NTi = 12.5 * technology / 2;
5010234Syasuko.eckert@amd.com    PTi = 25 * technology / 2;
5110234Syasuko.eckert@amd.com    NTtr = 10 * technology / 2; /*Transmission gate's nmos tr. length*/
5210234Syasuko.eckert@amd.com    PTtr = 20 * technology / 2; /* pmos tr. length*/
5310152Satgutier@umich.edu}
5410152Satgutier@umich.edu
5510234Syasuko.eckert@amd.comArbiter::~Arbiter() {}
5610152Satgutier@umich.edu
5710152Satgutier@umich.edudouble
5810152Satgutier@umich.eduArbiter::arb_req() {
5910234Syasuko.eckert@amd.com    double temp = ((R - 1) * (2 * gate_C(NTn1, 0) + gate_C(PTn1, 0)) + 2 *
6010234Syasuko.eckert@amd.com                   gate_C(NTn2, 0) +
6110234Syasuko.eckert@amd.com                   gate_C(PTn2, 0) + gate_C(NTi, 0) + gate_C(PTi, 0) +
6210234Syasuko.eckert@amd.com                   drain_C_(NTi, 0, 1, 1, g_tp.cell_h_def) +
6310234Syasuko.eckert@amd.com                   drain_C_(PTi, 1, 1, 1, g_tp.cell_h_def));
6410234Syasuko.eckert@amd.com    return temp;
6510152Satgutier@umich.edu}
6610152Satgutier@umich.edu
6710152Satgutier@umich.edudouble
6810152Satgutier@umich.eduArbiter::arb_pri() {
6910234Syasuko.eckert@amd.com    /* switching capacitance of flip-flop is ignored */
7010234Syasuko.eckert@amd.com    double temp = 2 * (2 * gate_C(NTn1, 0) + gate_C(PTn1, 0));
7110234Syasuko.eckert@amd.com    return temp;
7210152Satgutier@umich.edu}
7310152Satgutier@umich.edu
7410152Satgutier@umich.edu
7510152Satgutier@umich.edudouble
7610152Satgutier@umich.eduArbiter::arb_grant() {
7710234Syasuko.eckert@amd.com    double temp = drain_C_(NTn1, 0, 1, 1, g_tp.cell_h_def) * 2 +
7810234Syasuko.eckert@amd.com        drain_C_(PTn1, 1, 1, 1, g_tp.cell_h_def) + crossbar_ctrline();
7910234Syasuko.eckert@amd.com    return temp;
8010152Satgutier@umich.edu}
8110152Satgutier@umich.edu
8210152Satgutier@umich.edudouble
8310152Satgutier@umich.eduArbiter::arb_int() {
8410234Syasuko.eckert@amd.com    double temp = (drain_C_(NTn1, 0, 1, 1, g_tp.cell_h_def) * 2 +
8510234Syasuko.eckert@amd.com                   drain_C_(PTn1, 1, 1, 1, g_tp.cell_h_def) +
8610234Syasuko.eckert@amd.com                   2 * gate_C(NTn2, 0) + gate_C(PTn2, 0));
8710234Syasuko.eckert@amd.com    return temp;
8810152Satgutier@umich.edu}
8910152Satgutier@umich.edu
9010152Satgutier@umich.eduvoid
9110152Satgutier@umich.eduArbiter::compute_power() {
9210234Syasuko.eckert@amd.com    power.readOp.dynamic = (R * arb_req() * Vdd * Vdd / 2 + R * arb_pri() *
9310234Syasuko.eckert@amd.com                            Vdd * Vdd / 2 +
9410234Syasuko.eckert@amd.com                            arb_grant() * Vdd * Vdd + arb_int() * 0.5 * Vdd *
9510234Syasuko.eckert@amd.com                            Vdd);
9610234Syasuko.eckert@amd.com    double nor1_leak = cmos_Isub_leakage(g_tp.min_w_nmos_ * NTn1 * 2,
9710234Syasuko.eckert@amd.com                                         min_w_pmos * PTn1 * 2, 2, nor);
9810234Syasuko.eckert@amd.com    double nor2_leak = cmos_Isub_leakage(g_tp.min_w_nmos_ * NTn2 * R,
9910234Syasuko.eckert@amd.com                                         min_w_pmos * PTn2 * R, 2, nor);
10010234Syasuko.eckert@amd.com    double not_leak = cmos_Isub_leakage(g_tp.min_w_nmos_ * NTi,
10110234Syasuko.eckert@amd.com                                        min_w_pmos * PTi, 1, inv);
10210234Syasuko.eckert@amd.com    double nor1_leak_gate = cmos_Ig_leakage(g_tp.min_w_nmos_ * NTn1 * 2,
10310234Syasuko.eckert@amd.com                                            min_w_pmos * PTn1 * 2, 2, nor);
10410234Syasuko.eckert@amd.com    double nor2_leak_gate = cmos_Ig_leakage(g_tp.min_w_nmos_ * NTn2 * R,
10510234Syasuko.eckert@amd.com                                            min_w_pmos * PTn2 * R, 2, nor);
10610234Syasuko.eckert@amd.com    double not_leak_gate  = cmos_Ig_leakage(g_tp.min_w_nmos_ * NTi,
10710234Syasuko.eckert@amd.com                                            min_w_pmos * PTi, 1, inv);
10810234Syasuko.eckert@amd.com    //FIXME include priority table leakage
10910234Syasuko.eckert@amd.com    power.readOp.leakage = (nor1_leak + nor2_leak + not_leak) * Vdd;
11010234Syasuko.eckert@amd.com    power.readOp.gate_leakage = nor1_leak_gate * Vdd + nor2_leak_gate * Vdd +
11110234Syasuko.eckert@amd.com        not_leak_gate * Vdd;
11210152Satgutier@umich.edu}
11310152Satgutier@umich.edu
11410152Satgutier@umich.edudouble //wire cap with triple spacing
11510152Satgutier@umich.eduArbiter::Cw3(double length) {
11610234Syasuko.eckert@amd.com    Wire wc(g_ip->wt, length, 1, 3, 3);
11710234Syasuko.eckert@amd.com    double temp = (wc.wire_cap(length, true));
11810234Syasuko.eckert@amd.com    return temp;
11910152Satgutier@umich.edu}
12010152Satgutier@umich.edu
12110152Satgutier@umich.edudouble
12210152Satgutier@umich.eduArbiter::crossbar_ctrline() {
12310234Syasuko.eckert@amd.com    double temp = (Cw3(o_len * 1e-6 /* m */) +
12410234Syasuko.eckert@amd.com                   drain_C_(NTi, 0, 1, 1, g_tp.cell_h_def) + drain_C_(PTi, 1, 1, 1, g_tp.cell_h_def) +
12510234Syasuko.eckert@amd.com                   gate_C(NTi, 0) + gate_C(PTi, 0));
12610234Syasuko.eckert@amd.com    return temp;
12710152Satgutier@umich.edu}
12810152Satgutier@umich.edu
12910152Satgutier@umich.edudouble
13010152Satgutier@umich.eduArbiter::transmission_buf_ctrcap() {
13110234Syasuko.eckert@amd.com    double temp = gate_C(NTtr, 0) + gate_C(PTtr, 0);
13210234Syasuko.eckert@amd.com    return temp;
13310152Satgutier@umich.edu}
13410152Satgutier@umich.edu
13510152Satgutier@umich.edu
13610234Syasuko.eckert@amd.comvoid Arbiter::print_arbiter() {
13710234Syasuko.eckert@amd.com    cout << "\nArbiter Stats ("   << R << " input arbiter" << ")\n\n";
13810234Syasuko.eckert@amd.com    cout << "Flit size        : " << flit_size << " bits" << endl;
13910234Syasuko.eckert@amd.com    cout << "Dynamic Power    : " << power.readOp.dynamic*1e9 << " (nJ)" << endl;
14010234Syasuko.eckert@amd.com    cout << "Leakage Power    : " << power.readOp.leakage*1e3 << " (mW)" << endl;
14110152Satgutier@umich.edu}
14210152Satgutier@umich.edu
14310152Satgutier@umich.edu
144