push bpmov bp, sppcmpeqw xmm5, xmm5 ; xmm5 = all-ones (anything compares == itself)psrlw xmm5, 15 ; _mm_set1_epi16(1<<15)movq xmm0, [bp+4]psubw xmm5, xmm0 ; map the signed range to unsigned, in reverse orderphminposuw xmm1, xmm5 ; xmm1 = [ 0... minidx minval ]movd eax, xmm1 ; ax = minvalpsrldq xmm1, 2 ; xmm1 = [ 0... minidx ]psllw xmm1, 4 ; xmm1 = [ 0... minidx * 16 ]pcmpeqw xmm2, xmm6psrlq xmm2, 48 ; xmm2 = _mm_set1_epi64(0xFFFF)psllq xmm2, xmm1 ; xmm2 = _mm_set1_epi64(0xFFFF << (minidx*16)); force the min element to 65535, so we can go again and get the 2nd min (which might be 65535, but we don't care what position it was in)por xmm2, xmm5phminposuw xmm3, xmm2movd edx, xmm3 ; dx = 2nd min, upper half of edx=garbage (the index)mov cx, 1<<15 ; undo the range shiftneg axadd ax, cxsub cx, dximul cx ; signed multiply dx:ax = ax * cxpop bpret ; return 32-bit result in dx:ax (or caller can look at only the low 16 bits in ax)这是更多说明.它可能不会比使用整数寄存器的CMP/CMOV分类网络更好. (请参阅@Terje的评论,以获取有关使用哪种比较和交换的建议.)This is more instructions. It might not be better than a CMP/CMOV sorting network using integer registers. (See @Terje's comment for a suggestion on what compare-and-swap to use). 这篇关于x86 Assembly-4个给定数字中的2个最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 18:08