From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by mx.groups.io with SMTP id smtpd.web10.29950.1671474392906557011 for ; Mon, 19 Dec 2022 10:26:33 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=g2bLlzgY; spf=pass (domain: ventanamicro.com, ip: 209.85.208.43, mailfrom: tphan@ventanamicro.com) Received: by mail-ed1-f43.google.com with SMTP id z92so14180786ede.1 for ; Mon, 19 Dec 2022 10:26:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JN/ubwzQW/wh1sLqi+i6me0pESbHG16daDxQhroMSH0=; b=g2bLlzgYhFOcsd1HlfDJxpZ6SENudn4vw+HlL078RoQEhd05CDOda5HznBdMVjVCqX o0aSvmT6iOfXNWu/7F3C8S9uwAYAe4VyObIka03ZDOi2zrCdE+S56YI2j1xQnNCV1deE Iwr8XjrafXXLKPzUkqTl9E3RQ4Wqw03aPp2UKSnEze/m7YXuXkh/8cpGrdDon7Ar2TiZ olbLp4VVzsmCBWKGd31Ge3irl+As7Cuu4oSzbouohnGdYbCcaSFgq09Zh6BxprgDW7gf n0RPFOEpm9wxgtKYQ9g2pD226R6YRRAR1Sbsz++D+ndHx+uJPyrr/0ZRUym3UxXdO865 Mpfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JN/ubwzQW/wh1sLqi+i6me0pESbHG16daDxQhroMSH0=; b=QnxSnjUabfXQmiuO8GTLi4IdCNFE58NbyRETpKnN8hKgMJ5CWw3hVV+zvEQuW1aRNo +187jPTO+6yyS9DU+ZxtItgih7RQLeJSMAyIXqmYXHQAXdF6lNFBgIjq8tl0srJg/Kf4 NL1oMyEZFqQcjSFdkShgjzMuYCMcWnu//2KmXpjoZdVpCUHILuhzBm6+DBlPuPDzYhG2 BNZ3bvOyReba3jspz8OLIuMT2acbX8TsJHScLQ1MTE+jZEqz5ENun0DUX/Kx7B1zUmEU GEtg+uK9OG09YYDNy9ELttu37WiUSqpGDfCB7BNEbeA2ahDo0+wzZsJdo3ZKQS61snuf BwAQ== X-Gm-Message-State: ANoB5pm1oumTETm4DvzdFaXXF1Hqe/xN5cKhM7/iyer8N9pgHUme0I9S 5P5nnwHbCjUacEmCBvaUDK3OsbHlvpzWZxI3vLy8MA== X-Google-Smtp-Source: AA0mqf5DfxSB68vRPgtITAhNjq5vCpyZJx5pbyBu9UTK0mCXNjL/yH0Eu3BXlnYdEyIFvY+lrLlY0vq6VnkBjqWAQHU= X-Received: by 2002:aa7:cac2:0:b0:461:caa4:4ad3 with SMTP id l2-20020aa7cac2000000b00461caa44ad3mr52439424edt.392.1671474391225; Mon, 19 Dec 2022 10:26:31 -0800 (PST) MIME-Version: 1.0 References: <20221216184754.4381-1-tphan@ventanamicro.com> In-Reply-To: From: "Tuan Phan" Date: Mon, 19 Dec 2022 10:26:20 -0800 Message-ID: Subject: Re: [PATCH v2] CryptoPkg/IntrinsicLib: RiscV: Provide implementation of memcpy and __ctzdi2 To: "Kinney, Michael D" Cc: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" , "Yao, Jiewen" , "Wang, Jian J" , "Lu, Xiaoyu1" , "Jiang, Guomin" Content-Type: multipart/alternative; boundary="00000000000057280105f032755e" --00000000000057280105f032755e Content-Type: text/plain; charset="UTF-8" On Fri, Dec 16, 2022 at 4:06 PM Kinney, Michael D < michael.d.kinney@intel.com> wrote: > If that intrinsic is specific to RISCV, then should CompilerHelper.c go > into a RiscV64 subdir? > > Mike > > Hi Mike, While this intrinsic is not specific to RISCV, it is needed due to the GCC for RISCV64 does not generate internal implementation, requiring external link with libgcc/compile-rt. It can happen to other platforms or future GCC toolchain if it decides to move __ctzdi2 to libgcc. If you think it is better to put it in the RiscV64 subdir for now, I am good with it. Tuan, > -----Original Message----- > > From: Tuan Phan > > Sent: Friday, December 16, 2022 10:48 AM > > Cc: devel@edk2.groups.io; sunilvl@ventanamicro.com; Kinney, Michael D < > michael.d.kinney@intel.com>; Yao, Jiewen > > ; Wang, Jian J ; Lu, > Xiaoyu1 ; Jiang, Guomin > > ; Tuan Phan > > Subject: [PATCH v2] CryptoPkg/IntrinsicLib: RiscV: Provide > implementation of memcpy and __ctzdi2 > > > > The RiscV toolchain doesn't provide __ctzdi2 implementation when > > compiled with -nostdlib that needed by openssl library. > > So adding the implementation of __ctzdi2. > > > > Forcing to use CopyMem of EDK2 as memcpy buildin disabled for RiscV > > with -fno-builtin-memcpy flag. > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4103 > > Signed-off-by: Tuan Phan > > Acked-by: Sunil V L > > --- > > V2: > > - Add license header. > > - Add REF to the bugzilla. > > > > .../Library/IntrinsicLib/CompilerHelper.c | 42 +++++++++++++++++++ > > .../Library/IntrinsicLib/IntrinsicLib.inf | 6 ++- > > 2 files changed, 47 insertions(+), 1 deletion(-) > > create mode 100644 CryptoPkg/Library/IntrinsicLib/CompilerHelper.c > > > > diff --git a/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c > b/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c > > new file mode 100644 > > index 000000000000..3844fd14ae66 > > --- /dev/null > > +++ b/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c > > @@ -0,0 +1,42 @@ > > +/** @file > > + Implement functions that not available when compiled with -nostdlib. > > + > > + Copyright (c) 2022, Ventana Micro Systems Inc. All Rights > Reserved.
> > + SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +unsigned int > > +__ctzdi2 (unsigned long long x) > > +{ > > + unsigned int ret = 0; > > + > > + if (!x) { > > + return 64; > > + } > > + if (!(x & 0xffffffff)) { > > + x >>= 32; > > + ret |= 32; > > + } > > + if (!(x & 0xffff)) { > > + x >>= 16; > > + ret |= 16; > > + } > > + if (!(x & 0xff)) { > > + x >>= 8; > > + ret |= 8; > > + } > > + if (!(x & 0xf)) { > > + x >>= 4; > > + ret |= 4; > > + } > > + if (!(x & 0x3)) { > > + x >>= 2; > > + ret |= 2; > > + } > > + if (!(x & 0x1)) { > > + x >>= 1; > > + ret |= 1; > > + } > > + return ret; > > +} > > diff --git a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf > b/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf > > index 86e74b57b109..6796b39b07cf 100644 > > --- a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf > > +++ b/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf > > @@ -18,7 +18,7 @@ > > # > > > > # The following information is for reference only and not required by > the build tools. > > > > # > > > > -# VALID_ARCHITECTURES = IA32 X64 > > > > +# VALID_ARCHITECTURES = IA32 X64 RISCV64 > > > > # > > > > > > > > [Sources] > > > > @@ -43,6 +43,10 @@ > > [Sources.X64] > > > > CopyMem.c > > > > > > > > +[Sources.RISCV64] > > > > + CopyMem.c > > > > + CompilerHelper.c > > > > + > > > > [Packages] > > > > MdePkg/MdePkg.dec > > > > > > > > -- > > 2.25.1 > > --00000000000057280105f032755e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Dec 16, 2022 at 4:06 PM Kinne= y, Michael D <michael.d.ki= nney@intel.com> wrote:
If that intrinsic is specific to RISCV, then should CompilerH= elper.c go into a RiscV64 subdir?

Mike


Hi Mike,
While this intrinsi= c is not specific to RISCV,=C2=A0 it is needed due to the GCC for RISCV64 d= oes not generate internal implementation, requiring external link with libg= cc/compile-rt. It can happen to other platforms or future GCC toolchain=C2= =A0if it decides to move __ctzdi2 to libgcc.
If you think it = is better to put it in the RiscV64 subdir for now, I am good with it.
=

Tuan,

> -----Original Message-----
> From: Tuan Phan <tphan@ventanamicro.com>
> Sent: Friday, December 16, 2022 10:48 AM
> Cc: devel@ed= k2.groups.io; sunilvl@ventanamicro.com; Kinney, Michael D <michael.d.kinney@intel.com>; Yao, Jiewen
> <
jiewen.y= ao@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Lu, Xiaoyu1 <xiaoyu1.lu@intel.com>; Jiang, Guomin
> <
guomin= .jiang@intel.com>; Tuan Phan <tphan@ventanamicro.com>
> Subject: [PATCH v2] CryptoPkg/IntrinsicLib: RiscV: Provide implementat= ion of memcpy and __ctzdi2
>
> The RiscV toolchain doesn't provide __ctzdi2 implementation when > compiled with -nostdlib that needed by openssl library.
> So adding the implementation of __ctzdi2.
>
> Forcing to use CopyMem of EDK2 as memcpy buildin disabled for RiscV > with -fno-builtin-memcpy flag.
>
> REF: https://bugzilla.tianocore.org/show_b= ug.cgi?id=3D4103
> Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
> Acked-by: Sunil V L <sunilvl@ventanamicro.com>
> ---
> V2:
> - Add license header.
> - Add REF to the bugzilla.
>
>=C2=A0 .../Library/IntrinsicLib/CompilerHelper.c=C2=A0 =C2=A0 =C2=A0| 4= 2 +++++++++++++++++++
>=C2=A0 .../Library/IntrinsicLib/IntrinsicLib.inf=C2=A0 =C2=A0 =C2=A0|= =C2=A0 6 ++-
>=C2=A0 2 files changed, 47 insertions(+), 1 deletion(-)
>=C2=A0 create mode 100644 CryptoPkg/Library/IntrinsicLib/CompilerHelper= .c
>
> diff --git a/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c b/CryptoP= kg/Library/IntrinsicLib/CompilerHelper.c
> new file mode 100644
> index 000000000000..3844fd14ae66
> --- /dev/null
> +++ b/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c
> @@ -0,0 +1,42 @@
> +/** @file
> +=C2=A0 Implement functions that not available when compiled with -nos= tdlib.
> +
> +=C2=A0 Copyright (c) 2022, Ventana Micro Systems Inc. All Rights Rese= rved.<BR>
> +=C2=A0 SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +unsigned int
> +__ctzdi2 (unsigned long long x)
> +{
> +=C2=A0 unsigned int ret =3D 0;
> +
> +=C2=A0 if (!x) {
> +=C2=A0 =C2=A0 return 64;
> +=C2=A0 }
> +=C2=A0 if (!(x & 0xffffffff)) {
> +=C2=A0 =C2=A0 x >>=3D 32;
> +=C2=A0 =C2=A0 ret |=3D 32;
> +=C2=A0 }
> +=C2=A0 if (!(x & 0xffff)) {
> +=C2=A0 =C2=A0 x >>=3D 16;
> +=C2=A0 =C2=A0 ret |=3D 16;
> +=C2=A0 }
> +=C2=A0 if (!(x & 0xff)) {
> +=C2=A0 =C2=A0 x >>=3D 8;
> +=C2=A0 =C2=A0 ret |=3D 8;
> +=C2=A0 }
> +=C2=A0 if (!(x & 0xf)) {
> +=C2=A0 =C2=A0 x >>=3D 4;
> +=C2=A0 =C2=A0 ret |=3D 4;
> +=C2=A0 }
> +=C2=A0 if (!(x & 0x3)) {
> +=C2=A0 =C2=A0 x >>=3D 2;
> +=C2=A0 =C2=A0 ret |=3D 2;
> +=C2=A0 }
> +=C2=A0 if (!(x & 0x1)) {
> +=C2=A0 =C2=A0 x >>=3D 1;
> +=C2=A0 =C2=A0 ret |=3D 1;
> +=C2=A0 }
> +=C2=A0 return ret;
> +}
> diff --git a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf b/CryptoP= kg/Library/IntrinsicLib/IntrinsicLib.inf
> index 86e74b57b109..6796b39b07cf 100644
> --- a/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
> +++ b/CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
> @@ -18,7 +18,7 @@
>=C2=A0 #
>
>=C2=A0 # The following information is for reference only and not requir= ed by the build tools.
>
>=C2=A0 #
>
> -#=C2=A0 VALID_ARCHITECTURES=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =3D IA32 X64
>
> +#=C2=A0 VALID_ARCHITECTURES=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =3D IA32 X64 RISCV64
>
>=C2=A0 #
>
>
>
>=C2=A0 [Sources]
>
> @@ -43,6 +43,10 @@
>=C2=A0 [Sources.X64]
>
>=C2=A0 =C2=A0 CopyMem.c
>
>
>
> +[Sources.RISCV64]
>
> +=C2=A0 CopyMem.c
>
> +=C2=A0 CompilerHelper.c
>
> +
>
>=C2=A0 [Packages]
>
>=C2=A0 =C2=A0 MdePkg/MdePkg.dec
>
>
>
> --
> 2.25.1

--00000000000057280105f032755e--