I am benchmarking an ARMv7 NEON code on two ARMv8 processors in AArch32 mode: the Cortex-A53 and Cortex-A72. I am using the Raspberry Pi 3B and Raspberry Pi 4B boards with 32-bit Raspbian Buster.
My benchmarking method is as follows:
uint32_t x[4];
uint32_t t0 = ccnt_read();
for(int i = 0; i < 1000; i++)
armv7_neon(x);
uint32_t t1 = ccnt_read();
printf("%u\n",(t1-t0)/1000);
where the armv7_neon function is defined by the following instructions:
.global armv7_neon
.func armv7_neon, armv7_neon
.type armv7_neon, %function
armv7_neon:
vld1.32 {q0}, [r0]
vmvn.i32 q0, q0
vmov.i32 q8, #0x11111111
vshr.u32 q1, q0, #2
vshr.u32 q2, q0, #3
vmov.i32 q9, #0x20202020
vand q1, q1, q2
vmov.i32 q10, #0x40404040
vand q1, q1, q8
vmov.i32 q11, #0x80808080
veor q0, q0, q1
vmov.i32 q12, #0x02020202
vshl.u32 q1, q0, #5
vshl.u32 q2, q0, #1
vmov.i32 q13, #0x04040404
vand q1, q1, q2
vmov.i32 q14, #0x08080808
vand q3, q1, q9
vshl.u32 q1, q0, #5
vshl.u32 q2, q0, #4
veor q0, q0, q3
vand q1, q1, q2
vmov.i32 q15, #0x32323232
vand q1, q1, q10
vmov.i32 q8, #0x01010101
veor q0, q0, q1
vshl.u32 q1, q0, #2
vshl.u32 q2, q0, #1
vand q1, q1, q2
vand q3, q1, q11
vshr.u32 q1, q0, #2
vshl.u32 q2, q0, #1
veor q0, q0, q3
vand q1, q1, q2
vand q1, q1, q12
veor q0, q0, q1
vshr.u32 q1, q0, #5
vshl.u32 q2, q0, #1
vand q1, q1, q2
vand q3, q1, q13
vshr.u32 q1, q0, #1
vshr.u32 q2, q0, #2
veor q0, q0, q3
vand q1, q1, q2
vand q1, q1, q14
veor q0, q0, q1
vmvn.i32 q0, q0
vand q1, q0, q14
vand q2, q0, q15
vand q3, q0, q8
vand q8, q0, q11
vand q9, q0, q10
vand q10, q0, q13
vshl.u32 q1, q1, #1
vshl.u32 q2, q2, #2
vshl.u32 q3, q3, #5
vshr.u32 q8, q8, #6
vshr.u32 q9, q9, #4
vshr.u32 q10, q10, #2
vorr q0, q1, q2
vorr q1, q3, q8
vorr q2, q9, q10
vorr q3, q0, q1
vorr q0, q3, q2
vst1.32 {q0}, [r0]
bx lr
.endfunc
The code is simply compiled with the following options:
gcc -O3 -mfpu=neon-fp-armv8 -mcpu=cortex-a53
gcc -O3 -mfpu=neon-fp-armv8 -mcpu=cortex-a72
I get 74 and 99 cycles on the Cortex-A53 and Cortex-A72, respectively. I've come across this blogpost discussing some performance issues on the Cortex-A72 for tbl instructions, but the code I'm running does not contain any.
Where could this gap come from?