1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:24:41 -07:00

runtime: replace runtime.mcpy with runtime.memmove

faster string operations, and more

tested on linux/386

runtime_test.BenchmarkSliceToString                    642          532  -17.13%
runtime_test.BenchmarkStringToSlice                    636          528  -16.98%
runtime_test.BenchmarkConcatString                    1109          897  -19.12%

R=r, iant, rsc
CC=golang-dev
https://golang.org/cl/4674042
This commit is contained in:
Quan Yong Zhai 2011-07-12 17:30:40 -07:00 committed by Russ Cox
parent ba91dac3a9
commit fe9991e8b2
13 changed files with 22 additions and 57 deletions

View File

@ -708,7 +708,7 @@ void
·_Cfunc_CString(String s, int8 *p) ·_Cfunc_CString(String s, int8 *p)
{ {
p = runtime·cmalloc(s.len+1); p = runtime·cmalloc(s.len+1);
runtime·mcpy((byte*)p, s.str, s.len); runtime·memmove((byte*)p, s.str, s.len);
p[s.len] = 0; p[s.len] = 0;
FLUSH(&p); FLUSH(&p);
} }

View File

@ -45,7 +45,7 @@ runtime·closure(int32 siz, byte *fn, byte *arg0)
q = p + n - siz; q = p + n - siz;
if(siz > 0) { if(siz > 0) {
runtime·mcpy(q, (byte*)&arg0, siz); runtime·memmove(q, (byte*)&arg0, siz);
// SUBL $siz, SP // SUBL $siz, SP
*p++ = 0x81; *p++ = 0x81;

View File

@ -27,9 +27,6 @@ TEXT runtime·memmove(SB), 7, $0
MOVL to+0(FP), DI MOVL to+0(FP), DI
MOVL fr+4(FP), SI MOVL fr+4(FP), SI
MOVL n+8(FP), BX MOVL n+8(FP), BX
CMPL BX, $0
JLT fault
/* /*
* check and set for backwards * check and set for backwards
*/ */
@ -87,12 +84,3 @@ back:
MOVL to+0(FP),AX MOVL to+0(FP),AX
RET RET
/*
* if called with negative count,
* treat as error rather than
* rotating all of memory
*/
fault:
MOVL $0,SI
MOVL 0(SI), AX
RET

View File

@ -45,7 +45,7 @@ runtime·closure(int32 siz, byte *fn, byte *arg0)
q = p + n - siz; q = p + n - siz;
if(siz > 0) { if(siz > 0) {
runtime·mcpy(q, (byte*)&arg0, siz); runtime·memmove(q, (byte*)&arg0, siz);
// SUBQ $siz, SP // SUBQ $siz, SP
*p++ = 0x48; *p++ = 0x48;

View File

@ -28,8 +28,6 @@ TEXT runtime·memmove(SB), 7, $0
MOVQ to+0(FP), DI MOVQ to+0(FP), DI
MOVQ fr+8(FP), SI MOVQ fr+8(FP), SI
MOVLQSX n+16(FP), BX MOVLQSX n+16(FP), BX
CMPQ BX, $0
JLT fault
/* /*
* check and set for backwards * check and set for backwards
@ -88,12 +86,3 @@ back:
MOVQ to+0(FP),AX MOVQ to+0(FP),AX
RET RET
/*
* if called with negative count,
* treat as error rather than
* rotating all of memory
*/
fault:
MOVQ $0,SI
MOVQ 0(SI), AX
RET

View File

@ -83,7 +83,7 @@ runtime·closure(int32 siz, byte *fn, byte *arg0)
*pc++ = 0xe52de000 | (siz + 4); *pc++ = 0xe52de000 | (siz + 4);
if(siz > 0) { if(siz > 0) {
runtime·mcpy(q, (byte*)&arg0, siz); runtime·memmove(q, (byte*)&arg0, siz);
// MOVW $vars(PC), R0 // MOVW $vars(PC), R0
*pc = 0xe28f0000 | (int32)(q - (byte*)pc - 8); *pc = 0xe28f0000 | (int32)(q - (byte*)pc - 8);

View File

@ -65,7 +65,7 @@
#define malloc runtime·mal #define malloc runtime·mal
#define memset(a,b,c) runtime·memclr((byte*)(a), (uint32)(c)) #define memset(a,b,c) runtime·memclr((byte*)(a), (uint32)(c))
#define memcpy(a,b,c) runtime·mcpy((byte*)(a),(byte*)(b),(uint32)(c)) #define memcpy(a,b,c) runtime·memmove((byte*)(a),(byte*)(b),(uint32)(c))
#define assert(a) if(!(a)) runtime·throw("assert") #define assert(a) if(!(a)) runtime·throw("assert")
#define free(x) runtime·free(x) #define free(x) runtime·free(x)
#define memmove(a,b,c) runtime·memmove(a, b, c) #define memmove(a,b,c) runtime·memmove(a, b, c)

View File

@ -47,11 +47,11 @@ runtime·exit(int32)
pid = pid/10; pid = pid/10;
} }
p = buf; p = buf;
runtime·mcpy((void*)p, (void*)"/proc/", 6); runtime·memmove((void*)p, (void*)"/proc/", 6);
p += 6; p += 6;
for(q--; q >= tmp;) for(q--; q >= tmp;)
*p++ = *q--; *p++ = *q--;
runtime·mcpy((void*)p, (void*)"/notepg", 7); runtime·memmove((void*)p, (void*)"/notepg", 7);
/* post interrupt note */ /* post interrupt note */
fd = runtime·open(buf, OWRITE); fd = runtime·open(buf, OWRITE);

View File

@ -720,7 +720,7 @@ runtime·oldstack(void)
argsize = old.argsize; argsize = old.argsize;
if(argsize > 0) { if(argsize > 0) {
sp -= argsize; sp -= argsize;
runtime·mcpy(top->argp, sp, argsize); runtime·memmove(top->argp, sp, argsize);
} }
goid = old.gobuf.g->goid; // fault if g is bad, before gogo goid = old.gobuf.g->goid; // fault if g is bad, before gogo
USED(goid); USED(goid);
@ -802,7 +802,7 @@ runtime·newstack(void)
sp = (byte*)top; sp = (byte*)top;
if(argsize > 0) { if(argsize > 0) {
sp -= argsize; sp -= argsize;
runtime·mcpy(sp, m->moreargp, argsize); runtime·memmove(sp, m->moreargp, argsize);
} }
if(thechar == '5') { if(thechar == '5') {
// caller would have saved its LR below args. // caller would have saved its LR below args.
@ -903,7 +903,7 @@ runtime·newproc1(byte *fn, byte *argp, int32 narg, int32 nret, void *callerpc)
sp = newg->stackbase; sp = newg->stackbase;
sp -= siz; sp -= siz;
runtime·mcpy(sp, argp, narg); runtime·memmove(sp, argp, narg);
if(thechar == '5') { if(thechar == '5') {
// caller's LR // caller's LR
sp -= sizeof(void*); sp -= sizeof(void*);
@ -941,7 +941,7 @@ runtime·deferproc(int32 siz, byte* fn, ...)
d->argp = (byte*)(&fn+2); // skip caller's saved link register d->argp = (byte*)(&fn+2); // skip caller's saved link register
else else
d->argp = (byte*)(&fn+1); d->argp = (byte*)(&fn+1);
runtime·mcpy(d->args, d->argp, d->siz); runtime·memmove(d->args, d->argp, d->siz);
d->link = g->defer; d->link = g->defer;
g->defer = d; g->defer = d;
@ -968,7 +968,7 @@ runtime·deferreturn(uintptr arg0)
argp = (byte*)&arg0; argp = (byte*)&arg0;
if(d->argp != argp) if(d->argp != argp)
return; return;
runtime·mcpy(argp, d->args, d->siz); runtime·memmove(argp, d->args, d->siz);
g->defer = d->link; g->defer = d->link;
fn = d->fn; fn = d->fn;
runtime·free(d); runtime·free(d);
@ -1367,11 +1367,11 @@ os·setenv_c(String k, String v)
return; return;
arg[0] = runtime·malloc(k.len + 1); arg[0] = runtime·malloc(k.len + 1);
runtime·mcpy(arg[0], k.str, k.len); runtime·memmove(arg[0], k.str, k.len);
arg[0][k.len] = 0; arg[0][k.len] = 0;
arg[1] = runtime·malloc(v.len + 1); arg[1] = runtime·malloc(v.len + 1);
runtime·mcpy(arg[1], v.str, v.len); runtime·memmove(arg[1], v.str, v.len);
arg[1][v.len] = 0; arg[1][v.len] = 0;
runtime·asmcgocall(libcgo_setenv, arg); runtime·asmcgocall(libcgo_setenv, arg);

View File

@ -116,17 +116,6 @@ runtime·panicstring(int8 *s)
runtime·panic(err); runtime·panic(err);
} }
void
runtime·mcpy(byte *t, byte *f, uint32 n)
{
while(n > 0) {
*t = *f;
t++;
f++;
n--;
}
}
int32 int32
runtime·mcmp(byte *s1, byte *s2, uint32 n) runtime·mcmp(byte *s1, byte *s2, uint32 n)
{ {

View File

@ -406,7 +406,6 @@ uint32 runtime·rnd(uint32, uint32);
void runtime·prints(int8*); void runtime·prints(int8*);
void runtime·printf(int8*, ...); void runtime·printf(int8*, ...);
byte* runtime·mchr(byte*, byte, byte*); byte* runtime·mchr(byte*, byte, byte*);
void runtime·mcpy(byte*, byte*, uint32);
int32 runtime·mcmp(byte*, byte*, uint32); int32 runtime·mcmp(byte*, byte*, uint32);
void runtime·memmove(void*, void*, uint32); void runtime·memmove(void*, void*, uint32);
void* runtime·mal(uintptr); void* runtime·mal(uintptr);

View File

@ -60,7 +60,7 @@ runtime·gostring(byte *str)
l = runtime·findnull(str); l = runtime·findnull(str);
s = runtime·gostringsize(l); s = runtime·gostringsize(l);
runtime·mcpy(s.str, str, l); runtime·memmove(s.str, str, l);
return s; return s;
} }
@ -70,7 +70,7 @@ runtime·gostringn(byte *str, int32 l)
String s; String s;
s = runtime·gostringsize(l); s = runtime·gostringsize(l);
runtime·mcpy(s.str, str, l); runtime·memmove(s.str, str, l);
return s; return s;
} }
@ -113,8 +113,8 @@ runtime·catstring(String s1, String s2)
return s1; return s1;
s3 = runtime·gostringsize(s1.len + s2.len); s3 = runtime·gostringsize(s1.len + s2.len);
runtime·mcpy(s3.str, s1.str, s1.len); runtime·memmove(s3.str, s1.str, s1.len);
runtime·mcpy(s3.str+s1.len, s2.str, s2.len); runtime·memmove(s3.str+s1.len, s2.str, s2.len);
return s3; return s3;
} }
@ -134,7 +134,7 @@ concatstring(int32 n, String *s)
out = runtime·gostringsize(l); out = runtime·gostringsize(l);
l = 0; l = 0;
for(i=0; i<n; i++) { for(i=0; i<n; i++) {
runtime·mcpy(out.str+l, s[i].str, s[i].len); runtime·memmove(out.str+l, s[i].str, s[i].len);
l += s[i].len; l += s[i].len;
} }
return out; return out;
@ -225,14 +225,14 @@ func intstring(v int64) (s String) {
func slicebytetostring(b Slice) (s String) { func slicebytetostring(b Slice) (s String) {
s = runtime·gostringsize(b.len); s = runtime·gostringsize(b.len);
runtime·mcpy(s.str, b.array, s.len); runtime·memmove(s.str, b.array, s.len);
} }
func stringtoslicebyte(s String) (b Slice) { func stringtoslicebyte(s String) (b Slice) {
b.array = runtime·mallocgc(s.len, FlagNoPointers, 1, 1); b.array = runtime·mallocgc(s.len, FlagNoPointers, 1, 1);
b.len = s.len; b.len = s.len;
b.cap = s.len; b.cap = s.len;
runtime·mcpy(b.array, s.str, s.len); runtime·memmove(b.array, s.str, s.len);
} }
func sliceinttostring(b Slice) (s String) { func sliceinttostring(b Slice) (s String) {

View File

@ -159,7 +159,7 @@ makepath(byte *buf, int32 nbuf, byte *path)
break; break;
if(p > buf && p[-1] != '/') if(p > buf && p[-1] != '/')
*p++ = '/'; *p++ = '/';
runtime·mcpy(p, q, len+1); runtime·memmove(p, q, len+1);
p += len; p += len;
} }
} }