Finding smallest value in an array most efficiently

后端 未结 13 1699
慢半拍i
慢半拍i 2020-11-29 07:02

There are N values in the array, and one of them is the smallest value. How can I find the smallest value most efficiently?

13条回答
  •  心在旅途
    2020-11-29 07:46

    If you want to be really efficient and you have enough time to spent, use SIMD instruction.

    You can compare several pairs in one instruction:

    r0 := min(a0, b0)
    r1 := min(a1, b1)
    r2 := min(a2, b2)
    r3 := min(a3, b3)
    __m64 _mm_min_pu8(__m64 a , __m64 b );
    

    Today every computer supports it. Other already have written min function for you:

    http://smartdata.usbid.com/datasheets/usbid/2001/2001-q1/i_minmax.pdf

    or use already ready library.

提交回复
热议问题