condcodes.hh revision 4683:3b49d35562ed
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 2003-2005 The Regents of The University of Michigan 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org * 286145Snate@binkert.org * Authors: Gabe Black 296145Snate@binkert.org */ 306145Snate@binkert.org 316284Snate@binkert.org#ifndef __BASE_CONDCODE_HH__ 326145Snate@binkert.org#define __BASE_CONDCODE_HH__ 336145Snate@binkert.org 346145Snate@binkert.org#include "base/bitfield.hh" 356145Snate@binkert.org 366145Snate@binkert.org/** 376145Snate@binkert.org * Calculate the carry flag from an addition. This should work even when 386145Snate@binkert.org * a carry value is also added in. 396145Snate@binkert.org */ 406154Snate@binkert.orginline 416154Snate@binkert.orgbool 426154Snate@binkert.orgfindCarry(int width, uint64_t dest, uint64_t src1, uint64_t src2) { 436154Snate@binkert.org int shift = width - 1; 446154Snate@binkert.org return (~(dest >> shift) + (src1 >> shift) + (src2 >> shift)) & 0x2; 456154Snate@binkert.org} 466285Snate@binkert.org 476154Snate@binkert.org/** 486285Snate@binkert.org * Calculate the overflow flag from an addition. 496145Snate@binkert.org */ 506145Snate@binkert.orginline 516145Snate@binkert.orgbool 526145Snate@binkert.orgfindOverflow(int width, uint64_t dest, uint64_t src1, uint64_t src2) { 536285Snate@binkert.org int shift = width - 1; 546876Ssteve.reinhardt@amd.com return ((src1 ^ ~src2) & (src1 ^ dest)) & (1 << shift); 556876Ssteve.reinhardt@amd.com} 566145Snate@binkert.org 576285Snate@binkert.org/** 586285Snate@binkert.org * Calculate the parity of a value. 1 is for odd parity and 0 is for even. 596285Snate@binkert.org */ 606285Snate@binkert.orginline 616285Snate@binkert.orgbool 626285Snate@binkert.orgfindParity(int width, uint64_t dest) { 636285Snate@binkert.org dest &= width; 646285Snate@binkert.org dest ^= (dest >> 32); 656285Snate@binkert.org dest ^= (dest >> 16); 666285Snate@binkert.org dest ^= (dest >> 8); 676763SBrad.Beckmann@amd.com dest ^= (dest >> 4); 686763SBrad.Beckmann@amd.com dest ^= (dest >> 2); 696876Ssteve.reinhardt@amd.com dest ^= (dest >> 1); 706145Snate@binkert.org return dest & 1; 716876Ssteve.reinhardt@amd.com} 726145Snate@binkert.org 736876Ssteve.reinhardt@amd.com/** 746145Snate@binkert.org * Calculate the negative flag. 756145Snate@binkert.org */ 766145Snate@binkert.orginline 776145Snate@binkert.orgbool 786145Snate@binkert.orgfindNegative(int width, uint64_t dest) { 796145Snate@binkert.org return bits(dest, width - 1, width - 1); 806145Snate@binkert.org} 816285Snate@binkert.org 826145Snate@binkert.org/** 836145Snate@binkert.org * Calculate the zero flag. 846145Snate@binkert.org */ 856145Snate@binkert.orginline 866145Snate@binkert.orgbool 876145Snate@binkert.orgfindZero(int width, uint64_t dest) { 886145Snate@binkert.org return !(dest & mask(width)); 896285Snate@binkert.org} 906845Sdrh5@cs.wisc.edu 916145Snate@binkert.org#endif // __BASE_CONDCODE_HH__ 926145Snate@binkert.org