14338Sgblack@eecs.umich.edu// -*- mode:c++ -*-
24338Sgblack@eecs.umich.edu
34338Sgblack@eecs.umich.edu// Copyright (c) 2007 The Hewlett-Packard Development Company
44338Sgblack@eecs.umich.edu// All rights reserved.
54338Sgblack@eecs.umich.edu//
67087Snate@binkert.org// The license below extends only to copyright in the software and shall
77087Snate@binkert.org// not be construed as granting a license to any other intellectual
87087Snate@binkert.org// property including but not limited to intellectual property relating
97087Snate@binkert.org// to a hardware implementation of the functionality of the software
107087Snate@binkert.org// licensed hereunder.  You may use the software subject to the license
117087Snate@binkert.org// terms below provided that you ensure that this notice is replicated
127087Snate@binkert.org// unmodified and in its entirety in all distributions of the software,
137087Snate@binkert.org// modified or unmodified, in source code or in binary form.
144338Sgblack@eecs.umich.edu//
157087Snate@binkert.org// Redistribution and use in source and binary forms, with or without
167087Snate@binkert.org// modification, are permitted provided that the following conditions are
177087Snate@binkert.org// met: redistributions of source code must retain the above copyright
187087Snate@binkert.org// notice, this list of conditions and the following disclaimer;
197087Snate@binkert.org// redistributions in binary form must reproduce the above copyright
207087Snate@binkert.org// notice, this list of conditions and the following disclaimer in the
217087Snate@binkert.org// documentation and/or other materials provided with the distribution;
227087Snate@binkert.org// neither the name of the copyright holders nor the names of its
234338Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from
247087Snate@binkert.org// this software without specific prior written permission.
254338Sgblack@eecs.umich.edu//
264338Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
274338Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
284338Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
294338Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
304338Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
314338Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
324338Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
334338Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
344338Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
354338Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
364338Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
374338Sgblack@eecs.umich.edu//
384338Sgblack@eecs.umich.edu// Authors: Gabe Black
394338Sgblack@eecs.umich.edu
404519Sgblack@eecs.umich.edulet {{
414519Sgblack@eecs.umich.edu    # This will be populated with mappings between microop mnemonics and
424519Sgblack@eecs.umich.edu    # the classes that represent them.
434519Sgblack@eecs.umich.edu    microopClasses = {}
444338Sgblack@eecs.umich.edu}};
454338Sgblack@eecs.umich.edu
464519Sgblack@eecs.umich.edu//////////////////////////////////////////////////////////////////////////
474519Sgblack@eecs.umich.edu//
484519Sgblack@eecs.umich.edu// Base class for the python representation of x86 microops
494534Sgblack@eecs.umich.edu//
504534Sgblack@eecs.umich.edu//////////////////////////////////////////////////////////////////////////
514519Sgblack@eecs.umich.edu
524519Sgblack@eecs.umich.edulet {{
534519Sgblack@eecs.umich.edu    class X86Microop(object):
5411320Ssteve.reinhardt@amd.com
555666Sgblack@eecs.umich.edu        generatorNameTemplate = "generate_%s_%d"
565666Sgblack@eecs.umich.edu
575666Sgblack@eecs.umich.edu        generatorTemplate = '''
585666Sgblack@eecs.umich.edu            StaticInstPtr
595666Sgblack@eecs.umich.edu            ''' + generatorNameTemplate + '''(StaticInstPtr curMacroop)
605666Sgblack@eecs.umich.edu            {
615788Sgblack@eecs.umich.edu                static const char *macrocodeBlock = romMnemonic;
6212407Sgabeblack@google.com                static ExtMachInst dummyExtMachInst;
635666Sgblack@eecs.umich.edu                static const EmulEnv dummyEmulEnv(0, 0, 1, 1, 1);
645666Sgblack@eecs.umich.edu
655666Sgblack@eecs.umich.edu                Macroop * macroop = dynamic_cast<Macroop *>(curMacroop.get());
665666Sgblack@eecs.umich.edu                const ExtMachInst &machInst =
675666Sgblack@eecs.umich.edu                    macroop ? macroop->getExtMachInst() : dummyExtMachInst;
685666Sgblack@eecs.umich.edu                const EmulEnv &env =
695666Sgblack@eecs.umich.edu                    macroop ? macroop->getEmulEnv() : dummyEmulEnv;
705666Sgblack@eecs.umich.edu                // env may not be used in the microop's constructor.
716345Sgblack@eecs.umich.edu                InstRegIndex reg(env.reg);
725666Sgblack@eecs.umich.edu                reg = reg;
735667Sgblack@eecs.umich.edu                using namespace RomLabels;
745666Sgblack@eecs.umich.edu                return %s;
755666Sgblack@eecs.umich.edu            }
765666Sgblack@eecs.umich.edu        '''
775040Sgblack@eecs.umich.edu
784519Sgblack@eecs.umich.edu        def __init__(self, name):
794519Sgblack@eecs.umich.edu            self.name = name
804519Sgblack@eecs.umich.edu
817620Sgblack@eecs.umich.edu        def microFlagsText(self, flags):
827620Sgblack@eecs.umich.edu            wrapped = ("(1ULL << StaticInst::%s)" % flag for flag in flags)
837620Sgblack@eecs.umich.edu            return " | ".join(wrapped)
844519Sgblack@eecs.umich.edu
855666Sgblack@eecs.umich.edu        def getGeneratorDef(self, micropc):
865666Sgblack@eecs.umich.edu            return self.generatorTemplate % \
875666Sgblack@eecs.umich.edu                (self.className, micropc, \
887620Sgblack@eecs.umich.edu                 self.getAllocator(["IsMicroop", "IsDelayedCommit"]))
895666Sgblack@eecs.umich.edu
905666Sgblack@eecs.umich.edu        def getGenerator(self, micropc):
915666Sgblack@eecs.umich.edu            return self.generatorNameTemplate % (self.className, micropc)
924338Sgblack@eecs.umich.edu}};
93