strlen performance implementation

前端 未结 3 1228
别那么骄傲
别那么骄傲 2020-12-16 23:32

This is a multipurpose question:

  • How does this compare to the glibc strlen implementation?
  • Is there a better way to to this in general and for autovec
3条回答
  •  春和景丽
    2020-12-17 00:07

    To answer your second question, I think the naive byte-based strlen implementation will result in better auto-vectorization by the compiler, if it's smart and support for vector instruction set extensions (e.g. SSE) has been enabled (e.g. with -msse or an appropriate -march). Unfortunately, it won't result in any vectorization with baseline cpus which lack these features, even though the compiler could generate 32- or 64-bit pseudo-vectorized code like the C code cited in the question, if it were smart enough...

提交回复
热议问题