std::midpoint<long>實現
按照C++20標準,std::midpoint需要輸出:Half the sum of a and b. No overflow occurs. If a and b have integer type and the sum is odd, the result is rounded towards a.
對無符號數這相對簡單,rcr能包含進位視爲一個65位的臨時變量Timeline view:
Index 012345
DeER . cmpq %rsi, %rdi
DeER . movq %rsi, %rax
D=eER. adcq %rdi, %rax
D==eER rcrq %rax
但有符號數呢?
cycle數第一考慮,覆蓋輸入寄存器第二考慮,臨時寄存器數量第三,長度第四(有別的評價標準再說) mca說這是4cy DeER .. xorl %ecx, %ecx
DeER .. cmpq %rdi, %rsi
D=eER.. setl %al
DeE-R.. sarq %rsi
.DeER.. adcl %ecx, %ecx
.DeER.. sarq %rdi
.D=eER. sbbb %cl, %al
.DeE-R. movq %rsi, %rax
. D=eER adcq %rdi, %rax
页:
[1]