public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] CryptoPkg/IntrinsicLib: RiscV: Provide implementation of memcpy and __ctzdi2
@ 2022-12-15 17:48 tphan
  2022-12-16  5:12 ` Sunil V L
  0 siblings, 1 reply; 2+ messages in thread
From: tphan @ 2022-12-15 17:48 UTC (permalink / raw)
  Cc: devel, sunilvl, Tuan Phan

The RiscV toolchain doesn't provide __ctzdi2 implementation when
compiled with -nostdlib that needed by openssl library when EC 
enabled. So adding the simple implementation of __ctzdi2.

Forcing to use CopyMem of EDK2 as builtin memcpy disabled for RiscV
with -fno-builtin-memcpy flag.

Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
---
 .../Library/IntrinsicLib/CompilerHelper.c     | 41 +++++++++++++++++++
 .../Library/IntrinsicLib/IntrinsicLib.inf     |  6 ++-
 2 files changed, 46 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..9e700a11ed17
--- /dev/null
+++ b/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c
@@ -0,0 +1,41 @@
+/** @file
+  Implement functions that not available when compiled with -nostdlib flag.
+
+  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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] CryptoPkg/IntrinsicLib: RiscV: Provide implementation of memcpy and __ctzdi2
  2022-12-15 17:48 [PATCH] CryptoPkg/IntrinsicLib: RiscV: Provide implementation of memcpy and __ctzdi2 tphan
@ 2022-12-16  5:12 ` Sunil V L
  0 siblings, 0 replies; 2+ messages in thread
From: Sunil V L @ 2022-12-16  5:12 UTC (permalink / raw)
  To: Tuan Phan; +Cc: devel

On Thu, Dec 15, 2022 at 09:48:59AM -0800, Tuan Phan wrote:
> The RiscV toolchain doesn't provide __ctzdi2 implementation when
> compiled with -nostdlib that needed by openssl library when EC 
> enabled. So adding the simple implementation of __ctzdi2.
> 
> Forcing to use CopyMem of EDK2 as builtin memcpy disabled for RiscV
> with -fno-builtin-memcpy flag.
> 
Hi Tuan,

Thanks for the patch.

Please add "REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4103" in
the commit message and add the copyright in the new file created.

Please CC Mike (Michael D Kinney <michael.d.kinney@intel.com>) and the
maintainers of CryptoPkg.

Acked-by: Sunil V L <sunilvl@ventanamicro.com>

Thanks
Sunil
> Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
> ---
>  .../Library/IntrinsicLib/CompilerHelper.c     | 41 +++++++++++++++++++
>  .../Library/IntrinsicLib/IntrinsicLib.inf     |  6 ++-
>  2 files changed, 46 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..9e700a11ed17
> --- /dev/null
> +++ b/CryptoPkg/Library/IntrinsicLib/CompilerHelper.c
> @@ -0,0 +1,41 @@
> +/** @file
> +  Implement functions that not available when compiled with -nostdlib flag.
> +
> +  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
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-16  5:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-15 17:48 [PATCH] CryptoPkg/IntrinsicLib: RiscV: Provide implementation of memcpy and __ctzdi2 tphan
2022-12-16  5:12 ` Sunil V L

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox