Use hardware support for byteswapping on glibc x86 etc.
On Fedora 19 x86-64, the new bswap_64 needs 1 instruction,
whereas the old swap64 needed 30.
* admin/merge-gnulib (GNULIB_MODULES): Add byteswap.
* lib/byteswap.in.h, m4/byteswap.m4: New files, copied from Gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* src/fringe.c (init_fringe_bitmap) [WORDS_BIGENDIAN]:
* src/sound.c (le2hl, le2hs, be2hl) [!WINDOWSNT]:
Use byteswap.h's macros to swap bytes.
* src/lisp.h (swap16, swap32, swap64): Remove.
All uses replaced by bswap_16, bswap_32, bswap_64.
2013-10-04 07:36:22 +00:00
|
|
|
/* byteswap.h - Byte swapping
|
2021-01-01 09:13:56 +00:00
|
|
|
Copyright (C) 2005, 2007, 2009-2021 Free Software Foundation, Inc.
|
Use hardware support for byteswapping on glibc x86 etc.
On Fedora 19 x86-64, the new bswap_64 needs 1 instruction,
whereas the old swap64 needed 30.
* admin/merge-gnulib (GNULIB_MODULES): Add byteswap.
* lib/byteswap.in.h, m4/byteswap.m4: New files, copied from Gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* src/fringe.c (init_fringe_bitmap) [WORDS_BIGENDIAN]:
* src/sound.c (le2hl, le2hs, be2hl) [!WINDOWSNT]:
Use byteswap.h's macros to swap bytes.
* src/lisp.h (swap16, swap32, swap64): Remove.
All uses replaced by bswap_16, bswap_32, bswap_64.
2013-10-04 07:36:22 +00:00
|
|
|
Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005.
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2017-09-13 09:07:03 +00:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
Use hardware support for byteswapping on glibc x86 etc.
On Fedora 19 x86-64, the new bswap_64 needs 1 instruction,
whereas the old swap64 needed 30.
* admin/merge-gnulib (GNULIB_MODULES): Add byteswap.
* lib/byteswap.in.h, m4/byteswap.m4: New files, copied from Gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* src/fringe.c (init_fringe_bitmap) [WORDS_BIGENDIAN]:
* src/sound.c (le2hl, le2hs, be2hl) [!WINDOWSNT]:
Use byteswap.h's macros to swap bytes.
* src/lisp.h (swap16, swap32, swap64): Remove.
All uses replaced by bswap_16, bswap_32, bswap_64.
2013-10-04 07:36:22 +00:00
|
|
|
|
|
|
|
#ifndef _GL_BYTESWAP_H
|
|
|
|
#define _GL_BYTESWAP_H
|
|
|
|
|
|
|
|
/* Given an unsigned 16-bit argument X, return the value corresponding to
|
|
|
|
X with reversed byte order. */
|
|
|
|
#define bswap_16(x) ((((x) & 0x00FF) << 8) | \
|
|
|
|
(((x) & 0xFF00) >> 8))
|
|
|
|
|
|
|
|
/* Given an unsigned 32-bit argument X, return the value corresponding to
|
|
|
|
X with reversed byte order. */
|
|
|
|
#define bswap_32(x) ((((x) & 0x000000FF) << 24) | \
|
|
|
|
(((x) & 0x0000FF00) << 8) | \
|
|
|
|
(((x) & 0x00FF0000) >> 8) | \
|
|
|
|
(((x) & 0xFF000000) >> 24))
|
|
|
|
|
|
|
|
/* Given an unsigned 64-bit argument X, return the value corresponding to
|
|
|
|
X with reversed byte order. */
|
|
|
|
#define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \
|
|
|
|
(((x) & 0x000000000000FF00ULL) << 40) | \
|
|
|
|
(((x) & 0x0000000000FF0000ULL) << 24) | \
|
|
|
|
(((x) & 0x00000000FF000000ULL) << 8) | \
|
|
|
|
(((x) & 0x000000FF00000000ULL) >> 8) | \
|
|
|
|
(((x) & 0x0000FF0000000000ULL) >> 24) | \
|
|
|
|
(((x) & 0x00FF000000000000ULL) >> 40) | \
|
|
|
|
(((x) & 0xFF00000000000000ULL) >> 56))
|
|
|
|
|
|
|
|
#endif /* _GL_BYTESWAP_H */
|