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

📄 integer_rotate_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_Rotate_Instruction.cpp,v 1.1 2005/06/16 06:01:47 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_Utils.h"
#include "Utils/Debug.h"

namespace PPC {


	inline PPC_Register_Int PPC_WORD_ROTL(PPC_Register_Int data, PPC_s32 n)
	{
		n &= 0x1f;
		return(data << n) | (data >> (32-n));

	}


	//inline PPC_Register_Int PPC_MASK(PPC_s32 MB, PPC_s32 ME)
	//{
	//	PPC_u32 mask;
	//	if (MB <= ME) {
	//		if (ME-MB == 31) {
	//			mask = 0xffffffff;
	//		} else {
	//			mask = ((1<<(ME-MB+1))-1)<<(31-ME);
	//		}
	//	} else {
	//		mask = PPC_WORD_ROTL((1<<(32-MB+ME+1))-1, 31-ME);
	//	}
	//return mask;
	//}

	inline PPC_Register_Int PPC_MASK(int MB, int ME)
	{
	unsigned int mask;
	if (MB <= ME) {
		if (ME-MB == 31) {
			mask = 0xffffffff;
		} else {
			mask = ((1<<(ME-MB+1))-1)<<(31-ME);
		}
		} else {
		
		int lower = ((1<<(32-MB)) -1 );
        unsigned int upper = (( 1 << (ME+1))-1) << (31-ME);
        mask = upper | lower;
	
	}
	return mask;
	}


    // Rotate Left Word then AND with Mask
	PPC_INSTRUCTION_IMPL(op_rlwnmx)
	{
		PPC_s32 S, A, B, MB, ME;
		M_Form_Parser::parse(instr, S, A, B, MB, ME);

		PPC_TRACE_5("rlwnmx", S, A, B, MB, ME);

		PPC_u32 v = PPC_WORD_ROTL(REG_TO_INT(REG(S)),REG_TO_INT(REG(B)));
		PPC_u32 mask = PPC_MASK(MB,ME);
		//REG(A) = v & mask;
		REG(A).convert_from_int(v & mask);
		if (instr & Op_Flag::RC) {
			//update cr0 flags
            REG_UPDATE_CR0 (REG(A));
        }


	}


	//Rotate Left Word Immediate then AND with Mask
	PPC_INSTRUCTION_IMPL(op_rlwinmx)
	{
		PPC_s32 S, A, SH;
		PPC_u32 MB, ME;
		M_Form_Parser::parse(instr, S, A, SH, (PPC_s32 &)MB, (PPC_s32 &)ME );

		PPC_TRACE_5("rlwinmx", S, A, SH, MB, ME);

		PPC_u32 v = PPC_WORD_ROTL(REG_TO_INT(REG(S)),SH);
		PPC_u32 mask = PPC_MASK(MB,ME);
		//REG(A) = v & mask;
		REG(A).convert_from_int(v & mask);
		if (instr & Op_Flag::RC) {
			//update cr0 flags
            REG_UPDATE_CR0 (REG(A));
        }

	}

	//Rotate Left Word Immediate then Mask Insert
	PPC_INSTRUCTION_IMPL(op_rlwimix)
	{
		PPC_s32 S, A, SH, MB, ME;
		M_Form_Parser::parse(instr, S, A, SH, MB, ME);

		PPC_TRACE_5("rlwimix", S, A, SH, MB, ME);

		PPC_u32 v = PPC_WORD_ROTL(REG_TO_INT(REG(S)),SH);
		PPC_u32 mask = PPC_MASK(MB,ME);
		//REG(A)=(v & mask) | (ERG(A) & ~mask);
		v &= mask;
		mask =~mask;
		mask &= REG_TO_INT(REG(A));
		REG(A).convert_from_int(v | mask);
	    if (instr & Op_Flag::RC) {
			//update cr0 flags
            REG_UPDATE_CR0 (REG(A));
        }
	
	}

} //namespace PPC

⌨️ 快捷键说明

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