Fastest way to count number of 1s in a register, ARM assembly

后端 未结 6 1785
不思量自难忘°
不思量自难忘° 2020-12-05 11:44

So I had an interview question before regarding bit manipulation. The company is a well known GPU company. I had very little background in assembly language (weird despite b

6条回答
  •  长情又很酷
    2020-12-05 11:50

    long count_bits_long (long);

        vmov.32 d0[0], r0       // R0 --> SIMD
    
        vcnt.8  d0, d0          // count bits in bytes
        vpaddl.u8 d0, d0        // add adjacent pairs of bytes and put into 16b words
        vpaddl.u16 d0, d0       // add adjacent pairs of 16b words and put into 32b word
    
        vmov.32 r0, d0[0]       // SIMD --> R0
    
        mov pc, lr              // return
    

提交回复
热议问题