Skip to content

Commit b52343d

Browse files
t-8chtorvalds
authored andcommitted
ARM: clean up the memset64() C wrapper
The current logic to split the 64-bit argument into its 32-bit halves is byte-order specific and a bit clunky. Use a union instead which is easier to read and works in all cases. GCC still generates the same machine code. While at it, rename the arguments of the __memset64() prototype to actually reflect their semantics. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent cd7a565 commit b52343d

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

arch/arm/include/asm/string.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ static inline void *memset32(uint32_t *p, uint32_t v, __kernel_size_t n)
3939
}
4040

4141
#define __HAVE_ARCH_MEMSET64
42-
extern void *__memset64(uint64_t *, uint32_t low, __kernel_size_t, uint32_t hi);
42+
extern void *__memset64(uint64_t *, uint32_t first, __kernel_size_t, uint32_t second);
4343
static inline void *memset64(uint64_t *p, uint64_t v, __kernel_size_t n)
4444
{
45-
if (IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN))
46-
return __memset64(p, v, n * 8, v >> 32);
47-
else
48-
return __memset64(p, v >> 32, n * 8, v);
45+
union {
46+
uint64_t val;
47+
struct {
48+
uint32_t first, second;
49+
};
50+
} word = { .val = v };
51+
52+
return __memset64(p, word.first, n * 8, word.second);
4953
}
5054

5155
/*

0 commit comments

Comments
 (0)