]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use unoptimized memmove and memclr on Plan 9
authorAnthony Martin <ality@pbrane.org>
Thu, 13 Mar 2014 01:12:25 +0000 (18:12 -0700)
committerAnthony Martin <ality@pbrane.org>
Thu, 13 Mar 2014 01:12:25 +0000 (18:12 -0700)
On Plan 9, the kernel disallows the use of floating point
instructions while handling a note. Previously, we worked
around this by using a simple loop in place of memmove.

When I added that work-around, I verified that all paths
from the note handler didn't end up calling memmove. Now
that memclr is using SSE instructions, the same process
will have to be done again.

Instead of doing that, however, this CL just punts and
uses unoptimized functions everywhere on Plan 9.

LGTM=rsc
R=rsc, 0intro
CC=golang-codereviews
https://golang.org/cl/73830044

src/pkg/runtime/memclr_386.s
src/pkg/runtime/memclr_amd64.s
src/pkg/runtime/memclr_plan9_386.s [new file with mode: 0644]
src/pkg/runtime/memclr_plan9_amd64.s [new file with mode: 0644]
src/pkg/runtime/memmove_386.s
src/pkg/runtime/memmove_amd64.s
src/pkg/runtime/memmove_plan9_386.s [new file with mode: 0644]
src/pkg/runtime/memmove_plan9_amd64.s [new file with mode: 0644]

index 09b35d7e3c9f72181d8e396d011ce6475becc51a..4b7580cb49f4d1837026d68f867c3617403c0fe9 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build !plan9
+
 #include "../../cmd/ld/textflag.h"
 
 // void runtime·memclr(void*, uintptr)
index 8953a396b153f0d18616323e81aa98384c983d57..6b79363b2496486149a7fa7b782cfb731bec18ff 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build !plan9
+
 #include "../../cmd/ld/textflag.h"
 
 // void runtime·memclr(void*, uintptr)
diff --git a/src/pkg/runtime/memclr_plan9_386.s b/src/pkg/runtime/memclr_plan9_386.s
new file mode 100644 (file)
index 0000000..9b49678
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "../../cmd/ld/textflag.h"
+
+// void runtime·memclr(void*, uintptr)
+TEXT runtime·memclr(SB), NOSPLIT, $0-8
+       MOVL    ptr+0(FP), DI
+       MOVL    n+4(FP), BX
+       XORL    AX, AX
+
+clr_tail:
+       TESTL   BX, BX
+       JEQ     clr_0
+       CMPL    BX, $2
+       JBE     clr_1or2
+       CMPL    BX, $4
+       JBE     clr_3or4
+       CMPL    BX, $8
+       JBE     clr_5through8
+       CMPL    BX, $16
+       JBE     clr_9through16
+       MOVL    BX, CX
+       SHRL    $2, CX
+       REP
+       STOSL
+       ANDL    $3, BX
+       JNE     clr_tail
+       RET
+
+clr_1or2:
+       MOVB    AX, (DI)
+       MOVB    AX, -1(DI)(BX*1)
+clr_0:
+       RET
+clr_3or4:
+       MOVW    AX, (DI)
+       MOVW    AX, -2(DI)(BX*1)
+       RET
+clr_5through8:
+       MOVL    AX, (DI)
+       MOVL    AX, -4(DI)(BX*1)
+       RET
+clr_9through16:
+       MOVL    AX, (DI)
+       MOVL    AX, 4(DI)
+       MOVL    AX, -8(DI)(BX*1)
+       MOVL    AX, -4(DI)(BX*1)
+       RET
diff --git a/src/pkg/runtime/memclr_plan9_amd64.s b/src/pkg/runtime/memclr_plan9_amd64.s
new file mode 100644 (file)
index 0000000..6b33054
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "../../cmd/ld/textflag.h"
+
+// void runtime·memclr(void*, uintptr)
+TEXT runtime·memclr(SB), NOSPLIT, $0-16
+       MOVQ    ptr+0(FP), DI
+       MOVQ    n+8(FP), BX
+       XORQ    AX, AX
+
+clr_tail:
+       TESTQ   BX, BX
+       JEQ     clr_0
+       CMPQ    BX, $2
+       JBE     clr_1or2
+       CMPQ    BX, $4
+       JBE     clr_3or4
+       CMPQ    BX, $8
+       JBE     clr_5through8
+       CMPQ    BX, $16
+       JBE     clr_9through16
+       MOVQ    BX, CX
+       SHRQ    $2, CX
+       REP
+       STOSQ
+       ANDQ    $3, BX
+       JNE     clr_tail
+       RET
+
+clr_1or2:
+       MOVB    AX, (DI)
+       MOVB    AX, -1(DI)(BX*1)
+clr_0:
+       RET
+clr_3or4:
+       MOVW    AX, (DI)
+       MOVW    AX, -2(DI)(BX*1)
+       RET
+clr_5through8:
+       MOVL    AX, (DI)
+       MOVL    AX, -4(DI)(BX*1)
+       RET
+clr_9through16:
+       MOVQ    AX, (DI)
+       MOVQ    AX, -8(DI)(BX*1)
+       RET
index 13d575973a67ff2d38420965ecdd006e6d05dcb4..3aed8ad07b6c723c0eff862f5998a5c3bab51e87 100644 (file)
@@ -23,6 +23,8 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
+// +build !plan9
+
 #include "../../cmd/ld/textflag.h"
 
 TEXT runtime·memmove(SB), NOSPLIT, $0-12
index f1641cdb28782e23f8cf6fbb9cede23f8597e32b..5895846db6a9337c6582343240332c5e5345f193 100644 (file)
@@ -23,6 +23,8 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
+// +build !plan9
+
 #include "../../cmd/ld/textflag.h"
 
 // void runtime·memmove(void*, void*, uintptr)
diff --git a/src/pkg/runtime/memmove_plan9_386.s b/src/pkg/runtime/memmove_plan9_386.s
new file mode 100644 (file)
index 0000000..187616c
--- /dev/null
@@ -0,0 +1,127 @@
+// Inferno's libkern/memmove-386.s
+// http://code.google.com/p/inferno-os/source/browse/libkern/memmove-386.s
+//
+//         Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
+//         Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).  All rights reserved.
+//         Portions Copyright 2009 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#include "../../cmd/ld/textflag.h"
+
+TEXT runtime·memmove(SB), NOSPLIT, $0-12
+       MOVL    to+0(FP), DI
+       MOVL    fr+4(FP), SI
+       MOVL    n+8(FP), BX
+
+       // REP instructions have a high startup cost, so we handle small sizes
+       // with some straightline code.  The REP MOVSL instruction is really fast
+       // for large sizes.  The cutover is approximately 1K.
+tail:
+       TESTL   BX, BX
+       JEQ     move_0
+       CMPL    BX, $2
+       JBE     move_1or2
+       CMPL    BX, $4
+       JBE     move_3or4
+       CMPL    BX, $8
+       JBE     move_5through8
+       CMPL    BX, $16
+       JBE     move_9through16
+
+/*
+ * check and set for backwards
+ */
+       CMPL    SI, DI
+       JLS     back
+
+/*
+ * forward copy loop
+ */
+forward:       
+       MOVL    BX, CX
+       SHRL    $2, CX
+       ANDL    $3, BX
+
+       REP;    MOVSL
+       JMP     tail
+/*
+ * check overlap
+ */
+back:
+       MOVL    SI, CX
+       ADDL    BX, CX
+       CMPL    CX, DI
+       JLS     forward
+/*
+ * whole thing backwards has
+ * adjusted addresses
+ */
+
+       ADDL    BX, DI
+       ADDL    BX, SI
+       STD
+
+/*
+ * copy
+ */
+       MOVL    BX, CX
+       SHRL    $2, CX
+       ANDL    $3, BX
+
+       SUBL    $4, DI
+       SUBL    $4, SI
+       REP;    MOVSL
+
+       CLD
+       ADDL    $4, DI
+       ADDL    $4, SI
+       SUBL    BX, DI
+       SUBL    BX, SI
+       JMP     tail
+
+move_1or2:
+       MOVB    (SI), AX
+       MOVB    -1(SI)(BX*1), CX
+       MOVB    AX, (DI)
+       MOVB    CX, -1(DI)(BX*1)
+move_0:
+       RET
+move_3or4:
+       MOVW    (SI), AX
+       MOVW    -2(SI)(BX*1), CX
+       MOVW    AX, (DI)
+       MOVW    CX, -2(DI)(BX*1)
+       RET
+move_5through8:
+       MOVL    (SI), AX
+       MOVL    -4(SI)(BX*1), CX
+       MOVL    AX, (DI)
+       MOVL    CX, -4(DI)(BX*1)
+       RET
+move_9through16:
+       MOVL    (SI), AX
+       MOVL    4(SI), CX
+       MOVL    -8(SI)(BX*1), DX
+       MOVL    -4(SI)(BX*1), BP
+       MOVL    AX, (DI)
+       MOVL    CX, 4(DI)
+       MOVL    DX, -8(DI)(BX*1)
+       MOVL    BP, -4(DI)(BX*1)
+       RET
diff --git a/src/pkg/runtime/memmove_plan9_amd64.s b/src/pkg/runtime/memmove_plan9_amd64.s
new file mode 100644 (file)
index 0000000..6010827
--- /dev/null
@@ -0,0 +1,126 @@
+// Derived from Inferno's libkern/memmove-386.s (adapted for amd64)
+// http://code.google.com/p/inferno-os/source/browse/libkern/memmove-386.s
+//
+//         Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
+//         Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).  All rights reserved.
+//         Portions Copyright 2009 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#include "../../cmd/ld/textflag.h"
+
+// void runtime·memmove(void*, void*, uintptr)
+TEXT runtime·memmove(SB), NOSPLIT, $0-24
+
+       MOVQ    to+0(FP), DI
+       MOVQ    fr+8(FP), SI
+       MOVQ    n+16(FP), BX
+
+       // REP instructions have a high startup cost, so we handle small sizes
+       // with some straightline code.  The REP MOVSQ instruction is really fast
+       // for large sizes.  The cutover is approximately 1K.
+tail:
+       TESTQ   BX, BX
+       JEQ     move_0
+       CMPQ    BX, $2
+       JBE     move_1or2
+       CMPQ    BX, $4
+       JBE     move_3or4
+       CMPQ    BX, $8
+       JBE     move_5through8
+       CMPQ    BX, $16
+       JBE     move_9through16
+
+/*
+ * check and set for backwards
+ */
+       CMPQ    SI, DI
+       JLS     back
+
+/*
+ * forward copy loop
+ */
+forward:
+       MOVQ    BX, CX
+       SHRQ    $3, CX
+       ANDQ    $7, BX
+
+       REP;    MOVSQ
+       JMP     tail
+
+back:
+/*
+ * check overlap
+ */
+       MOVQ    SI, CX
+       ADDQ    BX, CX
+       CMPQ    CX, DI
+       JLS     forward
+       
+/*
+ * whole thing backwards has
+ * adjusted addresses
+ */
+       ADDQ    BX, DI
+       ADDQ    BX, SI
+       STD
+
+/*
+ * copy
+ */
+       MOVQ    BX, CX
+       SHRQ    $3, CX
+       ANDQ    $7, BX
+
+       SUBQ    $8, DI
+       SUBQ    $8, SI
+       REP;    MOVSQ
+
+       CLD
+       ADDQ    $8, DI
+       ADDQ    $8, SI
+       SUBQ    BX, DI
+       SUBQ    BX, SI
+       JMP     tail
+
+move_1or2:
+       MOVB    (SI), AX
+       MOVB    -1(SI)(BX*1), CX
+       MOVB    AX, (DI)
+       MOVB    CX, -1(DI)(BX*1)
+move_0:
+       RET
+move_3or4:
+       MOVW    (SI), AX
+       MOVW    -2(SI)(BX*1), CX
+       MOVW    AX, (DI)
+       MOVW    CX, -2(DI)(BX*1)
+       RET
+move_5through8:
+       MOVL    (SI), AX
+       MOVL    -4(SI)(BX*1), CX
+       MOVL    AX, (DI)
+       MOVL    CX, -4(DI)(BX*1)
+       RET
+move_9through16:
+       MOVQ    (SI), AX
+       MOVQ    -8(SI)(BX*1), CX
+       MOVQ    AX, (DI)
+       MOVQ    CX, -8(DI)(BX*1)
+       RET