github.com/aloncn/graphics-go@v0.0.1/src/runtime/memmove_ppc64x.s (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build ppc64 ppc64le 6 7 #include "textflag.h" 8 9 // void runtime·memmove(void*, void*, uintptr) 10 TEXT runtime·memmove(SB), NOSPLIT|NOFRAME, $0-24 11 MOVD to+0(FP), R3 12 MOVD from+8(FP), R4 13 MOVD n+16(FP), R5 14 CMP R5, $0 15 BNE check 16 RET 17 18 check: 19 ANDCC $7, R5, R7 // R7 is the number of bytes to copy and CR0[EQ] is set if there are none. 20 SRAD $3, R5, R6 // R6 is the number of words to copy 21 CMP R6, $0, CR1 // CR1[EQ] is set if there are no words to copy. 22 23 CMP R3, R4, CR2 24 BC 12, 9, backward // I think you should be able to write this as "BGT CR2, backward" 25 26 // Copying forward proceeds by copying R6 words then copying R7 bytes. 27 // R3 and R4 are advanced as we copy. Becuase PPC64 lacks post-increment 28 // load/store, R3 and R4 point before the bytes that are to be copied. 29 30 BC 12, 6, noforwardlarge // "BEQ CR1, noforwardlarge" 31 32 MOVD R6, CTR 33 34 SUB $8, R3 35 SUB $8, R4 36 37 forwardlargeloop: 38 MOVDU 8(R4), R8 39 MOVDU R8, 8(R3) 40 BC 16, 0, forwardlargeloop // "BDNZ" 41 42 ADD $8, R3 43 ADD $8, R4 44 45 noforwardlarge: 46 BNE forwardtail // Tests the bit set by ANDCC above 47 RET 48 49 forwardtail: 50 SUB $1, R3 51 SUB $1, R4 52 MOVD R7, CTR 53 54 forwardtailloop: 55 MOVBZU 1(R4), R8 56 MOVBZU R8, 1(R3) 57 BC 16, 0, forwardtailloop 58 RET 59 60 backward: 61 // Copying backwards proceeds by copying R7 bytes then copying R6 words. 62 // R3 and R4 are advanced to the end of the destination/source buffers 63 // respectively and moved back as we copy. 64 65 ADD R5, R4, R4 66 ADD R3, R5, R3 67 68 BEQ nobackwardtail 69 70 MOVD R7, CTR 71 72 backwardtailloop: 73 MOVBZU -1(R4), R8 74 MOVBZU R8, -1(R3) 75 BC 16, 0, backwardtailloop 76 77 nobackwardtail: 78 BC 4, 6, backwardlarge // "BNE CR1" 79 RET 80 81 backwardlarge: 82 MOVD R6, CTR 83 84 backwardlargeloop: 85 MOVDU -8(R4), R8 86 MOVDU R8, -8(R3) 87 BC 16, 0, backwardlargeloop // "BDNZ" 88 RET