Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/lib/memset.S |
| 3 | * |
| 4 | * Copyright (C) 1995-2000 Russell King |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * ASM optimised string functions |
| 11 | */ |
| 12 | #include <linux/linkage.h> |
| 13 | #include <asm/assembler.h> |
Lin Yongting | c2459d35 | 2014-11-16 03:14:58 +0100 | [diff] [blame] | 14 | #include <asm/unwind.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | .text |
| 17 | .align 5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | ENTRY(memset) |
Lin Yongting | c2459d35 | 2014-11-16 03:14:58 +0100 | [diff] [blame] | 20 | UNWIND( .fnstart ) |
Nicolas Pitre | 418df63a | 2013-03-12 13:00:42 +0100 | [diff] [blame] | 21 | ands r3, r0, #3 @ 1 unaligned? |
| 22 | mov ip, r0 @ preserve r0 as return value |
| 23 | bne 6f @ 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /* |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 25 | * we know that the pointer in ip is aligned to a word boundary. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | */ |
Nicolas Pitre | 418df63a | 2013-03-12 13:00:42 +0100 | [diff] [blame] | 27 | 1: orr r1, r1, r1, lsl #8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | orr r1, r1, r1, lsl #16 |
| 29 | mov r3, r1 |
| 30 | cmp r2, #16 |
| 31 | blt 4f |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 32 | |
| 33 | #if ! CALGN(1)+0 |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 36 | * We need 2 extra registers for this loop - use r8 and the LR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | */ |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 38 | stmfd sp!, {r8, lr} |
Lin Yongting | c2459d35 | 2014-11-16 03:14:58 +0100 | [diff] [blame] | 39 | UNWIND( .fnend ) |
| 40 | UNWIND( .fnstart ) |
| 41 | UNWIND( .save {r8, lr} ) |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 42 | mov r8, r1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | mov lr, r1 |
| 44 | |
| 45 | 2: subs r2, r2, #64 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 46 | stmgeia ip!, {r1, r3, r8, lr} @ 64 bytes at a time. |
| 47 | stmgeia ip!, {r1, r3, r8, lr} |
| 48 | stmgeia ip!, {r1, r3, r8, lr} |
| 49 | stmgeia ip!, {r1, r3, r8, lr} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | bgt 2b |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 51 | ldmeqfd sp!, {r8, pc} @ Now <64 bytes to go. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* |
| 53 | * No need to correct the count; we're only testing bits from now on |
| 54 | */ |
| 55 | tst r2, #32 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 56 | stmneia ip!, {r1, r3, r8, lr} |
| 57 | stmneia ip!, {r1, r3, r8, lr} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | tst r2, #16 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 59 | stmneia ip!, {r1, r3, r8, lr} |
| 60 | ldmfd sp!, {r8, lr} |
Lin Yongting | c2459d35 | 2014-11-16 03:14:58 +0100 | [diff] [blame] | 61 | UNWIND( .fnend ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 63 | #else |
| 64 | |
| 65 | /* |
| 66 | * This version aligns the destination pointer in order to write |
| 67 | * whole cache lines at once. |
| 68 | */ |
| 69 | |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 70 | stmfd sp!, {r4-r8, lr} |
Lin Yongting | c2459d35 | 2014-11-16 03:14:58 +0100 | [diff] [blame] | 71 | UNWIND( .fnend ) |
| 72 | UNWIND( .fnstart ) |
| 73 | UNWIND( .save {r4-r8, lr} ) |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 74 | mov r4, r1 |
| 75 | mov r5, r1 |
| 76 | mov r6, r1 |
| 77 | mov r7, r1 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 78 | mov r8, r1 |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 79 | mov lr, r1 |
| 80 | |
| 81 | cmp r2, #96 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 82 | tstgt ip, #31 |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 83 | ble 3f |
| 84 | |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 85 | and r8, ip, #31 |
| 86 | rsb r8, r8, #32 |
| 87 | sub r2, r2, r8 |
| 88 | movs r8, r8, lsl #(32 - 4) |
| 89 | stmcsia ip!, {r4, r5, r6, r7} |
| 90 | stmmiia ip!, {r4, r5} |
| 91 | tst r8, #(1 << 30) |
| 92 | mov r8, r1 |
| 93 | strne r1, [ip], #4 |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 94 | |
| 95 | 3: subs r2, r2, #64 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 96 | stmgeia ip!, {r1, r3-r8, lr} |
| 97 | stmgeia ip!, {r1, r3-r8, lr} |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 98 | bgt 3b |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 99 | ldmeqfd sp!, {r4-r8, pc} |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 100 | |
| 101 | tst r2, #32 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 102 | stmneia ip!, {r1, r3-r8, lr} |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 103 | tst r2, #16 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 104 | stmneia ip!, {r4-r7} |
| 105 | ldmfd sp!, {r4-r8, lr} |
Lin Yongting | c2459d35 | 2014-11-16 03:14:58 +0100 | [diff] [blame] | 106 | UNWIND( .fnend ) |
Nicolas Pitre | f91a8dc | 2008-04-11 21:04:28 -0400 | [diff] [blame] | 107 | |
| 108 | #endif |
| 109 | |
Lin Yongting | c2459d35 | 2014-11-16 03:14:58 +0100 | [diff] [blame] | 110 | UNWIND( .fnstart ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | 4: tst r2, #8 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 112 | stmneia ip!, {r1, r3} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | tst r2, #4 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 114 | strne r1, [ip], #4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* |
| 116 | * When we get here, we've got less than 4 bytes to zero. We |
| 117 | * may have an unaligned pointer as well. |
| 118 | */ |
| 119 | 5: tst r2, #2 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 120 | strneb r1, [ip], #1 |
| 121 | strneb r1, [ip], #1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | tst r2, #1 |
Ivan Djelic | 455bd4c | 2013-03-06 20:09:27 +0100 | [diff] [blame] | 123 | strneb r1, [ip], #1 |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 124 | ret lr |
Nicolas Pitre | 418df63a | 2013-03-12 13:00:42 +0100 | [diff] [blame] | 125 | |
| 126 | 6: subs r2, r2, #4 @ 1 do we have enough |
| 127 | blt 5b @ 1 bytes to align with? |
| 128 | cmp r3, #2 @ 1 |
| 129 | strltb r1, [ip], #1 @ 1 |
| 130 | strleb r1, [ip], #1 @ 1 |
| 131 | strb r1, [ip], #1 @ 1 |
| 132 | add r2, r2, r3 @ 1 (r2 = r2 - (4 - r3)) |
| 133 | b 1b |
Lin Yongting | c2459d35 | 2014-11-16 03:14:58 +0100 | [diff] [blame] | 134 | UNWIND( .fnend ) |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 135 | ENDPROC(memset) |