Raymond Toy pushed to branch issue-435-add-core-math-lisp-support at cmucl / cmucl Commits: 06d942be by Raymond Toy at 2026-03-03T19:26:00-08:00 Address review comments Update exports.lisp. Add new file openlibm/e_log2f.c to get the function log2f and use it in irrat.c. This requires updating Config.x86_common too. - - - - - 4 changed files: - src/code/exports.lisp - src/lisp/Config.x86_common - src/lisp/irrat.c - + src/lisp/openlibm/e_log2f.c Changes: ===================================== src/code/exports.lisp ===================================== @@ -2190,7 +2190,30 @@ "STANDARD-PPRINT-DISPATCH-TABLE-MODIFIED-ERROR" "%IEEE754-REM-PI/2" - "%SINCOS") + "%SINCOS" + ;; Single-float functions + "%ACOSF" + "%ACOSHF" + "%ASINF" + "%ASINHF" + "%ATAN2F" + "%ATANF" + "%ATANHF" + "%COSF" + "%COSHF" + "%EXPF" + "%EXPM1F" + "%HYPOTF" + "%LOG10F" + "%LOG1PF" + "%LOG2F" + "%LOGF" + "%POWF" + "%SINF" + "%SINHF" + "%TANF" + "%TANHF" + ) #+heap-overflow-check (:export "DYNAMIC-SPACE-OVERFLOW-WARNING-HIT" "DYNAMIC-SPACE-OVERFLOW-ERROR-HIT" @@ -2227,30 +2250,7 @@ "DD-PI" "INVALID-CASE") #+random-xoroshiro - (:export "RANDOM-STATE-JUMP") - ;; Single-float functions - (:export "%ACOSF" - "%ACOSHF" - "%ASINF" - "%ASINHF" - "%ATAN2F" - "%ATANF" - "%ATANHF" - "%COSF" - "%COSHF" - "%EXPF" - "%EXPM1F" - "%HYPOTF" - "%LOG10F" - "%LOG1PF" - "%LOG2F" - "%LOGF" - "%POWF" - "%SINF" - "%SINHF" - "%TANF" - "%TANHF" - )) + (:export "RANDOM-STATE-JUMP")) (dolist (name ===================================== src/lisp/Config.x86_common ===================================== @@ -110,6 +110,7 @@ OPENLIBM_SRCS = \ $(OPENLIBM_DIR)/e_hypotf.c \ $(OPENLIBM_DIR)/e_log10f.c \ $(OPENLIBM_DIR)/e_logf.c \ + $(OPENLIBM_DIR)/e_log2f.c \ $(OPENLIBM_DIR)/e_powf.c \ $(OPENLIBM_DIR)/e_rem_pio2f.c \ $(OPENLIBM_DIR)/e_sinhf.c \ ===================================== src/lisp/irrat.c ===================================== @@ -596,6 +596,6 @@ lisp_log2f(float x) #ifdef FEATURE_CORE_MATH return cr_log2f(x); #else - return (float) fdlibm_log2((double) x); + return log2f(x); #endif } ===================================== src/lisp/openlibm/e_log2f.c ===================================== @@ -0,0 +1,85 @@ +/* + * ==================================================== + * 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 "cdefs-compat.h" +//__FBSDID("$FreeBSD: src/lib/msun/src/e_log2f.c,v 1.5 2011/10/15 05:23:28 das Exp $"); + +/* + * Float version of e_log2.c. See the latter for most comments. + */ + +#include <openlibm_math.h> + +#include "math_private.h" +#include "k_logf.h" + +// VBS +#define float_t float + +static const float +two25 = 3.3554432000e+07, /* 0x4c000000 */ +ivln2hi = 1.4428710938e+00, /* 0x3fb8b000 */ +ivln2lo = -1.7605285393e-04; /* 0xb9389ad4 */ + +static const float zero = 0.0; + +OLM_DLLEXPORT float +__ieee754_log2f(float x) +{ + float f,hfsq,hi,lo,r,y; + int32_t i,k,hx; + + GET_FLOAT_WORD(hx,x); + + k=0; + if (hx < 0x00800000) { /* x < 2**-126 */ + if ((hx&0x7fffffff)==0) + return -two25/zero; /* log(+-0)=-inf */ + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */ + k -= 25; x *= two25; /* subnormal number, scale up x */ + GET_FLOAT_WORD(hx,x); + } + if (hx >= 0x7f800000) return x+x; + if (hx == 0x3f800000) + return zero; /* log(1) = +0 */ + k += (hx>>23)-127; + hx &= 0x007fffff; + i = (hx+(0x4afb0d))&0x800000; + SET_FLOAT_WORD(x,hx|(i^0x3f800000)); /* normalize x or x/2 */ + k += (i>>23); + y = (float)k; + f = x - (float)1.0; + hfsq = (float)0.5*f*f; + r = k_log1pf(f); + + /* + * We no longer need to avoid falling into the multi-precision + * calculations due to compiler bugs breaking Dekker's theorem. + * Keep avoiding this as an optimization. See e_log2.c for more + * details (some details are here only because the optimization + * is not yet available in double precision). + * + * Another compiler bug turned up. With gcc on i386, + * (ivln2lo + ivln2hi) would be evaluated in float precision + * despite runtime evaluations using double precision. So we + * must cast one of its terms to float_t. This makes the whole + * expression have type float_t, so return is forced to waste + * time clobbering its extra precision. + */ + if (sizeof(float_t) > sizeof(float)) + return (r - hfsq + f) * ((float_t)ivln2lo + ivln2hi) + y; + + hi = f - hfsq; + GET_FLOAT_WORD(hx,hi); + SET_FLOAT_WORD(hi,hx&0xfffff000); + lo = (f - hi) - hfsq + r; + return (lo+hi)*ivln2lo + lo*ivln2hi + hi*ivln2hi + y; +} View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/06d942be90150dd2ab2a003a... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/06d942be90150dd2ab2a003a... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)