⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 integer_compare_instruction.cpp

📁 浙江大学的悟空嵌入式系统模拟器
💻 CPP
字号:
/**
 *  Copyright (c) 2005 Zhejiang University, P.R.China
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */ 

//=============================================================================
/**
 *  \file    Processor/PPC/Integer_Shift_Instruction.cpp
 *
 *  $Id: Integer_Compare_Instruction.cpp,v 1.1 2005/06/16 06:01:46 qilj Exp $
 *
 *  \author  Wei He <hwzd1997@163.com>
 *
 */
//=============================================================================
#include "Instruction.h"
#include "Instr_Flag.h"
#include "Instr_Declare.h"
#include "Parser.h"
#include "Register.h"
#include "Types.h"
#include "Reg_Flag.h"
#include "Reg_Utils.h"
#include "Utils/Debug.h"


namespace PPC {

	static PPC_u32 PPC_CMP_AND_MASK[8] = {
		0xfffffff0,
		0xffffff0f,
		0xfffff0ff,
		0xffff0fff,
		0xfff0ffff,
		0xff0fffff,
		0xf0ffffff,
		0x0fffffff,
	};

	
	//Compare
	PPC_INSTRUCTION_IMPL(op_cmp)
	{
		PPC_u32 cr;
		PPC_s32 A, B;
		X_Form_Parser::parse_x(instr, (PPC_s32 &)cr, A, B);

		PPC_TRACE_3("cmp", cr, A, B);

		cr >>= 2;
		PPC_s32 a = REG_TO_INT(REG(A));
		PPC_s32 b = REG_TO_INT(REG(B));
		PPC_u32 c;
		if(a < b){
			c = 8;
		}else if(a > b){
			c = 4;
		}else{
			c = 2;
		}
		if(REG_TO_INT(REG(XER)) & (1<< Reg_Flag::XER_SO) )
			c |= 1;
		cr = 7 - cr;
		//REG(CR) &= PPC_CMP_AND_MASK[CR];
		int reg_cr = REG_TO_INT(REG(CR));
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) & PPC_CMP_AND_MASK[cr]);
		//REG(CR) |= c << (cr * 4)
		cr *= 4;
		c <<= cr;
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) | c);
		int reg_cr_2 = REG_TO_INT(REG(CR));
	}


	//Compare Immediate
	PPC_INSTRUCTION_IMPL(op_cmpi)
	{
		PPC_u32 cr, imm;
		PPC_s32 A;
        D_Form_Parser::parse_simm(instr, (PPC_s32 &)cr, A, imm);

		PPC_TRACE_3("cmpi", cr, A, imm);

		cr >>= 2;
		PPC_s32 a = REG_TO_INT(REG(A));
		// does the imm should be changed to a signed int?
		PPC_u32 c;
		if(a < (PPC_s32)imm){
			c = 8;
		}else if(a > (PPC_s32)imm){
			c = 4;
		}else {
			c = 2;
		}
		if(REG_TO_INT(REG(XER)) & (1 << Reg_Flag::XER_SO))
			c |= 1;
		cr = 7 - cr;
		//REG(CR) &= PPC_CMP_AND_MASK[cr];
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) & PPC_CMP_AND_MASK[cr]);
		//REG(CR) |= c << (cr*4)
		cr *= 4;
		c <<= cr;
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) | c);
	
	}


	
	//Compare Logical Immediate
	PPC_INSTRUCTION_IMPL(op_cmpli)
	{
		PPC_u32 cr, imm;
		PPC_s32 A;
        D_Form_Parser::parse_uimm(instr, (PPC_s32&)cr, A, imm);

		PPC_TRACE_3("cmpli", cr, A, imm);

		cr >>= 2;
		PPC_s32 a = REG_TO_INT(REG(A));
		PPC_u32 c;
		if(a < imm){
			c = 8;
		}else if(a > imm){
			c = 4;
		}else {
			c = 2;
		}
		if(REG_TO_INT(REG(XER)) & (1 << Reg_Flag::XER_SO))
			c |= 1;
		cr = 7 - cr;
		//REG(CR) &= PPC_CMP_AND_MASK[cr];
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) & PPC_CMP_AND_MASK[cr]);
		//REG(CR) |= c << (cr*4)
		cr *= 4;
		c <<= cr;
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) | c);
	
	}

	//Compare Logical
	PPC_INSTRUCTION_IMPL(op_cmpl)
	{
		PPC_u32 cr;
		PPC_s32 A, B;
		X_Form_Parser::parse_x(instr, (PPC_s32 &)cr, A, B);

		PPC_TRACE_3("cmpl", cr, A, B);

		cr >>= 2;
		PPC_u32 a = REG_TO_INT(REG(A));
		PPC_u32 b = REG_TO_INT(REG(B));
		PPC_u32 c;
		if(a < b){
			c = 8;
		}else if(a > b){
			c = 4;
		}else {
			c = 2;
		}
		if(REG_TO_INT(REG(XER)) & (1 << Reg_Flag::XER_SO))
			c |= 1;
		cr = 7 - cr;
		//REG(CR) &= PPC_CMP_AND_MASK[cr];
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) & PPC_CMP_AND_MASK[cr]);
		//REG(CR) |= c << (cr*4)
		cr *= 4;
		c <<= cr;
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) | c);
	
	}


	


} //namespace PPC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -