From owner-svn-src-head@freebsd.org Wed May 9 15:16:26 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 5F886FC092E; Wed, 9 May 2018 15:16:26 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 140717C0F2; Wed, 9 May 2018 15:16:26 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E4C0A1332C; Wed, 9 May 2018 15:16:25 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w49FGPVP007532; Wed, 9 May 2018 15:16:25 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w49FGPhQ007531; Wed, 9 May 2018 15:16:25 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201805091516.w49FGPhQ007531@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Wed, 9 May 2018 15:16:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r333413 - head/sys/amd64/amd64 X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/amd64/amd64 X-SVN-Commit-Revision: 333413 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Wed, 09 May 2018 15:16:26 -0000 Author: mjg Date: Wed May 9 15:16:25 2018 New Revision: 333413 URL: https://svnweb.freebsd.org/changeset/base/333413 Log: amd64: depessimize bcmp for small buffers Adapt assembly generated by clang for memcmp and use it for <= 64 sized compares (which are the vast majority). Sample result of doing stats on Broadwell (% of samples): before: 4.0 kernel bcmp cache_lookup after : 0.7 kernel bcmp cache_lookup The routine is most definitely still not optimal. Anyone interested in spending time improving it is welcome to take over. Reviewed by: kib Modified: head/sys/amd64/amd64/support.S Modified: head/sys/amd64/amd64/support.S ============================================================================== --- head/sys/amd64/amd64/support.S Wed May 9 14:50:32 2018 (r333412) +++ head/sys/amd64/amd64/support.S Wed May 9 15:16:25 2018 (r333413) @@ -98,17 +98,40 @@ END(sse2_pagezero) ENTRY(bcmp) PUSH_FRAME_POINTER + test %rdx,%rdx + je 1f + cmpq $64,%rdx + jg 4f + + xor %ecx,%ecx +2: + movzbl (%rdi,%rcx,1),%eax + movzbl (%rsi,%rcx,1),%r8d + cmp %r8b,%al + jne 3f + add $0x1,%rcx + cmp %rcx,%rdx + jne 2b +1: + xor %eax,%eax + POP_FRAME_POINTER + retq +3: + mov $1,%eax + POP_FRAME_POINTER + retq +4: movq %rdx,%rcx shrq $3,%rcx repe cmpsq - jne 1f + jne 5f movq %rdx,%rcx andq $7,%rcx repe cmpsb -1: +5: setne %al movsbl %al,%eax POP_FRAME_POINTER