forked from GPUOpen-Drivers/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged main:7dc3575ef2dc into amd-gfx:b2004a9a0490
Local branch amd-gfx b2004a9 Merged main:214387c2c694 into amd-gfx:47fd8032da63 Remote branch main 7dc3575 [llvm] Remove redundant return and continue statements (NFC)
- Loading branch information
Showing
58 changed files
with
301 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===-- Implementation of memmove -----------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/string/memmove.h" | ||
#include "src/__support/common.h" | ||
#include "src/stdlib/abs_utils.h" | ||
#include "src/string/memcpy.h" | ||
#include <stddef.h> // size_t, ptrdiff_t | ||
#include <unistd.h> // ssize_t | ||
|
||
namespace __llvm_libc { | ||
|
||
// src_m and dest_m might be the beginning or end. | ||
static inline void move_byte(unsigned char *dest_m, const unsigned char *src_m, | ||
size_t count, ssize_t direction) { | ||
for (ssize_t offset = 0; count; --count, offset += direction) | ||
dest_m[offset] = src_m[offset]; | ||
} | ||
|
||
LLVM_LIBC_FUNCTION(void *, memmove, | ||
(void *dest, const void *src, size_t count)) { | ||
unsigned char *dest_c = reinterpret_cast<unsigned char *>(dest); | ||
const unsigned char *src_c = reinterpret_cast<const unsigned char *>(src); | ||
|
||
// If the distance between src_c and dest_c is equal to or greater | ||
// than count (integer_abs(src_c - dest_c) >= count), they would not overlap. | ||
// e.g. greater equal overlapping | ||
// [12345678] [12345678] [12345678] | ||
// src_c: [_ab_____] [_ab_____] [_ab_____] | ||
// dest_c:[_____yz_] [___yz___] [__yz____] | ||
|
||
// Use memcpy if src_c and dest_c do not overlap. | ||
if (__llvm_libc::integer_abs(src_c - dest_c) >= static_cast<ptrdiff_t>(count)) | ||
return __llvm_libc::memcpy(dest_c, src_c, count); | ||
|
||
// Overlap cases. | ||
// If dest_c starts before src_c (dest_c < src_c), copy forward(pointer add 1) | ||
// from beginning to end. | ||
// If dest_c starts after src_c (dest_c > src_c), copy backward(pointer add | ||
// -1) from end to beginning. | ||
// If dest_c and src_c start at the same address (dest_c == src_c), | ||
// just return dest. | ||
// e.g. forward backward | ||
// *--> <--* | ||
// src_c : [___abcde_] [_abcde___] | ||
// dest_c: [_abc--___] [___--cde_] | ||
|
||
// TODO: Optimize `move_byte(...)` function. | ||
if (dest_c < src_c) | ||
move_byte(dest_c, src_c, count, /*pointer add*/ 1); | ||
if (dest_c > src_c) | ||
move_byte(dest_c + count - 1, src_c + count - 1, count, /*pointer add*/ -1); | ||
return dest; | ||
} | ||
|
||
} // namespace __llvm_libc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===-- Implementation header for memmove -----------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_STRING_MEMMOVE_H | ||
#define LLVM_LIBC_SRC_STRING_MEMMOVE_H | ||
|
||
#include <stddef.h> // size_t | ||
|
||
namespace __llvm_libc { | ||
|
||
void *memmove(void *dest, const void *src, size_t count); | ||
|
||
} // namespace __llvm_libc | ||
|
||
#endif // LLVM_LIBC_SRC_STRING_MEMMOVE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//===-- Unittests for memmove ---------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/string/memcmp.h" | ||
#include "src/string/memmove.h" | ||
#include "utils/CPP/ArrayRef.h" | ||
#include "utils/UnitTest/Test.h" | ||
|
||
class MemmoveTest : public __llvm_libc::testing::Test { | ||
public: | ||
void check_memmove(void *dest, const void *src, size_t count, const void *str, | ||
const __llvm_libc::cpp::ArrayRef<unsigned char> expected) { | ||
void *result = __llvm_libc::memmove(dest, src, count); | ||
// Making sure the pointer returned is same with dest. | ||
EXPECT_EQ(result, dest); | ||
// expected is designed according to str. | ||
// dest and src might be part of str. | ||
// Making sure the str is same with expected. | ||
EXPECT_EQ(__llvm_libc::memcmp(str, expected.data(), expected.size()), 0); | ||
} | ||
}; | ||
|
||
TEST_F(MemmoveTest, MoveZeroByte) { | ||
unsigned char dest[] = {'a', 'b'}; | ||
const unsigned char src[] = {'y', 'z'}; | ||
const unsigned char expected[] = {'a', 'b'}; | ||
check_memmove(dest, src, 0, dest, expected); | ||
} | ||
|
||
TEST_F(MemmoveTest, OverlapThatDestAndSrcPointToSameAddress) { | ||
unsigned char str[] = {'a', 'b'}; | ||
const unsigned char expected[] = {'a', 'b'}; | ||
check_memmove(str, str, 1, str, expected); | ||
} | ||
|
||
TEST_F(MemmoveTest, OverlapThatDestStartsBeforeSrc) { | ||
// Set boundary at beginning and end for not overstepping when | ||
// copy forward or backward. | ||
unsigned char str[] = {'z', 'a', 'b', 'c', 'z'}; | ||
const unsigned char expected[] = {'z', 'b', 'c', 'c', 'z'}; | ||
// dest is &str[1]. | ||
check_memmove(&str[1], &str[2], 2, str, expected); | ||
} | ||
|
||
TEST_F(MemmoveTest, OverlapThatDestStartsAfterSrc) { | ||
unsigned char str[] = {'z', 'a', 'b', 'c', 'z'}; | ||
const unsigned char expected[] = {'z', 'a', 'a', 'b', 'z'}; | ||
check_memmove(&str[2], &str[1], 2, str, expected); | ||
} | ||
|
||
// e.g. dest follow src. | ||
// str: [abcdefghij] | ||
// [__src_____] | ||
// [_____dest_] | ||
TEST_F(MemmoveTest, SrcFollowDest) { | ||
unsigned char str[] = {'z', 'a', 'b', 'z'}; | ||
const unsigned char expected[] = {'z', 'b', 'b', 'z'}; | ||
check_memmove(&str[1], &str[2], 1, str, expected); | ||
} | ||
|
||
TEST_F(MemmoveTest, DestFollowSrc) { | ||
unsigned char str[] = {'z', 'a', 'b', 'z'}; | ||
const unsigned char expected[] = {'z', 'a', 'a', 'z'}; | ||
check_memmove(&str[2], &str[1], 1, str, expected); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,6 @@ class LiveRegUnits { | |
UsedRegUnits.addReg(Reg); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
/// Initialize and clear the set. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.