Page MenuHomeFreeBSD

amd64: mostly depessimize copystr
ClosedPublic

Authored by mjg on Sep 22 2018, 1:16 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Sep 26, 11:38 AM
Unknown Object (File)
Wed, Sep 24, 8:47 AM
Unknown Object (File)
Aug 29 2025, 12:55 AM
Unknown Object (File)
Aug 27 2025, 6:35 AM
Unknown Object (File)
Aug 13 2025, 4:30 PM
Unknown Object (File)
Jul 30 2025, 4:46 AM
Unknown Object (File)
Jul 5 2025, 1:39 AM
Unknown Object (File)
Jun 29 2025, 4:59 PM
Subscribers

Details

Summary

The asm version should probably get removed and be re-coded in C. It can however work as a template for copyinstr changes later.

commit message;

amd64: mostly depessimize copystr

  • remove a forward branch in the common case
  • replace xchg + lodsb/stosb loop with simple movs

A simple test on Intel(R) Core(TM) i7-4600U CPU @ 2.10GH copying /foo/bar/baz in a loop
goes from 295715863 ops/s to 465807408.

Test Plan

verified the same result with:

#include <string.h>
#include <stdio.h>

int     copystr(const void * kfaddr,
            void * kdaddr, size_t len,
            size_t * lencopied);


int
main(void)
{
	char src[10], dst[10];
	int i, r;
	size_t c;

	strcpy(src, "abcde");
	for (i = 0; i < 10; i++) {
		memset(dst, 'A', sizeof(dst));
		r = copystr(src, dst, i, &c);
		printf("i=%d r=%d c=%ld dst=[%10s]\n", i, r, c, dst);
	}
	return (0);
}

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 19744

Event Timeline

sys/amd64/amd64/support.S
1030

movb

1034

testb

mjg marked 2 inline comments as done.
This revision is now accepted and ready to land.Sep 27 2018, 2:33 PM
This revision was automatically updated to reflect the committed changes.