branch.isa revision 7152
16019Shines@cs.fsu.edu// -*- mode:c++ -*- 26019Shines@cs.fsu.edu 37152Sgblack@eecs.umich.edu// Copyright (c) 2010 ARM Limited 47152Sgblack@eecs.umich.edu// All rights reserved 57152Sgblack@eecs.umich.edu// 67152Sgblack@eecs.umich.edu// The license below extends only to copyright in the software and shall 77152Sgblack@eecs.umich.edu// not be construed as granting a license to any other intellectual 87152Sgblack@eecs.umich.edu// property including but not limited to intellectual property relating 97152Sgblack@eecs.umich.edu// to a hardware implementation of the functionality of the software 107152Sgblack@eecs.umich.edu// licensed hereunder. You may use the software subject to the license 117152Sgblack@eecs.umich.edu// terms below provided that you ensure that this notice is replicated 127152Sgblack@eecs.umich.edu// unmodified and in its entirety in all distributions of the software, 137152Sgblack@eecs.umich.edu// modified or unmodified, in source code or in binary form. 147152Sgblack@eecs.umich.edu// 156019Shines@cs.fsu.edu// Copyright (c) 2007-2008 The Florida State University 166019Shines@cs.fsu.edu// All rights reserved. 176019Shines@cs.fsu.edu// 186019Shines@cs.fsu.edu// Redistribution and use in source and binary forms, with or without 196019Shines@cs.fsu.edu// modification, are permitted provided that the following conditions are 206019Shines@cs.fsu.edu// met: redistributions of source code must retain the above copyright 216019Shines@cs.fsu.edu// notice, this list of conditions and the following disclaimer; 226019Shines@cs.fsu.edu// redistributions in binary form must reproduce the above copyright 236019Shines@cs.fsu.edu// notice, this list of conditions and the following disclaimer in the 246019Shines@cs.fsu.edu// documentation and/or other materials provided with the distribution; 256019Shines@cs.fsu.edu// neither the name of the copyright holders nor the names of its 266019Shines@cs.fsu.edu// contributors may be used to endorse or promote products derived from 276019Shines@cs.fsu.edu// this software without specific prior written permission. 286019Shines@cs.fsu.edu// 296019Shines@cs.fsu.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 306019Shines@cs.fsu.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 316019Shines@cs.fsu.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 326019Shines@cs.fsu.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 336019Shines@cs.fsu.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 346019Shines@cs.fsu.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 356019Shines@cs.fsu.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 366019Shines@cs.fsu.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 376019Shines@cs.fsu.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 386019Shines@cs.fsu.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 396019Shines@cs.fsu.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 406019Shines@cs.fsu.edu// 416019Shines@cs.fsu.edu// Authors: Stephen Hines 426019Shines@cs.fsu.edu 436019Shines@cs.fsu.edu//////////////////////////////////////////////////////////////////// 446019Shines@cs.fsu.edu// 456019Shines@cs.fsu.edu// Control transfer instructions 466019Shines@cs.fsu.edu// 476019Shines@cs.fsu.edu 487152Sgblack@eecs.umich.edudef format ArmBBlxImm() {{ 497152Sgblack@eecs.umich.edu decode_block = ''' 507152Sgblack@eecs.umich.edu if (machInst.condCode == 0xF) { 517152Sgblack@eecs.umich.edu int32_t imm = (sext<26>(bits(machInst, 23, 0) << 2)) | 527152Sgblack@eecs.umich.edu (bits(machInst, 24) << 1); 537152Sgblack@eecs.umich.edu return new BlxImm(machInst, imm); 547152Sgblack@eecs.umich.edu } else { 557152Sgblack@eecs.umich.edu return new B(machInst, sext<26>(bits(machInst, 23, 0) << 2), 567152Sgblack@eecs.umich.edu (ConditionCode)(uint32_t)machInst.condCode); 577152Sgblack@eecs.umich.edu } 587152Sgblack@eecs.umich.edu ''' 597152Sgblack@eecs.umich.edu}}; 607152Sgblack@eecs.umich.edu 617152Sgblack@eecs.umich.edudef format ArmBlBlxImm() {{ 627152Sgblack@eecs.umich.edu decode_block = ''' 637152Sgblack@eecs.umich.edu if (machInst.condCode == 0xF) { 647152Sgblack@eecs.umich.edu int32_t imm = (sext<26>(bits(machInst, 23, 0) << 2)) | 657152Sgblack@eecs.umich.edu (bits(machInst, 24) << 1); 667152Sgblack@eecs.umich.edu return new BlxImm(machInst, imm); 677152Sgblack@eecs.umich.edu } else { 687152Sgblack@eecs.umich.edu return new Bl(machInst, sext<26>(bits(machInst, 23, 0) << 2), 697152Sgblack@eecs.umich.edu (ConditionCode)(uint32_t)machInst.condCode); 707152Sgblack@eecs.umich.edu } 717152Sgblack@eecs.umich.edu ''' 727152Sgblack@eecs.umich.edu}}; 737152Sgblack@eecs.umich.edu 747152Sgblack@eecs.umich.edudef format ArmBx() {{ 757152Sgblack@eecs.umich.edu decode_block = ''' 767152Sgblack@eecs.umich.edu return new BxReg(machInst, (IntRegIndex)(uint32_t)bits(machInst, 3, 0), 777152Sgblack@eecs.umich.edu (ConditionCode)(uint32_t)machInst.condCode); 787152Sgblack@eecs.umich.edu ''' 797152Sgblack@eecs.umich.edu}}; 807152Sgblack@eecs.umich.edu 817152Sgblack@eecs.umich.edudef format ArmBlxReg() {{ 827152Sgblack@eecs.umich.edu decode_block = ''' 837152Sgblack@eecs.umich.edu return new BlxReg(machInst, (IntRegIndex)(uint32_t)bits(machInst, 3, 0), 847152Sgblack@eecs.umich.edu (ConditionCode)(uint32_t)machInst.condCode); 857152Sgblack@eecs.umich.edu ''' 867152Sgblack@eecs.umich.edu}}; 877152Sgblack@eecs.umich.edu 886019Shines@cs.fsu.edudef format Branch(code,*opt_flags) {{ 896019Shines@cs.fsu.edu 906019Shines@cs.fsu.edu #Build Instruction Flags 916019Shines@cs.fsu.edu #Use Link & Likely Flags to Add Link/Condition Code 926019Shines@cs.fsu.edu inst_flags = ('IsDirectControl', ) 936259Sjack-m5ml2@cs.york.ac.uk linking = False 946019Shines@cs.fsu.edu for x in opt_flags: 956019Shines@cs.fsu.edu if x == 'Link': 966259Sjack-m5ml2@cs.york.ac.uk linking = True 976019Shines@cs.fsu.edu code += 'LR = NPC;\n' 986019Shines@cs.fsu.edu else: 996019Shines@cs.fsu.edu inst_flags += (x, ) 1006019Shines@cs.fsu.edu 1016019Shines@cs.fsu.edu #Take into account uncond. branch instruction 1026019Shines@cs.fsu.edu if 'cond == 1' in code: 1036019Shines@cs.fsu.edu inst_flags += ('IsUnCondControl', ) 1046019Shines@cs.fsu.edu else: 1056019Shines@cs.fsu.edu inst_flags += ('IsCondControl', ) 1066019Shines@cs.fsu.edu 1076724Sgblack@eecs.umich.edu icode = 'if (testPredicate(CondCodes, condCode)) {\n' 1086019Shines@cs.fsu.edu icode += code 1096019Shines@cs.fsu.edu icode += ' NPC = NPC + 4 + disp;\n' 1106019Shines@cs.fsu.edu icode += '} else {\n' 1116019Shines@cs.fsu.edu icode += ' NPC = NPC;\n' 1126259Sjack-m5ml2@cs.york.ac.uk if linking: 1136259Sjack-m5ml2@cs.york.ac.uk icode += ' LR = LR;\n' 1146019Shines@cs.fsu.edu icode += '};\n' 1156019Shines@cs.fsu.edu 1166019Shines@cs.fsu.edu code = icode 1176019Shines@cs.fsu.edu 1186019Shines@cs.fsu.edu iop = InstObjParams(name, Name, 'Branch', code, inst_flags) 1196019Shines@cs.fsu.edu header_output = BasicDeclare.subst(iop) 1206019Shines@cs.fsu.edu decoder_output = BasicConstructor.subst(iop) 1216019Shines@cs.fsu.edu decode_block = BasicDecode.subst(iop) 1226019Shines@cs.fsu.edu exec_output = BasicExecute.subst(iop) 1236019Shines@cs.fsu.edu}}; 1246019Shines@cs.fsu.edu 1256019Shines@cs.fsu.edudef format BranchExchange(code,*opt_flags) {{ 1266019Shines@cs.fsu.edu #Build Instruction Flags 1276019Shines@cs.fsu.edu #Use Link & Likely Flags to Add Link/Condition Code 1286019Shines@cs.fsu.edu inst_flags = ('IsIndirectControl', ) 1296259Sjack-m5ml2@cs.york.ac.uk linking = False 1306019Shines@cs.fsu.edu for x in opt_flags: 1316019Shines@cs.fsu.edu if x == 'Link': 1326259Sjack-m5ml2@cs.york.ac.uk linking = True 1336019Shines@cs.fsu.edu code += 'LR = NPC;\n' 1346019Shines@cs.fsu.edu else: 1356019Shines@cs.fsu.edu inst_flags += (x, ) 1366019Shines@cs.fsu.edu 1376019Shines@cs.fsu.edu #Take into account uncond. branch instruction 1386019Shines@cs.fsu.edu if 'cond == 1' in code: 1396019Shines@cs.fsu.edu inst_flags += ('IsUnCondControl', ) 1406019Shines@cs.fsu.edu else: 1416019Shines@cs.fsu.edu inst_flags += ('IsCondControl', ) 1426019Shines@cs.fsu.edu 1436019Shines@cs.fsu.edu #Condition code 1446019Shines@cs.fsu.edu 1456724Sgblack@eecs.umich.edu icode = 'if (testPredicate(CondCodes, condCode)) {\n' 1466019Shines@cs.fsu.edu icode += code 1476019Shines@cs.fsu.edu icode += ' NPC = Rm & 0xfffffffe; // Masks off bottom bit\n' 1486019Shines@cs.fsu.edu icode += '} else {\n' 1496019Shines@cs.fsu.edu icode += ' NPC = NPC;\n' 1506259Sjack-m5ml2@cs.york.ac.uk if linking: 1516259Sjack-m5ml2@cs.york.ac.uk icode += ' LR = LR;\n' 1526019Shines@cs.fsu.edu icode += '};\n' 1536019Shines@cs.fsu.edu 1546019Shines@cs.fsu.edu code = icode 1556019Shines@cs.fsu.edu 1566019Shines@cs.fsu.edu iop = InstObjParams(name, Name, 'BranchExchange', code, inst_flags) 1576019Shines@cs.fsu.edu header_output = BasicDeclare.subst(iop) 1586019Shines@cs.fsu.edu decoder_output = BasicConstructor.subst(iop) 1596019Shines@cs.fsu.edu decode_block = BasicDecode.subst(iop) 1606019Shines@cs.fsu.edu exec_output = BasicExecute.subst(iop) 1616019Shines@cs.fsu.edu}}; 1626019Shines@cs.fsu.edu 163