From nobody Tue Jul 04 17:46:16 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QwVbB03DXz4lLNp for ; Tue, 4 Jul 2023 17:46:30 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QwVb95km4z3r7R for ; Tue, 4 Jul 2023 17:46:29 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-3fbc244d386so64306865e9.2 for ; Tue, 04 Jul 2023 10:46:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688492788; x=1691084788; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lD1hE0TiWoEGoQcNBUDh+f9AD1z7SpbkOQhN7WOJYYA=; b=EqKOkOC3A8zqfYkYq+vaR1c14pNKIt18L+Wan4nN/j6GVCecQfyJ7dwpwpUIDXBxb3 GDjEmzk5A3B3WBTa+EKfecggkuz/8phJjxtENHwGj87cf6aWXL+1gu6HVRA2aT9aBiw4 1eWLHulsApIU8XRN6GND+3KbQQmG9KOhpCyrwqiK5KW0j384XVv98ARNh417Fxlt1D+q 24Xg1RsHwLasBgmK770Z/ChJtxgmZghx+bIQK7TxOZ7+WEcohR7x40Z/ISjWWSW8uJ6N bU8duJlFzsrX2u6TRD8Y/2Bh01aeEpBlx9eWcTV7BAbVV/4KqWBYP4wQ+TQPVpnngm1W /YUg== X-Gm-Message-State: ABy/qLbXtOYkwzum4MZ3/k7Z2NgilV38ZFKwni3q0MxHMrbySvh9wp3R /GndKYKh/4arpudF0RHIvWUQ5A== X-Google-Smtp-Source: APBJJlH/lg4oTSZbHAKPN8rwOR56sbPzFQ7heIkgJJwm526RXVKLXK+YgdRFG1edBknUKdndhVUQew== X-Received: by 2002:a05:600c:2059:b0:3fb:d1db:545a with SMTP id p25-20020a05600c205900b003fbd1db545amr7934769wmg.15.1688492787580; Tue, 04 Jul 2023 10:46:27 -0700 (PDT) Received: from smtpclient.apple ([131.111.5.246]) by smtp.gmail.com with ESMTPSA id p8-20020a7bcc88000000b003fb225d414fsm24327367wma.21.2023.07.04.10.46.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jul 2023 10:46:26 -0700 (PDT) Content-Type: text/plain; charset=us-ascii List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: Re: git: ee8b0c436d72 - main - lib/libc/string: replace ffs/fls implementations with clang builtins: cc: error: no such file or directory: '/usr/src/lib/libc/i386/string/ffs.S' From: Jessica Clarke In-Reply-To: <20230704193224.392af7f9@thor.intern.walstatt.dynvpn.de> Date: Tue, 4 Jul 2023 18:46:16 +0100 Cc: Robert Clausecker , "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: <202307032023.363KNhu6031914@gitrepo.freebsd.org> <20230704193224.392af7f9@thor.intern.walstatt.dynvpn.de> To: FreeBSD User X-Mailer: Apple Mail (2.3731.600.7) X-Rspamd-Queue-Id: 4QwVb95km4z3r7R X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 4 Jul 2023, at 18:31, FreeBSD User wrote: >=20 > Am Mon, 3 Jul 2023 20:23:43 GMT > Robert Clausecker schrieb: >=20 > This commit seems to break buildworld: >=20 > [...] >=20 > cc -DCOMPAT_32BIT -march=3Di686 -mmmx -msse -msse2 -target = x86_64-unknown-freebsd14.0 -m32 > --sysroot=3D/usr/obj/usr/src/amd64.amd64/tmp = -B/usr/obj/usr/src/amd64.amd64/tmp/usr/bin > -B/usr/obj/usr/src/amd64.amd64/tmp/usr/lib32 -fpic -DPIC -O2 -pipe -O3 = -fno-common > -DNO__SCCSID -DNO__RCSID -I/usr/src/lib/libc/include = -I/usr/src/include > -I/usr/src/lib/libc/i386 -DNLS -ftls-model=3Dinitial-exec = -DCRT_IRELOC_REL > -DINIT_IRELOCS=3D"init_cpu_features()" -I/usr/src/lib/libc/csu/i386 = -D__DBINTERFACE_PRIVATE > -I/usr/src/contrib/gdtoa -I/usr/src/contrib/libc-vis -DINET6 > -I/usr/obj/usr/src/amd64.amd64/obj-lib32/lib/libc = -I/usr/src/lib/libc/resolv -D_ACL_PRIVATE > -DPOSIX_MISTAKE -I/usr/src/lib/libmd = -I/usr/src/contrib/jemalloc/include -DMALLOC_PRODUCTION > -I/usr/src/lib/libc/locale -DBROKEN_DES -DPORTMAP -DDES_BUILTIN = -I/usr/src/lib/libc/rpc -DYP > -DNS_CACHING -DSYMBOL_VERSIONING -DNDEBUG -MD -MF.depend.ffs.pico = -MTffs.pico -std=3Dgnu99 > -Wno-format-zero-length -fstack-protector-strong -Wsystem-headers = -Wall -Wno-format-y2k > -Wno-uninit--- ffs.nossppico --- cc -DCOMPAT_32BIT -march=3Di686 -mmmx = -msse -msse2 -target > x86_64-unknown-freebsd14.0 -m32 = --sysroot=3D/usr/obj/usr/src/amd64.amd64/tmp > -B/usr/obj/usr/src/amd64.amd64/tmp/usr/bin = -B/usr/obj/usr/src/amd64.amd64/tmp/usr/lib32 -fpic > -DPIC -O2 -pipe -O3 -fno-common -DNO__SCCSID -DNO__RCSID = -I/usr/src/lib/libc/include > -I/usr/src/include -I/usr/src/lib/libc/i386 -DNLS = -ftls-model=3Dinitial-exec -DCRT_IRELOC_REL > -DINIT_IRELOCS=3D"init_cpu_features()" -I/usr/src/lib/libc/csu/i386 = -D__DBINTERFACE_PRIVATE > -I/usr/src/contrib/gdtoa -I/usr/src/contrib/libc-vis -DINET6 > -I/usr/obj/usr/src/amd64.amd64/obj-lib32/lib/libc = -I/usr/src/lib/libc/resolv -D_ACL_PRIVATE > -DPOSIX_MISTAKE -I/usr/src/lib/libmd = -I/usr/src/contrib/jemalloc/include -DMALLOC_PRODUCTION > -I/usr/src/lib/libc/locale -DBROKEN_DES -DPORTMAP -DDES_BUILTIN = -I/usr/src/lib/libc/rpc -DYP > -DNS_CACHING -DSYMBOL_VERSIONING -DNDEBUG -MD -MF.depend.ffs.nossppico = -MTffs.nossppico > -std=3Dgnu99 -Wno-format-zero-length -Wsystem-headers -Wall = -Wno-format-y2k -Wno-uninitialized > -Wno-pointe--- ffsl.nossppico --- cc -DCOMPAT_32BIT -march=3Di686 = -mmmx -msse -msse2 -target > x86_64-unknown-freebsd14.0 -m32 = --sysroot=3D/usr/obj/usr/src/amd64.amd64/tmp > -B/usr/obj/usr/src/amd64.amd64/tmp/usr/bin = -B/usr/obj/usr/src/amd64.amd64/tmp/usr/lib32 -fpic > -DPIC -O2 -pipe -O3 -fno-common -DNO__SCCSID -DNO__RCSID = -I/usr/src/lib/libc/include > -I/usr/src/include -I/usr/src/lib/libc/i386 -DNLS = -ftls-model=3Dinitial-exec -DCRT_IRELOC_REL > -DINIT_IRELOCS=3D"init_cpu_features()" -I/usr/src/lib/libc/csu/i386 = -D__DBINTERFACE_PRIVATE > -I/usr/src/contrib/gdtoa -I/usr/src/contrib/libc-vis -DINET6 > -I/usr/obj/usr/src/amd64.amd64/obj-lib32/lib/libc = -I/usr/src/lib/libc/resolv -D_ACL_PRIVATE > -DPOSIX_MISTAKE -I/usr/src/lib/libmd = -I/usr/src/contrib/jemalloc/include -DMALLOC_PRODUCTION > -I/usr/src/lib/libc/locale -DBROKEN_DES -DPORTMAP -DDES_BUILTIN = -I/usr/src/lib/libc/rpc -DYP > -DNS_CACHING -DSYMBOL_VERSIONING -DNDEBUG -MD = -MF.depend.ffsl.nossppico -MTffsl.nossppico > -std=3Dgnu99 -Wno-format-zero-length -Wsystem-headers -Wall = -Wno-format-y2k -Wno-uninitialized > -Wno-p--- ffs.pico --- ialized -Wno-pointer-sign -Wdate-time = -Wno-empty-body > -Wno-string-plus-int -Wno-unused-const-variable = -Wno-error=3Dunused-but-set-parameter > -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality = -Wno-unused-function > -Wno-enum-conversion -Wno-unused-local-typedef = -Wno-address-of-packed-member -Wno-switch > -Wno-switch-enum -Wno-knr-promoted-parameter -Qunused-arguments = -I/usr/src/lib/libutil > -I/usr/src/lib/msun/i387 -I/usr/src/lib/msun/x86 = -I/usr/src/lib/msun/src -c > /usr/src/lib/libc/i386/string/ffs.S -o ffs.pico cc: error: no such = file or directory: > '/usr/src/lib/libc/i386/string/ffs.S' cc: error: no input files >=20 > [...] > --- ffs.pico --- > *** [ffs.pico] Error code 1 >=20 > make[4]: stopped in /usr/src/lib/libc > --- ffs.nossppico --- > cc: error: no such file or directory: = '/usr/src/lib/libc/i386/string/ffs.S' > cc: error: no input files > *** [ffs.nossppico] Error code 1 > [...] That looks like a missing depends cleanup (needed for arm and i386). I assume this is a -DWITHOUT_CLEAN (-DNO_CLEAN) build? Jess >> The branch main has been updated by fuz: >>=20 >> URL: = https://cgit.FreeBSD.org/src/commit/?id=3Dee8b0c436d7221c25e8be3c3fe1f9da7= 8b9d5b16 >>=20 >> commit ee8b0c436d7221c25e8be3c3fe1f9da78b9d5b16 >> Author: Robert Clausecker >> AuthorDate: 2023-06-23 16:22:54 +0000 >> Commit: Robert Clausecker >> CommitDate: 2023-07-03 20:18:27 +0000 >>=20 >> lib/libc/string: replace ffs/fls implementations with clang = builtins >>=20 >> Most architectures we support (except for riscv64) have = instructions >> to compute these functions very quickly. Replace old code with = the >> ffs and clz builtin functions, allowing clang to generate good = code >> for all architectures. >>=20 >> As a consequence, toss out arm and i386 ffs() implementations. >>=20 >> Sponsored by: FreeBSD Foundation >> Approved by: mhorne >> MFC after: 1 week >> Differential Revision: https://reviews.freebsd.org/D40730 >> --- >> lib/libc/arm/string/Makefile.inc | 1 - >> lib/libc/arm/string/ffs.S | 57 = --------------------------------------- >> lib/libc/i386/string/Makefile.inc | 1 - >> lib/libc/i386/string/ffs.S | 56 = -------------------------------------- >> lib/libc/string/ffs.c | 12 ++++----- >> lib/libc/string/ffsl.c | 12 ++++----- >> lib/libc/string/ffsll.c | 12 ++++----- >> lib/libc/string/fls.c | 13 +++++---- >> lib/libc/string/flsl.c | 14 +++++----- >> lib/libc/string/flsll.c | 13 +++++---- >> 10 files changed, 34 insertions(+), 157 deletions(-) >>=20 >> diff --git a/lib/libc/arm/string/Makefile.inc = b/lib/libc/arm/string/Makefile.inc >> index cf3175ea4e8c..550de34adb0e 100644 >> --- a/lib/libc/arm/string/Makefile.inc >> +++ b/lib/libc/arm/string/Makefile.inc >> @@ -3,7 +3,6 @@ >> MDSRCS+=3D \ >> bcopy.S \ >> bzero.S \ >> - ffs.S \ >> memcmp.S \ >> memcpy.S \ >> memmove.S \ >> diff --git a/lib/libc/arm/string/ffs.S b/lib/libc/arm/string/ffs.S >> deleted file mode 100644 >> index 5756dd81d21d..000000000000 >> --- a/lib/libc/arm/string/ffs.S >> +++ /dev/null >> @@ -1,57 +0,0 @@ >> -/* $NetBSD: ffs.S,v 1.5 2003/04/05 23:08:52 bjh21 Exp $ */ >> -/* >> - * Copyright (c) 2001 Christopher Gilbert >> - * All rights reserved. >> - * >> - * Redistribution and use in source and binary forms, with or = without >> - * modification, are permitted provided that the following = conditions >> - * are met: >> - * 1. Redistributions of source code must retain the above copyright >> - * notice, this list of conditions and the following disclaimer. >> - * 2. Redistributions in binary form must reproduce the above = copyright >> - * notice, this list of conditions and the following disclaimer = in the >> - * documentation and/or other materials provided with the = distribution. >> - * 3. The name of the company nor the name of the author may be used = to >> - * endorse or promote products derived from this software without = specific >> - * prior written permission. >> - * >> - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS = OR >> - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED = WARRANTIES >> - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE = DISCLAIMED. >> - * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY = DIRECT, >> - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL = DAMAGES >> - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS = OR >> - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS = INTERRUPTION) >> - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN = CONTRACT, STRICT >> - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN = ANY WAY >> - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE = POSSIBILITY OF >> - * SUCH DAMAGE. >> - */ >> - >> -#include >> - >> -__FBSDID("$FreeBSD$"); >> - >> -.syntax unified >> - >> -/* >> - * ffs - find first set bit, this algorithm isolates the first set >> - * bit, then multiplies the number by 0x0450fbaf which leaves the = top >> - * 6 bits as an index into the table. This algorithm should be a = win >> - * over the checking each bit in turn as per the C compiled version. >> - * >> - * This is the ffs algorithm devised by d.seal and posted to = comp.sys.arm on >> - * 16 Feb 1994. >> - */ >> - >> -ENTRY(ffs) >> - /* Standard trick to isolate bottom bit in r0 or 0 if r0 =3D 0 on = entry */ >> - rsb r1, r0, #0 >> - ands r0, r0, r1 >> - itt ne >> - clzne r0, r0 >> - rsbne r0, r0, #32 >> - RET >> -END(ffs) >> - >> - .section .note.GNU-stack,"",%progbits >> diff --git a/lib/libc/i386/string/Makefile.inc = b/lib/libc/i386/string/Makefile.inc >> index a8c50a285cbd..f3678b93bec3 100644 >> --- a/lib/libc/i386/string/Makefile.inc >> +++ b/lib/libc/i386/string/Makefile.inc >> @@ -4,7 +4,6 @@ MDSRCS+=3D \ >> bcmp.S \ >> bcopy.S \ >> bzero.S \ >> - ffs.S \ >> memcmp.S \ >> memcpy.S \ >> memmove.S \ >> diff --git a/lib/libc/i386/string/ffs.S b/lib/libc/i386/string/ffs.S >> deleted file mode 100644 >> index 3a0431c6a845..000000000000 >> --- a/lib/libc/i386/string/ffs.S >> +++ /dev/null >> @@ -1,56 +0,0 @@ >> -/* >> - * Copyright (c) 1993 Winning Strategies, Inc. >> - * All rights reserved. >> - * >> - * Redistribution and use in source and binary forms, with or = without >> - * modification, are permitted provided that the following = conditions >> - * are met: >> - * 1. Redistributions of source code must retain the above copyright >> - * notice, this list of conditions and the following disclaimer. >> - * 2. Redistributions in binary form must reproduce the above = copyright >> - * notice, this list of conditions and the following disclaimer = in the >> - * documentation and/or other materials provided with the = distribution. >> - * 3. All advertising materials mentioning features or use of this = software >> - * must display the following acknowledgement: >> - * This product includes software developed by Winning = Strategies, Inc. >> - * 4. The name of the author may not be used to endorse or promote = products >> - * derived from this software without specific prior written = permission >> - * >> - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS = OR >> - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED = WARRANTIES >> - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE = DISCLAIMED. >> - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, >> - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES = (INCLUDING, BUT >> - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS = OF USE, >> - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON = ANY >> - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR = TORT >> - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE = USE OF >> - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >> - */ >> - >> -#include >> -__FBSDID("$FreeBSD$"); >> - >> -/* >> - * ffs(value) >> - * finds the first bit set in value and returns the index of=20 >> - * that bit. Bits are numbered starting from 1, starting at the >> - * rightmost bit. A return value of 0 means that the argument >> - * was zero. >> - * >> - * Written by: >> - * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. >> - */ >> - >> -ENTRY(ffs) >> - bsfl 4(%esp),%eax >> - jz L1 /* ZF is set if all bits are 0 */ >> - incl %eax /* bits numbered from 1, not 0 */ >> - ret >> - >> - .align 2 >> -L1: xorl %eax,%eax /* clear result */ >> - ret >> -END(ffs) >> - >> - .section .note.GNU-stack,"",%progbits >> diff --git a/lib/libc/string/ffs.c b/lib/libc/string/ffs.c >> index 738ef90ce091..c011b3390612 100644 >> --- a/lib/libc/string/ffs.c >> +++ b/lib/libc/string/ffs.c >> @@ -3,6 +3,10 @@ >> * >> * Copyright (c) 1990, 1993 >> * The Regents of the University of California. All rights reserved. >> + * Copyright (c) 2023 The FreeBSD Foundation >> + * >> + * Portions of this software were developed by Robert Clausecker >> + * under sponsorship from the FreeBSD Foundation. >> * >> * Redistribution and use in source and binary forms, with or without >> * modification, are permitted provided that the following conditions >> @@ -43,11 +47,5 @@ __FBSDID("$FreeBSD$"); >> int >> ffs(int mask) >> { >> - int bit; >> - >> - if (mask =3D=3D 0) >> - return(0); >> - for (bit =3D 1; !(mask & 1); bit++) >> - mask =3D (unsigned int)mask >> 1; >> - return (bit); >> + return (__builtin_ffs(mask)); >> } >> diff --git a/lib/libc/string/ffsl.c b/lib/libc/string/ffsl.c >> index dbd894b9655b..6e1ac8ec45c1 100644 >> --- a/lib/libc/string/ffsl.c >> +++ b/lib/libc/string/ffsl.c >> @@ -3,6 +3,10 @@ >> * >> * Copyright (c) 1990, 1993 >> * The Regents of the University of California. All rights reserved. >> + * Copyright (c) 2023 The FreeBSD Foundation >> + * >> + * Portions of this software were developed by Robert Clausecker >> + * under sponsorship from the FreeBSD Foundation. >> * >> * Redistribution and use in source and binary forms, with or without >> * modification, are permitted provided that the following conditions >> @@ -40,11 +44,5 @@ __FBSDID("$FreeBSD$"); >> int >> ffsl(long mask) >> { >> - int bit; >> - >> - if (mask =3D=3D 0) >> - return (0); >> - for (bit =3D 1; !(mask & 1); bit++) >> - mask =3D (unsigned long)mask >> 1; >> - return (bit); >> + return (__builtin_ffsl(mask)); >> } >> diff --git a/lib/libc/string/ffsll.c b/lib/libc/string/ffsll.c >> index 91886de2f127..b945658b9008 100644 >> --- a/lib/libc/string/ffsll.c >> +++ b/lib/libc/string/ffsll.c >> @@ -3,6 +3,10 @@ >> * >> * Copyright (c) 1990, 1993 >> * The Regents of the University of California. All rights reserved. >> + * Copyright (c) 2023 The FreeBSD Foundation >> + * >> + * Portions of this software were developed by Robert Clausecker >> + * under sponsorship from the FreeBSD Foundation. >> * >> * Redistribution and use in source and binary forms, with or without >> * modification, are permitted provided that the following conditions >> @@ -40,11 +44,5 @@ __FBSDID("$FreeBSD$"); >> int >> ffsll(long long mask) >> { >> - int bit; >> - >> - if (mask =3D=3D 0) >> - return (0); >> - for (bit =3D 1; !(mask & 1); bit++) >> - mask =3D (unsigned long long)mask >> 1; >> - return (bit); >> + return (__builtin_ffsll(mask)); >> } >> diff --git a/lib/libc/string/fls.c b/lib/libc/string/fls.c >> index d9edc41f9599..3c4719776778 100644 >> --- a/lib/libc/string/fls.c >> +++ b/lib/libc/string/fls.c >> @@ -3,6 +3,10 @@ >> * >> * Copyright (c) 1990, 1993 >> * The Regents of the University of California. All rights reserved. >> + * Copyright (c) 2023 The FreeBSD Foundation >> + * >> + * Portions of this software were developed by Robert Clausecker >> + * under sponsorship from the FreeBSD Foundation. >> * >> * Redistribution and use in source and binary forms, with or without >> * modification, are permitted provided that the following conditions >> @@ -32,6 +36,7 @@ >> #include >> __FBSDID("$FreeBSD$"); >>=20 >> +#include >> #include >>=20 >> /* >> @@ -40,11 +45,5 @@ __FBSDID("$FreeBSD$"); >> int >> fls(int mask) >> { >> - int bit; >> - >> - if (mask =3D=3D 0) >> - return (0); >> - for (bit =3D 1; mask !=3D 1; bit++) >> - mask =3D (unsigned int)mask >> 1; >> - return (bit); >> + return (mask =3D=3D 0 ? 0 : CHAR_BIT * sizeof(mask) - = __builtin_clz(mask)); >> } >> diff --git a/lib/libc/string/flsl.c b/lib/libc/string/flsl.c >> index 60370cf7d832..f5280b77a4e2 100644 >> --- a/lib/libc/string/flsl.c >> +++ b/lib/libc/string/flsl.c >> @@ -3,6 +3,11 @@ >> * >> * Copyright (c) 1990, 1993 >> * The Regents of the University of California. All rights reserved. >> + * Copyright (c) 2023 The FreeBSD Foundation >> + >> + * >> + * Portions of this software were developed by Robert Clausecker >> + * under sponsorship from the FreeBSD Foundation. >> * >> * Redistribution and use in source and binary forms, with or without >> * modification, are permitted provided that the following conditions >> @@ -32,6 +37,7 @@ >> #include >> __FBSDID("$FreeBSD$"); >>=20 >> +#include >> #include >>=20 >> /* >> @@ -40,11 +46,5 @@ __FBSDID("$FreeBSD$"); >> int >> flsl(long mask) >> { >> - int bit; >> - >> - if (mask =3D=3D 0) >> - return (0); >> - for (bit =3D 1; mask !=3D 1; bit++) >> - mask =3D (unsigned long)mask >> 1; >> - return (bit); >> + return (mask =3D=3D 0 ? 0 : CHAR_BIT * sizeof(mask) - = __builtin_clzl(mask)); >> } >> diff --git a/lib/libc/string/flsll.c b/lib/libc/string/flsll.c >> index 275aaa0e2e15..ab504b8e592f 100644 >> --- a/lib/libc/string/flsll.c >> +++ b/lib/libc/string/flsll.c >> @@ -3,6 +3,10 @@ >> * >> * Copyright (c) 1990, 1993 >> * The Regents of the University of California. All rights reserved. >> + * Copyright (c) 2023 The FreeBSD Foundation >> + * >> + * Portions of this software were developed by Robert Clausecker >> + * under sponsorship from the FreeBSD Foundation. >> * >> * Redistribution and use in source and binary forms, with or without >> * modification, are permitted provided that the following conditions >> @@ -32,6 +36,7 @@ >> #include >> __FBSDID("$FreeBSD$"); >>=20 >> +#include >> #include >>=20 >> /* >> @@ -40,11 +45,5 @@ __FBSDID("$FreeBSD$"); >> int >> flsll(long long mask) >> { >> - int bit; >> - >> - if (mask =3D=3D 0) >> - return (0); >> - for (bit =3D 1; mask !=3D 1; bit++) >> - mask =3D (unsigned long long)mask >> 1; >> - return (bit); >> + return (mask =3D=3D 0 ? 0 : CHAR_BIT * sizeof(mask) - = __builtin_clzll(mask)); >> } >>=20 >=20 >=20 >=20 > --=20 > O. Hartmann Jess