public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code
@ 2016-08-11 18:20 Ard Biesheuvel
  2016-08-11 18:20 ` [PATCH 2/3] BaseTools RVCT: ignore various RVC diagnostics Ard Biesheuvel
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Ard Biesheuvel @ 2016-08-11 18:20 UTC (permalink / raw)
  To: edk2-devel, leif.lindholm, eugene, liming.gao; +Cc: Ard Biesheuvel

This replaces the various implementations of memset and memcpy,
including the ARM RTABI ones (__aeabi_mem[set|clr]_[|4|8]) with
a single C implementation for each. The ones we have are either not
very sophisticated (ARM), or they are too sophisticated (memcpy() on
AARCH64, which may perform unaligned accesses) or already coded in C
(memset on AArch64).

The Tianocore codebase mandates the explicit use of its SetMem() and
CopyMem() equivalents, of which various implementations exist for use
in different contexts (PEI, DXE). Few compiler generated references to
these functions should remain, and so our implementations in this BASE
library should be small and usable with the MMU off.

So replace them with a simple C implementation that builds correctly
on GCC/AARCH64, CLANG/AARCH64, GCC/ARM, CLANG/ARM and RVCT/ARM.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memcpy.S          | 119 --------------------
 ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memset.c          |  25 ----
 ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S              |  32 ------
 ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm            |  40 -------
 ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm           |  60 ----------
 ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S              |  61 ----------
 ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm            |  50 --------
 ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf |  11 +-
 ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c                  |  43 +++++++
 ArmPkg/Library/CompilerIntrinsicsLib/memset.c                  |  55 +++++++++
 10 files changed, 101 insertions(+), 395 deletions(-)

diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memcpy.S b/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memcpy.S
deleted file mode 100644
index 4dd6cf207754..000000000000
--- a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memcpy.S
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2011 - 2013, ARM Ltd
- * 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 may not be used to endorse or promote
- *    products derived from this software without specific prior written
- *    permission.
- *
- * THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD 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 <AsmMacroIoLibV8.h>
-
-// Taken from Newlib BSD implementation.
-ASM_FUNC(memcpy)
-        // Copy dst to x6, so we can preserve return value.
-        mov     x6, x0
-
-        // NOTE: although size_t is unsigned, this code uses signed
-        // comparisons on x2 so relies on nb never having its top bit
-        // set. In practice this is not going to be a real problem.
-
-        // Require at least 64 bytes to be worth aligning.
-        cmp     x2, #64
-        blt     qwordcopy
-
-        // Compute offset to align destination to 16 bytes.
-        neg     x3, x0
-        and     x3, x3, 15
-
-        cbz     x3, blockcopy           // offset == 0 is likely
-
-        // We know there is at least 64 bytes to be done, so we
-        // do a 16 byte misaligned copy at first and then later do
-        // all 16-byte aligned copies.  Some bytes will be copied
-        // twice, but there's no harm in that since memcpy does not
-        // guarantee correctness on overlap.
-
-        sub     x2, x2, x3              // nb -= offset
-        ldp     x4, x5, [x1]
-        add     x1, x1, x3
-        stp     x4, x5, [x6]
-        add     x6, x6, x3
-
-        // The destination pointer is now qword (16 byte) aligned.
-        // (The src pointer might be.)
-
-blockcopy:
-        // Copy 64 bytes at a time.
-        subs    x2, x2, #64
-        blt     3f
-2:      subs    x2, x2, #64
-        ldp     x4, x5, [x1,#0]
-        ldp     x8, x9, [x1,#16]
-        ldp     x10,x11,[x1,#32]
-        ldp     x12,x13,[x1,#48]
-        add     x1, x1, #64
-        stp     x4, x5, [x6,#0]
-        stp     x8, x9, [x6,#16]
-        stp     x10,x11,[x6,#32]
-        stp     x12,x13,[x6,#48]
-        add     x6, x6, #64
-        bge     2b
-
-        // Unwind pre-decrement
-3:      add     x2, x2, #64
-
-qwordcopy:
-        // Copy 0-48 bytes, 16 bytes at a time.
-        subs    x2, x2, #16
-        blt     tailcopy
-2:      ldp     x4, x5, [x1],#16
-        subs    x2, x2, #16
-        stp     x4, x5, [x6],#16
-        bge     2b
-
-        // No need to unwind the pre-decrement, it would not change
-        // the low 4 bits of the count. But how likely is it for the
-        // byte count to be multiple of 16? Is it worth the overhead
-        // of testing for x2 == -16?
-
-tailcopy:
-        // Copy trailing 0-15 bytes.
-        tbz     x2, #3, 1f
-        ldr     x4, [x1],#8             // copy 8 bytes
-        str     x4, [x6],#8
-1:
-        tbz     x2, #2, 1f
-        ldr     w4, [x1],#4             // copy 4 bytes
-        str     w4, [x6],#4
-1:
-        tbz     x2, #1, 1f
-        ldrh    w4, [x1],#2             // copy 2 bytes
-        strh    w4, [x6],#2
-1:
-        tbz     x2, #0, return
-        ldrb    w4, [x1]                // copy 1 byte
-        strb    w4, [x6]
-
-return:
-        // This is the only return point of memcpy.
-        ret
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memset.c b/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memset.c
deleted file mode 100644
index 069c932a6763..000000000000
--- a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memset.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/** @file
-
-  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
-
-  This program and the accompanying materials
-  are licensed and made available under the terms and conditions of the BSD License
-  which accompanies this distribution.  The full text of the license may be found at
-  http://opensource.org/licenses/bsd-license.php
-
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include <Base.h>
-
-void *memset(void *Destination, int Value, int Count)
-{
-  CHAR8 *Ptr = Destination;
-
-  while (Count--)
-          *Ptr++ = Value;
-
-  return Destination;
-}
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S
deleted file mode 100644
index b68ed8a6ea6b..000000000000
--- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S
+++ /dev/null
@@ -1,32 +0,0 @@
-#------------------------------------------------------------------------------
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-#
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution.  The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#------------------------------------------------------------------------------
-
-  .text
-  .align 2
-  GCC_ASM_EXPORT(__aeabi_memcpy)
-  GCC_ASM_EXPORT(memcpy)
-
-ASM_PFX(__aeabi_memcpy):
-ASM_PFX(memcpy):
-  cmp     r2, #0
-  bxeq    lr
-  push    {lr}
-  mov     lr, r0
-L5:
-  ldrb  r3, [r1], #1  @ zero_extendqisi2
-  strb  r3, [lr], #1
-  subs r2, r2, #1
-  bne  L5
-  pop  {pc}
-
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm
deleted file mode 100644
index ae911971286a..000000000000
--- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm
+++ /dev/null
@@ -1,40 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// This program and the accompanying materials
-// are licensed and made available under the terms and conditions of the BSD License
-// which accompanies this distribution.  The full text of the license may be found at
-// http://opensource.org/licenses/bsd-license.php
-//
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-//
-//------------------------------------------------------------------------------
-
-
-
-    INCLUDE AsmMacroExport.inc
-
-;
-;VOID
-;EFIAPI
-;__aeabi_memcpy (
-; IN  VOID    *Destination,
-; IN  VOID    *Source,
-; IN  UINT32  Size
-; );
-;
- RVCT_ASM_EXPORT __aeabi_memcpy
-  cmp     r2, #0
-  bxeq    lr
-  push    {lr}
-  mov     lr, r0
-L5
-  ldrb  r3, [r1], #1
-  strb  r3, [lr], #1
-  subs r2, r2, #1
-  bne  L5
-  pop  {pc}
-
-  END
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm
deleted file mode 100644
index 3465e89eba34..000000000000
--- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm
+++ /dev/null
@@ -1,60 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-//
-// This program and the accompanying materials
-// are licensed and made available under the terms and conditions of the BSD License
-// which accompanies this distribution.  The full text of the license may be found at
-// http://opensource.org/licenses/bsd-license.php
-//
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-//
-//------------------------------------------------------------------------------
-
-
-
-    INCLUDE AsmMacroExport.inc
-
-;
-;VOID
-;EFIAPI
-;__aeabi_memcpy (
-; IN  VOID    *Destination,
-; IN  VOID    *Source,
-; IN  UINT32  Size
-; );
-;
- RVCT_ASM_EXPORT __aeabi_memcpy4
-    stmdb   sp!, {r4, lr}
-    subs    r2, r2, #32     ; 0x20
-    bcc     memcpy4_label2
-memcpy4_label1
-    ldmcsia r1!, {r3, r4, ip, lr}
-    stmcsia r0!, {r3, r4, ip, lr}
-    ldmcsia r1!, {r3, r4, ip, lr}
-    stmcsia r0!, {r3, r4, ip, lr}
-    subcss  r2, r2, #32     ; 0x20
-    bcs     memcpy4_label1
-memcpy4_label2
-    movs    ip, r2, lsl #28
-    ldmcsia r1!, {r3, r4, ip, lr}
-    stmcsia r0!, {r3, r4, ip, lr}
-    ldmmiia r1!, {r3, r4}
-    stmmiia r0!, {r3, r4}
-    ldmia   sp!, {r4, lr}
-    movs    ip, r2, lsl #30
-    ldrcs   r3, [r1], #4
-    strcs   r3, [r0], #4
-    bxeq    lr
-
-_memcpy4_lastbytes_aligned
-    movs    r2, r2, lsl #31
-    ldrcsh  r3, [r1], #2
-    ldrmib  r2, [r1], #1
-    strcsh  r3, [r0], #2
-    strmib  r2, [r0], #1
-    bx      lr
-
-    END
-
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S
deleted file mode 100644
index 65f6289b410b..000000000000
--- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S
+++ /dev/null
@@ -1,61 +0,0 @@
-#------------------------------------------------------------------------------
-#
-# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
-#
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution.  The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#------------------------------------------------------------------------------
-
-
-  .text
-  .syntax unified
-  .align 2
-  GCC_ASM_EXPORT (memset)
-  GCC_ASM_EXPORT (__aeabi_memset)
-
-# VOID
-# EFIAPI
-# __aeabi_memset (
-#  IN  VOID    *Destination,
-#  IN  UINT32  Size
-#  IN  UINT32  Character,
-#  );
-ASM_PFX(__aeabi_memset):
-  subs  ip, r1, #0
-  bxeq  lr
-  mov   r1, r2
-  b     L10
-
-# VOID
-# EFIAPI
-# memset (
-#  IN  VOID    *Destination,
-#  IN  UINT32  Character,
-#  IN  UINT32  Size
-#  );
-  //
-  // This object may be pulled in to satisfy an undefined reference to
-  // __aeabi_memset above, but in some cases, memset() is already provided
-  // by another library (i.e., CryptoPkg/IntrinsicLib), in which case we
-  // prefer the other version. So allow this one to be overridden by
-  // giving it weak linkage.
-  //
-  .weak   memset
-ASM_PFX(memset):
-  subs ip, r2, #0
-  bxeq lr
-  @ args = 0, pretend = 0, frame = 0
-  @ frame_needed = 1, uses_anonymous_args = 0
-L10:
-  strb  r1, [r0], #1
-  subs  ip, ip, #1
-  @ While size is not 0
-  bne  L10
-  bx   lr
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm
deleted file mode 100644
index bae3c1fada11..000000000000
--- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm
+++ /dev/null
@@ -1,50 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
-// Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
-//
-// This program and the accompanying materials
-// are licensed and made available under the terms and conditions of the BSD License
-// which accompanies this distribution.  The full text of the license may be found at
-// http://opensource.org/licenses/bsd-license.php
-//
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-//
-//------------------------------------------------------------------------------
-
-
-    EXPORT  __aeabi_memset
-    EXPORT  __aeabi_memclr
-    EXPORT  __aeabi_memclr4
-
-    AREA    Memset, CODE, READONLY
-
-; void __aeabi_memclr4(void *dest, size_t n);
-; void __aeabi_memclr(void *dest, size_t n);
-__aeabi_memclr
-__aeabi_memclr4
-  mov   r2, #0
-
-;
-;VOID
-;EFIAPI
-;__aeabi_memset (
-; IN  VOID    *Destination,
-; IN  UINT32  Size,
-; IN  UINT32  Character
-; );
-;
-__aeabi_memset
-  cmp  r1, #0
-  bxeq lr
-  ; args = 0, pretend = 0, frame = 0
-  ; frame_needed = 1, uses_anonymous_args = 0
-L10
-  strb  r2, [r0], #1
-  subs  r1, r1, #1
-  ; While size is not 0
-  bne  L10
-  bx   lr
-
-  END
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf b/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
index 103f515064ba..44333141a70a 100644
--- a/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+++ b/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
@@ -22,17 +22,14 @@ [Defines]
   VERSION_STRING                 = 1.0
   LIBRARY_CLASS                  = CompilerIntrinsicsLib
 
-[Sources.AARCH64]
-  AArch64/memcpy.S
-  AArch64/memset.c
+[Sources]
+  memcpy.c
+  memset.c
 
 [Sources.ARM]
   Arm/mullu.asm        | RVCT
   Arm/switch.asm       | RVCT
   Arm/llsr.asm         | RVCT
-  Arm/memcpy.asm       | RVCT
-  Arm/memcpy4.asm      | RVCT
-  Arm/memset.asm       | RVCT
   Arm/memmove.asm      | RVCT
   Arm/uread.asm        | RVCT
   Arm/uwrite.asm       | RVCT
@@ -58,8 +55,6 @@ [Sources.ARM]
   Arm/divsi3.S     | GCC
   Arm/lshrdi3.S    | GCC
 
-  Arm/memcpy.S     | GCC
-  Arm/memset.S     | GCC
   Arm/memmove.S    | GCC
 
 #  Arm/modsi3.c     | GCC
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c
new file mode 100644
index 000000000000..62c79a6d2491
--- /dev/null
+++ b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c
@@ -0,0 +1,43 @@
+//------------------------------------------------------------------------------
+//
+// Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution.  The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+//
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+//------------------------------------------------------------------------------
+
+typedef __SIZE_TYPE__ size_t;
+
+static __attribute__((__used__))
+void *__memcpy(void *dest, const void *src, size_t n)
+{
+  unsigned char *d = dest;
+  unsigned char const *s = src;
+
+  while (n--)
+    *d++ = *s++;
+
+  return dest;
+}
+
+__attribute__((__alias__("__memcpy")))
+void *memcpy(void *dest, const void *src, size_t n);
+
+#ifdef __arm__
+
+__attribute__((__alias__("__memcpy")))
+void __aeabi_memcpy(void *dest, const void *src, size_t n);
+
+__attribute__((__alias__("__memcpy")))
+void __aeabi_memcpy4(void *dest, const void *src, size_t n);
+
+__attribute__((__alias__("__memcpy")))
+void __aeabi_memcpy8(void *dest, const void *src, size_t n);
+
+#endif
diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memset.c b/ArmPkg/Library/CompilerIntrinsicsLib/memset.c
new file mode 100644
index 000000000000..81505f155827
--- /dev/null
+++ b/ArmPkg/Library/CompilerIntrinsicsLib/memset.c
@@ -0,0 +1,55 @@
+//------------------------------------------------------------------------------
+//
+// Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution.  The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+//
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+//------------------------------------------------------------------------------
+
+typedef __SIZE_TYPE__ size_t;
+
+static __attribute__((__used__))
+void *__memset(void *s, int c, size_t n)
+{
+  unsigned char *d = s;
+
+  while (n--)
+    *d++ = c;
+
+  return s;
+}
+
+__attribute__((__alias__("__memset")))
+void *memset(void *dest, size_t n, int c);
+
+#ifdef __arm__
+
+void __aeabi_memset(void *dest, size_t n, int c)
+{
+  __memset(dest, c, n);
+}
+
+__attribute__((__alias__("__aeabi_memset")))
+void __aeabi_memset4(void *dest, size_t n, int c);
+
+__attribute__((__alias__("__aeabi_memset")))
+void __aeabi_memset8(void *dest, size_t n, int c);
+
+void __aeabi_memclr(void *dest, size_t n)
+{
+  __memset(dest, 0, n);
+}
+
+__attribute__((__alias__("__aeabi_memclr")))
+void __aeabi_memclr4(void *dest, size_t n);
+
+__attribute__((__alias__("__aeabi_memclr")))
+void __aeabi_memclr8(void *dest, size_t n);
+
+#endif
-- 
2.7.4



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

* [PATCH 2/3] BaseTools RVCT: ignore various RVC diagnostics
  2016-08-11 18:20 [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Ard Biesheuvel
@ 2016-08-11 18:20 ` Ard Biesheuvel
  2016-08-12  3:04   ` Gao, Liming
  2016-08-11 18:20 ` [PATCH 3/3] MdePkg RVCT: add definition of UNREACHABLE Ard Biesheuvel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Ard Biesheuvel @ 2016-08-11 18:20 UTC (permalink / raw)
  To: edk2-devel, leif.lindholm, eugene, liming.gao; +Cc: Ard Biesheuvel

This updates the RVCT CC flags so various diagnostics that trigger
warnings-as-errors are silenced. In particular, RVCT complains about
missing newlines at the end of source files, mixing of enums and int
values and return statements followed by a break, all of which occur
in the Tianocore codebase, but none of which are actual errors in the
code. So just silence them.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 BaseTools/Conf/tools_def.template | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 2002c4c0598b..e3d70133caaa 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -7449,7 +7449,7 @@ RELEASE_XCODE5_X64_CC_FLAGS   = -target x86_64-pc-win32-macho -c    -Os       -W
 ####################################################################################
 
 DEFINE RVCT_ALL_ASM_FLAGS   = --diag_suppress=1786 --diag_error=warning --apcs /interwork
-DEFINE RVCT_ALL_CC_FLAGS    = --c90 --no_autoinline --asm --gnu --apcs /interwork --signed_chars --no_unaligned_access --split_sections --enum_is_int --preinclude AutoGen.h --diag_suppress=186 --diag_warning 167 --diag_error=warning --diag_style=ide --protect_stack
+DEFINE RVCT_ALL_CC_FLAGS    = --c90 --no_autoinline --asm --gnu --apcs /interwork --signed_chars --no_unaligned_access --split_sections --enum_is_int --preinclude AutoGen.h --diag_suppress=186,188,1,111,68 --diag_warning 167 --diag_error=warning --diag_style=ide --protect_stack
 DEFINE RVCT_ALL_DLINK_FLAGS = --no_scanlib --no_exceptions --datacompressor off --strict --symbols --diag_style=ide --no_legacyalign --scatter $(EDK_TOOLS_PATH)/Scripts/Rvct-Align32.sct
 
 ####################################################################################
-- 
2.7.4



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

* [PATCH 3/3] MdePkg RVCT: add definition of UNREACHABLE
  2016-08-11 18:20 [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Ard Biesheuvel
  2016-08-11 18:20 ` [PATCH 2/3] BaseTools RVCT: ignore various RVC diagnostics Ard Biesheuvel
@ 2016-08-11 18:20 ` Ard Biesheuvel
  2016-08-12  3:04   ` Gao, Liming
  2016-08-11 21:34 ` [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Cohen, Eugene
  2016-09-01 13:11 ` Leif Lindholm
  3 siblings, 1 reply; 12+ messages in thread
From: Ard Biesheuvel @ 2016-08-11 18:20 UTC (permalink / raw)
  To: edk2-devel, leif.lindholm, eugene, liming.gao; +Cc: Ard Biesheuvel

The RVCT compiler in --gnu mode appears to simply strip of the __builtin
prefix when it encounters calls to __builtin_xxx() functions, and so
the __builtin_unreachable() we emit for GCC results in linker errors
regarding undefined references against 'unreachable()'.

So define UNREACHABLE() to a NOP instead.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 MdePkg/Include/Arm/ProcessorBind.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MdePkg/Include/Arm/ProcessorBind.h b/MdePkg/Include/Arm/ProcessorBind.h
index c2482c2f50f0..5ee7465c05a3 100644
--- a/MdePkg/Include/Arm/ProcessorBind.h
+++ b/MdePkg/Include/Arm/ProcessorBind.h
@@ -28,6 +28,13 @@
 #pragma pack()
 #endif
 
+//
+// RVCT does not support the __builtin_unreachable() macro
+//
+#ifdef __ARMCC_VERSION
+#define UNREACHABLE()
+#endif
+
 #if _MSC_EXTENSIONS 
   //
   // use Microsoft* C complier dependent integer width types 
-- 
2.7.4



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

* Re: [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code
  2016-08-11 18:20 [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Ard Biesheuvel
  2016-08-11 18:20 ` [PATCH 2/3] BaseTools RVCT: ignore various RVC diagnostics Ard Biesheuvel
  2016-08-11 18:20 ` [PATCH 3/3] MdePkg RVCT: add definition of UNREACHABLE Ard Biesheuvel
@ 2016-08-11 21:34 ` Cohen, Eugene
  2016-08-11 21:45   ` Ard Biesheuvel
  2016-09-01 13:11 ` Leif Lindholm
  3 siblings, 1 reply; 12+ messages in thread
From: Cohen, Eugene @ 2016-08-11 21:34 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel@lists.01.org, leif.lindholm@linaro.org,
	liming.gao@intel.com

> This replaces the various implementations of memset and memcpy,
> including the ARM RTABI ones (__aeabi_mem[set|clr]_[|4|8]) with
> a single C implementation for each. The ones we have are either not
> very sophisticated (ARM), or they are too sophisticated (memcpy() on
> AARCH64, which may perform unaligned accesses) or already coded in
> C
> (memset on AArch64).

Ard,

I'm concerned about the performance impact of this change... there's a reason for all that complexity and it's to optimize performance.

Why does memcpy performance matter?  In addition to the overall memcpy stuff scattered around C code we have an instance that is particularly sensitive to memcpy performance.  For DMA operations when invoking double-buffering or access to portions of a buffer that is common mapped (i.e. uncached on non-coherent DMA systems) the impact of a non-optimized memcpy is enormous compared to the optimized ones because the penalty is amplified by orders of magnitude due to uncached memory access latency.

So I would ask that before a change like this is brought in that we characterize the cached-cached and cached-uncached (and perhaps unaligned cached-cached) performance across the implementations.  Based on my experience I'm expecting both cases will take a massive performance hit.

>From your commit message I'm inferring that the problem you're solving is to play nice in environments that can't tolerate unaligned access like when the MMU is off.  I get that - and I think a variant of the library that plays nice in these limited cases makes sense.  However, I don't think we should drag down the performance down of the rest of the environment where we spend the vast majority of our time executing.

Eugene





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

* Re: [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code
  2016-08-11 21:34 ` [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Cohen, Eugene
@ 2016-08-11 21:45   ` Ard Biesheuvel
  2016-08-11 21:50     ` Cohen, Eugene
  0 siblings, 1 reply; 12+ messages in thread
From: Ard Biesheuvel @ 2016-08-11 21:45 UTC (permalink / raw)
  To: Cohen, Eugene
  Cc: edk2-devel@lists.01.org, leif.lindholm@linaro.org,
	liming.gao@intel.com

On 11 August 2016 at 23:34, Cohen, Eugene <eugene@hp.com> wrote:
>> This replaces the various implementations of memset and memcpy,
>> including the ARM RTABI ones (__aeabi_mem[set|clr]_[|4|8]) with
>> a single C implementation for each. The ones we have are either not
>> very sophisticated (ARM), or they are too sophisticated (memcpy() on
>> AARCH64, which may perform unaligned accesses) or already coded in
>> C
>> (memset on AArch64).
>
> Ard,
>
> I'm concerned about the performance impact of this change... there's a reason for all that complexity and it's to optimize performance.
>
> Why does memcpy performance matter?  In addition to the overall memcpy stuff scattered around C code we have an instance that is particularly sensitive to memcpy performance.  For DMA operations when invoking double-buffering or access to portions of a buffer that is common mapped (i.e. uncached on non-coherent DMA systems) the impact of a non-optimized memcpy is enormous compared to the optimized ones because the penalty is amplified by orders of magnitude due to uncached memory access latency.
>

That code would be using CopyMem(), no? This only serves the compiler
generated calls, which are few since Tianocore does not allow
initialized locals.

> So I would ask that before a change like this is brought in that we characterize the cached-cached and cached-uncached (and perhaps unaligned cached-cached) performance across the implementations.  Based on my experience I'm expecting both cases will take a massive performance hit.
>
> From your commit message I'm inferring that the problem you're solving is to play nice in environments that can't tolerate unaligned access like when the MMU is off.  I get that - and I think a variant of the library that plays nice in these limited cases makes sense.  However, I don't think we should drag down the performance down of the rest of the environment where we spend the vast majority of our time executing.
>
> Eugene
>
>
>


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

* Re: [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code
  2016-08-11 21:45   ` Ard Biesheuvel
@ 2016-08-11 21:50     ` Cohen, Eugene
  2016-08-11 21:53       ` Ard Biesheuvel
  2016-08-11 23:04       ` Andrew Fish
  0 siblings, 2 replies; 12+ messages in thread
From: Cohen, Eugene @ 2016-08-11 21:50 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: edk2-devel@lists.01.org, leif.lindholm@linaro.org,
	liming.gao@intel.com

> > Why does memcpy performance matter?  In addition to the overall
> memcpy stuff scattered around C code we have an instance that is
> particularly sensitive to memcpy performance.  For DMA operations
> when invoking double-buffering or access to portions of a buffer that
> is common mapped (i.e. uncached on non-coherent DMA systems) the
> impact of a non-optimized memcpy is enormous compared to the
> optimized ones because the penalty is amplified by orders of
> magnitude due to uncached memory access latency.
> >
> 
> That code would be using CopyMem(), no? This only serves the
> compiler
> generated calls, which are few since Tianocore does not allow
> initialized locals.

I see and agree that should minimize the impact.   I guess I'll ask the naive question.  Could the BaseMemoryLib and CompilerIntrinsicsLib share the same stuff?


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

* Re: [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code
  2016-08-11 21:50     ` Cohen, Eugene
@ 2016-08-11 21:53       ` Ard Biesheuvel
  2016-08-11 23:04       ` Andrew Fish
  1 sibling, 0 replies; 12+ messages in thread
From: Ard Biesheuvel @ 2016-08-11 21:53 UTC (permalink / raw)
  To: Cohen, Eugene
  Cc: edk2-devel@lists.01.org, leif.lindholm@linaro.org,
	liming.gao@intel.com

On 11 August 2016 at 23:50, Cohen, Eugene <eugene@hp.com> wrote:
>> > Why does memcpy performance matter?  In addition to the overall
>> memcpy stuff scattered around C code we have an instance that is
>> particularly sensitive to memcpy performance.  For DMA operations
>> when invoking double-buffering or access to portions of a buffer that
>> is common mapped (i.e. uncached on non-coherent DMA systems) the
>> impact of a non-optimized memcpy is enormous compared to the
>> optimized ones because the penalty is amplified by orders of
>> magnitude due to uncached memory access latency.
>> >
>>
>> That code would be using CopyMem(), no? This only serves the
>> compiler
>> generated calls, which are few since Tianocore does not allow
>> initialized locals.
>
> I see and agree that should minimize the impact.   I guess I'll ask the naive question.  Could the BaseMemoryLib and CompilerIntrinsicsLib share the same stuff?
>

Let me look into that


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

* Re: [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code
  2016-08-11 21:50     ` Cohen, Eugene
  2016-08-11 21:53       ` Ard Biesheuvel
@ 2016-08-11 23:04       ` Andrew Fish
  2016-08-12  8:09         ` Ard Biesheuvel
  1 sibling, 1 reply; 12+ messages in thread
From: Andrew Fish @ 2016-08-11 23:04 UTC (permalink / raw)
  To: Eugene Cohen
  Cc: Ard Biesheuvel, edk2-devel@lists.01.org, liming.gao@intel.com,
	leif.lindholm@linaro.org


> On Aug 11, 2016, at 2:50 PM, Cohen, Eugene <eugene@hp.com> wrote:
> 
>>> Why does memcpy performance matter?  In addition to the overall
>> memcpy stuff scattered around C code we have an instance that is
>> particularly sensitive to memcpy performance.  For DMA operations
>> when invoking double-buffering or access to portions of a buffer that
>> is common mapped (i.e. uncached on non-coherent DMA systems) the
>> impact of a non-optimized memcpy is enormous compared to the
>> optimized ones because the penalty is amplified by orders of
>> magnitude due to uncached memory access latency.
>>> 
>> 
>> That code would be using CopyMem(), no? This only serves the
>> compiler
>> generated calls, which are few since Tianocore does not allow
>> initialized locals.
> 
> I see and agree that should minimize the impact.   I guess I'll ask the naive question.  Could the BaseMemoryLib and CompilerIntrinsicsLib share the same stuff?
> 

Eugene,

I think if a CompilerIntrinsicsLib implementation consumes the BaseMemoryLib class (lists it in the INF) then I think it should just work.

Thanks,

Andrew Fish

> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel



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

* Re: [PATCH 2/3] BaseTools RVCT: ignore various RVC diagnostics
  2016-08-11 18:20 ` [PATCH 2/3] BaseTools RVCT: ignore various RVC diagnostics Ard Biesheuvel
@ 2016-08-12  3:04   ` Gao, Liming
  0 siblings, 0 replies; 12+ messages in thread
From: Gao, Liming @ 2016-08-12  3:04 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel@lists.01.org, leif.lindholm@linaro.org,
	eugene@hp.com

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Friday, August 12, 2016 2:21 AM
> To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; eugene@hp.com; Gao,
> Liming <liming.gao@intel.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Subject: [PATCH 2/3] BaseTools RVCT: ignore various RVC diagnostics
> 
> This updates the RVCT CC flags so various diagnostics that trigger
> warnings-as-errors are silenced. In particular, RVCT complains about
> missing newlines at the end of source files, mixing of enums and int
> values and return statements followed by a break, all of which occur
> in the Tianocore codebase, but none of which are actual errors in the
> code. So just silence them.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  BaseTools/Conf/tools_def.template | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/BaseTools/Conf/tools_def.template
> b/BaseTools/Conf/tools_def.template
> index 2002c4c0598b..e3d70133caaa 100755
> --- a/BaseTools/Conf/tools_def.template
> +++ b/BaseTools/Conf/tools_def.template
> @@ -7449,7 +7449,7 @@ RELEASE_XCODE5_X64_CC_FLAGS   = -target
> x86_64-pc-win32-macho -c    -Os       -W
> 
> ##########################################################
> ##########################
> 
>  DEFINE RVCT_ALL_ASM_FLAGS   = --diag_suppress=1786 --
> diag_error=warning --apcs /interwork
> -DEFINE RVCT_ALL_CC_FLAGS    = --c90 --no_autoinline --asm --gnu --apcs
> /interwork --signed_chars --no_unaligned_access --split_sections --
> enum_is_int --preinclude AutoGen.h --diag_suppress=186 --diag_warning
> 167 --diag_error=warning --diag_style=ide --protect_stack
> +DEFINE RVCT_ALL_CC_FLAGS    = --c90 --no_autoinline --asm --gnu --apcs
> /interwork --signed_chars --no_unaligned_access --split_sections --
> enum_is_int --preinclude AutoGen.h --diag_suppress=186,188,1,111,68 --
> diag_warning 167 --diag_error=warning --diag_style=ide --protect_stack
>  DEFINE RVCT_ALL_DLINK_FLAGS = --no_scanlib --no_exceptions --
> datacompressor off --strict --symbols --diag_style=ide --no_legacyalign --
> scatter $(EDK_TOOLS_PATH)/Scripts/Rvct-Align32.sct
> 
> 
> ##########################################################
> ##########################
> --
> 2.7.4



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

* Re: [PATCH 3/3] MdePkg RVCT: add definition of UNREACHABLE
  2016-08-11 18:20 ` [PATCH 3/3] MdePkg RVCT: add definition of UNREACHABLE Ard Biesheuvel
@ 2016-08-12  3:04   ` Gao, Liming
  0 siblings, 0 replies; 12+ messages in thread
From: Gao, Liming @ 2016-08-12  3:04 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel@lists.01.org, leif.lindholm@linaro.org,
	eugene@hp.com

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Ard Biesheuvel
> Sent: Friday, August 12, 2016 2:21 AM
> To: edk2-devel@lists.01.org; leif.lindholm@linaro.org; eugene@hp.com; Gao,
> Liming <liming.gao@intel.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Subject: [edk2] [PATCH 3/3] MdePkg RVCT: add definition of UNREACHABLE
> 
> The RVCT compiler in --gnu mode appears to simply strip of the __builtin
> prefix when it encounters calls to __builtin_xxx() functions, and so
> the __builtin_unreachable() we emit for GCC results in linker errors
> regarding undefined references against 'unreachable()'.
> 
> So define UNREACHABLE() to a NOP instead.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  MdePkg/Include/Arm/ProcessorBind.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/MdePkg/Include/Arm/ProcessorBind.h
> b/MdePkg/Include/Arm/ProcessorBind.h
> index c2482c2f50f0..5ee7465c05a3 100644
> --- a/MdePkg/Include/Arm/ProcessorBind.h
> +++ b/MdePkg/Include/Arm/ProcessorBind.h
> @@ -28,6 +28,13 @@
>  #pragma pack()
>  #endif
> 
> +//
> +// RVCT does not support the __builtin_unreachable() macro
> +//
> +#ifdef __ARMCC_VERSION
> +#define UNREACHABLE()
> +#endif
> +
>  #if _MSC_EXTENSIONS
>    //
>    // use Microsoft* C complier dependent integer width types
> --
> 2.7.4
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code
  2016-08-11 23:04       ` Andrew Fish
@ 2016-08-12  8:09         ` Ard Biesheuvel
  0 siblings, 0 replies; 12+ messages in thread
From: Ard Biesheuvel @ 2016-08-12  8:09 UTC (permalink / raw)
  To: Andrew Fish
  Cc: Eugene Cohen, edk2-devel@lists.01.org, liming.gao@intel.com,
	leif.lindholm@linaro.org

On 12 August 2016 at 01:04, Andrew Fish <afish@apple.com> wrote:
>
>> On Aug 11, 2016, at 2:50 PM, Cohen, Eugene <eugene@hp.com> wrote:
>>
>>>> Why does memcpy performance matter?  In addition to the overall
>>> memcpy stuff scattered around C code we have an instance that is
>>> particularly sensitive to memcpy performance.  For DMA operations
>>> when invoking double-buffering or access to portions of a buffer that
>>> is common mapped (i.e. uncached on non-coherent DMA systems) the
>>> impact of a non-optimized memcpy is enormous compared to the
>>> optimized ones because the penalty is amplified by orders of
>>> magnitude due to uncached memory access latency.
>>>>
>>>
>>> That code would be using CopyMem(), no? This only serves the
>>> compiler
>>> generated calls, which are few since Tianocore does not allow
>>> initialized locals.
>>
>> I see and agree that should minimize the impact.   I guess I'll ask the naive question.  Could the BaseMemoryLib and CompilerIntrinsicsLib share the same stuff?
>>
>
> Eugene,
>
> I think if a CompilerIntrinsicsLib implementation consumes the BaseMemoryLib class (lists it in the INF) then I think it should just work.
>

Adding this

"""
--- a/ArmPkg/Library/BaseMemoryLibStm/AArch64/CopyMem.c
+++ b/ArmPkg/Library/BaseMemoryLibStm/AArch64/CopyMem.c
@@ -144,3 +144,10 @@ InternalMemCopyMem (
   }
   return DestinationBuffer;
 }
+
+//
+// Make this implementation satisfy references to the intrinsic memcpy() that
+// may be emitted by the compiler.
+//
+__attribute__((__weak__, __alias__("InternalMemCopyMem")))
+void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n);
"""

(and something similar for memset()) will make the AArch64 platforms I
usually test with build happily without the compilerintrinsicslib.
Since no other changes are required, this means that BaseMemoryLib is
already pulled into all modules one way or the other, and so it would
seem like an improvement not to have both implementations, since they
do exactly the same.

For ARM, this is obviously different given the RT abi and its __aeabi_
prefixed entry points. I suppose the memcpy and memset intrinsincs are
more a GCC thing than an ARM thing.


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

* Re: [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code
  2016-08-11 18:20 [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Ard Biesheuvel
                   ` (2 preceding siblings ...)
  2016-08-11 21:34 ` [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Cohen, Eugene
@ 2016-09-01 13:11 ` Leif Lindholm
  3 siblings, 0 replies; 12+ messages in thread
From: Leif Lindholm @ 2016-09-01 13:11 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel, eugene, liming.gao

On Thu, Aug 11, 2016 at 08:20:30PM +0200, Ard Biesheuvel wrote:
> This replaces the various implementations of memset and memcpy,
> including the ARM RTABI ones (__aeabi_mem[set|clr]_[|4|8]) with
> a single C implementation for each. The ones we have are either not
> very sophisticated (ARM), or they are too sophisticated (memcpy() on
> AARCH64, which may perform unaligned accesses) or already coded in C
> (memset on AArch64).
> 
> The Tianocore codebase mandates the explicit use of its SetMem() and
> CopyMem() equivalents, of which various implementations exist for use
> in different contexts (PEI, DXE). Few compiler generated references to
> these functions should remain, and so our implementations in this BASE
> library should be small and usable with the MMU off.
> 
> So replace them with a simple C implementation that builds correctly
> on GCC/AARCH64, CLANG/AARCH64, GCC/ARM, CLANG/ARM and RVCT/ARM.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

This looks like a worthwhile bit of code cleanup.

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memcpy.S          | 119 --------------------
>  ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memset.c          |  25 ----
>  ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S              |  32 ------
>  ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm            |  40 -------
>  ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm           |  60 ----------
>  ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S              |  61 ----------
>  ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm            |  50 --------
>  ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf |  11 +-
>  ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c                  |  43 +++++++
>  ArmPkg/Library/CompilerIntrinsicsLib/memset.c                  |  55 +++++++++
>  10 files changed, 101 insertions(+), 395 deletions(-)
> 
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memcpy.S b/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memcpy.S
> deleted file mode 100644
> index 4dd6cf207754..000000000000
> --- a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memcpy.S
> +++ /dev/null
> @@ -1,119 +0,0 @@
> -/*
> - * Copyright (c) 2011 - 2013, ARM Ltd
> - * 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 may not be used to endorse or promote
> - *    products derived from this software without specific prior written
> - *    permission.
> - *
> - * THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD 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 <AsmMacroIoLibV8.h>
> -
> -// Taken from Newlib BSD implementation.
> -ASM_FUNC(memcpy)
> -        // Copy dst to x6, so we can preserve return value.
> -        mov     x6, x0
> -
> -        // NOTE: although size_t is unsigned, this code uses signed
> -        // comparisons on x2 so relies on nb never having its top bit
> -        // set. In practice this is not going to be a real problem.
> -
> -        // Require at least 64 bytes to be worth aligning.
> -        cmp     x2, #64
> -        blt     qwordcopy
> -
> -        // Compute offset to align destination to 16 bytes.
> -        neg     x3, x0
> -        and     x3, x3, 15
> -
> -        cbz     x3, blockcopy           // offset == 0 is likely
> -
> -        // We know there is at least 64 bytes to be done, so we
> -        // do a 16 byte misaligned copy at first and then later do
> -        // all 16-byte aligned copies.  Some bytes will be copied
> -        // twice, but there's no harm in that since memcpy does not
> -        // guarantee correctness on overlap.
> -
> -        sub     x2, x2, x3              // nb -= offset
> -        ldp     x4, x5, [x1]
> -        add     x1, x1, x3
> -        stp     x4, x5, [x6]
> -        add     x6, x6, x3
> -
> -        // The destination pointer is now qword (16 byte) aligned.
> -        // (The src pointer might be.)
> -
> -blockcopy:
> -        // Copy 64 bytes at a time.
> -        subs    x2, x2, #64
> -        blt     3f
> -2:      subs    x2, x2, #64
> -        ldp     x4, x5, [x1,#0]
> -        ldp     x8, x9, [x1,#16]
> -        ldp     x10,x11,[x1,#32]
> -        ldp     x12,x13,[x1,#48]
> -        add     x1, x1, #64
> -        stp     x4, x5, [x6,#0]
> -        stp     x8, x9, [x6,#16]
> -        stp     x10,x11,[x6,#32]
> -        stp     x12,x13,[x6,#48]
> -        add     x6, x6, #64
> -        bge     2b
> -
> -        // Unwind pre-decrement
> -3:      add     x2, x2, #64
> -
> -qwordcopy:
> -        // Copy 0-48 bytes, 16 bytes at a time.
> -        subs    x2, x2, #16
> -        blt     tailcopy
> -2:      ldp     x4, x5, [x1],#16
> -        subs    x2, x2, #16
> -        stp     x4, x5, [x6],#16
> -        bge     2b
> -
> -        // No need to unwind the pre-decrement, it would not change
> -        // the low 4 bits of the count. But how likely is it for the
> -        // byte count to be multiple of 16? Is it worth the overhead
> -        // of testing for x2 == -16?
> -
> -tailcopy:
> -        // Copy trailing 0-15 bytes.
> -        tbz     x2, #3, 1f
> -        ldr     x4, [x1],#8             // copy 8 bytes
> -        str     x4, [x6],#8
> -1:
> -        tbz     x2, #2, 1f
> -        ldr     w4, [x1],#4             // copy 4 bytes
> -        str     w4, [x6],#4
> -1:
> -        tbz     x2, #1, 1f
> -        ldrh    w4, [x1],#2             // copy 2 bytes
> -        strh    w4, [x6],#2
> -1:
> -        tbz     x2, #0, return
> -        ldrb    w4, [x1]                // copy 1 byte
> -        strb    w4, [x6]
> -
> -return:
> -        // This is the only return point of memcpy.
> -        ret
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memset.c b/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memset.c
> deleted file mode 100644
> index 069c932a6763..000000000000
> --- a/ArmPkg/Library/CompilerIntrinsicsLib/AArch64/memset.c
> +++ /dev/null
> @@ -1,25 +0,0 @@
> -/** @file
> -
> -  Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
> -
> -  This program and the accompanying materials
> -  are licensed and made available under the terms and conditions of the BSD License
> -  which accompanies this distribution.  The full text of the license may be found at
> -  http://opensource.org/licenses/bsd-license.php
> -
> -  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> -  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> -
> -**/
> -
> -#include <Base.h>
> -
> -void *memset(void *Destination, int Value, int Count)
> -{
> -  CHAR8 *Ptr = Destination;
> -
> -  while (Count--)
> -          *Ptr++ = Value;
> -
> -  return Destination;
> -}
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S
> deleted file mode 100644
> index b68ed8a6ea6b..000000000000
> --- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.S
> +++ /dev/null
> @@ -1,32 +0,0 @@
> -#------------------------------------------------------------------------------
> -#
> -# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> -#
> -# This program and the accompanying materials
> -# are licensed and made available under the terms and conditions of the BSD License
> -# which accompanies this distribution.  The full text of the license may be found at
> -# http://opensource.org/licenses/bsd-license.php
> -#
> -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> -#
> -#------------------------------------------------------------------------------
> -
> -  .text
> -  .align 2
> -  GCC_ASM_EXPORT(__aeabi_memcpy)
> -  GCC_ASM_EXPORT(memcpy)
> -
> -ASM_PFX(__aeabi_memcpy):
> -ASM_PFX(memcpy):
> -  cmp     r2, #0
> -  bxeq    lr
> -  push    {lr}
> -  mov     lr, r0
> -L5:
> -  ldrb  r3, [r1], #1  @ zero_extendqisi2
> -  strb  r3, [lr], #1
> -  subs r2, r2, #1
> -  bne  L5
> -  pop  {pc}
> -
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm
> deleted file mode 100644
> index ae911971286a..000000000000
> --- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy.asm
> +++ /dev/null
> @@ -1,40 +0,0 @@
> -//------------------------------------------------------------------------------
> -//
> -// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> -//
> -// This program and the accompanying materials
> -// are licensed and made available under the terms and conditions of the BSD License
> -// which accompanies this distribution.  The full text of the license may be found at
> -// http://opensource.org/licenses/bsd-license.php
> -//
> -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> -//
> -//------------------------------------------------------------------------------
> -
> -
> -
> -    INCLUDE AsmMacroExport.inc
> -
> -;
> -;VOID
> -;EFIAPI
> -;__aeabi_memcpy (
> -; IN  VOID    *Destination,
> -; IN  VOID    *Source,
> -; IN  UINT32  Size
> -; );
> -;
> - RVCT_ASM_EXPORT __aeabi_memcpy
> -  cmp     r2, #0
> -  bxeq    lr
> -  push    {lr}
> -  mov     lr, r0
> -L5
> -  ldrb  r3, [r1], #1
> -  strb  r3, [lr], #1
> -  subs r2, r2, #1
> -  bne  L5
> -  pop  {pc}
> -
> -  END
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm
> deleted file mode 100644
> index 3465e89eba34..000000000000
> --- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memcpy4.asm
> +++ /dev/null
> @@ -1,60 +0,0 @@
> -//------------------------------------------------------------------------------
> -//
> -// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> -//
> -// This program and the accompanying materials
> -// are licensed and made available under the terms and conditions of the BSD License
> -// which accompanies this distribution.  The full text of the license may be found at
> -// http://opensource.org/licenses/bsd-license.php
> -//
> -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> -//
> -//------------------------------------------------------------------------------
> -
> -
> -
> -    INCLUDE AsmMacroExport.inc
> -
> -;
> -;VOID
> -;EFIAPI
> -;__aeabi_memcpy (
> -; IN  VOID    *Destination,
> -; IN  VOID    *Source,
> -; IN  UINT32  Size
> -; );
> -;
> - RVCT_ASM_EXPORT __aeabi_memcpy4
> -    stmdb   sp!, {r4, lr}
> -    subs    r2, r2, #32     ; 0x20
> -    bcc     memcpy4_label2
> -memcpy4_label1
> -    ldmcsia r1!, {r3, r4, ip, lr}
> -    stmcsia r0!, {r3, r4, ip, lr}
> -    ldmcsia r1!, {r3, r4, ip, lr}
> -    stmcsia r0!, {r3, r4, ip, lr}
> -    subcss  r2, r2, #32     ; 0x20
> -    bcs     memcpy4_label1
> -memcpy4_label2
> -    movs    ip, r2, lsl #28
> -    ldmcsia r1!, {r3, r4, ip, lr}
> -    stmcsia r0!, {r3, r4, ip, lr}
> -    ldmmiia r1!, {r3, r4}
> -    stmmiia r0!, {r3, r4}
> -    ldmia   sp!, {r4, lr}
> -    movs    ip, r2, lsl #30
> -    ldrcs   r3, [r1], #4
> -    strcs   r3, [r0], #4
> -    bxeq    lr
> -
> -_memcpy4_lastbytes_aligned
> -    movs    r2, r2, lsl #31
> -    ldrcsh  r3, [r1], #2
> -    ldrmib  r2, [r1], #1
> -    strcsh  r3, [r0], #2
> -    strmib  r2, [r0], #1
> -    bx      lr
> -
> -    END
> -
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S
> deleted file mode 100644
> index 65f6289b410b..000000000000
> --- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.S
> +++ /dev/null
> @@ -1,61 +0,0 @@
> -#------------------------------------------------------------------------------
> -#
> -# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> -# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
> -#
> -# This program and the accompanying materials
> -# are licensed and made available under the terms and conditions of the BSD License
> -# which accompanies this distribution.  The full text of the license may be found at
> -# http://opensource.org/licenses/bsd-license.php
> -#
> -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> -#
> -#------------------------------------------------------------------------------
> -
> -
> -  .text
> -  .syntax unified
> -  .align 2
> -  GCC_ASM_EXPORT (memset)
> -  GCC_ASM_EXPORT (__aeabi_memset)
> -
> -# VOID
> -# EFIAPI
> -# __aeabi_memset (
> -#  IN  VOID    *Destination,
> -#  IN  UINT32  Size
> -#  IN  UINT32  Character,
> -#  );
> -ASM_PFX(__aeabi_memset):
> -  subs  ip, r1, #0
> -  bxeq  lr
> -  mov   r1, r2
> -  b     L10
> -
> -# VOID
> -# EFIAPI
> -# memset (
> -#  IN  VOID    *Destination,
> -#  IN  UINT32  Character,
> -#  IN  UINT32  Size
> -#  );
> -  //
> -  // This object may be pulled in to satisfy an undefined reference to
> -  // __aeabi_memset above, but in some cases, memset() is already provided
> -  // by another library (i.e., CryptoPkg/IntrinsicLib), in which case we
> -  // prefer the other version. So allow this one to be overridden by
> -  // giving it weak linkage.
> -  //
> -  .weak   memset
> -ASM_PFX(memset):
> -  subs ip, r2, #0
> -  bxeq lr
> -  @ args = 0, pretend = 0, frame = 0
> -  @ frame_needed = 1, uses_anonymous_args = 0
> -L10:
> -  strb  r1, [r0], #1
> -  subs  ip, ip, #1
> -  @ While size is not 0
> -  bne  L10
> -  bx   lr
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm b/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm
> deleted file mode 100644
> index bae3c1fada11..000000000000
> --- a/ArmPkg/Library/CompilerIntrinsicsLib/Arm/memset.asm
> +++ /dev/null
> @@ -1,50 +0,0 @@
> -//------------------------------------------------------------------------------
> -//
> -// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
> -// Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
> -//
> -// This program and the accompanying materials
> -// are licensed and made available under the terms and conditions of the BSD License
> -// which accompanies this distribution.  The full text of the license may be found at
> -// http://opensource.org/licenses/bsd-license.php
> -//
> -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> -//
> -//------------------------------------------------------------------------------
> -
> -
> -    EXPORT  __aeabi_memset
> -    EXPORT  __aeabi_memclr
> -    EXPORT  __aeabi_memclr4
> -
> -    AREA    Memset, CODE, READONLY
> -
> -; void __aeabi_memclr4(void *dest, size_t n);
> -; void __aeabi_memclr(void *dest, size_t n);
> -__aeabi_memclr
> -__aeabi_memclr4
> -  mov   r2, #0
> -
> -;
> -;VOID
> -;EFIAPI
> -;__aeabi_memset (
> -; IN  VOID    *Destination,
> -; IN  UINT32  Size,
> -; IN  UINT32  Character
> -; );
> -;
> -__aeabi_memset
> -  cmp  r1, #0
> -  bxeq lr
> -  ; args = 0, pretend = 0, frame = 0
> -  ; frame_needed = 1, uses_anonymous_args = 0
> -L10
> -  strb  r2, [r0], #1
> -  subs  r1, r1, #1
> -  ; While size is not 0
> -  bne  L10
> -  bx   lr
> -
> -  END
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf b/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
> index 103f515064ba..44333141a70a 100644
> --- a/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
> +++ b/ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
> @@ -22,17 +22,14 @@ [Defines]
>    VERSION_STRING                 = 1.0
>    LIBRARY_CLASS                  = CompilerIntrinsicsLib
>  
> -[Sources.AARCH64]
> -  AArch64/memcpy.S
> -  AArch64/memset.c
> +[Sources]
> +  memcpy.c
> +  memset.c
>  
>  [Sources.ARM]
>    Arm/mullu.asm        | RVCT
>    Arm/switch.asm       | RVCT
>    Arm/llsr.asm         | RVCT
> -  Arm/memcpy.asm       | RVCT
> -  Arm/memcpy4.asm      | RVCT
> -  Arm/memset.asm       | RVCT
>    Arm/memmove.asm      | RVCT
>    Arm/uread.asm        | RVCT
>    Arm/uwrite.asm       | RVCT
> @@ -58,8 +55,6 @@ [Sources.ARM]
>    Arm/divsi3.S     | GCC
>    Arm/lshrdi3.S    | GCC
>  
> -  Arm/memcpy.S     | GCC
> -  Arm/memset.S     | GCC
>    Arm/memmove.S    | GCC
>  
>  #  Arm/modsi3.c     | GCC
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c
> new file mode 100644
> index 000000000000..62c79a6d2491
> --- /dev/null
> +++ b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c
> @@ -0,0 +1,43 @@
> +//------------------------------------------------------------------------------
> +//
> +// Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
> +//
> +// This program and the accompanying materials
> +// are licensed and made available under the terms and conditions of the BSD License
> +// which accompanies this distribution.  The full text of the license may be found at
> +// http://opensource.org/licenses/bsd-license.php
> +//
> +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +//
> +//------------------------------------------------------------------------------
> +
> +typedef __SIZE_TYPE__ size_t;
> +
> +static __attribute__((__used__))
> +void *__memcpy(void *dest, const void *src, size_t n)
> +{
> +  unsigned char *d = dest;
> +  unsigned char const *s = src;
> +
> +  while (n--)
> +    *d++ = *s++;
> +
> +  return dest;
> +}
> +
> +__attribute__((__alias__("__memcpy")))
> +void *memcpy(void *dest, const void *src, size_t n);
> +
> +#ifdef __arm__
> +
> +__attribute__((__alias__("__memcpy")))
> +void __aeabi_memcpy(void *dest, const void *src, size_t n);
> +
> +__attribute__((__alias__("__memcpy")))
> +void __aeabi_memcpy4(void *dest, const void *src, size_t n);
> +
> +__attribute__((__alias__("__memcpy")))
> +void __aeabi_memcpy8(void *dest, const void *src, size_t n);
> +
> +#endif
> diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memset.c b/ArmPkg/Library/CompilerIntrinsicsLib/memset.c
> new file mode 100644
> index 000000000000..81505f155827
> --- /dev/null
> +++ b/ArmPkg/Library/CompilerIntrinsicsLib/memset.c
> @@ -0,0 +1,55 @@
> +//------------------------------------------------------------------------------
> +//
> +// Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
> +//
> +// This program and the accompanying materials
> +// are licensed and made available under the terms and conditions of the BSD License
> +// which accompanies this distribution.  The full text of the license may be found at
> +// http://opensource.org/licenses/bsd-license.php
> +//
> +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +//
> +//------------------------------------------------------------------------------
> +
> +typedef __SIZE_TYPE__ size_t;
> +
> +static __attribute__((__used__))
> +void *__memset(void *s, int c, size_t n)
> +{
> +  unsigned char *d = s;
> +
> +  while (n--)
> +    *d++ = c;
> +
> +  return s;
> +}
> +
> +__attribute__((__alias__("__memset")))
> +void *memset(void *dest, size_t n, int c);
> +
> +#ifdef __arm__
> +
> +void __aeabi_memset(void *dest, size_t n, int c)
> +{
> +  __memset(dest, c, n);
> +}
> +
> +__attribute__((__alias__("__aeabi_memset")))
> +void __aeabi_memset4(void *dest, size_t n, int c);
> +
> +__attribute__((__alias__("__aeabi_memset")))
> +void __aeabi_memset8(void *dest, size_t n, int c);
> +
> +void __aeabi_memclr(void *dest, size_t n)
> +{
> +  __memset(dest, 0, n);
> +}
> +
> +__attribute__((__alias__("__aeabi_memclr")))
> +void __aeabi_memclr4(void *dest, size_t n);
> +
> +__attribute__((__alias__("__aeabi_memclr")))
> +void __aeabi_memclr8(void *dest, size_t n);
> +
> +#endif
> -- 
> 2.7.4
> 


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

end of thread, other threads:[~2016-09-01 13:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-11 18:20 [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Ard Biesheuvel
2016-08-11 18:20 ` [PATCH 2/3] BaseTools RVCT: ignore various RVC diagnostics Ard Biesheuvel
2016-08-12  3:04   ` Gao, Liming
2016-08-11 18:20 ` [PATCH 3/3] MdePkg RVCT: add definition of UNREACHABLE Ard Biesheuvel
2016-08-12  3:04   ` Gao, Liming
2016-08-11 21:34 ` [PATCH 1/3] ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code Cohen, Eugene
2016-08-11 21:45   ` Ard Biesheuvel
2016-08-11 21:50     ` Cohen, Eugene
2016-08-11 21:53       ` Ard Biesheuvel
2016-08-11 23:04       ` Andrew Fish
2016-08-12  8:09         ` Ard Biesheuvel
2016-09-01 13:11 ` Leif Lindholm

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