xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/arm/bswapdi2.S (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1//===------- bswapdi2 - Implement bswapdi2 --------------------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "../assembly.h"
10
11	.syntax unified
12	.text
13	DEFINE_CODE_STATE
14
15//
16// extern uint64_t __bswapdi2(uint64_t);
17//
18// Reverse all the bytes in a 64-bit integer.
19//
20	.p2align 2
21DEFINE_COMPILERRT_FUNCTION(__bswapdi2)
22#if __ARM_ARCH < 6
23    // before armv6 does not have "rev" instruction
24    // r2 = rev(r0)
25    eor r2, r0, r0, ror #16
26    bic r2, r2, #0xff0000
27    mov r2, r2, lsr #8
28    eor r2, r2, r0, ror #8
29    // r0 = rev(r1)
30    eor r0, r1, r1, ror #16
31    bic r0, r0, #0xff0000
32    mov r0, r0, lsr #8
33    eor r0, r0, r1, ror #8
34#else
35    rev r2, r0  // r2 = rev(r0)
36    rev r0, r1  // r0 = rev(r1)
37#endif
38    mov r1, r2  // r1 = r2 = rev(r0)
39    JMP(lr)
40END_COMPILERRT_FUNCTION(__bswapdi2)
41
42NO_EXEC_STACK_DIRECTIVE
43
44