brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 9792079 Raw
56 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file contains basic implementations of Scalable Matrix Extension (SME)11/// compatible memcpy and memmove functions to be used when their assembly-12/// optimized counterparts can't.13///14//===----------------------------------------------------------------------===//15 16#include <stddef.h>17 18static void *__arm_sc_memcpy_fwd(void *dest, const void *src,19                                 size_t n) __arm_streaming_compatible {20  unsigned char *destp = (unsigned char *)dest;21  const unsigned char *srcp = (const unsigned char *)src;22 23  for (size_t i = 0; i < n; ++i)24    destp[i] = srcp[i];25  return dest;26}27 28static void *__arm_sc_memcpy_rev(void *dest, const void *src,29                                 size_t n) __arm_streaming_compatible {30  unsigned char *destp = (unsigned char *)dest;31  const unsigned char *srcp = (const unsigned char *)src;32 33  while (n > 0) {34    --n;35    destp[n] = srcp[n];36  }37  return dest;38}39 40extern void *__arm_sc_memcpy(void *__restrict dest, const void *__restrict src,41                             size_t n) __arm_streaming_compatible {42  return __arm_sc_memcpy_fwd(dest, src, n);43}44 45extern void *__arm_sc_memmove(void *dest, const void *src,46                              size_t n) __arm_streaming_compatible {47  unsigned char *destp = (unsigned char *)dest;48  const unsigned char *srcp = (const unsigned char *)src;49 50  if ((srcp > (destp + n)) || (destp > (srcp + n)))51    return __arm_sc_memcpy(dest, src, n);52  if (srcp > destp)53    return __arm_sc_memcpy_fwd(dest, src, n);54  return __arm_sc_memcpy_rev(dest, src, n);55}56