blob: a0283e14e1e086d5f1e174748f32f878fa529dcb [file] [log] [blame]
Stephen Canonfe22a3f2010-07-03 01:00:49 +00001//===------- bswapdi2 - Implement bswapdi2 --------------------------------===//
Nick Kledzike80e9782009-09-12 01:23:48 +00002//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Nick Kledzike80e9782009-09-12 01:23:48 +00007//
8//===----------------------------------------------------------------------===//
9
Daniel Dunbar19336a22009-10-27 17:49:50 +000010#include "../assembly.h"
Nick Kledzike80e9782009-09-12 01:23:48 +000011
12//
13// extern uint64_t __bswapdi2(uint64_t);
14//
15// Reverse all the bytes in a 64-bit integer.
16//
Stephen Canone735b292010-07-03 21:47:50 +000017.align 2
Daniel Dunbarb4b1e8c2009-10-27 17:50:21 +000018DEFINE_COMPILERRT_FUNCTION(__bswapdi2)
Nick Kledzik455c2632010-07-03 00:12:47 +000019#if __ARM_ARCH_5TEJ__ || __ARM_ARCH_4T__
Stephen Canone735b292010-07-03 21:47:50 +000020 // before armv6 does not have "rev" instruction
21 // r2 = rev(r0)
22 eor r2, r0, r0, ror #16
23 bic r2, r2, #0xff0000
24 mov r2, r2, lsr #8
25 eor r2, r2, r0, ror #8
26 // r0 = rev(r1)
27 eor r0, r1, r1, ror #16
28 bic r0, r0, #0xff0000
29 mov r0, r0, lsr #8
30 eor r0, r0, r1, ror #8
Nick Kledzik455c2632010-07-03 00:12:47 +000031#else
Stephen Canone735b292010-07-03 21:47:50 +000032 rev r2, r0 // r2 = rev(r0)
33 rev r0, r1 // r0 = rev(r1)
Nick Kledzik455c2632010-07-03 00:12:47 +000034#endif
Stephen Canone735b292010-07-03 21:47:50 +000035 mov r1, r2 // r1 = r2 = rev(r0)
Stephen Canonfe22a3f2010-07-03 01:00:49 +000036 bx lr