[e16e8f2] | 1 | /* ----------------------------------------------------------------------- * |
---|
| 2 | * |
---|
| 3 | * Copyright 2008 H. Peter Anvin - All Rights Reserved |
---|
| 4 | * |
---|
| 5 | * Permission is hereby granted, free of charge, to any person |
---|
| 6 | * obtaining a copy of this software and associated documentation |
---|
| 7 | * files (the "Software"), to deal in the Software without |
---|
| 8 | * restriction, including without limitation the rights to use, |
---|
| 9 | * copy, modify, merge, publish, distribute, sublicense, and/or |
---|
| 10 | * sell copies of the Software, and to permit persons to whom |
---|
| 11 | * the Software is furnished to do so, subject to the following |
---|
| 12 | * conditions: |
---|
| 13 | * |
---|
| 14 | * The above copyright notice and this permission notice shall |
---|
| 15 | * be included in all copies or substantial portions of the Software. |
---|
| 16 | * |
---|
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
---|
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
---|
| 19 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
---|
| 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
---|
| 21 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
---|
| 22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
| 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
---|
| 24 | * OTHER DEALINGS IN THE SOFTWARE. |
---|
| 25 | * |
---|
| 26 | * ----------------------------------------------------------------------- */ |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | * memset.S |
---|
| 30 | * |
---|
| 31 | * Reasonably efficient memset, using aligned transfers at least |
---|
| 32 | * for the destination operand. |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | .globl memset |
---|
| 36 | .type memset,@function |
---|
| 37 | .text |
---|
| 38 | memset: |
---|
| 39 | movl 0xc(%esp),%ecx |
---|
| 40 | movl 0x8(%esp),%edx |
---|
| 41 | movl 0x4(%esp),%eax |
---|
| 42 | |
---|
| 43 | jecxz 6f |
---|
| 44 | |
---|
| 45 | pushl %edi |
---|
| 46 | pushl %ebx |
---|
| 47 | pushl %eax /* Return value */ |
---|
| 48 | |
---|
| 49 | movl %eax,%edi |
---|
| 50 | movb %dl,%dh |
---|
| 51 | movzwl %dx,%eax |
---|
| 52 | shll $16,%edx |
---|
| 53 | orl %edx,%eax |
---|
| 54 | |
---|
| 55 | /* Initial alignment */ |
---|
| 56 | movl %edi,%edx |
---|
| 57 | shrl $1,%edx |
---|
| 58 | jnc 1f |
---|
| 59 | stosb |
---|
| 60 | decl %ecx |
---|
| 61 | 1: |
---|
| 62 | movb %cl,%bl |
---|
| 63 | cmpl $2,%ecx |
---|
| 64 | jb 3f |
---|
| 65 | shrl $1,%edx |
---|
| 66 | jnc 2f |
---|
| 67 | stosw |
---|
| 68 | subl $2,%ecx |
---|
| 69 | 2: |
---|
| 70 | /* Bulk transfer */ |
---|
| 71 | movb %cl,%bl |
---|
| 72 | shrl $2,%ecx |
---|
| 73 | rep; stosl |
---|
| 74 | |
---|
| 75 | testb $2,%bl |
---|
| 76 | jz 4f |
---|
| 77 | stosw |
---|
| 78 | 3: |
---|
| 79 | 4: |
---|
| 80 | testb $1,%bl |
---|
| 81 | jz 5f |
---|
| 82 | stosb |
---|
| 83 | 5: |
---|
| 84 | popl %eax /* Return value */ |
---|
| 85 | popl %ebx |
---|
| 86 | popl %edi |
---|
| 87 | 6: |
---|
| 88 | ret |
---|
| 89 | |
---|
| 90 | .size memset, .-memset |
---|