diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2021-04-21 08:01:30 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-04-21 14:05:20 +0200 |
| commit | ad3ce6afab30fb68cfcda40a1910b87279795c5a (patch) | |
| tree | 6a6febdaae83e071a85576bb6fa1fd5b8abb2936 /pkg/csource/csource.go | |
| parent | 7ffd6ad61b0d0c6290f73b3652f79c63b305351e (diff) | |
pkg/compiler: optimize array[const] representation
Represent array[const[X, int8], N] as string["XX...X"].
This replaces potentially huge number of:
NONFAILING(*(uint8_t*)0x2000126c = 0);
NONFAILING(*(uint8_t*)0x2000126d = 0);
NONFAILING(*(uint8_t*)0x2000126e = 0);
with a single memcpy. In one reproducer we had 3991 such lines.
Also replace memcpy's with memset's when possible.
Update #1070
Diffstat (limited to 'pkg/csource/csource.go')
| -rw-r--r-- | pkg/csource/csource.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index 24717a31a..c30db6b9d 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -366,8 +366,13 @@ func (ctx *context) copyin(w *bytes.Buffer, csumSeq *int, copyin prog.ExecCopyin case prog.ExecArgResult: ctx.copyinVal(w, copyin.Addr, arg.Size, ctx.resultArgToStr(arg), arg.Format) case prog.ExecArgData: - fmt.Fprintf(w, "\tNONFAILING(memcpy((void*)0x%x, \"%s\", %v));\n", - copyin.Addr, toCString(arg.Data, arg.Readable), len(arg.Data)) + if bytes.Equal(arg.Data, bytes.Repeat(arg.Data[:1], len(arg.Data))) { + fmt.Fprintf(w, "\tNONFAILING(memset((void*)0x%x, %v, %v));\n", + copyin.Addr, arg.Data[0], len(arg.Data)) + } else { + fmt.Fprintf(w, "\tNONFAILING(memcpy((void*)0x%x, \"%s\", %v));\n", + copyin.Addr, toCString(arg.Data, arg.Readable), len(arg.Data)) + } case prog.ExecArgCsum: switch arg.Kind { case prog.ExecArgCsumInet: |
