2 Star 3 Fork 0

thor / unisim

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
shifter.c 879 Bytes
一键复制 编辑 原始数据 按行查看 历史
thor 提交于 2013-11-18 12:40 . cmsr
#include "shifter.h"
#include "sim.h"
#include "helper.h"
#include <stdlib.h>
int shifter(shifttype_t shifttype, int n1, int n2)
{
int res, C = 0;
switch(shifttype) {
case SHIFT_LL:
if (n2 == 32) {
res = 0;
} else if (n2 > 32) {
res = 0;
} else {
res = n1 << n2;
if (n2) C = B(n1, 32 - n2);
}
break;
case SHIFT_LR:
if (n2 == 32) {
res = 0;
} else if (n2 > 32) {
res = 0;
} else {
res = ((unsigned)n1) >> n2;
if (n2) C = B(n1, n2-1);
}
break;
case SHIFT_AR:
if (n2 >= 32) {
res = n1 >> 31;
} else {
res = n1 >> n2;
if (n2) C = B(n1, n2-1);
}
break;
case SHIFT_LP:
if (n2 == 32) {
res = n1;
} else {
n2 %= 32;
res = (((unsigned)n1) >> n2) | (n1 << (32-n2));
}
break;
default:
printf("unknown shift type!\n");
exit(0);
}
d_reg.C = C;
return res;
}
C
1
https://gitee.com/thor/unisim.git
git@gitee.com:thor/unisim.git
thor
unisim
unisim
master

搜索帮助