emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114516: Use hardware support for byteswapping on gl


From: Paul Eggert
Subject: [Emacs-diffs] trunk r114516: Use hardware support for byteswapping on glibc x86 etc.
Date: Fri, 04 Oct 2013 07:36:43 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114516
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Fri 2013-10-04 00:36:22 -0700
message:
  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.
added:
  lib/byteswap.in.h              byteswap.in.h-20131004071940-zgnnwf7aw8ghclao-1
  m4/byteswap.m4                 byteswap.m4-20131004071940-zgnnwf7aw8ghclao-2
modified:
  ChangeLog                      changelog-20091113204419-o5vbwnq5f7feedwu-1538
  admin/ChangeLog                changelog-20091113204419-o5vbwnq5f7feedwu-2226
  admin/merge-gnulib             mergegnulib-20120521022411-ndnoaiok33j6dn0g-1
  lib/gnulib.mk                  gnulib.mk-20110108211121-3ig4un4ogtyyca3s-7
  m4/gnulib-comp.m4              glcomp.m4-20110127072028-6mkjqxjzdsx0wp15-1
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/data.c                     data.c-20091113204419-o5vbwnq5f7feedwu-251
  src/fringe.c                   fringe.c-20091113204419-o5vbwnq5f7feedwu-2965
  src/lisp.h                     lisp.h-20091113204419-o5vbwnq5f7feedwu-253
  src/sound.c                    sound.c-20091113204419-o5vbwnq5f7feedwu-1323
  src/xsettings.c                xsettings.c-20091117210551-bqxn4u9uesl3d17a-4
=== modified file 'ChangeLog'
--- a/ChangeLog 2013-10-03 07:06:52 +0000
+++ b/ChangeLog 2013-10-04 07:36:22 +0000
@@ -1,3 +1,9 @@
+2013-10-04  Paul Eggert  <address@hidden>
+
+       Use hardware insns for byteswapping on glibc hosts that support it.
+       * lib/byteswap.in.h, m4/byteswap.m4: New files, copied from Gnulib.
+       * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
+
 2013-10-03  Paul Eggert  <address@hidden>
 
        Merge from gnulib, incorporating:

=== modified file 'admin/ChangeLog'
--- a/admin/ChangeLog   2013-08-28 06:01:52 +0000
+++ b/admin/ChangeLog   2013-10-04 07:36:22 +0000
@@ -1,3 +1,8 @@
+2013-10-04  Paul Eggert  <address@hidden>
+
+       Use hardware support for byteswapping on glibc x86 etc.
+       * merge-gnulib (GNULIB_MODULES): Add byteswap.
+
 2013-08-28  Paul Eggert  <address@hidden>
 
        * unidata/Makefile.in (SHELL): Now @SHELL@, not /bin/sh,

=== modified file 'admin/merge-gnulib'
--- a/admin/merge-gnulib        2013-08-04 16:56:56 +0000
+++ b/admin/merge-gnulib        2013-10-04 07:36:22 +0000
@@ -26,7 +26,7 @@
 GNULIB_URL=git://git.savannah.gnu.org/gnulib.git
 
 GNULIB_MODULES='
-  alloca-opt c-ctype c-strcase
+  alloca-opt byteswap c-ctype c-strcase
   careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512
   dtoastr dtotimespec dup2 environ execinfo faccessat
   fcntl fcntl-h fdatasync fdopendir filemode fstatat fsync

=== added file 'lib/byteswap.in.h'
--- a/lib/byteswap.in.h 1970-01-01 00:00:00 +0000
+++ b/lib/byteswap.in.h 2013-10-04 07:36:22 +0000
@@ -0,0 +1,44 @@
+/* byteswap.h - Byte swapping
+   Copyright (C) 2005, 2007, 2009-2013 Free Software Foundation, Inc.
+   Written by Oskar Liljeblad <address@hidden>, 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
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#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 */

=== modified file 'lib/gnulib.mk'
--- a/lib/gnulib.mk     2013-10-03 07:06:52 +0000
+++ b/lib/gnulib.mk     2013-10-04 07:36:22 +0000
@@ -21,7 +21,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib 
--m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux 
--avoid=close --avoid=dup --avoid=fchdir --avoid=fstat --avoid=malloc-posix 
--avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die 
--avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select 
--avoid=sigprocmask --avoid=sys_types --avoid=threadlib 
--makefile-name=gnulib.mk --conditional-dependencies --no-libtool 
--macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat 
close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr 
dtotimespec dup2 environ execinfo faccessat fcntl fcntl-h fdatasync fdopendir 
filemode fstatat fsync getloadavg getopt-gnu gettime gettimeofday intprops 
largefile lstat manywarnings memrchr mkostemp mktime pipe2 pselect 
pthread_sigmask putenv qacl readlink readlinkat sig2str socklen stat-time 
stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat 
sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib 
--m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux 
--avoid=close --avoid=dup --avoid=fchdir --avoid=fstat --avoid=malloc-posix 
--avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die 
--avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select 
--avoid=sigprocmask --avoid=sys_types --avoid=threadlib 
--makefile-name=gnulib.mk --conditional-dependencies --no-libtool 
--macro-prefix=gl --no-vc-files alloca-opt byteswap c-ctype c-strcase 
careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 
dtoastr dtotimespec dup2 environ execinfo faccessat fcntl fcntl-h fdatasync 
fdopendir filemode fstatat fsync getloadavg getopt-gnu gettime gettimeofday 
intprops largefile lstat manywarnings memrchr mkostemp mktime pipe2 pselect 
pthread_sigmask putenv qacl readlink readlinkat sig2str socklen stat-time 
stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat 
sys_time time timer-time timespec-add timespec-sub unsetenv utimens warnings
 
 
 MOSTLYCLEANFILES += core *.stackdump
@@ -81,6 +81,29 @@
 
 ## end   gnulib module binary-io
 
+## begin gnulib module byteswap
+
+BUILT_SOURCES += $(BYTESWAP_H)
+
+# We need the following in order to create <byteswap.h> when the system
+# doesn't have one.
+if GL_GENERATE_BYTESWAP_H
+byteswap.h: byteswap.in.h $(top_builddir)/config.status
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         cat $(srcdir)/byteswap.in.h; \
+       } > address@hidden && \
+       mv -f address@hidden $@
+else
+byteswap.h: $(top_builddir)/config.status
+       rm -f $@
+endif
+MOSTLYCLEANFILES += byteswap.h byteswap.h-t
+
+EXTRA_DIST += byteswap.in.h
+
+## end   gnulib module byteswap
+
 ## begin gnulib module c-ctype
 
 libgnu_a_SOURCES += c-ctype.h c-ctype.c

=== added file 'm4/byteswap.m4'
--- a/m4/byteswap.m4    1970-01-01 00:00:00 +0000
+++ b/m4/byteswap.m4    2013-10-04 07:36:22 +0000
@@ -0,0 +1,19 @@
+# byteswap.m4 serial 4
+dnl Copyright (C) 2005, 2007, 2009-2013 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Oskar Liljeblad.
+
+AC_DEFUN([gl_BYTESWAP],
+[
+  dnl Prerequisites of lib/byteswap.in.h.
+  AC_CHECK_HEADERS([byteswap.h], [
+    BYTESWAP_H=''
+  ], [
+    BYTESWAP_H='byteswap.h'
+  ])
+  AC_SUBST([BYTESWAP_H])
+  AM_CONDITIONAL([GL_GENERATE_BYTESWAP_H], [test -n "$BYTESWAP_H"])
+])

=== modified file 'm4/gnulib-comp.m4'
--- a/m4/gnulib-comp.m4 2013-10-03 07:06:52 +0000
+++ b/m4/gnulib-comp.m4 2013-10-04 07:36:22 +0000
@@ -42,6 +42,7 @@
   # Code from module allocator:
   # Code from module at-internal:
   # Code from module binary-io:
+  # Code from module byteswap:
   # Code from module c-ctype:
   # Code from module c-strcase:
   # Code from module careadlinkat:
@@ -169,6 +170,7 @@
   gl_COMMON
   gl_source_base='lib'
   gl_FUNC_ALLOCA
+  gl_BYTESWAP
   AC_CHECK_FUNCS_ONCE([readlinkat])
   gl_CLOCK_TIME
   gl_CLOSE_STREAM
@@ -794,6 +796,7 @@
   lib/at-func.c
   lib/binary-io.c
   lib/binary-io.h
+  lib/byteswap.in.h
   lib/c-ctype.c
   lib/c-ctype.h
   lib/c-strcase.h
@@ -912,6 +915,7 @@
   m4/00gnulib.m4
   m4/acl.m4
   m4/alloca.m4
+  m4/byteswap.m4
   m4/c-strtod.m4
   m4/clock_time.m4
   m4/close-stream.m4

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-10-04 06:51:50 +0000
+++ b/src/ChangeLog     2013-10-04 07:36:22 +0000
@@ -1,5 +1,14 @@
 2013-10-04  Paul Eggert  <address@hidden>
 
+       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.
+       * fringe.c (init_fringe_bitmap) [WORDS_BIGENDIAN]:
+       * sound.c (le2hl, le2hs, be2hl) [!WINDOWSNT]:
+       Use byteswap.h's macros to swap bytes.
+       * lisp.h (swap16, swap32, swap64): Remove.
+       All uses replaced by bswap_16, bswap_32, bswap_64.
+
        * bytecode.c (exec_byte_code): Use some more volatile variables
        to work around local variables getting clobbered by longjmp.
        Port to pre-C99, which doesn't allow decls after stmts.

=== modified file 'src/data.c'
--- a/src/data.c        2013-10-03 16:16:31 +0000
+++ b/src/data.c        2013-10-04 07:36:22 +0000
@@ -21,6 +21,7 @@
 #include <config.h>
 #include <stdio.h>
 
+#include <byteswap.h>
 #include <intprops.h>
 
 #include "lisp.h"
@@ -3185,9 +3186,9 @@
 {
 #ifdef WORDS_BIGENDIAN
 # if BITS_PER_SIZE_T == 64
-  return swap64 (val);
+  return bswap_64 (val);
 # else
-  return swap32 (val);
+  return bswap_32 (val);
 # endif
 #else
   return val;

=== modified file 'src/fringe.c'
--- a/src/fringe.c      2013-10-02 11:49:24 +0000
+++ b/src/fringe.c      2013-10-04 07:36:22 +0000
@@ -20,6 +20,8 @@
 #include <config.h>
 #include <stdio.h>
 
+#include <byteswap.h>
+
 #include "lisp.h"
 #include "frame.h"
 #include "window.h"
@@ -1519,7 +1521,7 @@
                                   | (swap_nibble[(b>>12) & 0xf]));
              b >>= (16 - fb->width);
 #ifdef WORDS_BIGENDIAN
-             b = ((b >> 8) | (b << 8));
+             b = bswap_16 (b);
 #endif
              *bits++ = b;
            }

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2013-10-03 16:16:31 +0000
+++ b/src/lisp.h        2013-10-04 07:36:22 +0000
@@ -4366,30 +4366,6 @@
     return 0;
 }
 
-INLINE uint16_t
-swap16 (uint16_t val)
-{
-    return (val << 8) | (val & 0xFF);
-}
-
-INLINE uint32_t
-swap32 (uint32_t val)
-{
-  uint32_t low = swap16 (val & 0xFFFF);
-  uint32_t high = swap16 (val >> 16);
-  return (low << 16) | high;
-}
-
-#ifdef UINT64_MAX
-INLINE uint64_t
-swap64 (uint64_t val)
-{
-  uint64_t low = swap32 (val & 0xFFFFFFFF);
-  uint64_t high = swap32 (val >> 32);
-  return (low << 32) | high;
-}
-#endif
-
 #if ((SIZE_MAX >> 31) >> 1) & 1
 # define BITS_PER_SIZE_T 64
 #else

=== modified file 'src/sound.c'
--- a/src/sound.c       2013-07-16 21:35:45 +0000
+++ b/src/sound.c       2013-10-04 07:36:22 +0000
@@ -55,6 +55,8 @@
 /* BEGIN: Non Windows Includes */
 #ifndef WINDOWSNT
 
+#include <byteswap.h>
+
 #include <sys/ioctl.h>
 
 /* FreeBSD has machine/soundcard.h.  Voxware sound driver docs mention
@@ -461,8 +463,7 @@
 le2hl (u_int32_t value)
 {
 #ifdef WORDS_BIGENDIAN
-  unsigned char *p = (unsigned char *) &value;
-  value = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
+  value = bswap_32 (value);
 #endif
   return value;
 }
@@ -475,8 +476,7 @@
 le2hs (u_int16_t value)
 {
 #ifdef WORDS_BIGENDIAN
-  unsigned char *p = (unsigned char *) &value;
-  value = p[0] + (p[1] << 8);
+  value = bswap_16 (value);
 #endif
   return value;
 }
@@ -489,29 +489,10 @@
 be2hl (u_int32_t value)
 {
 #ifndef WORDS_BIGENDIAN
-  unsigned char *p = (unsigned char *) &value;
-  value = p[3] + (p[2] << 8) + (p[1] << 16) + (p[0] << 24);
-#endif
-  return value;
-}
-
-
-#if 0 /* Currently not used.  */
-
-/* Convert 16-bit value VALUE which is in big-endian byte-order
-   to host byte-order.  */
-
-static u_int16_t
-be2hs (u_int16_t value)
-{
-#ifndef WORDS_BIGENDIAN
-  unsigned char *p = (unsigned char *) &value;
-  value = p[1] + (p[0] << 8);
-#endif
-  return value;
-}
-
-#endif /* 0 */
+  value = bswap_32 (value);
+#endif
+  return value;
+}
 
 /***********************************************************************
                          RIFF-WAVE (*.wav)

=== modified file 'src/xsettings.c'
--- a/src/xsettings.c   2013-09-22 09:31:55 +0000
+++ b/src/xsettings.c   2013-10-04 07:36:22 +0000
@@ -22,6 +22,9 @@
 #include <float.h>
 #include <limits.h>
 #include <fcntl.h>
+
+#include <byteswap.h>
+
 #include "lisp.h"
 #include "xterm.h"
 #include "xsettings.h"
@@ -405,7 +408,7 @@
 
   if (bytes < 12) return BadLength;
   memcpy (&n_settings, prop+8, 4);
-  if (my_bo != that_bo) n_settings = swap32 (n_settings);
+  if (my_bo != that_bo) n_settings = bswap_32 (n_settings);
   bytes_parsed = 12;
 
   memset (settings, 0, sizeof (*settings));
@@ -427,7 +430,7 @@
 
       memcpy (&nlen, prop+bytes_parsed, 2);
       bytes_parsed += 2;
-      if (my_bo != that_bo) nlen = swap16 (nlen);
+      if (my_bo != that_bo) nlen = bswap_16 (nlen);
       if (bytes_parsed+nlen > bytes) return BadLength;
       to_cpy = nlen > 127 ? 127 : nlen;
       memcpy (name, prop+bytes_parsed, to_cpy);
@@ -454,7 +457,7 @@
           if (want_this)
             {
               memcpy (&ival, prop+bytes_parsed, 4);
-              if (my_bo != that_bo) ival = swap32 (ival);
+              if (my_bo != that_bo) ival = bswap_32 (ival);
             }
           bytes_parsed += 4;
           break;
@@ -463,7 +466,7 @@
           if (bytes_parsed+4 > bytes) return BadLength;
           memcpy (&vlen, prop+bytes_parsed, 4);
           bytes_parsed += 4;
-          if (my_bo != that_bo) vlen = swap32 (vlen);
+          if (my_bo != that_bo) vlen = bswap_32 (vlen);
           if (want_this)
             {
               to_cpy = vlen > 127 ? 127 : vlen;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]