3.58
long decode2(long x,long y,long z)
{
return (((y-z)<<63)>>63)^((y-z)*x)
}
3.59
用x0,y0來(lái)表示x,y的低位番甩,x1,y1來(lái)表示x,y的高位
xy=(x0+x1264)*(y0+y1*264)
=x0y0+x1y02^64+x0y12^64+x1y12^642^64
最后一項(xiàng)超過(guò)128位且在128位以內(nèi)的部分為零所以可以舍去最后一項(xiàng)
x0y0也可能超過(guò)64位吱肌,設(shè)超過(guò)位z1,未超過(guò)的位z0
xy=2^64(x1y0+x0y1+z1)+z0
所以z0要放在低位,其余的放在高位
movq %rdx, %rax #%rax = y0.
cqto #有符號(hào)運(yùn)算,因此用cqto,這里會(huì)自動(dòng)關(guān)聯(lián)%rdx和%rax分別表示高位和低位,假如y是負(fù)數(shù),那么%rdx所有位都是1(此時(shí)值是-1),否則,%rdx全為0, %rdx = y1.
movq %rsi, %rcx # %rcx = x0.
sarq $63, %rcx # 將%rcx向右移63位,跟%rdx的含義一樣,要么是-1,要么是0, %rcx = x1.
imulq %rax, %rcx # %rcx = y0 * x1
imulq %rsi, %rdx # %rdx = x0 * y1
addq %rdx, %rcx # %rcx = y0 * x1 + x0 * y1
mulq %rsi # 無(wú)符號(hào)計(jì)算 x0*y0,并將x0*y0的128位結(jié)果的高位放在%rdx,低位放在%rax,因此這里%rdx = z1, %rax = z0.
addq %rcx, %rdx # %rdx = y0*x1+x0*y1+z1
movq %rax, (%rdi) # 將%rax的值放到結(jié)果的低位
movq %rdx, 8(%rdi)# 將%rdx的值放到結(jié)果的高位
ret
3.60
long loop(long x,int n)
{
long result=0;
long mask;
for(mask=1;mask!=0;mask=mask<<(n&0xff))
result|=mask&x;
}
A. %rdi 存x
%esi存n
%rax存result
%rdx存mask
B.result 初始值為0
mask初始值為1
C.mask!=0;
D.mask=mask<<(n&0xff)
E.result|=mask&x;
3.62
case MODE_A:
result = *p2;
action = *p1;
*p2 = action;
break;
case MODE_B:
result = *p1 + *p2;
*p1 = result;
break;
case MODE_C:
*p1 = 59;
result = *p2;
break;
case MODE_D:
result = *p2;
*p1 = result;
result = 27;
break;
case MODE_E:
result = 27;
break;
default:
result = 12;
3.64
A.
&D[i][j][k] = XD + L(i * S * T + j * T + k)
B.
由A題目中的公式以及匯編至第9行第10行計(jì)算出來(lái)的可得:
S * T = 65
T = 13
S * T * R * 8 = 3640
R = 7
S = 5
T = 13