From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 30136 invoked from network); 14 Feb 2021 09:10:30 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 14 Feb 2021 09:10:30 -0000 Received: from mail-wr1-f49.google.com ([209.85.221.49]) by 1ess; Sun Feb 14 04:05:02 -0500 2021 Received: by mail-wr1-f49.google.com with SMTP id v15so4982799wrx.4 for <9front@9front.org>; Sun, 14 Feb 2021 01:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:date:to:subject:mime-version :content-transfer-encoding; bh=tWckz3K9CIUNCVgUuxwfiq5E7TxkruaViwBnrwKIrlc=; b=PRLWIkDEDNyXbDxAAPfoeEWHjz/LW0bFc5H+5z83zDhqOdj3E7QmbcAcipHVSezpQo eWy9QEyUb2pO73rc8nfjJYXKwEd5DzVUxFCIgYbC06fa706O3yN74gFebLvn5XJx8/K9 bJeh6bBqVWMieIK6d2LwfCLK/ykH/86Fwp5KQ3HE17eV/QgEae7BDiM618FfRCEnK82d Y83kZy4ge7AmdH+KFTUS9jt3o/edKtO0OeEBAKMX77E9ts82JXJuwywhJTemGoo4MvDL FsgablfM3mBGT78ngSkY1qmEfJKHrZ+kdBwN6KsIqI6+JYQJmYLBRk1WyJzxRlcf8Lxc ba2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:date:to:subject:mime-version :content-transfer-encoding; bh=tWckz3K9CIUNCVgUuxwfiq5E7TxkruaViwBnrwKIrlc=; b=KaK10sYngvYptO4wKgktIAkT6czmo24mMnCMS7Uc7RJ2WLRRh37FuaFFE82wIYo9fH 1tnPoCqKcZbe1XpzABU6G3XgMxJ+0VO4o3mjc1e6as2hxP6bREwX240qF+2CjQAVsLou gQcaoHb9Y80CaUssEAyxSNbQIGBLEHr9ODefeOBfSmcqF1x/41rwUg7jn9v9Yq0gB5fy 7jmefA5sGuBG8yBlFuUODkZ0GxRn65UyJvTA5TtyhXQUbLpXffHWvdkAmtBnNx9oKbgo d1Y/Wzkauh+3GWEI4ur2+0acSHxiAHYhY1mgDeVSmTjhuY2akWLxmqNa3uFmEQ1ikGGM WrDA== X-Gm-Message-State: AOAM532D5kMYexTnxD9TMOj/vLjxhVCBECT8ADpjVxOd+kthPDwb84ta bDLEZdkDOF9M/3B0bo/e8f4= X-Google-Smtp-Source: ABdhPJymKDZpOVQd3BLFD125xUaTr9WNFGTghY16r//XkN2Jhc8nJkSaHKfkIZtDKbxHrWlCtWNa+g== X-Received: by 2002:a5d:58c2:: with SMTP id o2mr13030596wrf.141.1613293491641; Sun, 14 Feb 2021 01:04:51 -0800 (PST) Return-Path: Received: from hades (lfbn-idf1-1-101-190.w82-124.abo.wanadoo.fr. [82.124.189.190]) by smtp.gmail.com with ESMTPSA id d10sm18076026wrn.88.2021.02.14.01.04.50 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Feb 2021 01:04:51 -0800 (PST) From: telephil9@gmail.com X-Google-Original-From: pme@gmail.com Message-ID: Date: Sun, 14 Feb 2021 10:04:49 +0100 To: 9front@9front.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: distributed extensible persistence-based factory Subject: [9front] [PATCH] APE: add ceilf, fabsf and lroundf Reply-To: 9front@9front.org Precedence: bulk Hi, Here is a patch to add ceilf, fabsf and lroundf to APE math library. These functions are needed for the netsurf port. Source code was copied from sourceware newlib. Looking at implementations from various OSes, I see that OpenBSD uses these exact same versions copied from the same sources. Thanks --phil diff -r ce98610ce572 sys/include/ape/math.h --- a/sys/include/ape/math.h Wed Feb 10 15:42:18 2021 -0800 +++ b/sys/include/ape/math.h Sun Feb 14 10:02:40 2021 +0100 @@ -30,10 +30,13 @@ extern double modf(double, double *); extern double pow(double, double); extern double sqrt(double); +extern float ceilf(float); extern double ceil(double); extern double fabs(double); +extern float fabsf(float); extern double floor(double); extern double fmod(double, double); +extern long int lroundf(float); extern double NaN(void); extern int isNaN(double); extern double Inf(int); diff -r ce98610ce572 sys/src/ape/lib/ap/math/ceilf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/ape/lib/ap/math/ceilf.c Sun Feb 14 10:02:40 2021 +0100 @@ -0,0 +1,46 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include +#include +#include "math_private.h" + +static const float huge = 1.0e30; + +float +ceilf(float x) +{ + int32_t i0,jj0; + uint32_t i; + + GET_FLOAT_WORD(i0,x); + jj0 = ((i0>>23)&0xff)-0x7f; + if(jj0<23) { + if(jj0<0) { /* raise inexact if x != 0 */ + if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */ + if(i0<0) {i0=0x80000000;} + else if(i0!=0) { i0=0x3f800000;} + } + } else { + i = (0x007fffff)>>jj0; + if((i0&i)==0) return x; /* x is integral */ + if(huge+x>(float)0.0) { /* raise inexact flag */ + if(i0>0) i0 += (0x00800000)>>jj0; + i0 &= (~i); + } + } + } else { + if(jj0==0x80) return x+x; /* inf or NaN */ + else return x; /* x is integral */ + } + SET_FLOAT_WORD(x,i0); + return x; +} diff -r ce98610ce572 sys/src/ape/lib/ap/math/fabsf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/ape/lib/ap/math/fabsf.c Sun Feb 14 10:02:40 2021 +0100 @@ -0,0 +1,27 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * fabsf(x) returns the absolute value of x. + */ + +#include +#include +#include "math_private.h" + +float +fabsf(float x) +{ + uint32_t ix; + GET_FLOAT_WORD(ix,x); + SET_FLOAT_WORD(x,ix&0x7fffffff); + return x; +} diff -r ce98610ce572 sys/src/ape/lib/ap/math/lroundf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/ape/lib/ap/math/lroundf.c Sun Feb 14 10:02:40 2021 +0100 @@ -0,0 +1,42 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ +#include +#include +#include "math_private.h" + +long int +lroundf(float x) +{ + int32_t exponent_less_127; + uint32_t w; + long int result; + int32_t sign; + GET_FLOAT_WORD (w, x); + exponent_less_127 = ((w & 0x7f800000) >> 23) - 127; + sign = (w & 0x80000000) != 0 ? -1 : 1; + w &= 0x7fffff; + w |= 0x800000; + if (exponent_less_127 < (int)((8 * sizeof (long int)) - 1)) + { + if (exponent_less_127 < 0) + return exponent_less_127 < -1 ? 0 : sign; + else if (exponent_less_127 >= 23) + result = (long int) w << (exponent_less_127 - 23); + else + { + w += 0x400000 >> exponent_less_127; + result = w >> (23 - exponent_less_127); + } + } + else + return (long int) x; + return sign * result; +} diff -r ce98610ce572 sys/src/ape/lib/ap/math/math_private.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/src/ape/lib/ap/math/math_private.h Sun Feb 14 10:02:40 2021 +0100 @@ -0,0 +1,42 @@ +#ifndef __MATH_PRIVATE +#define __MATH_PRIVATE +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* A union which permits us to convert between a float and a 32 bit + int. */ + +typedef union +{ + float value; + uint32_t word; +} ieee_float_shape_type; + +/* Get a 32 bit int from a float. */ + +#define GET_FLOAT_WORD(i,d) \ +do { \ + ieee_float_shape_type gf_u; \ + gf_u.value = (d); \ + (i) = gf_u.word; \ +} while (0) + +/* Set a float from a 32 bit int. */ + +#define SET_FLOAT_WORD(d,i) \ +do { \ + ieee_float_shape_type sf_u; \ + sf_u.word = (i); \ + (d) = sf_u.value; \ +} while (0) + + +#endif /* __MATH_PRIVATE */ diff -r ce98610ce572 sys/src/ape/lib/ap/math/mkfile --- a/sys/src/ape/lib/ap/math/mkfile Wed Feb 10 15:42:18 2021 -0800 +++ b/sys/src/ape/lib/ap/math/mkfile Sun Feb 14 10:02:40 2021 +0100 @@ -5,9 +5,11 @@ asin.$O\ atan.$O\ atan2.$O\ + ceilf.$O\ erf.$O\ exp.$O\ fabs.$O\ + fabsf.$O\ floor.$O\ fmin.$O\ fmod.$O\ @@ -17,6 +19,7 @@ j1.$O\ jn.$O\ log.$O\ + lroundf.$O\ pow.$O\ sin.$O\ sinh.$O\