Add BSWAP16 and BSWAP32 macros for use in assembly.

This commit is contained in:
matt 2012-07-15 19:59:48 +00:00
parent 4438cf030d
commit 67e5bbcb5f

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.9 2012/07/12 17:23:02 matt Exp $ */
/* $NetBSD: byte_swap.h,v 1.10 2012/07/15 19:59:48 matt Exp $ */
/*-
* Copyright (c) 1997, 1999, 2002 The NetBSD Foundation, Inc.
@ -32,6 +32,33 @@
#ifndef _ARM_BYTE_SWAP_H_
#define _ARM_BYTE_SWAP_H_
#ifdef _LOCORE
#if (ARM_ARCH_6 + ARM_ARCH_7) > 0
#define BSWAP16(_src, _dst, _tmp) \
rev16 _dst, _src
#define BSWAP32(_src, _dst, _tmp) \
rev _dst, _src
#else
#define BSWAP16(_src, _dst, _tmp) \
mov _tmp, _src, ror #8 ;\
orr _tmp, _tmp, _tmp, lsr #16 ;\
bic _dst, _tmp, _tmp, lsl #16
#define BSWAP32(_src, _dst, _tmp) \
eor _tmp, _src, _src, ror #16 ;\
bic _tmp, _tmp, #0x00FF0000 ;\
mov _dst, _src, ror #8 ;\
eor _dst, _dst, _tmp, lsr #8
#endif
#else
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
@ -87,5 +114,6 @@ __byte_swap_u16_variable(uint16_t v)
__END_DECLS
#endif
#endif /* _LOCORE */
#endif /* _ARM_BYTE_SWAP_H_ */