📄 integer_shift_instruction.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_Shift_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 {
// shift left word
PPC_INSTRUCTION_IMPL(op_slwx)
{
PPC_s32 S, A, B;
X_Form_Parser::parse_x(instr, S, A, B);
PPC_TRACE_3("slwx", S, A, B);
PPC_u32 s = REG_TO_INT(REG(B)) & 0x3f;
if(s > 31){
//REG(A) = 0
REG(A).convert_from_int(0);
}else{
//REG(A)=REG(S)<<s
REG(A).convert_from_int( REG_TO_INT(REG(S)) << s);
}
if (instr & Op_Flag::RC) {
REG_UPDATE_CR0 (REG(A));
}
}
//Shift Right Algebraic Word
PPC_INSTRUCTION_IMPL(op_srawx){
PPC_s32 S, A, B;
X_Form_Parser::parse_x (instr, S, A, B);
PPC_u32 SH = REG_TO_INT(REG(B)) & 0x3f;
REG(A).convert_from_int(REG_TO_INT(REG(S)));
REG_CLEAR_BIT (XER, Reg_Flag::XER_CA);
if(REG_TO_INT(REG(A)) & 0x80000000){
PPC_u32 ca = 0;
for(PPC_u32 i = 0; i < SH; i ++){
//REG(A)>>=1
REG(A).convert_from_int(REG_TO_INT(REG(A))>>1);
//REG(A)|=Ox8000000
REG(A).convert_from_int(REG_TO_INT(REG(A))|0x80000000);
}
if(ca)
REG_SET_BIT (XER, Reg_Flag::XER_CA);
}else{
if(SH > 31){
REG(A).convert_from_int(0);
}else{
REG(A).convert_from_int(REG_TO_INT(REG(A))>>SH);
}
}
if (instr & Op_Flag::RC)
REG_UPDATE_CR0 (REG (A));
}
//Shift Right Algebraic Word Immediate
PPC_INSTRUCTION_IMPL(op_srawix){
PPC_s32 S, A;
PPC_u32 SH;
X_Form_Parser::parse_x (instr, S, A, (PPC_s32 &)SH);
REG(A) = REG(S);
REG_CLEAR_BIT (XER, Reg_Flag::XER_CA);
if(REG_TO_INT(REG(A)) & 0x80000000){
PPC_u32 ca = 0;
for(PPC_u32 i = 0; i < SH; i++){
if(REG_TO_INT(REG(A)) & 1)
ca = 1;
//REG(A) >>= 1
REG(A).convert_from_int(REG_TO_INT(REG(A))>>1);
//REG(A) |= 0x80000000
REG(A).convert_from_int(REG_TO_INT(REG(A))|0x80000000);
}
if(ca)
REG_SET_BIT (XER, Reg_Flag::XER_CA);
}else{
//REG(A) >>= SH
REG(A).convert_from_int(REG_TO_INT(REG(A))>>SH);
}
if (instr & Op_Flag::RC)
REG_UPDATE_CR0 (REG (A));
}
//Shift Right Word
PPC_INSTRUCTION_IMPL(op_srwx){
PPC_s32 S, A, B;
X_Form_Parser::parse_x (instr, S, A, B);
PPC_u32 v = REG_TO_INT(REG(B)) & 0x3f;
if(v > 31){
REG(A).convert_from_int(0);
}else{
//REG(A) = REG(S) >> v
REG(A).convert_from_int(REG_TO_INT(REG(S))>>v);
}
if (instr & Op_Flag::RC)
REG_UPDATE_CR0 (REG (A));
}
} // namespace PPC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -