Port-vax archive

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

Re: pkgsrc: python310 issues -> no ca-certificates



On Tue, Jul 18, 2023 at 01:01:19PM +0100, David Brownlee wrote:
> On Tue, 18 Jul 2023 at 11:15, Jan-Benedict Glaw <jbglaw%lug-owl.de@localhost> wrote:
> >
> > Hi!
> >
> > ...and `nextafter` belongs to ${COMMON_SRCS} and is IEEE754 specific.
> > So I wonder: Should we implement a VAX version? Can probably be done,
> > though some care must be taken as D- and G-float can, in theory, be
> > choosen as a gcc command line option. Or drop the declaration?
> 
> I think we can probably accept supporting a single VAX FP format (I
> think the odds on someone porting NetBSD to the uVAX I and adding the
> infrastructure for separate F+G and F+D builds... are low :)
> 
> >   Another route could be to accept that VAX FP is too dead and go for
> > soft float all the way. :-/
> 
> As Johnny mentions, most of the VAX FP vs IEEE 754 differences are not
> relevant for general use of most software. They mainly only trigger in
> test cases, scientific and overly clever code. At this point we should
> be happy with something "good enough" to get most software building
> and running on VAX (with some patching to avoid some tests where
> required).
> 
> Anyone with FAX FP-foo up for creating VAX variants of
> lib/libm/src/s_nextafter{,f,l}.c ? :)
> 
> David

Attached is a proof of concept for nextafter/nextafterf in C, but not
polished into a library object and seperate regression tests.

At one point I found I needed to debug dtoa() so there's some of that
kind of thing in there too.

I was working on this last December, but interest waned, and I don't
expect to finish it myself.

	Jonathan Kollasch
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <inttypes.h>
//#include <fenv.h>
#include <errno.h>

typedef union {
	float value;
	uint32_t dword;
} float_shape_type;

static inline uint32_t
badc(uint32_t x)
{
	return ((x & 0xFFFF) << 16) | (x >> 16);
}

#define GET_FLOAT_WORD(i,d) \
do {\
	float_shape_type gf_u;\
	gf_u.value = d;\
	(i) = badc(gf_u.dword);\
} while (0)

#define SET_FLOAT_WORD(d, i) \
do {\
	float_shape_type sf_u;\
	sf_u.dword = badc(i);\
	(d) = sf_u.value;\
} while (0)

typedef union {
	double value;
	uint64_t qword;
	uint32_t dword[2];
} double_shape_type;


#define EXTRACT_WORDS(ix0,ix1,d) \
do {\
	double_shape_type ew_u;\
	ew_u.value = (d);\
	(ix0) = badc(ew_u.dword[0]);\
	(ix1) = badc(ew_u.dword[1]);\
} while (0)

#define INSERT_WORDS(d,ix0,ix1) \
do {\
	double_shape_type iw_u;\
	iw_u.dword[0] = badc(ix0);\
	iw_u.dword[1] = badc(ix1);\
	(d) = iw_u.value;\
} while (0)

#if 1
double
nextafter(double x, double y)
{
	int32_t hx,hy,ix,iy;
	u_int32_t lx,ly;
	EXTRACT_WORDS(hx,lx,x);
	EXTRACT_WORDS(hy,ly,y);
	ix = hx&0x7fffffff;
	iy = hy&0x7fffffff;

	if(x==y) return y;
	if((ix|lx)==0) {
		INSERT_WORDS(x,(hy&0x80000000UL)|0x800000,0x1);
		y = x * x;
		if (y == x) return y;
		else return x;
	}
	if(hx>=0) {
		if(hx>hy||((hx==hy)&&(lx>ly))) {
			if(lx==0) hx -= 1;
			lx -= 1;
		} else {
			lx += 1;
			if(lx==0) hx += 1;
		}
	} else {
		if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){
			if(lx==0) hx -= 1;
			lx -= 1;
		} else {
			lx += 1;
			if(lx==0) hx += 1;
		}
	}
#if 0
	hy = hx&0x7f800000;
	if(hy>=0x7f800000) return x+x;
	if(hy<0x00800000) {
		y = x * x;
		if(y!=x) {
			INSERT_WORDS(y,hx,lx);
			return y;
		}
	}
#endif
	INSERT_WORDS(x,hx,lx);
	return x;
}
#endif

#if 1
float
nextafterf(float x, float y)
{
	int32_t hx,hy,ix,iy;
	GET_FLOAT_WORD(hx,x);
	GET_FLOAT_WORD(hy,y);
	ix = hx & 0x7FFFFFFFu;
	iy = hy & 0x7FFFFFFFu;
	if (x==y) return y;
	if (ix == 0) {
		SET_FLOAT_WORD(x,(hy&0x80000000UL)|0x800000);
		y = x * x;
		if (y == x) return y;
		else return x;
	}
	if (hx >= 0) {
		if (hx > hy)
			hx -= 1;
		else
			hx += 1;
	} else {
		if (hy >= 0 || hx > hy) 
			hx -= 1;
		else
			hx += 1;
	}
	//hy = hx & 0x7F800000;
	//if (hy >= 0x7F800000) return x + x;
	SET_FLOAT_WORD(x,hx);
	return x;
}
#endif

volatile double A = 3.0, B = 2.0, C = 9.0e15, D = 1.0;
volatile uint64_t * const Ap = (void *)&A;
volatile uint64_t * const Bp = (void *)&B;
volatile uint64_t * const Cp = (void *)&C;
volatile uint64_t * const Dp = (void *)&D;

volatile float a = 3.0f, b = 2.0f, c = 9.0e15f, d = 1.0f * INFINITY;
volatile uint32_t * const ap = (void *)&a;
volatile uint32_t * const bp = (void *)&b;
volatile uint32_t * const cp = (void *)&c;
volatile uint32_t * const dp = (void *)&d;


extern char * __dtoa(double d0, int mode, int ndigits, int *decpt, int *sign, char **rve);

int
main(int argc, char **argv)
{
	int decpt, sign;
	*Ap = 0x0001000000004080;
	printf("%.22g %016"PRIx64"\n", A, *Ap);
	*Ap = 0x0001000000000080;
	printf("%.22g %016"PRIx64"\n", A, *Ap);
	//puts(__dtoa(A, 3, 20, &decpt, &sign, NULL));
	A = A + A;
	printf("%.22g %016"PRIx64"\n", A, *Ap);
	printf("%.22g %016"PRIx64"\n", A, *Ap);
	*Bp = 0xffffffffffff413f;
	*Bp = 0x0000000100004140;
	printf("%.20g %016"PRIx64"\n", B, *Bp);
	printf("%.20g %016"PRIx64"\n", C, *Cp);
	printf("%.20g %016"PRIx64"\n", D, *Dp);
	puts("");
	*Cp = 0x00008000FFFFFFFFull;
	*Dp = 0x00008000FFFF7FFFull;
	printf("%.10g %016"PRIx64"\n", C, *Cp);
	printf("%.10g %016"PRIx64"\n", D, *Dp);
	C = 1.0e16;
	puts(__dtoa(C, 0, 14, &decpt, &sign, NULL));
	D = 1.0 * INFINITY;
	puts(__dtoa(D, 0, 14, &decpt, &sign, NULL));
	puts("--");
	printf("%20.20g %016"PRIx64"\n", C, *Cp);
	printf("%20.20g %016"PRIx64"\n", D, *Dp);
	puts("");


	printf("%.10g %08"PRIx32"\n", a, *ap);
	printf("%.10g %08"PRIx32"\n", b, *bp);
	printf("%.10g %08"PRIx32"\n", c, *cp);
	printf("%.10g %08"PRIx32"\n", d, *dp);
	puts("");
	*cp = 0xFFFFFFFF;
	//*dp = 0xFFFF7FFF;
	printf("%.10g %08"PRIx32"\n", c, *cp);
	printf("%.10g %08"PRIx32"\n", d, *dp);
	puts("");

	B = nextafter(A, C);
	printf("%.20g %.20g %.20g\n", A, C, B);
	printf("%016"PRIx64" %016"PRIx64" %016"PRIx64"\n", *Ap, *Cp, *Bp);
	puts("");

	B = nextafter(A, D);
	printf("%.18g %.18g %.18g\n", A, D, B);
	printf("%016"PRIx64" %016"PRIx64" %016"PRIx64"\n", *Ap, *Dp, *Bp);
	puts("");

	*ap = 0xffff7fff;
	b = nextafterf(a, c);
	printf("%.9g %.9g %.9g\n", a, c, b);
	printf("%08"PRIx32" %08"PRIx32" %08"PRIx32"\n", *ap, *cp, *bp);
	puts("");

	b = nextafterf(a, d);
	printf("%.9g %.9g %.9g\n", a, d, b);
        printf("%08"PRIx32" %08"PRIx32" %08"PRIx32"\n", *ap, *dp, *bp);
        puts("");


        errno = 0;
        //feclearexcept(0x1);

	*ap = 0x00000000;
	b = nextafterf(a, -d);

	int err = 0; //fetestexcept(0x1);

	b = nextafterf(a, -d);
	printf("%.9g %.9g %.9g\n", a, -d, b);
        printf("%08"PRIx32" %08"PRIx32" %08"PRIx32" %d\n", *ap, *dp, *bp, err);
        puts("");

	b = nextafterf(a, d);
	printf("%.9g %.9g %.9g\n", a, d, b);
        printf("%08"PRIx32" %08"PRIx32" %08"PRIx32" %d\n", *ap, *dp, *bp, err);
        puts("");

	b = nextafterf(a, (float)-INFINITY);
	printf("%.9g %.9g %.9g\n", a, (float)-INFINITY, b);
        puts("");
	printf("%.9g %.9g %.9g %.9g\n", -d, d, -INFINITY, INFINITY);
	printf("%.9g %.9g %.9g %.9g\n", -d, d, -DBL_MAX, DBL_MAX);
	printf("%.9g %.9g\n", -INFINITY, INFINITY);
	printf("%.9g %.9g\n", -DBL_MAX, DBL_MAX);
	printf("%.9g %.9g\n", -0.5 * __builtin_huge_val(), __builtin_huge_val());

#if 0
	B = nextafter(0.0, 1.0);
	printf("%.19g %.19g %.19g\n", 0.0, 1.0, B);
	B = nextafter(0.0, -INFINITY);
	printf("%.19g %.19g %.19g\n", 0.0, -1.0, B);
        puts("");
#endif
	return EXIT_SUCCESS;
}


Home | Main Index | Thread Index | Old Index