aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2013-10-04 00:36:22 -0700
committerPaul Eggert2013-10-04 00:36:22 -0700
commit4eed3157327f8406921658442a11af7e9d84d603 (patch)
treee727a3017628ce840707d71998d4f6423a8fbde3 /src
parent157fec2e190a84345138a0cc69e35f177c4d4a56 (diff)
downloademacs-4eed3157327f8406921658442a11af7e9d84d603.tar.gz
emacs-4eed3157327f8406921658442a11af7e9d84d603.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/data.c5
-rw-r--r--src/fringe.c4
-rw-r--r--src/lisp.h24
-rw-r--r--src/sound.c29
-rw-r--r--src/xsettings.c11
6 files changed, 27 insertions, 55 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4fae03d6965..38fb35ddf54 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,14 @@
12013-10-04 Paul Eggert <eggert@cs.ucla.edu> 12013-10-04 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 Use hardware support for byteswapping on glibc x86 etc.
4 On Fedora 19 x86-64, the new bswap_64 needs 1 instruction,
5 whereas the old swap64 needed 30.
6 * fringe.c (init_fringe_bitmap) [WORDS_BIGENDIAN]:
7 * sound.c (le2hl, le2hs, be2hl) [!WINDOWSNT]:
8 Use byteswap.h's macros to swap bytes.
9 * lisp.h (swap16, swap32, swap64): Remove.
10 All uses replaced by bswap_16, bswap_32, bswap_64.
11
3 * bytecode.c (exec_byte_code): Use some more volatile variables 12 * bytecode.c (exec_byte_code): Use some more volatile variables
4 to work around local variables getting clobbered by longjmp. 13 to work around local variables getting clobbered by longjmp.
5 Port to pre-C99, which doesn't allow decls after stmts. 14 Port to pre-C99, which doesn't allow decls after stmts.
diff --git a/src/data.c b/src/data.c
index b268616fd26..a6bfe50a3bb 100644
--- a/src/data.c
+++ b/src/data.c
@@ -21,6 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21#include <config.h> 21#include <config.h>
22#include <stdio.h> 22#include <stdio.h>
23 23
24#include <byteswap.h>
24#include <intprops.h> 25#include <intprops.h>
25 26
26#include "lisp.h" 27#include "lisp.h"
@@ -3185,9 +3186,9 @@ size_t_to_host_endian (size_t val)
3185{ 3186{
3186#ifdef WORDS_BIGENDIAN 3187#ifdef WORDS_BIGENDIAN
3187# if BITS_PER_SIZE_T == 64 3188# if BITS_PER_SIZE_T == 64
3188 return swap64 (val); 3189 return bswap_64 (val);
3189# else 3190# else
3190 return swap32 (val); 3191 return bswap_32 (val);
3191# endif 3192# endif
3192#else 3193#else
3193 return val; 3194 return val;
diff --git a/src/fringe.c b/src/fringe.c
index 85103f7f08d..3537027f1dd 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -20,6 +20,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20#include <config.h> 20#include <config.h>
21#include <stdio.h> 21#include <stdio.h>
22 22
23#include <byteswap.h>
24
23#include "lisp.h" 25#include "lisp.h"
24#include "frame.h" 26#include "frame.h"
25#include "window.h" 27#include "window.h"
@@ -1519,7 +1521,7 @@ init_fringe_bitmap (int which, struct fringe_bitmap *fb, int once_p)
1519 | (swap_nibble[(b>>12) & 0xf])); 1521 | (swap_nibble[(b>>12) & 0xf]));
1520 b >>= (16 - fb->width); 1522 b >>= (16 - fb->width);
1521#ifdef WORDS_BIGENDIAN 1523#ifdef WORDS_BIGENDIAN
1522 b = ((b >> 8) | (b << 8)); 1524 b = bswap_16 (b);
1523#endif 1525#endif
1524 *bits++ = b; 1526 *bits++ = b;
1525 } 1527 }
diff --git a/src/lisp.h b/src/lisp.h
index f949978ceed..2f0279ef542 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4366,30 +4366,6 @@ functionp (Lisp_Object object)
4366 return 0; 4366 return 0;
4367} 4367}
4368 4368
4369INLINE uint16_t
4370swap16 (uint16_t val)
4371{
4372 return (val << 8) | (val & 0xFF);
4373}
4374
4375INLINE uint32_t
4376swap32 (uint32_t val)
4377{
4378 uint32_t low = swap16 (val & 0xFFFF);
4379 uint32_t high = swap16 (val >> 16);
4380 return (low << 16) | high;
4381}
4382
4383#ifdef UINT64_MAX
4384INLINE uint64_t
4385swap64 (uint64_t val)
4386{
4387 uint64_t low = swap32 (val & 0xFFFFFFFF);
4388 uint64_t high = swap32 (val >> 32);
4389 return (low << 32) | high;
4390}
4391#endif
4392
4393#if ((SIZE_MAX >> 31) >> 1) & 1 4369#if ((SIZE_MAX >> 31) >> 1) & 1
4394# define BITS_PER_SIZE_T 64 4370# define BITS_PER_SIZE_T 64
4395#else 4371#else
diff --git a/src/sound.c b/src/sound.c
index 27e06b8abab..f8c6b483056 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -55,6 +55,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
55/* BEGIN: Non Windows Includes */ 55/* BEGIN: Non Windows Includes */
56#ifndef WINDOWSNT 56#ifndef WINDOWSNT
57 57
58#include <byteswap.h>
59
58#include <sys/ioctl.h> 60#include <sys/ioctl.h>
59 61
60/* FreeBSD has machine/soundcard.h. Voxware sound driver docs mention 62/* FreeBSD has machine/soundcard.h. Voxware sound driver docs mention
@@ -461,8 +463,7 @@ static u_int32_t
461le2hl (u_int32_t value) 463le2hl (u_int32_t value)
462{ 464{
463#ifdef WORDS_BIGENDIAN 465#ifdef WORDS_BIGENDIAN
464 unsigned char *p = (unsigned char *) &value; 466 value = bswap_32 (value);
465 value = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
466#endif 467#endif
467 return value; 468 return value;
468} 469}
@@ -475,8 +476,7 @@ static u_int16_t
475le2hs (u_int16_t value) 476le2hs (u_int16_t value)
476{ 477{
477#ifdef WORDS_BIGENDIAN 478#ifdef WORDS_BIGENDIAN
478 unsigned char *p = (unsigned char *) &value; 479 value = bswap_16 (value);
479 value = p[0] + (p[1] << 8);
480#endif 480#endif
481 return value; 481 return value;
482} 482}
@@ -489,30 +489,11 @@ static u_int32_t
489be2hl (u_int32_t value) 489be2hl (u_int32_t value)
490{ 490{
491#ifndef WORDS_BIGENDIAN 491#ifndef WORDS_BIGENDIAN
492 unsigned char *p = (unsigned char *) &value; 492 value = bswap_32 (value);
493 value = p[3] + (p[2] << 8) + (p[1] << 16) + (p[0] << 24);
494#endif 493#endif
495 return value; 494 return value;
496} 495}
497 496
498
499#if 0 /* Currently not used. */
500
501/* Convert 16-bit value VALUE which is in big-endian byte-order
502 to host byte-order. */
503
504static u_int16_t
505be2hs (u_int16_t value)
506{
507#ifndef WORDS_BIGENDIAN
508 unsigned char *p = (unsigned char *) &value;
509 value = p[1] + (p[0] << 8);
510#endif
511 return value;
512}
513
514#endif /* 0 */
515
516/*********************************************************************** 497/***********************************************************************
517 RIFF-WAVE (*.wav) 498 RIFF-WAVE (*.wav)
518 ***********************************************************************/ 499 ***********************************************************************/
diff --git a/src/xsettings.c b/src/xsettings.c
index 8fe82fec74b..e5a66c4cf0a 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -22,6 +22,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22#include <float.h> 22#include <float.h>
23#include <limits.h> 23#include <limits.h>
24#include <fcntl.h> 24#include <fcntl.h>
25
26#include <byteswap.h>
27
25#include "lisp.h" 28#include "lisp.h"
26#include "xterm.h" 29#include "xterm.h"
27#include "xsettings.h" 30#include "xsettings.h"
@@ -405,7 +408,7 @@ parse_settings (unsigned char *prop,
405 408
406 if (bytes < 12) return BadLength; 409 if (bytes < 12) return BadLength;
407 memcpy (&n_settings, prop+8, 4); 410 memcpy (&n_settings, prop+8, 4);
408 if (my_bo != that_bo) n_settings = swap32 (n_settings); 411 if (my_bo != that_bo) n_settings = bswap_32 (n_settings);
409 bytes_parsed = 12; 412 bytes_parsed = 12;
410 413
411 memset (settings, 0, sizeof (*settings)); 414 memset (settings, 0, sizeof (*settings));
@@ -427,7 +430,7 @@ parse_settings (unsigned char *prop,
427 430
428 memcpy (&nlen, prop+bytes_parsed, 2); 431 memcpy (&nlen, prop+bytes_parsed, 2);
429 bytes_parsed += 2; 432 bytes_parsed += 2;
430 if (my_bo != that_bo) nlen = swap16 (nlen); 433 if (my_bo != that_bo) nlen = bswap_16 (nlen);
431 if (bytes_parsed+nlen > bytes) return BadLength; 434 if (bytes_parsed+nlen > bytes) return BadLength;
432 to_cpy = nlen > 127 ? 127 : nlen; 435 to_cpy = nlen > 127 ? 127 : nlen;
433 memcpy (name, prop+bytes_parsed, to_cpy); 436 memcpy (name, prop+bytes_parsed, to_cpy);
@@ -454,7 +457,7 @@ parse_settings (unsigned char *prop,
454 if (want_this) 457 if (want_this)
455 { 458 {
456 memcpy (&ival, prop+bytes_parsed, 4); 459 memcpy (&ival, prop+bytes_parsed, 4);
457 if (my_bo != that_bo) ival = swap32 (ival); 460 if (my_bo != that_bo) ival = bswap_32 (ival);
458 } 461 }
459 bytes_parsed += 4; 462 bytes_parsed += 4;
460 break; 463 break;
@@ -463,7 +466,7 @@ parse_settings (unsigned char *prop,
463 if (bytes_parsed+4 > bytes) return BadLength; 466 if (bytes_parsed+4 > bytes) return BadLength;
464 memcpy (&vlen, prop+bytes_parsed, 4); 467 memcpy (&vlen, prop+bytes_parsed, 4);
465 bytes_parsed += 4; 468 bytes_parsed += 4;
466 if (my_bo != that_bo) vlen = swap32 (vlen); 469 if (my_bo != that_bo) vlen = bswap_32 (vlen);
467 if (want_this) 470 if (want_this)
468 { 471 {
469 to_cpy = vlen > 127 ? 127 : vlen; 472 to_cpy = vlen > 127 ? 127 : vlen;