From owner-svn-src-all@freebsd.org Wed Jan 10 18:39:30 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 67749E6E22A; Wed, 10 Jan 2018 18:39:30 +0000 (UTC) (envelope-from rpokala@mac.com) Received: from mr11p00im-asmtp003.me.com (mr11p00im-asmtp003.me.com [17.110.69.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4AA8F38D; Wed, 10 Jan 2018 18:39:30 +0000 (UTC) (envelope-from rpokala@mac.com) Received: from process-dkim-sign-daemon.mr11p00im-asmtp003.me.com by mr11p00im-asmtp003.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0P2C00G00QVKBL00@mr11p00im-asmtp003.me.com>; Wed, 10 Jan 2018 18:39:01 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mac.com; s=04042017; t=1515609541; bh=3tLPCJRupHM6ks8p1T2ZVR5d++6JU5a/P9MxrP7Y+gI=; h=Date:Subject:From:To:Message-id:MIME-version:Content-type; b=xaUmMNwch76I3xTWPzyrepfxjm0ENzSgO8UBoatsc/IscwhvyCqb+eFSUi37MmbO3 958hcefSXKz6GsxIAv75YfryiG2OrHmI5i8GLHPNuR0xluyfbbJ/n/FPfW8IiXhNO1 QxmEaSegr+tXOOTJRWZpixGAITvzhIysBmHqHoYhFeaDKIN1x4Bi/0BKuyQaDldVje v5oCYmnxDRnt6/2FjTNT1jQwNJVrNC9rux/4SLDPVBstdhzJxJhTyMpIivLm87K1ce 11VPFBjjnv2Rz32gAAJbn9IlwVlA4qCUfgeeZxTBO7BinF2BhrfNTGgHz9e5nc9QoL PakW5NlONa6IQ== Received: from icloud.com ([127.0.0.1]) by mr11p00im-asmtp003.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTPSA id <0P2C009E7RSYRY30@mr11p00im-asmtp003.me.com>; Wed, 10 Jan 2018 18:39:00 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-10_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1015 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1801100260 User-Agent: Microsoft-MacOutlook/f.29.0.171205 Date: Wed, 10 Jan 2018 10:38:58 -0800 Subject: Re: svn commit: r327763 - in head/sys: conf contrib/zstd/lib/freebsd From: Ravi Pokala To: Conrad Meyer , John Baldwin , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Message-id: <042A7C15-5EEA-497C-AF81-4F9960FE988A@mac.com> Thread-topic: svn commit: r327763 - in head/sys: conf contrib/zstd/lib/freebsd References: <201801100630.w0A6UxLT041383@repo.freebsd.org> In-reply-to: MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 7bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jan 2018 18:39:30 -0000 Ah, it looks like r327776 fixed this. Thanks John! -Ravi (rpokala@) -----Original Message----- From: on behalf of Ravi Pokala Date: 2018-01-10, Wednesday at 08:51 To: Conrad Meyer , , , Subject: Re: svn commit: r327763 - in head/sys: conf contrib/zstd/lib/freebsd Hi Conrad, Alas, this still doesn't look right on RISC-V: zstd_kfreebsd.o: In function `__ctzdi2': /usr/home/rpokala/freebsd/clean/base/head/sys/contrib/zstd/lib/freebsd/zstd_kfreebsd.c:58: undefined reference to `ffsll' I got substantively the same error both before and after `pkg upgrade' brought in updated RISC-V stuff: riscv64-binutils (2.29.51.20170726 -> 2.29_20180105,1) riscv64-gcc (7.1.1 -> 7.2.0) Thanks, Ravi (rpokala@) -----Original Message----- From: on behalf of Conrad Meyer Date: 2018-01-09, Tuesday at 22:30 To: , , Subject: svn commit: r327763 - in head/sys: conf contrib/zstd/lib/freebsd Author: cem Date: Wed Jan 10 06:30:59 2018 New Revision: 327763 URL: https://svnweb.freebsd.org/changeset/base/327763 Log: Finally, fix Zstd kernel build on MIPS and RISC-V Add an implementation of the intrinsics invoked by __builtin_ctz{,ll} and __builtin_clz{,ll}, and include this compilation unit on platforms that lack assembly intrinsics for those builtins (MIPS and RISC-V). Future cleanup work might involve bringing these into a mini libcompiler-rt for the standalone kernel environment. Or cleaning up the approach upstream takes for builtins in standalone environments (or just FreeBSD). For now, at least this builds, and doesn't require modifying the vendor code. Reported by: jeff, markj, mizhka Reviewed by: jhb (earlier version), rpokala (comment text earlier version) Sponsored by: Dell EMC Isilon Added: head/sys/contrib/zstd/lib/freebsd/zstd_kfreebsd.c (contents, props changed) Modified: head/sys/conf/files.mips head/sys/conf/files.riscv Modified: head/sys/conf/files.mips ============================================================================== --- head/sys/conf/files.mips Wed Jan 10 05:52:24 2018 (r327762) +++ head/sys/conf/files.mips Wed Jan 10 06:30:59 2018 (r327763) @@ -112,3 +112,6 @@ cddl/compat/opensolaris/kern/opensolaris_atomic.c opti cddl/dev/dtrace/mips/dtrace_asm.S optional dtrace compile-with "${DTRACE_S}" cddl/dev/dtrace/mips/dtrace_subr.c optional dtrace compile-with "${DTRACE_C}" cddl/dev/fbt/mips/fbt_isa.c optional dtrace_fbt | dtraceall compile-with "${FBT_C}" + +# Zstd +contrib/zstd/lib/freebsd/zstd_kfreebsd.c standard compile-with ${ZSTD_C} Modified: head/sys/conf/files.riscv ============================================================================== --- head/sys/conf/files.riscv Wed Jan 10 05:52:24 2018 (r327762) +++ head/sys/conf/files.riscv Wed Jan 10 06:30:59 2018 (r327763) @@ -56,3 +56,6 @@ riscv/riscv/uio_machdep.c standard riscv/riscv/uma_machdep.c standard riscv/riscv/unwind.c optional ddb | kdtrace_hooks | stack riscv/riscv/vm_machdep.c standard + +# Zstd +contrib/zstd/lib/freebsd/zstd_kfreebsd.c standard compile-with ${ZSTD_C} Added: head/sys/contrib/zstd/lib/freebsd/zstd_kfreebsd.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/contrib/zstd/lib/freebsd/zstd_kfreebsd.c Wed Jan 10 06:30:59 2018 (r327763) @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2018 Conrad Meyer + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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. + * + * $FreeBSD$ + */ + +#include "zstd_kfreebsd.h" + +/* + * The kernel as a standalone target does not link against libgcc or + * libcompiler-rt. On platforms (e.g., MIPS and RISCV) that do not have a + * direct assembly implementation of the relevant builtin functions that zstd + * references, the compiler converts them into calls to the runtime library + * intrinsics. Since the kernel does not link against the runtime libraries, + * this results in a failure to link the kernel. + * + * The goal of the following definitions is to use supported kernel constructs + * to implement the same functionality, without adding diff to the Zstd contrib + * code. + * + * A subsequent enhancement might create a mini compiler-rt library for kernel + * use and move these over there instead. + */ + +/* Count trailing zeros */ +int +__ctzsi2(int x) +{ + if (x == 0) + return (sizeof(x) * NBBY); + return (ffs(x) - 1); +} + +long long +__ctzdi2(long long x) +{ + if (x == 0) + return (sizeof(x) * NBBY); + return (ffsll(x) - 1); +} + +/* Count leading zeros */ +int +__clzsi2(int x) +{ + return (sizeof(x) * NBBY - fls(x)); +} + +long long +__clzdi2(long long x) +{ + return (sizeof(x) * NBBY - flsll(x)); +}