Altivec support probably wasn't maintained for years. Fix it to compile

on powerpc64.

Tested also on amd64.

Hardware sponsored by IntegriCloud.

PR:		ports/235560
Submitted by:	Piotr Kubaj <pkubaj@anongoth.pl>
This commit is contained in:
db
2019-02-06 23:49:11 +00:00
parent e58c710417
commit 92b45a60c5
13 changed files with 347 additions and 8 deletions
+1 -3
View File
@@ -14,12 +14,10 @@ COMMENT= Several forward error correction (FEC) decoders
LICENSE= LGPL21
BROKEN_powerpc64= fails to compile: cc1: error: unrecognized command line option -faltivec
MAKEFILE= makefile
GNU_CONFIGURE= yes
USES= autoreconf gmake tar:bzip2
USES= autoreconf compiler:c11 gmake tar:bzip2
USE_LDCONFIG= yes
PLIST_FILES= include/fec.h \
lib/libfec.so \
+8 -3
View File
@@ -4,6 +4,7 @@
#include <stdio.h>
#include "fec.h"
#ifdef __VEC__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
@@ -33,15 +34,19 @@ void find_cpu_mode(void){
Cpu_mode = MMX;
}
#endif
//#ifdef __VEC__
#if 0
// This looks very Linux specific
#ifdef __VEC__
{
/* Ask the OS if we have Altivec support */
#ifdef __APPLE__
int selectors[2] = { CTL_HW, HW_VECTORUNIT };
#endif
int hasVectorUnit = 0;
size_t length = sizeof(hasVectorUnit);
#ifdef __APPLE__
int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
#elif __FreeBSD__
int error = sysctlbyname("hw.altivec", &hasVectorUnit, &length, NULL, 0);
#endif
if(0 == error && hasVectorUnit)
Cpu_mode = ALTIVEC;
}
+2 -1
View File
@@ -17,7 +17,8 @@
+ cpu_features.o"
;;
powerpc*)
ARCH_OPTION="-fno-common -faltivec"
- ARCH_OPTION="-fno-common -faltivec"
+ ARCH_OPTION="-fno-common -maltivec"
MLIBS="viterbi27_av.o viterbi29_av.o viterbi39_av.o viterbi615_av.o \
encode_rs_av.o \
- dotprod_av.o sumsq_av.o peakval_av.o cpu_mode_ppc.o"
+28
View File
@@ -0,0 +1,28 @@
--- dotprod_av.c.orig 2019-02-05 19:37:00 UTC
+++ dotprod_av.c
@@ -3,6 +3,7 @@
* Copyright 2004 Phil Karn
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
+#include <altivec.h>
#include <stdlib.h>
#include "fec.h"
@@ -70,7 +71,7 @@ long dotprod_av(void *p,signed short a[]){
nblocks = (dp->len+al-1)/8+1;
/* Sum into four vectors each holding four 32-bit partial sums */
- sums3 = sums2 = sums1 = sums0 = (vector signed int)(0);
+ sums3 = sums2 = sums1 = sums0 = (vector signed int){0};
while(nblocks >= 4){
sums0 = vec_msums(ar[nblocks-1],d[nblocks-1],sums0);
sums1 = vec_msums(ar[nblocks-2],d[nblocks-2],sums1);
@@ -85,7 +86,7 @@ long dotprod_av(void *p,signed short a[]){
sums0 = vec_msums(ar[nblocks],d[nblocks],sums0);
}
/* Sum 4 partial sums into final result */
- s.v = vec_sums(sums0,(vector signed int)(0));
+ s.v = vec_sums(sums0,(vector signed int){0});
return s.w[3];
}
+27
View File
@@ -0,0 +1,27 @@
--- encode_rs_8.c.orig 2019-02-06 10:40:06 UTC
+++ encode_rs_8.c
@@ -3,6 +3,7 @@
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
#include <string.h>
+#include <sys/types.h>
#include "fixed.h"
#ifdef __VEC__
#include <sys/sysctl.h>
@@ -36,10 +37,16 @@ void encode_rs_8(data_t *data, data_t *parity,int pad)
}
#elif __VEC__
/* Ask the OS if we have Altivec support */
+#ifdef __APPLE__
int selectors[2] = { CTL_HW, HW_VECTORUNIT };
+#endif
int hasVectorUnit = 0;
size_t length = sizeof(hasVectorUnit);
+#ifdef __APPLE__
int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
+#elif __FreeBSD__
+ int error = sysctlbyname("hw.altivec", &hasVectorUnit, &length, NULL, 0);
+#endif
if(0 == error && hasVectorUnit)
cpu_mode = ALTIVEC;
else
+41
View File
@@ -0,0 +1,41 @@
--- encode_rs_av.c.orig 2019-02-05 19:29:53 UTC
+++ encode_rs_av.c
@@ -2,6 +2,7 @@
* Copyright 2004, Phil Karn KA9Q
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
+#include <altivec.h>
#include <stdio.h>
#include <string.h>
#include "fixed.h"
@@ -12,8 +13,8 @@
*/
static union { vector unsigned char v; unsigned char c[16]; } table[256];
-static vector unsigned char reverse = (vector unsigned char)(0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1);
-static vector unsigned char shift_right = (vector unsigned char)(15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30);
+static vector unsigned char reverse = (vector unsigned char){0,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
+static vector unsigned char shift_right = (vector unsigned char){15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
extern data_t CCSDS_alpha_to[];
extern data_t CCSDS_index_of[];
@@ -40,8 +41,8 @@ void encode_rs_av(unsigned char *data,unsigned char *p
union { vector unsigned char v[2]; unsigned char c[32]; } shift_register;
int i;
- shift_register.v[0] = (vector unsigned char)(0);
- shift_register.v[1] = (vector unsigned char)(0);
+ shift_register.v[0] = (vector unsigned char){0};
+ shift_register.v[1] = (vector unsigned char){0};
for(i=0;i<NN-NROOTS-pad;i++){
vector unsigned char feedback0,feedback1;
@@ -53,7 +54,7 @@ void encode_rs_av(unsigned char *data,unsigned char *p
/* Shift right one byte */
shift_register.v[1] = vec_perm(shift_register.v[0],shift_register.v[1],shift_right) ^ feedback1;
- shift_register.v[0] = vec_sro(shift_register.v[0],(vector unsigned char)(8)) ^ feedback0;
+ shift_register.v[0] = vec_sro(shift_register.v[0],(vector unsigned char){8}) ^ feedback0;
shift_register.c[0] = f;
}
for(i=0;i<NROOTS;i++)
+1 -1
View File
@@ -1,6 +1,6 @@
--- fec.h.orig 2006-10-13 01:10:53 UTC
+++ fec.h
@@ -262,7 +262,7 @@ extern enum cpu_mode {UNKNOWN=0,PORT,MMX
@@ -262,7 +262,7 @@ extern enum cpu_mode {UNKNOWN=0,PORT,MMX,SSE,SSE2,ALTI
void find_cpu_mode(void); /* Call this once at startup to set Cpu_mode */
/* Determine parity of argument: 1 = odd, 0 = even */
+25
View File
@@ -0,0 +1,25 @@
--- peakval_av.c.orig 2019-02-05 19:35:25 UTC
+++ peakval_av.c
@@ -6,6 +6,7 @@
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
+#include <altivec.h>
#include "fec.h"
signed short peakval_av(signed short *in,int cnt){
@@ -14,11 +15,11 @@ signed short peakval_av(signed short *in,int cnt){
union { vector signed char cv; vector signed short hv; signed short s[8]; signed char c[16];} s;
vector signed short smallest,largest;
- smallest = (vector signed short)(0);
- largest = (vector signed short)(0);
+ smallest = (vector signed short){0};
+ largest = (vector signed short){0};
if((pad = (int)in & 15)!=0){
/* Load unaligned leading word */
- x = vec_perm(vec_ld(0,in),(vector signed short)(0),vec_lvsl(0,in));
+ x = vec_perm(vec_ld(0,in),(vector signed short){0},vec_lvsl(0,in));
if(cnt < 8){ /* Shift right to chop stuff beyond end of short block */
s.c[15] = (8-cnt)<<4;
x = vec_sro(x,s.cv);
+47
View File
@@ -0,0 +1,47 @@
--- sumsq_av.c.orig 2019-02-05 19:36:10 UTC
+++ sumsq_av.c
@@ -8,6 +8,7 @@
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
+#include <altivec.h>
#include "fec.h"
unsigned long long sumsq_av(signed short *in,int cnt){
@@ -17,15 +18,15 @@ unsigned long long sumsq_av(signed short *in,int cnt){
int pad;
union { vector unsigned char cv; vector unsigned int iv; unsigned int w[4]; unsigned char c[16];} s;
- carries = sums = (vector unsigned int)(0);
+ carries = sums = (vector unsigned int){0};
if((pad = (int)in & 15)!=0){
/* Load unaligned leading word */
- x = vec_perm(vec_ld(0,in),(vector signed short)(0),vec_lvsl(0,in));
+ x = vec_perm(vec_ld(0,in),(vector signed short){0},vec_lvsl(0,in));
if(cnt < 8){ /* Shift right to chop stuff beyond end of short block */
s.c[15] = (8-cnt)<<4;
x = vec_sro(x,s.cv);
}
- sums = (vector unsigned int)vec_msum(x,x,(vector signed int)(0));
+ sums = (vector unsigned int)vec_msum(x,x,(vector signed int){0});
in += 8-pad/2;
cnt -= 8-pad/2;
}
@@ -36,7 +37,7 @@ unsigned long long sumsq_av(signed short *in,int cnt){
* the earlier terms separately to handle the carries
* The cast to unsigned is OK because squares are always positive
*/
- s1 = (vector unsigned int)vec_msum(x,x,(vector signed int)(0));
+ s1 = (vector unsigned int)vec_msum(x,x,(vector signed int){0});
carries = vec_add(carries,vec_addc(sums,s1));
sums = vec_add(sums,s1);
in += 8;
@@ -47,7 +48,7 @@ unsigned long long sumsq_av(signed short *in,int cnt){
x = vec_ld(0,in);
s.c[15] = (8-cnt)<<4;
x = vec_sro(x,s.cv);
- s1 = (vector unsigned int)vec_msum(x,x,(vector signed int)(0));
+ s1 = (vector unsigned int)vec_msum(x,x,(vector signed int){0});
carries = vec_add(carries,vec_addc(sums,s1));
sums = vec_add(sums,s1);
}
+41
View File
@@ -0,0 +1,41 @@
--- viterbi27_av.c.orig 2019-02-05 19:34:45 UTC
+++ viterbi27_av.c
@@ -1,6 +1,7 @@
/* K=7 r=1/2 Viterbi decoder for PowerPC G4/G5 Altivec instructions
* Feb 2004, Phil Karn, KA9Q
*/
+#include <altivec.h>
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
@@ -31,7 +32,7 @@ int init_viterbi27_av(void *p,int starting_state){
if(p == NULL)
return -1;
for(i=0;i<4;i++)
- vp->metrics1.v[i] = (vector unsigned char)(63);
+ vp->metrics1.v[i] = (vector unsigned char){63};
vp->old_metrics = &vp->metrics1;
vp->new_metrics = &vp->metrics2;
vp->dp = vp->decisions;
@@ -134,8 +135,8 @@ int update_viterbi27_blk_av(void *p,unsigned char *sym
/* Form first set of 16 branch metrics */
metric = vec_avg(vec_xor(Branchtab27[0].v[0],sym0v),vec_xor(Branchtab27[1].v[0],sym1v));
- metric = vec_sr(metric,(vector unsigned char)(3));
- m_metric = vec_sub((vector unsigned char)(31),metric);
+ metric = vec_sr(metric,(vector unsigned char){3});
+ m_metric = vec_sub((vector unsigned char){31},metric);
/* Form first set of path metrics */
m0 = vec_adds(vp->old_metrics->v[0],metric);
@@ -145,8 +146,8 @@ int update_viterbi27_blk_av(void *p,unsigned char *sym
/* Form second set of 16 branch metrics */
metric = vec_avg(vec_xor(Branchtab27[0].v[1],sym0v),vec_xor(Branchtab27[1].v[1],sym1v));
- metric = vec_sr(metric,(vector unsigned char)(3));
- m_metric = vec_sub((vector unsigned char)(31),metric);
+ metric = vec_sr(metric,(vector unsigned char){3});
+ m_metric = vec_sub((vector unsigned char){31},metric);
/* Compare and select first set */
decision0 = vec_cmpgt(m0,m1);
+34
View File
@@ -0,0 +1,34 @@
--- viterbi29_av.c.orig 2019-02-05 19:33:58 UTC
+++ viterbi29_av.c
@@ -2,9 +2,11 @@
* Copyright Feb 2004, Phil Karn, KA9Q
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
+#include <altivec.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
+#include <sys/types.h>
#include <sys/sysctl.h>
#include "fec.h"
@@ -31,7 +33,7 @@ int init_viterbi29_av(void *p,int starting_state){
if(p == NULL)
return -1;
for(i=0;i<16;i++)
- vp->metrics1.v[i] = (vector unsigned char)(63);
+ vp->metrics1.v[i] = (vector unsigned char){63};
vp->old_metrics = &vp->metrics1;
vp->new_metrics = &vp->metrics2;
@@ -136,8 +138,8 @@ int update_viterbi29_blk_av(void *p,unsigned char *sym
/* Form branch metrics */
metric = vec_avg(vec_xor(Branchtab29[0].v[i],sym1v),vec_xor(Branchtab29[1].v[i],sym2v));
- metric = vec_sr(metric,(vector unsigned char)(3));
- m_metric = (vector unsigned char)(31) - metric;
+ metric = vec_sr(metric,(vector unsigned char){3});
+ m_metric = (vector unsigned char){31} - metric;
/* Add branch metrics to path metrics */
m0 = vec_adds(vp->old_metrics->v[i],metric);
+46
View File
@@ -0,0 +1,46 @@
--- viterbi39_av.c.orig 2019-02-05 19:31:24 UTC
+++ viterbi39_av.c
@@ -3,6 +3,7 @@
* Copyright Aug 2006, Phil Karn, KA9Q
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
+#include <altivec.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
@@ -30,7 +31,7 @@ int init_viterbi39_av(void *p,int starting_state){
int i;
for(i=0;i<32;i++)
- vp->metrics1.v[i] = (vector unsigned short)(1000);
+ vp->metrics1.v[i] = (vector unsigned short){1000};
vp->old_metrics = &vp->metrics1;
vp->new_metrics = &vp->metrics2;
@@ -111,7 +112,7 @@ int update_viterbi39_blk_av(void *p,unsigned char *sym
struct v39 *vp = p;
decision_t *d = (decision_t *)vp->dp;
int path_metric = 0;
- vector unsigned char decisions = (vector unsigned char)(0);
+ vector unsigned char decisions = (vector unsigned char){0};
while(nbits--){
vector unsigned short symv,sym0v,sym1v,sym2v;
@@ -122,7 +123,7 @@ int update_viterbi39_blk_av(void *p,unsigned char *sym
/* Splat the 0th symbol across sym0v, the 1st symbol across sym1v, etc */
s = (vector unsigned char)vec_perm(vec_ld(0,syms),vec_ld(5,syms),vec_lvsl(0,syms));
- symv = (vector unsigned short)vec_mergeh((vector unsigned char)(0),s); /* Unsigned byte->word unpack */
+ symv = (vector unsigned short)vec_mergeh((vector unsigned char){0},s); /* Unsigned byte->word unpack */
sym0v = vec_splat(symv,0);
sym1v = vec_splat(symv,1);
sym2v = vec_splat(symv,2);
@@ -140,7 +141,7 @@ int update_viterbi39_blk_av(void *p,unsigned char *sym
m0 = vec_add(vec_xor(Branchtab39[0].v[i],sym0v),vec_xor(Branchtab39[1].v[i],sym1v));
m1 = vec_xor(Branchtab39[2].v[i],sym2v);
metric = vec_add(m0,m1);
- m_metric = vec_sub((vector unsigned short)(765),metric);
+ m_metric = vec_sub((vector unsigned short){765},metric);
/* Add branch metrics to path metrics */
m0 = vec_adds(vp->old_metrics->v[i],metric);
+46
View File
@@ -0,0 +1,46 @@
--- viterbi615_av.c.orig 2019-02-05 19:33:18 UTC
+++ viterbi615_av.c
@@ -3,6 +3,7 @@
* Copyright Mar 2004, Phil Karn, KA9Q
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
+#include <altivec.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
@@ -33,7 +34,7 @@ int init_viterbi615_av(void *p,int starting_state){
return -1;
for(i=0;i<2048;i++)
- vp->metrics1.v[i] = (vector unsigned short)(5000);
+ vp->metrics1.v[i] = (vector unsigned short){5000};
vp->old_metrics = &vp->metrics1;
vp->new_metrics = &vp->metrics2;
@@ -111,7 +112,7 @@ int update_viterbi615_blk_av(void *p,unsigned char *sy
struct v615 *vp = p;
decision_t *d = (decision_t *)vp->dp;
int path_metric = 0;
- vector unsigned char decisions = (vector unsigned char)(0);
+ vector unsigned char decisions = (vector unsigned char){0};
while(nbits--){
vector unsigned short symv,sym0v,sym1v,sym2v,sym3v,sym4v,sym5v;
@@ -122,7 +123,7 @@ int update_viterbi615_blk_av(void *p,unsigned char *sy
/* Splat the 0th symbol across sym0v, the 1st symbol across sym1v, etc */
s = (vector unsigned char)vec_perm(vec_ld(0,syms),vec_ld(5,syms),vec_lvsl(0,syms));
- symv = (vector unsigned short)vec_mergeh((vector unsigned char)(0),s); /* Unsigned byte->word unpack */
+ symv = (vector unsigned short)vec_mergeh((vector unsigned char){0},s); /* Unsigned byte->word unpack */
sym0v = vec_splat(symv,0);
sym1v = vec_splat(symv,1);
sym2v = vec_splat(symv,2);
@@ -145,7 +146,7 @@ int update_viterbi615_blk_av(void *p,unsigned char *sy
m2 = vec_add(vec_xor(Branchtab615[4].v[i],sym4v),vec_xor(Branchtab615[5].v[i],sym5v));
metric = vec_add(m0,m1);
metric = vec_add(metric,m2);
- m_metric = vec_sub((vector unsigned short)(1530),metric);
+ m_metric = vec_sub((vector unsigned short){1530},metric);
/* Add branch metrics to path metrics */
m0 = vec_adds(vp->old_metrics->v[i],metric);