From owner-svn-src-head@freebsd.org Mon May 7 19:05:15 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EF379FB9BD3 for ; Mon, 7 May 2018 19:05:14 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: from mail-yb0-x243.google.com (mail-yb0-x243.google.com [IPv6:2607:f8b0:4002:c09::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7B1B76FDBA for ; Mon, 7 May 2018 19:05:14 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: by mail-yb0-x243.google.com with SMTP id v12-v6so1332277ybl.10 for ; Mon, 07 May 2018 12:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=qEUUokfFjZWRfEbxLyU40ZAscVaU9TjavJqPF8EQOzo=; b=m8mPrPBal3b3kDZNj71WEqZcsNljlsaZrspxQYAXsNeZP0cjQMDLnrySqrB7VxORpS LJZtsnRMWVW8DIxzNCKR0mm9JHryCRsEQo1dEBHqtNyZadoyNUXHyPQ0IxUH6hkHsxwQ OxupPXejwCtf821bMlqD73vWSSa7bKZOZqmZ2+vBgHp6TkLbA7M2LyigqpM1uDZO2gUN ZvXc696s1VO/XPk70sJ0e0z/VG8A3zJNJG/Yepk8LlQ2I9lCAsHe0Z+JUYxNXFGRwg4I GwaTgkmGBlaJk1/+K4ri8PLPHy5nVRYQIouyg82hYlqMRhFED7b6bBwoZOp7NnfkqIU5 cUew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=qEUUokfFjZWRfEbxLyU40ZAscVaU9TjavJqPF8EQOzo=; b=hcjd3nc0gvjnk1GXSc2ld6ija5mxOFEZFA7H4kEdRPbHs884aJ2xqIbd5V0Yf/QuCo muY+pp0QNIIJ5nFmg3GmMBFHCllw5BHO7gLY89iyckPPwUy3KPQflsyyQOpWBRQQNksY dUbRsH1gUn4lWZGyeQNGPAYz/cmgar52aeZmqhAnC8j2lBxLdbgGeshidFTdHx9rq3HB DQPoQ4wK57ic7jtL3lNz+jdDk6NC5Qb4BXVtdT1TcCW/kKfGjoCIWD9+bn1EgcdxJKCn 2qj0GMKk22lchmZQ2wp9Hig90Crf5ZnoMHw81k1036a07ZMXf7ddl7/ob6TWz51Au1Ne Bfeg== X-Gm-Message-State: ALKqPwfqpFIElR3PKPQb8jNcBtLo4dUfTQR5gXHTMPcg0GngyEu1pTiv MkAHKTCLodP+CU+s8v0pI5PopxPVB4qcTH++4DaqVA== X-Google-Smtp-Source: AB8JxZohNaFbRwk/w9Bxwr3TuqFun00IVbWc1D5Hw842rUHj88yg2VtcVW4J2gfbDG7LEncfvfeGpTAXGX+n+XNaaIU= X-Received: by 2002:a25:6d03:: with SMTP id i3-v6mr5023630ybc.348.1525719913969; Mon, 07 May 2018 12:05:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:3894:0:0:0:0:0 with HTTP; Mon, 7 May 2018 12:05:13 -0700 (PDT) In-Reply-To: References: <201805071507.w47F7SOs035073@repo.freebsd.org> From: Oliver Pinter Date: Mon, 7 May 2018 21:05:13 +0200 Message-ID: Subject: Re: svn commit: r333324 - in head/sys: amd64/amd64 conf To: Mateusz Guzik Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 May 2018 19:05:15 -0000 On 5/7/18, Oliver Pinter wrote: > On 5/7/18, Mateusz Guzik wrote: >> Author: mjg >> Date: Mon May 7 15:07:28 2018 >> New Revision: 333324 >> URL: https://svnweb.freebsd.org/changeset/base/333324 >> >> Log: >> amd64: replace libkern's memset and memmove with assembly variants >> >> memmove is repurposed bcopy (arguments swapped, return value added) >> The libkern variant is a wrapper around bcopy, so this is a big >> improvement. >> >> memset is repurposed memcpy. The librkern variant is doing fishy stuff, >> including branching on 0 and calling bzero. >> >> Both functions are rather crude and subject to partial depessimization. >> >> This is a soft prerequisite to adding variants utilizing the >> 'Enhanced REP MOVSB/STOSB' bit and let the kernel patch at runtime. >> >> Modified: >> head/sys/amd64/amd64/support.S >> head/sys/conf/files.amd64 >> >> Modified: head/sys/amd64/amd64/support.S >> ============================================================================== >> --- head/sys/amd64/amd64/support.S Mon May 7 15:07:26 2018 (r333323) >> +++ head/sys/amd64/amd64/support.S Mon May 7 15:07:28 2018 (r333324) >> @@ -162,6 +162,58 @@ ENTRY(bcopy) >> END(bcopy) >> >> /* >> + * memmove(dst, src, cnt) >> + * rdi, rsi, rdx >> + * Original by: >> + * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 >> + */ >> +ENTRY(memmove) >> + PUSH_FRAME_POINTER >> + movq %rdi,%r9 >> + movq %rdx,%rcx >> + >> + movq %rdi,%rax >> + subq %rsi,%rax >> + cmpq %rcx,%rax /* overlapping && src < dst? */ >> + jb 1f >> + >> + shrq $3,%rcx /* copy by 64-bit words */ >> + rep >> + movsq >> + movq %rdx,%rcx >> + andq $7,%rcx /* any bytes left? */ >> + rep >> + movsb >> + movq %r9,%rax >> + POP_FRAME_POINTER >> + ret >> + >> + /* ALIGN_TEXT */ >> +1: >> + addq %rcx,%rdi /* copy backwards */ >> + addq %rcx,%rsi >> + decq %rdi >> + decq %rsi >> + andq $7,%rcx /* any fractional bytes? */ >> + std >> + rep >> + movsb >> + movq %rdx,%rcx /* copy remainder by 32-bit words */ >> + shrq $3,%rcx >> + subq $7,%rsi >> + subq $7,%rdi >> + rep >> + movsq >> + cld >> + movq %r9,%rax >> + POP_FRAME_POINTER >> + ret >> +END(memmove) >> + >> +/* >> + * memcpy(dst, src, len) >> + * rdi, rsi, rdx >> + * >> * Note: memcpy does not support overlapping copies >> */ >> ENTRY(memcpy) >> @@ -178,6 +230,27 @@ ENTRY(memcpy) >> POP_FRAME_POINTER >> ret >> END(memcpy) >> + >> +/* >> + * memset(dst, c, len) >> + * rdi, rsi, rdx >> + */ >> +ENTRY(memset) >> + PUSH_FRAME_POINTER >> + movq %rdi,%r9 >> + movq %rdx,%rcx >> + movq %rsi,%rax >> + shrq $3,%rcx >> + rep >> + stosq > > According to Intel SDM stosq stores the whole RAX into destination, > and then increments the destination register with 8. This > implementation is wrong, since the c is a char, and the The RAX looks > like 000000CC, so the stored patter would be 000000CC * SIZE / 8 * 8 + > CC * SIZE % 8 in destination buffer. Attached the proof. > >> + movq %rdx,%rcx >> + andq $7,%rcx >> + rep >> + stosb >> + movq %r9,%rax >> + POP_FRAME_POINTER >> + ret >> +END(memset) >> >> /* >> * pagecopy(%rdi=from, %rsi=to) >> >> Modified: head/sys/conf/files.amd64 >> ============================================================================== >> --- head/sys/conf/files.amd64 Mon May 7 15:07:26 2018 (r333323) >> +++ head/sys/conf/files.amd64 Mon May 7 15:07:28 2018 (r333324) >> @@ -620,8 +620,6 @@ isa/vga_isa.c optional vga >> kern/kern_clocksource.c standard >> kern/link_elf_obj.c standard >> libkern/x86/crc32_sse42.c standard >> -libkern/memmove.c standard >> -libkern/memset.c standard >> # >> # IA32 binary support >> # >> _______________________________________________ >> svn-src-head@freebsd.org mailing list >> https://lists.freebsd.org/mailman/listinfo/svn-src-head >> To unsubscribe, send any mail to "svn-src-head-unsubscribe@freebsd.org" >> >