Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 1 | // Inferno's libkern/memset-arm.s |
| 2 | // http://code.google.com/p/inferno-os/source/browse/libkern/memset-arm.s |
| 3 | // |
| 4 | // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. |
| 5 | // Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. |
| 6 | // Portions Copyright 2009 The Go Authors. All rights reserved. |
| 7 | // |
| 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | // of this software and associated documentation files (the "Software"), to deal |
| 10 | // in the Software without restriction, including without limitation the rights |
| 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | // copies of the Software, and to permit persons to whom the Software is |
| 13 | // furnished to do so, subject to the following conditions: |
| 14 | // |
| 15 | // The above copyright notice and this permission notice shall be included in |
| 16 | // all copies or substantial portions of the Software. |
| 17 | // |
| 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | // THE SOFTWARE. |
| 25 | |
Russ Cox | cb040d5 | 2014-09-04 23:05:18 -0400 | [diff] [blame] | 26 | #include "textflag.h" |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 27 | |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 28 | #define TO R8 |
| 29 | #define TOE R11 |
| 30 | #define N R12 |
| 31 | #define TMP R12 /* N and TMP don't overlap */ |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 32 | |
Keith Randall | 0273dc1 | 2013-08-07 12:20:05 -0700 | [diff] [blame] | 33 | TEXT runtime·memclr(SB),NOSPLIT,$0-8 |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 34 | MOVW ptr+0(FP), TO |
| 35 | MOVW n+4(FP), N |
| 36 | MOVW $0, R0 |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 37 | |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 38 | ADD N, TO, TOE /* to end pointer */ |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 39 | |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 40 | CMP $4, N /* need at least 4 bytes to copy */ |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 41 | BLT _1tail |
| 42 | |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 43 | _4align: /* align on 4 */ |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 44 | AND.S $3, TO, TMP |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 45 | BEQ _4aligned |
| 46 | |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 47 | MOVBU.P R0, 1(TO) /* implicit write back */ |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 48 | B _4align |
| 49 | |
| 50 | _4aligned: |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 51 | SUB $31, TOE, TMP /* do 32-byte chunks if possible */ |
| 52 | CMP TMP, TO |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 53 | BHS _4tail |
| 54 | |
Dave Cheney | 0782603 | 2012-06-25 07:59:50 +1000 | [diff] [blame] | 55 | MOVW R0, R1 /* replicate */ |
| 56 | MOVW R0, R2 |
| 57 | MOVW R0, R3 |
| 58 | MOVW R0, R4 |
| 59 | MOVW R0, R5 |
| 60 | MOVW R0, R6 |
| 61 | MOVW R0, R7 |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 62 | |
| 63 | _f32loop: |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 64 | CMP TMP, TO |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 65 | BHS _4tail |
| 66 | |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 67 | MOVM.IA.W [R0-R7], (TO) |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 68 | B _f32loop |
| 69 | |
| 70 | _4tail: |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 71 | SUB $3, TOE, TMP /* do remaining words if possible */ |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 72 | _4loop: |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 73 | CMP TMP, TO |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 74 | BHS _1tail |
| 75 | |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 76 | MOVW.P R0, 4(TO) /* implicit write back */ |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 77 | B _4loop |
| 78 | |
| 79 | _1tail: |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 80 | CMP TO, TOE |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 81 | BEQ _return |
| 82 | |
Rob Pike | 69ddb7a | 2015-02-13 14:21:18 -0800 | [diff] [blame] | 83 | MOVBU.P R0, 1(TO) /* implicit write back */ |
Kai Backman | be639b9 | 2009-06-23 11:54:23 -0700 | [diff] [blame] | 84 | B _1tail |
| 85 | |
| 86 | _return: |
| 87 | RET |