Clone of PhatAC @ https://github.com/floaterxk/PhatAC

byte_order_generic.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. /*
  13. Endianness-independent definitions for architectures other
  14. than the x86 architecture.
  15. */
  16. static inline int16 sint2korr(const uchar *A)
  17. {
  18. return
  19. (int16) (((int16) (A[0])) +
  20. ((int16) (A[1]) << 8))
  21. ;
  22. }
  23. static inline int32 sint4korr(const uchar *A)
  24. {
  25. return
  26. (int32) (((int32) (A[0])) +
  27. (((int32) (A[1]) << 8)) +
  28. (((int32) (A[2]) << 16)) +
  29. (((int32) (A[3]) << 24)))
  30. ;
  31. }
  32. static inline uint16 uint2korr(const uchar *A)
  33. {
  34. return
  35. (uint16) (((uint16) (A[0])) +
  36. ((uint16) (A[1]) << 8))
  37. ;
  38. }
  39. static inline uint32 uint4korr(const uchar *A)
  40. {
  41. return
  42. (uint32) (((uint32) (A[0])) +
  43. (((uint32) (A[1])) << 8) +
  44. (((uint32) (A[2])) << 16) +
  45. (((uint32) (A[3])) << 24))
  46. ;
  47. }
  48. static inline ulonglong uint8korr(const uchar *A)
  49. {
  50. return
  51. ((ulonglong)(((uint32) (A[0])) +
  52. (((uint32) (A[1])) << 8) +
  53. (((uint32) (A[2])) << 16) +
  54. (((uint32) (A[3])) << 24)) +
  55. (((ulonglong) (((uint32) (A[4])) +
  56. (((uint32) (A[5])) << 8) +
  57. (((uint32) (A[6])) << 16) +
  58. (((uint32) (A[7])) << 24))) <<
  59. 32))
  60. ;
  61. }
  62. static inline longlong sint8korr(const uchar *A)
  63. {
  64. return (longlong) uint8korr(A);
  65. }
  66. static inline void int2store(uchar *T, uint16 A)
  67. {
  68. uint def_temp= A ;
  69. *(T)= (uchar)(def_temp);
  70. *(T+1)= (uchar)(def_temp >> 8);
  71. }
  72. static inline void int4store(uchar *T, uint32 A)
  73. {
  74. *(T)= (uchar) (A);
  75. *(T+1)=(uchar) (A >> 8);
  76. *(T+2)=(uchar) (A >> 16);
  77. *(T+3)=(uchar) (A >> 24);
  78. }
  79. static inline void int8store(uchar *T, ulonglong A)
  80. {
  81. uint def_temp= (uint) A,
  82. def_temp2= (uint) (A >> 32);
  83. int4store(T, def_temp);
  84. int4store(T+4,def_temp2);
  85. }