mem.isa revision 8140
17119Sgblack@eecs.umich.edu// -*- mode:c++ -*- 27119Sgblack@eecs.umich.edu 37119Sgblack@eecs.umich.edu// Copyright (c) 2010 ARM Limited 47119Sgblack@eecs.umich.edu// All rights reserved 57119Sgblack@eecs.umich.edu// 67119Sgblack@eecs.umich.edu// The license below extends only to copyright in the software and shall 77119Sgblack@eecs.umich.edu// not be construed as granting a license to any other intellectual 87119Sgblack@eecs.umich.edu// property including but not limited to intellectual property relating 97119Sgblack@eecs.umich.edu// to a hardware implementation of the functionality of the software 107119Sgblack@eecs.umich.edu// licensed hereunder. You may use the software subject to the license 117119Sgblack@eecs.umich.edu// terms below provided that you ensure that this notice is replicated 127119Sgblack@eecs.umich.edu// unmodified and in its entirety in all distributions of the software, 137119Sgblack@eecs.umich.edu// modified or unmodified, in source code or in binary form. 147119Sgblack@eecs.umich.edu// 157119Sgblack@eecs.umich.edu// Redistribution and use in source and binary forms, with or without 167119Sgblack@eecs.umich.edu// modification, are permitted provided that the following conditions are 177119Sgblack@eecs.umich.edu// met: redistributions of source code must retain the above copyright 187119Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer; 197119Sgblack@eecs.umich.edu// redistributions in binary form must reproduce the above copyright 207119Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the 217119Sgblack@eecs.umich.edu// documentation and/or other materials provided with the distribution; 227119Sgblack@eecs.umich.edu// neither the name of the copyright holders nor the names of its 237119Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from 247119Sgblack@eecs.umich.edu// this software without specific prior written permission. 257119Sgblack@eecs.umich.edu// 267119Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 277119Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 287119Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 297119Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 307119Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 317119Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 327119Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 337119Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 347119Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 357119Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 367119Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 377119Sgblack@eecs.umich.edu// 387119Sgblack@eecs.umich.edu// Authors: Gabe Black 397119Sgblack@eecs.umich.edu 407119Sgblack@eecs.umich.edulet {{ 417119Sgblack@eecs.umich.edu 427590Sgblack@eecs.umich.edu class LoadStoreInst(object): 437590Sgblack@eecs.umich.edu def __init__(self): 447590Sgblack@eecs.umich.edu self.fullExecTemplate = eval(self.execBase + 'Execute') 457590Sgblack@eecs.umich.edu self.initiateAccTemplate = eval(self.execBase + 'InitiateAcc') 467590Sgblack@eecs.umich.edu self.completeAccTemplate = eval(self.execBase + 'CompleteAcc') 477590Sgblack@eecs.umich.edu self.declareTemplate = eval(self.decConstBase + 'Declare') 487590Sgblack@eecs.umich.edu self.constructTemplate = eval(self.decConstBase + 'Constructor') 497205Sgblack@eecs.umich.edu 507590Sgblack@eecs.umich.edu def fillTemplates(self, name, Name, codeBlobs, memFlags, instFlags, 518140SMatt.Horsnell@arm.com base = 'Memory', wbDecl = None, pcDecl = None): 527590Sgblack@eecs.umich.edu # Make sure flags are in lists (convert to lists if not). 537590Sgblack@eecs.umich.edu memFlags = makeList(memFlags) 547590Sgblack@eecs.umich.edu instFlags = makeList(instFlags) 557119Sgblack@eecs.umich.edu 567590Sgblack@eecs.umich.edu eaCode = codeBlobs["ea_code"] 577205Sgblack@eecs.umich.edu 587590Sgblack@eecs.umich.edu # This shouldn't be part of the eaCode, but until the exec templates 597590Sgblack@eecs.umich.edu # are converted over it's the easiest place to put it. 607590Sgblack@eecs.umich.edu eaCode += '\n unsigned memAccessFlags = ' 617590Sgblack@eecs.umich.edu eaCode += (string.join(memFlags, '|') + ';') 627119Sgblack@eecs.umich.edu 637590Sgblack@eecs.umich.edu codeBlobs["ea_code"] = eaCode 647119Sgblack@eecs.umich.edu 657646Sgene.wu@arm.com macroName = Name 667646Sgene.wu@arm.com instFlagsCopy = list(instFlags) 677646Sgene.wu@arm.com codeBlobsCopy = dict(codeBlobs) 688140SMatt.Horsnell@arm.com 698140SMatt.Horsnell@arm.com use_uops = 0 708140SMatt.Horsnell@arm.com if wbDecl is not None or pcDecl is not None: 717646Sgene.wu@arm.com instFlagsCopy.append('IsMicroop') 727646Sgene.wu@arm.com Name = Name + 'Acc' 738140SMatt.Horsnell@arm.com use_uops = 1 748140SMatt.Horsnell@arm.com 758140SMatt.Horsnell@arm.com use_wb = 0 768140SMatt.Horsnell@arm.com use_pc = 0 778140SMatt.Horsnell@arm.com if wbDecl is not None: 788140SMatt.Horsnell@arm.com use_wb = 1 798140SMatt.Horsnell@arm.com if pcDecl is not None: 808140SMatt.Horsnell@arm.com use_pc = 1 818140SMatt.Horsnell@arm.com 827646Sgene.wu@arm.com codeBlobsCopy['acc_name'] = Name 837646Sgene.wu@arm.com codeBlobsCopy['wb_decl'] = wbDecl 848140SMatt.Horsnell@arm.com codeBlobsCopy['pc_decl'] = pcDecl 857646Sgene.wu@arm.com codeBlobsCopy['use_uops'] = 0 868140SMatt.Horsnell@arm.com codeBlobsCopy['use_wb'] = 0 878140SMatt.Horsnell@arm.com codeBlobsCopy['use_pc'] = 0 887119Sgblack@eecs.umich.edu 897646Sgene.wu@arm.com iop = InstObjParams(name, Name, base, 907646Sgene.wu@arm.com codeBlobsCopy, instFlagsCopy) 917646Sgene.wu@arm.com 927646Sgene.wu@arm.com header_output = self.declareTemplate.subst(iop) 937646Sgene.wu@arm.com decoder_output = self.constructTemplate.subst(iop) 947646Sgene.wu@arm.com exec_output = self.fullExecTemplate.subst(iop) + \ 957646Sgene.wu@arm.com self.initiateAccTemplate.subst(iop) + \ 967646Sgene.wu@arm.com self.completeAccTemplate.subst(iop) 977646Sgene.wu@arm.com 988140SMatt.Horsnell@arm.com if wbDecl is not None or pcDecl is not None: 997646Sgene.wu@arm.com iop = InstObjParams(name, macroName, base, 1007646Sgene.wu@arm.com { "wb_decl" : wbDecl, 1018140SMatt.Horsnell@arm.com "pc_decl" : pcDecl, 1027646Sgene.wu@arm.com "acc_name" : Name, 1038140SMatt.Horsnell@arm.com "use_uops" : use_uops, 1048140SMatt.Horsnell@arm.com "use_pc" : use_pc, 1058140SMatt.Horsnell@arm.com "use_wb" : use_wb }, 1067646Sgene.wu@arm.com ['IsMacroop']) 1077646Sgene.wu@arm.com header_output += self.declareTemplate.subst(iop) 1087646Sgene.wu@arm.com decoder_output += self.constructTemplate.subst(iop) 1097646Sgene.wu@arm.com exec_output += PanicExecute.subst(iop) + \ 1107646Sgene.wu@arm.com PanicInitiateAcc.subst(iop) + \ 1117646Sgene.wu@arm.com PanicCompleteAcc.subst(iop) 1127646Sgene.wu@arm.com 1137646Sgene.wu@arm.com return (header_output, decoder_output, exec_output) 1147119Sgblack@eecs.umich.edu 1157422Sgblack@eecs.umich.edu def pickPredicate(blobs): 1167422Sgblack@eecs.umich.edu for val in blobs.values(): 1177422Sgblack@eecs.umich.edu if re.search('(?<!Opt)CondCodes', val): 1187422Sgblack@eecs.umich.edu return condPredicateTest 1197422Sgblack@eecs.umich.edu return predicateTest 1207422Sgblack@eecs.umich.edu 1217119Sgblack@eecs.umich.edu def memClassName(base, post, add, writeback, \ 1227119Sgblack@eecs.umich.edu size=4, sign=False, user=False): 1237119Sgblack@eecs.umich.edu Name = base 1247119Sgblack@eecs.umich.edu 1257590Sgblack@eecs.umich.edu parts = { "P" : post, "A" : add, "W" : writeback, 1267590Sgblack@eecs.umich.edu "S" : sign, "U" : user } 1277119Sgblack@eecs.umich.edu 1287590Sgblack@eecs.umich.edu for (letter, val) in parts.items(): 1297590Sgblack@eecs.umich.edu if val: 1307590Sgblack@eecs.umich.edu Name += "_%sY" % letter 1317590Sgblack@eecs.umich.edu else: 1327590Sgblack@eecs.umich.edu Name += "_%sN" % letter 1337119Sgblack@eecs.umich.edu 1347119Sgblack@eecs.umich.edu Name += ('_SZ%d' % size) 1357119Sgblack@eecs.umich.edu 1367119Sgblack@eecs.umich.edu return Name 1377119Sgblack@eecs.umich.edu 1387119Sgblack@eecs.umich.edu def buildMemSuffix(sign, size): 1397119Sgblack@eecs.umich.edu if size == 4: 1407119Sgblack@eecs.umich.edu memSuffix = '' 1417119Sgblack@eecs.umich.edu elif size == 2: 1427119Sgblack@eecs.umich.edu if sign: 1437119Sgblack@eecs.umich.edu memSuffix = '.sh' 1447119Sgblack@eecs.umich.edu else: 1457119Sgblack@eecs.umich.edu memSuffix = '.uh' 1467119Sgblack@eecs.umich.edu elif size == 1: 1477119Sgblack@eecs.umich.edu if sign: 1487119Sgblack@eecs.umich.edu memSuffix = '.sb' 1497119Sgblack@eecs.umich.edu else: 1507119Sgblack@eecs.umich.edu memSuffix = '.ub' 1517119Sgblack@eecs.umich.edu else: 1527590Sgblack@eecs.umich.edu raise Exception, "Unrecognized size for access %d" % size 1537119Sgblack@eecs.umich.edu 1547119Sgblack@eecs.umich.edu return memSuffix 1557119Sgblack@eecs.umich.edu 1567119Sgblack@eecs.umich.edu def buildMemBase(base, post, writeback): 1577119Sgblack@eecs.umich.edu if post and writeback: 1587132Sgblack@eecs.umich.edu base = "MemoryPostIndex<%s>" % base 1597119Sgblack@eecs.umich.edu elif not post and writeback: 1607132Sgblack@eecs.umich.edu base = "MemoryPreIndex<%s>" % base 1617119Sgblack@eecs.umich.edu elif not post and not writeback: 1627132Sgblack@eecs.umich.edu base = "MemoryOffset<%s>" % base 1637119Sgblack@eecs.umich.edu else: 1647119Sgblack@eecs.umich.edu raise Exception, "Illegal combination of post and writeback" 1657119Sgblack@eecs.umich.edu return base 1667119Sgblack@eecs.umich.edu}}; 1677119Sgblack@eecs.umich.edu 168