kernel - Refactor bcmp, bcopy, bzero, memset
commit5d48b3120a651eee088cced1b4cffd8a264722c6
authorMatthew Dillon <dillon@apollo.backplane.com>
Sun, 6 May 2018 04:52:37 +0000 (5 21:52 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 8 May 2018 17:01:21 +0000 (8 10:01 -0700)
tree95c62e671dd783a8eeac422e97efbcdffc317065
parentfdfeda0af16f48a4d43d7e574734598d2d657e81
kernel - Refactor bcmp, bcopy, bzero, memset

* For now continue to use stosq/stosb, movsq/movsb, cmpsq/cmpsb sequences
  which are well optimized on AMD and Intel.  Do not just use the '*b'
  string op.  While this is optimized on Intel it is not optimized on
  AMD.

* Note that two string ops in a row result in a serious pessimization.
  To fix this, for now, conditionalize the movsb, stosb, or cmpsb op so
  it is only executed when the remaining count is non-zero.  That is,
  assume nominal 8-byte alignment.

* Refactor pagezero() to use a movq/addq/jne sequence.  This is
  significantly faster than movsq on AMD and only just very slightly
  slower than movsq on Intel.

* Also use the above adjusted kernel code in libc for these functions,
  with minor modifications.  Since we are copying the code wholesale,
  replace the copyright for the related files in libc.

* Refactor libc's memset() to replicate the data to all 64 bits code and
  then use code similar to bzero().

Reported-by: mjg_ (info on pessimizations)
lib/libc/x86_64/string/bcmp.S [copied from lib/libc/x86_64/string/bcopy.S with 58% similarity]
lib/libc/x86_64/string/bcopy.S
lib/libc/x86_64/string/bzero.S [copied from lib/libc/x86_64/string/bcopy.S with 59% similarity]
lib/libc/x86_64/string/memset.S
sys/platform/pc64/x86_64/support.s