shithub: freetype+ttf2subf

Download patch

ref: e1d0249e5aeb76fb0bd5b1b6a6ac71599be871bf
parent: bd28952e23bcd268a623ea5202e1cde4a92defe4
author: Werner Lemberg <[email protected]>
date: Wed Aug 23 04:18:22 EDT 2017

[sfnt] Fix clang compilation (#51788).

* src/sfnt/pngshim.c (premultiply_data): Use vectors instead of
scalars.
(vector_shuffle): New macro to take of a different built-in function
name on clang.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-08-23  Werner Lemberg  <[email protected]>
+
+	[sfnt] Fix clang compilation (#51788).
+
+	* src/sfnt/pngshim.c (premultiply_data): Use vectors instead of
+	scalars.
+	(vector_shuffle): New macro to take of a different built-in function
+	name on clang.
+
 2017-08-22  Werner Lemberg  <[email protected]>
 
 	[base] Don't zero out allocated memory twice (#51816).
--- a/src/sfnt/pngshim.c
+++ b/src/sfnt/pngshim.c
@@ -69,6 +69,15 @@
     defined( __OPTIMIZE__ )                                            && \
     __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 
+#ifdef __clang__
+    /* the clang documentation doesn't cover the two-argument case of */
+    /* `__builtin_shufflevector'; however, it is is implemented since */
+    /* version 2.8                                                    */
+#define vector_shuffle  __builtin_shufflevector
+#else
+#define vector_shuffle  __builtin_shuffle
+#endif
+
     typedef unsigned short  v82 __attribute__(( vector_size( 16 ) ));
 
 
@@ -79,6 +88,13 @@
       unsigned char*  base = &data[i];
 
       v82  s, s0, s1, a;
+
+      /* clang <= 3.9 can't apply scalar values to vectors */
+      /* (or rather, it needs a different syntax)          */
+      v82  n0x80 = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
+      v82  n0xFF = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+      v82  n8    = { 8, 8, 8, 8, 8, 8, 8, 8 };
+
       v82  ma = { 1, 1, 3, 3, 5, 5, 7, 7 };
       v82  o1 = { 0, 0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF };
       v82  m0 = { 1, 0, 3, 2, 5, 4, 7, 6 };
@@ -85,21 +101,21 @@
 
 
       memcpy( &s, base, 16 );               /* RGBA RGBA RGBA RGBA */
-      s0 = s & 0xFF;                        /*  R B  R B  R B  R B */
-      s1 = s >> 8;                          /*  G A  G A  G A  G A */
+      s0 = s & n0xFF;                       /*  R B  R B  R B  R B */
+      s1 = s >> n8;                         /*  G A  G A  G A  G A */
 
-      a  = __builtin_shuffle( s1, ma );     /*  A A  A A  A A  A A */
+      a   = vector_shuffle( s1, ma );       /*  A A  A A  A A  A A */
       s1 |= o1;                             /*  G 1  G 1  G 1  G 1 */
-      s0 = __builtin_shuffle( s0, m0 );     /*  B R  B R  B R  B R */
+      s0  = vector_shuffle( s0, m0 );       /*  B R  B R  B R  B R */
 
       s0 *= a;
       s1 *= a;
-      s0 += 0x80;
-      s1 += 0x80;
-      s0 = ( s0 + ( s0 >> 8 ) ) >> 8;
-      s1 = ( s1 + ( s1 >> 8 ) ) >> 8;
+      s0 += n0x80;
+      s1 += n0x80;
+      s0  = ( s0 + ( s0 >> n8 ) ) >> n8;
+      s1  = ( s1 + ( s1 >> n8 ) ) >> n8;
 
-      s = s0 | ( s1 << 8 );
+      s = s0 | ( s1 << n8 );
       memcpy( base, &s, 16 );
     }
 #endif /* use `vector_size' */