On 1/22/25 11:41 PM, Ziqi Chen wrote:
We use memcpy() here is due to memcpy() can be faster than direct
assignment. We don't worry about safety because they are same struct
"ufs_pa_layer_attr" so that we can ensure the accuracy of number of
bytes and member type.
The memcpy() call we are discussing is not in the hot path so it doesn't
have to be hyper-optimized. Making the compiler perform type checking is
more important in this code path than micro-optimizing the code.
Additionally, please do not try to be smarter than the compiler.
Compilers are able to convert struct assignments into a memcpy() call if
there are good reasons to assume that the memcpy() call will be faster.
Given the small size of struct ufs_pa_layer_attr (7 * 4 = 28 bytes),
memberwise assignment probably is faster than a memcpy() call. The trunk
version of gcc (ARM64) translates a memberwise assignment of struct
ufs_pa_layer_attr into the following four assembler instructions (x0 and
x1 point to struct ufs_pa_layer_attr instances, q30 and q31 are 128 bit
registers):
ldr q30, [x1]
ldr q31, [x1, 12]
str q30, [x0]
str q31, [x0, 12]
Thanks,
Bart.