about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-12-26 06:13:41 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-12-26 06:13:41 +0000
commit51ffbae51ba9379bad460566cdf9babaa63b14c3 (patch)
tree441f6e9297c478261bdce544497decaf6abc31a4 /lib
parentd6f45222d7b29adb9defdd79dd8ad1dbc97bb3e1 (diff)
downloadnetpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.tar.gz
netpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.tar.xz
netpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.zip
Update to current Development release - 10.65.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2083 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile9
-rw-r--r--lib/libpbm3.c49
-rw-r--r--lib/libsystem.c29
-rw-r--r--lib/util/Makefile11
-rw-r--r--lib/util/nstring.c22
-rw-r--r--lib/util/pm_c_util.h2
-rw-r--r--lib/util/vasprintf.c6
7 files changed, 77 insertions, 51 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 8d9b3175..6512949f 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -84,13 +84,12 @@ extra_staticlib: $(EXTRA_STATICLIB)
 # type, but request a static library in addition.
 #----------------------------------------------------------------------------
 
-# Note that the user may have configured -I options into CPPFLAGS/CFLAGS.
-CFLAGS_ALL = $(INCLUDES) -DNDEBUG $(CPPFLAGS) $(CFLAGS) $(CFLAGS_SHLIB) \
- $(CFLAGS_PERSONAL) $(CADD)
+$(LIBOBJECTS): CFLAGS_TARGET=$(CFLAGS_SHLIB)
+
+libpbm3.o: CFLAGS_TARGET+=$(CFLAGS_SSE)
 
 $(LIBOBJECTS): %.o: %.c importinc
-# We have to get the command all on one line to avoid messy make messages
-	$(CC) -c $(CFLAGS_ALL) -o $@ $<
+	$(CC) -c $(INCLUDES) $(CFLAGS_ALL) -o $@ $<
 
 MAJ = 11
 MIN = $(NETPBM_MINOR_RELEASE)
diff --git a/lib/libpbm3.c b/lib/libpbm3.c
index d6a953c2..020e1558 100644
--- a/lib/libpbm3.c
+++ b/lib/libpbm3.c
@@ -16,21 +16,28 @@
 #include "pbm.h"
 
 #ifndef PACKBITS_SSE
-#if HAVE_GCC_SSE2 && HAVE_GCC_BSWAP && defined(__SSE2__)
+#if WANT_SSE && defined(__SSE2__) && HAVE_GCC_BSWAP
   #define PACKBITS_SSE 2
 #else
   #define PACKBITS_SSE 0
 #endif
 #endif
 
-/* HAVE_GCC_SSE2 means we have the means to use SSE CPU facilities
-   to make PBM raster processing faster.  GCC only.
+/* WANT_SSE means we want to use SSE CPU facilities to make PBM raster
+   processing faster.  This implies it's actually possible - i.e. the
+   build environment has <emmintrin.h>.
 
-   The GNU Compiler -msse2 option makes SSE/SSE2 available.
-   For x86-32 with MMX/SSE, "-msse2" must be explicitly given.
+   The GNU Compiler -msse2 option makes SSE/SSE2 available, and is
+   evidenced by __SSE2__.
+   For x86-32 with SSE, "-msse2" must be explicitly given.
    For x86-64 and AMD64, "-msse2" is the default (from Gcc v.4.)
 */
 
+#if PACKBITS_SSE == 2
+  #include <emmintrin.h>
+#endif
+
+
 void
 pbm_writepbminit(FILE * const fileP, 
                  int    const cols, 
@@ -81,16 +88,28 @@ packBitsWithSse2(  FILE *          const fileP,
       PCMPGTB128  Packed CoMPare Greater Than Byte
     
         Compares 16 bytes in parallel
-        Result is x00 if greater than, xFF if not for each byte       
+        Result is x00 if greater than, xFF if not for each byte
+
     
       PMOVMSKB128 Packed MOVe MaSK Byte 
     
-        Result is a byte of the MSBs of 16 bytes
+        Result is 16 bits, the MSBs of 16 bytes
         x00 xFF x00 xFF xFF xFF x00 x00 xFF xFF xFF xFF x00 x00 x00 x00 
         --> 0101110011110000B = 0x5CF0
         
         The result is actually a 64 bit int, but the higher bits are
         always 0.
+
+      We use SSE instructions in "_mm_" form in favor of "__builtin_".
+      In GCC the "__builtin_" form is documented but "_mm_" is not.
+      Former versions of this source file used "__builtin_".  This was
+      changed to make possible compilation with clang, which does not
+      implement some "__builtin_" forms.
+
+      __builtin_ia32_pcmpgtb128 :  _mm_cmpgt_epi8
+      __builtin_ia32_pmovmskb128 : _mm_movemask_epi8
+
+      The conversion requires <emmintrin.h> .
     */
 
     typedef char v16qi __attribute__ ((vector_size(16)));
@@ -110,11 +129,10 @@ packBitsWithSse2(  FILE *          const fileP,
         bit128.i64[1]=__builtin_bswap64( *(uint64_t*) &bitrow[col+8]);
 
         {
-            v16qi const compare =
-                __builtin_ia32_pcmpgtb128(bit128.v16, zero128);
-            uint16_t const blackMask = 
-                (uint16_t) __builtin_ia32_pmovmskb128(compare);
-
+            v16qi const compare = (v16qi)
+                _mm_cmpgt_epi8((__m128i)bit128.v16, (__m128i) zero128);
+            uint16_t const blackMask = _mm_movemask_epi8 ((__m128i)compare);
+            
             *(uint16_t *) & packedBits[col/8] = blackMask;
         }
     }
@@ -128,10 +146,9 @@ packBitsWithSse2(  FILE *          const fileP,
             bit128.byte[ (i&8) + 7-(i&7) ] = bitrow[j];
       
         {
-            v16qi const compare =
-                __builtin_ia32_pcmpgtb128( bit128.v16, zero128 );
-            uint16_t const blackMask =
-                __builtin_ia32_pmovmskb128( compare );
+            v16qi const compare = (v16qi)
+                _mm_cmpgt_epi8((__m128i)bit128.v16, (__m128i) zero128);
+            uint16_t const blackMask = _mm_movemask_epi8 ((__m128i)compare);
 
             if ( cols%16 >8 )  /* Two partial bytes */
                 *(uint16_t *) & packedBits[col/8] = blackMask;
diff --git a/lib/libsystem.c b/lib/libsystem.c
index 8db663bc..48c6f06d 100644
--- a/lib/libsystem.c
+++ b/lib/libsystem.c
@@ -13,6 +13,7 @@
    Contributed to the public domain.
 =============================================================================*/
 #define _XOPEN_SOURCE
+#define _BSD_SOURCE  /* Make SIGWINCH defined on OpenBSD */
 
 #include <stdarg.h>
 #include <unistd.h>
@@ -220,6 +221,18 @@ spawnProcessor(const char *  const progName,
 static const char *
 signalName(unsigned int const signalClass) {
 
+/* There are various signal classes that are not universally defined,
+   so we make a half-hearted attempt to determine whether they are and
+   not try to recognize the ones that aren't.  We do this by testing
+   whether a macro is defind with the signal class name.  That could give
+   a false negative, because the signal class name isn't necessarily
+   defined as a macro, but it's a really, really small problem to miss
+   one of these signal classes here, so we don't bother with all the work
+   it would take to do it right.
+
+   OpenBSD does not have SIGWINCH and SIGIO in 2013.  Everyone else seems
+   to have it.
+*/
     switch (signalClass) {
     case SIGHUP: /* POSIX.1 */
         return "SIGHUP";
@@ -273,12 +286,6 @@ signalName(unsigned int const signalClass) {
         return "SIGVTALRM";
     case SIGPROF:
         return "SIGPROF";
-/* Most systems have SIGWINCH and SIGIO, but at least OpenBSD, in 2013,
-   does not.  Systems that do don't necessarily supply it as a macro, so
-   the following tests are not perfect, but a false negative is a really,
-   really, small problem, so we don't bother with all the work it would
-   take to do better.
-*/
 #ifdef SIGWINCH
     case SIGWINCH:
         return "SIGWINCH";
@@ -287,16 +294,14 @@ signalName(unsigned int const signalClass) {
     case SIGIO:
         return "SIGIO";
 #endif
+#ifdef SIGPWR
+    case SIGPWR:
+        return "SIGPWR";
+#endif
     case SIGSYS:
         return "SIGSYS";
     default:
         return "???";
-
-        /* There are various other signal classes on some systems, but
-           not defined by POSIX and not on at least one system we
-           know of for which someone wanted to compile Netpbm.  The
-           list includes: SIGPWR, SIGLOST, SIGINFO, SIGRTxx.
-        */
     }
 }
 
diff --git a/lib/util/Makefile b/lib/util/Makefile
index 5bf1995e..28dfddfe 100644
--- a/lib/util/Makefile
+++ b/lib/util/Makefile
@@ -5,6 +5,8 @@ endif
 SUBDIR = lib/util
 VPATH=.:$(SRCDIR)/$(SUBDIR)
 
+default:all
+
 include $(BUILDDIR)/config.mk
 
 # nstring is required for asprintf(), etc.  Also some systems don't have
@@ -22,13 +24,14 @@ UTILOBJECTS = \
 
 MERGE_OBJECTS =
 
+include $(SRCDIR)/common.mk
+
 all: $(UTILOBJECTS)
 
-include $(SRCDIR)/common.mk
+$(UTILOBJECTS): CFLAGS_TARGET=$(CFLAGS_SHLIB)
 
 $(UTILOBJECTS):%.o:%.c importinc
-	$(CC) -c $(INCLUDES) -DNDEBUG $(CPPFLAGS) $(CFLAGS) $(CFLAGS_SHLIB) \
-	  $(CFLAGS_PERSONAL) $(CADD) -o $@ $<
+	$(CC) -c $(INCLUDES) $(CFLAGS_ALL) -o $@ $<
 
 testnstring: test.c nstring.h nstring.o
-	$(CC) $(CFLAGS) $(CADD) -o $@ nstring.o $<
+	$(CC) $(CFLAGS_ALL) -o $@ nstring.o $<
diff --git a/lib/util/nstring.c b/lib/util/nstring.c
index e95d9824..bb2ba92e 100644
--- a/lib/util/nstring.c
+++ b/lib/util/nstring.c
@@ -134,12 +134,6 @@
 
 #include "nstring.h"
 
-#if (defined(__GLIBC__) || defined(__GNU_LIBRARY__))
-  #define HAVE_VASPRINTF 1
-#else
-  #define HAVE_VASPRINTF 0
-#endif
-
 #ifdef isdigit
 #undef isdigit
 #endif
@@ -797,9 +791,12 @@ pm_asprintf(const char ** const resultP,
     va_list varargs;
     
 #if HAVE_VASPRINTF
+    int rc;
     va_start(varargs, fmt);
-    vasprintf((char **)&result, fmt, varargs);
+    rc = vasprintf((char **)&result, fmt, varargs);
     va_end(varargs);
+    if (rc < 0)
+        result = pm_strsol;
 #else
     size_t dryRunLen;
     
@@ -811,20 +808,23 @@ pm_asprintf(const char ** const resultP,
 
     if (dryRunLen + 1 < dryRunLen)
         /* arithmetic overflow */
-        result = NULL;
+        result = pm_strsol;
     else {
         size_t const allocSize = dryRunLen + 1;
-        result = malloc(allocSize);
-        if (result != NULL) {
+        char * buffer;
+        buffer = malloc(allocSize);
+        if (buffer != NULL) {
             va_list varargs;
             size_t realLen;
 
             va_start(varargs, fmt);
 
-            pm_vsnprintf(result, allocSize, fmt, varargs, &realLen);
+            pm_vsnprintf(buffer, allocSize, fmt, varargs, &realLen);
                 
             assert(realLen == dryRunLen);
             va_end(varargs);
+
+            result = buffer;
         }
     }
 #endif
diff --git a/lib/util/pm_c_util.h b/lib/util/pm_c_util.h
index 79897cf0..01a07657 100644
--- a/lib/util/pm_c_util.h
+++ b/lib/util/pm_c_util.h
@@ -83,7 +83,7 @@
   #define TRUE true
   #endif
 #ifndef FALSE
-#define FALSE false
+  #define FALSE false
   #endif
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
diff --git a/lib/util/vasprintf.c b/lib/util/vasprintf.c
index 209827eb..e38252fa 100644
--- a/lib/util/vasprintf.c
+++ b/lib/util/vasprintf.c
@@ -18,9 +18,11 @@ pm_vasprintf(const char ** const resultP,
     char * result;
 
 #if HAVE_VASPRINTF
-    vasprintf(&result, format, varargs);
+    int rc;
 
-    if (result == NULL)
+    rc = vasprintf(&result, format, varargs);
+
+    if (rc < 0)
         *resultP = pm_strsol;
     else
         *resultP = result;