2020-05-09 12:04:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-09 12:04:14 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-08 11:34:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2020-05-16 10:00:04 +00:00
|
|
|
#if defined(KERNEL)
|
|
|
|
# include <Kernel/StdLib.h>
|
2020-03-08 11:34:33 +00:00
|
|
|
#else
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
|
2020-04-30 09:43:25 +00:00
|
|
|
ALWAYS_INLINE void fast_u32_copy(u32* dest, const u32* src, size_t count)
|
2020-03-08 11:34:33 +00:00
|
|
|
{
|
2021-05-31 15:25:40 +00:00
|
|
|
#if ARCH(I386)
|
2020-03-08 11:34:33 +00:00
|
|
|
asm volatile(
|
|
|
|
"rep movsl\n"
|
2020-07-27 13:54:39 +00:00
|
|
|
: "+S"(src), "+D"(dest), "+c"(count)::"memory");
|
2021-05-31 15:25:40 +00:00
|
|
|
#else
|
|
|
|
__builtin_memcpy(dest, src, count * 4);
|
|
|
|
#endif
|
2020-03-08 11:34:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 09:43:25 +00:00
|
|
|
ALWAYS_INLINE void fast_u32_fill(u32* dest, u32 value, size_t count)
|
2020-03-08 11:34:33 +00:00
|
|
|
{
|
2021-05-31 15:25:40 +00:00
|
|
|
#if ARCH(I386)
|
2020-03-08 11:34:33 +00:00
|
|
|
asm volatile(
|
|
|
|
"rep stosl\n"
|
|
|
|
: "=D"(dest), "=c"(count)
|
|
|
|
: "D"(dest), "c"(count), "a"(value)
|
|
|
|
: "memory");
|
2021-05-31 15:25:40 +00:00
|
|
|
#else
|
|
|
|
for (auto* p = dest; p < (dest + count); ++p) {
|
|
|
|
*p = value;
|
|
|
|
}
|
|
|
|
#endif
|
2020-03-08 11:34:33 +00:00
|
|
|
}
|