## ffmpeg / libavutil / bswap.h @ be449fca

History | View | Annotate | Download (3.25 KB)

1 | 04d7f601 | Diego Biurrun | ```
/*
``` |
---|---|---|---|

2 | ```
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
``` |
||

3 | ```
*
``` |
||

4 | b78e7197 | Diego Biurrun | ```
* This file is part of FFmpeg.
``` |

5 | ```
*
``` |
||

6 | ```
* FFmpeg is free software; you can redistribute it and/or
``` |
||

7 | 04d7f601 | Diego Biurrun | ```
* modify it under the terms of the GNU Lesser General Public
``` |

8 | ```
* License as published by the Free Software Foundation; either
``` |
||

9 | b78e7197 | Diego Biurrun | ```
* version 2.1 of the License, or (at your option) any later version.
``` |

10 | 04d7f601 | Diego Biurrun | ```
*
``` |

11 | b78e7197 | Diego Biurrun | ```
* FFmpeg is distributed in the hope that it will be useful,
``` |

12 | 04d7f601 | Diego Biurrun | ```
* but WITHOUT ANY WARRANTY; without even the implied warranty of
``` |

13 | ```
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
``` |
||

14 | ```
* Lesser General Public License for more details.
``` |
||

15 | ```
*
``` |
||

16 | ```
* You should have received a copy of the GNU Lesser General Public
``` |
||

17 | b78e7197 | Diego Biurrun | ```
* License along with FFmpeg; if not, write to the Free Software
``` |

18 | 04d7f601 | Diego Biurrun | ```
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
``` |

19 | ```
*/
``` |
||

20 | |||

21 | 983e3246 | Michael Niedermayer | ```
/**
``` |

22 | ```
* @file bswap.h
``` |
||

23 | 7ce68923 | Diego Biurrun | ```
* byte swapping routines
``` |

24 | 983e3246 | Michael Niedermayer | ```
*/
``` |

25 | |||

26 | 98790382 | Stefano Sabatini | ```
#ifndef AVUTIL_BSWAP_H
``` |

27 | ```
#define AVUTIL_BSWAP_H
``` |
||

28 | a9b3f630 | Nick Kurshev | |

29 | 99545457 | Måns Rullgård | #include <stdint.h> |

30 | a087028a | Diego Biurrun | #include "config.h" |

31 | 99545457 | Måns Rullgård | #include "common.h" |

32 | |||

33 | 85074d3c | Zuxy Meng | ```
static av_always_inline av_const uint16_t bswap_16(uint16_t x)
``` |

34 | a9b3f630 | Nick Kurshev | { |

35 | bf5d7db5 | Ramiro Polla | ```
#if defined(ARCH_X86)
``` |

36 | be449fca | Diego Pettenò | __asm__("rorw $8, %0" : "+r"(x)); |

37 | bf5d7db5 | Ramiro Polla | ```
#elif defined(ARCH_SH4)
``` |

38 | be449fca | Diego Pettenò | __asm__("swap.b %0,%0" : "=r"(x) : "0"(x)); |

39 | ea66f252 | Måns Rullgård | ```
#elif defined(HAVE_ARMV6)
``` |

40 | be449fca | Diego Pettenò | __asm__("rev16 %0, %0" : "+r"(x)); |

41 | bf5d7db5 | Ramiro Polla | ```
#else
``` |

42 | x= (x>>8) | (x<<8); |
||

43 | ```
#endif
``` |
||

44 | a9b3f630 | Nick Kurshev | ```
return x;
``` |

45 | } |
||

46 | |||

47 | 85074d3c | Zuxy Meng | ```
static av_always_inline av_const uint32_t bswap_32(uint32_t x)
``` |

48 | a9b3f630 | Nick Kurshev | { |

49 | bf5d7db5 | Ramiro Polla | ```
#if defined(ARCH_X86)
``` |

50 | 6bd859d6 | Måns Rullgård | ```
#ifdef HAVE_BSWAP
``` |

51 | be449fca | Diego Pettenò | __asm__("bswap %0" : "+r" (x)); |

52 | a9b3f630 | Nick Kurshev | ```
#else
``` |

53 | be449fca | Diego Pettenò | ```
__asm__("rorw $8, %w0 \n\t"
``` |

54 | 3662d880 | Måns Rullgård | ```
"rorl $16, %0 \n\t"
``` |

55 | ```
"rorw $8, %w0"
``` |
||

56 | ```
: "+r"(x));
``` |
||

57 | a9b3f630 | Nick Kurshev | ```
#endif
``` |

58 | 0c6bd2ea | BERO | ```
#elif defined(ARCH_SH4)
``` |

59 | be449fca | Diego Pettenò | ```
__asm__("swap.b %0,%0\n"
``` |

60 | 70fa2e27 | Måns Rullgård | ```
"swap.w %0,%0\n"
``` |

61 | ```
"swap.b %0,%0\n"
``` |
||

62 | : "=r"(x) : "0"(x)); |
||

63 | ea66f252 | Måns Rullgård | ```
#elif defined(HAVE_ARMV6)
``` |

64 | be449fca | Diego Pettenò | __asm__("rev %0, %0" : "+r"(x)); |

65 | c696a863 | Måns Rullgård | ```
#elif defined(ARCH_ARMV4L)
``` |

66 | 6ad1fa5a | Bernhard Rosenkränzer | uint32_t t; |

67 | be449fca | Diego Pettenò | ```
__asm__ ("eor %1, %0, %0, ror #16 \n\t"
``` |

68 | 70fa2e27 | Måns Rullgård | ```
"bic %1, %1, #0xFF0000 \n\t"
``` |

69 | ```
"mov %0, %0, ror #8 \n\t"
``` |
||

70 | ```
"eor %0, %0, %1, lsr #8 \n\t"
``` |
||

71 | : "+r"(x), "+r"(t)); |
||

72 | 20d45dc2 | Marc Hoffman | ```
#elif defined(ARCH_BFIN)
``` |

73 | ```
unsigned tmp;
``` |
||

74 | be449fca | Diego Pettenò | ```
__asm__("%1 = %0 >> 8 (V); \n\t"
``` |

75 | 27af15dc | Diego Biurrun | ```
"%0 = %0 << 8 (V); \n\t"
``` |

76 | ```
"%0 = %0 | %1; \n\t"
``` |
||

77 | ```
"%0 = PACK(%0.L, %0.H); \n\t"
``` |
||

78 | 20d45dc2 | Marc Hoffman | : "+d"(x), "=&d"(tmp)); |

79 | 6ad1fa5a | Bernhard Rosenkränzer | ```
#else
``` |

80 | 33f72572 | Michael Niedermayer | x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); |

81 | 853d15c2 | Ramiro Polla | x= (x>>16) | (x<<16); |

82 | bf5d7db5 | Ramiro Polla | ```
#endif
``` |

83 | 853d15c2 | Ramiro Polla | ```
return x;
``` |

84 | 24dea064 | Michael Niedermayer | } |

85 | a9b3f630 | Nick Kurshev | |

86 | 85074d3c | Zuxy Meng | static inline uint64_t av_const bswap_64(uint64_t x) |

87 | 74fc9989 | Fabrice Bellard | { |

88 | 33f72572 | Michael Niedermayer | ```
#if 0
``` |

89 | ```
x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
``` |
||

90 | ```
x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
``` |
||

91 | ```
return (x>>32) | (x<<32);
``` |
||

92 | bf5d7db5 | Ramiro Polla | ```
#elif defined(ARCH_X86_64)
``` |

93 | be449fca | Diego Pettenò | __asm__("bswap %0": "=r" (x) : "0" (x)); |

94 | bf5d7db5 | Ramiro Polla | ```
return x;
``` |

95 | 33f72572 | Michael Niedermayer | ```
#else
``` |

96 | 115329f1 | Diego Biurrun | ```
union {
``` |

97 | 74fc9989 | Fabrice Bellard | uint64_t ll; |

98 | 115329f1 | Diego Biurrun | ```
uint32_t l[2];
``` |

99 | 74fc9989 | Fabrice Bellard | } w, r; |

100 | w.ll = x; |
||

101 | r.l[0] = bswap_32 (w.l[1]); |
||

102 | r.l[1] = bswap_32 (w.l[0]); |
||

103 | ```
return r.ll;
``` |
||

104 | 33f72572 | Michael Niedermayer | ```
#endif
``` |

105 | 74fc9989 | Fabrice Bellard | } |

106 | a9b3f630 | Nick Kurshev | |

107 | ```
// be2me ... BigEndian to MachineEndian
``` |
||

108 | ```
// le2me ... LittleEndian to MachineEndian
``` |
||

109 | |||

110 | ```
#ifdef WORDS_BIGENDIAN
``` |
||

111 | ```
#define be2me_16(x) (x)
``` |
||

112 | ```
#define be2me_32(x) (x)
``` |
||

113 | ```
#define be2me_64(x) (x)
``` |
||

114 | ```
#define le2me_16(x) bswap_16(x)
``` |
||

115 | ```
#define le2me_32(x) bswap_32(x)
``` |
||

116 | ```
#define le2me_64(x) bswap_64(x)
``` |
||

117 | ```
#else
``` |
||

118 | ```
#define be2me_16(x) bswap_16(x)
``` |
||

119 | ```
#define be2me_32(x) bswap_32(x)
``` |
||

120 | ```
#define be2me_64(x) bswap_64(x)
``` |
||

121 | ```
#define le2me_16(x) (x)
``` |
||

122 | ```
#define le2me_32(x) (x)
``` |
||

123 | ```
#define le2me_64(x) (x)
``` |
||

124 | ```
#endif
``` |
||

125 | |||

126 | 98790382 | Stefano Sabatini | #endif /* AVUTIL_BSWAP_H */ |