swap64.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. swap64.c - 64-bit byte swapping functions.
  3. Copyright (C) 1995 - 2001 Michael Riepe
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  15. */
  16. #include <private.h>
  17. #include <byteswap.h>
  18. #if __LIBELF64
  19. #ifndef lint
  20. static const char rcsid[] = "@(#) $Id: swap64.c,v 1.6 2008/05/23 08:15:35 michael Exp $";
  21. #endif /* lint */
  22. __libelf_u64_t
  23. _elf_load_u64L(const unsigned char *from) {
  24. return ((__libelf_u64_t)__load_u32L(from + 4) << 32)
  25. | (__libelf_u64_t)__load_u32L(from);
  26. }
  27. __libelf_u64_t
  28. _elf_load_u64M(const unsigned char *from) {
  29. return ((__libelf_u64_t)__load_u32M(from) << 32)
  30. | (__libelf_u64_t)__load_u32M(from + 4);
  31. }
  32. __libelf_i64_t
  33. _elf_load_i64L(const unsigned char *from) {
  34. return ((__libelf_i64_t)__load_i32L(from + 4) << 32)
  35. | (__libelf_u64_t)__load_u32L(from);
  36. }
  37. __libelf_i64_t
  38. _elf_load_i64M(const unsigned char *from) {
  39. return ((__libelf_i64_t)__load_i32M(from) << 32)
  40. | (__libelf_u64_t)__load_u32M(from + 4);
  41. }
  42. void
  43. _elf_store_u64L(unsigned char *to, __libelf_u64_t v) {
  44. __store_u32L(to, (__libelf_u32_t)v);
  45. v >>= 32;
  46. __store_u32L(to + 4, (__libelf_u32_t)v);
  47. }
  48. void
  49. _elf_store_u64M(unsigned char *to, __libelf_u64_t v) {
  50. __store_u32M(to + 4, (__libelf_u32_t)v);
  51. v >>= 32;
  52. __store_u32M(to, (__libelf_u32_t)v);
  53. }
  54. void
  55. _elf_store_i64L(unsigned char *to, __libelf_u64_t v) {
  56. __store_u32L(to, (__libelf_u32_t)v);
  57. v >>= 32;
  58. __store_i32L(to + 4, (__libelf_u32_t)v);
  59. }
  60. void
  61. _elf_store_i64M(unsigned char *to, __libelf_u64_t v) {
  62. __store_u32M(to + 4, (__libelf_u32_t)v);
  63. v >>= 32;
  64. __store_i32M(to, (__libelf_u32_t)v);
  65. }
  66. #endif /* __LIBELF64 */