/*-1* Copyright (c) 2018 The FreeBSD Foundation2*3* This software was developed by Mateusz Guzik <[email protected]>4* under sponsorship from the FreeBSD Foundation.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <machine/asm.h>29/*30* Note: this routine was written with kernel use in mind (read: no simd),31* it is only present in userspace as a temporary measure until something32* better gets imported.33*/3435#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */3637.macro MEMSET erms38movq %rdi,%rax39movq %rdx,%rcx40movzbq %sil,%r841movabs $0x0101010101010101,%r1042imulq %r8,%r104344cmpq $32,%rcx45jbe 101632f4647cmpq $256,%rcx48ja 1256f4950ALIGN_TEXT51103200:52movq %r10,(%rdi)53movq %r10,8(%rdi)54movq %r10,16(%rdi)55movq %r10,24(%rdi)56leaq 32(%rdi),%rdi57subq $32,%rcx58cmpq $32,%rcx59ja 103200b60cmpb $16,%cl61ja 201632f62movq %r10,-16(%rdi,%rcx)63movq %r10,-8(%rdi,%rcx)64ret65ALIGN_TEXT66101632:67cmpb $16,%cl68jl 100816f69201632:70movq %r10,(%rdi)71movq %r10,8(%rdi)72movq %r10,-16(%rdi,%rcx)73movq %r10,-8(%rdi,%rcx)74ret75ALIGN_TEXT76100816:77cmpb $8,%cl78jl 100408f79movq %r10,(%rdi)80movq %r10,-8(%rdi,%rcx)81ret82ALIGN_TEXT83100408:84cmpb $4,%cl85jl 100204f86movl %r10d,(%rdi)87movl %r10d,-4(%rdi,%rcx)88ret89ALIGN_TEXT90100204:91cmpb $2,%cl92jl 100001f93movw %r10w,(%rdi)94movw %r10w,-2(%rdi,%rcx)95ret96ALIGN_TEXT97100001:98cmpb $0,%cl99je 100000f100movb %r10b,(%rdi)101100000:102ret103ALIGN_TEXT1041256:105movq %rdi,%r9106movq %r10,%rax107testl $15,%edi108jnz 3f1091:110.if \erms == 1111rep112stosb113movq %r9,%rax114.else115movq %rcx,%rdx116shrq $3,%rcx117rep118stosq119movq %r9,%rax120andl $7,%edx121jnz 2f122ret1232:124movq %r10,-8(%rdi,%rdx)125.endif126ret127ALIGN_TEXT1283:129movq %r10,(%rdi)130movq %r10,8(%rdi)131movq %rdi,%r8132andq $15,%r8133leaq -16(%rcx,%r8),%rcx134neg %r8135leaq 16(%rdi,%r8),%rdi136jmp 1b137.endm138139140ENTRY(memset)141MEMSET erms=0142END(memset)143144.section .note.GNU-stack,"",%progbits145146147