Commit 1ff1405c authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: add type algorithms for zero-sized types

BenchmarkChanSem old=127ns new=78.6ns

R=golang-dev, bradfitz, sameer, rsc
CC=golang-dev
https://golang.org/cl/5558049
parent 43b4db19
......@@ -40,12 +40,14 @@ enum
// These values are known by runtime.
// The MEMx and NOEQx values must run in parallel. See algtype.
AMEM = 0,
AMEM0,
AMEM8,
AMEM16,
AMEM32,
AMEM64,
AMEM128,
ANOEQ,
ANOEQ0,
ANOEQ8,
ANOEQ16,
ANOEQ32,
......
......@@ -586,6 +586,8 @@ algtype(Type *t)
if(isslice(t))
return ASLICE;
switch(t->width) {
case 0:
return a + AMEM0 - AMEM;
case 1:
return a + AMEM8 - AMEM;
case 2:
......
......@@ -88,6 +88,23 @@ runtime·memcopy(uintptr s, void *a, void *b)
runtime·memmove(a, b, s);
}
void
runtime·memequal0(bool *eq, uintptr s, void *a, void *b)
{
USED(s);
USED(a);
USED(b);
*eq = true;
}
void
runtime·memcopy0(uintptr s, void *a, void *b)
{
USED(s);
USED(a);
USED(b);
}
void
runtime·memequal8(bool *eq, uintptr s, void *a, void *b)
{
......@@ -332,11 +349,13 @@ runtime·algarray[] =
[AINTER] { runtime·interhash, runtime·interequal, runtime·interprint, runtime·intercopy },
[ANILINTER] { runtime·nilinterhash, runtime·nilinterequal, runtime·nilinterprint, runtime·nilintercopy },
[ASLICE] { runtime·nohash, runtime·noequal, runtime·memprint, runtime·slicecopy },
[AMEM0] { runtime·memhash, runtime·memequal0, runtime·memprint, runtime·memcopy0 },
[AMEM8] { runtime·memhash, runtime·memequal8, runtime·memprint, runtime·memcopy8 },
[AMEM16] { runtime·memhash, runtime·memequal16, runtime·memprint, runtime·memcopy16 },
[AMEM32] { runtime·memhash, runtime·memequal32, runtime·memprint, runtime·memcopy32 },
[AMEM64] { runtime·memhash, runtime·memequal64, runtime·memprint, runtime·memcopy64 },
[AMEM128] { runtime·memhash, runtime·memequal128, runtime·memprint, runtime·memcopy128 },
[ANOEQ0] { runtime·nohash, runtime·noequal, runtime·memprint, runtime·memcopy0 },
[ANOEQ8] { runtime·nohash, runtime·noequal, runtime·memprint, runtime·memcopy8 },
[ANOEQ16] { runtime·nohash, runtime·noequal, runtime·memprint, runtime·memcopy16 },
[ANOEQ32] { runtime·nohash, runtime·noequal, runtime·memprint, runtime·memcopy32 },
......
......@@ -371,3 +371,12 @@ func BenchmarkChanCreation(b *testing.B) {
<-c
}
}
func BenchmarkChanSem(b *testing.B) {
type Empty struct{}
c := make(chan Empty, 1)
for i := 0; i < b.N; i++ {
c <- Empty{}
<-c
}
}
......@@ -358,12 +358,14 @@ enum {
enum
{
AMEM,
AMEM0,
AMEM8,
AMEM16,
AMEM32,
AMEM64,
AMEM128,
ANOEQ,
ANOEQ0,
ANOEQ8,
ANOEQ16,
ANOEQ32,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment