blob: 4c3af1f6d04df7b4da00b6d760ce83c35483be8e [file] [log] [blame]
Stephen Canonfe22a3f2010-07-03 01:00:49 +00001//===------- bswapsi2 - Implement bswapsi2 --------------------------------===//
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 uint32_t __bswapsi2(uint32_t);
14//
Nick Kledzik6e8c3ac2009-09-13 18:34:39 +000015// Reverse all the bytes in a 32-bit integer.
Nick Kledzike80e9782009-09-12 01:23:48 +000016//
Stephen Canone735b292010-07-03 21:47:50 +000017.align 2
Daniel Dunbarb4b1e8c2009-10-27 17:50:21 +000018DEFINE_COMPILERRT_FUNCTION(__bswapsi2)
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 eor r1, r0, r0, ror #16
22 bic r1, r1, #0xff0000
23 mov r1, r1, lsr #8
24 eor r0, r1, r0, ror #8
Nick Kledzik455c2632010-07-03 00:12:47 +000025#else
Stephen Canone735b292010-07-03 21:47:50 +000026 rev r0, r0
Nick Kledzik455c2632010-07-03 00:12:47 +000027#endif
Stephen Canone735b292010-07-03 21:47:50 +000028 bx lr