Raymond Toy pushed to branch issue-435-add-core-math-compile-code at cmucl / cmucl Commits: e1f841fb by Raymond Toy at 2026-02-24T18:15:35-08:00 Merge branch 'issue-435-add-core-math-compile-code' into 'master' Forgot to add log1pf.c See merge request cmucl/cmucl!355 - - - - - f2f15905 by Raymond Toy at 2026-02-24T18:35:58-08:00 Address #435: Compile single-float core-math routines Update config files and Makefiles to include the single-float core-math routines. Add interfaces to the routines in irrat.c. This verifies that we have included everything and it compiles. The lisp interface hasn't been updated, so none of these get called. - - - - - 3 changed files: - src/lisp/Config.x86_common - src/lisp/GNUmakefile - src/lisp/irrat.c Changes: ===================================== src/lisp/Config.x86_common ===================================== @@ -65,6 +65,34 @@ CORE64_SRCS=\ $(CORE_MATH_64)/log1p/log1p.c \ $(CORE_MATH_64)/expm1/expm1.c \ $(CORE_MATH_64)/sincos/sincos.c + +CORE_MATH_32=core-math/src/binary32 +CORE32_SRCS=\ + $(CORE_MATH_32)/sin/sinf.c \ + $(CORE_MATH_32)/cos/cosf.c \ + $(CORE_MATH_32)/tan/tanf.c \ + $(CORE_MATH_32)/atan2/atan2f.c \ + $(CORE_MATH_32)/asin/asinf.c \ + $(CORE_MATH_32)/acos/acosf.c \ + $(CORE_MATH_32)/atan/atanf.c \ + $(CORE_MATH_32)/sinh/sinhf.c \ + $(CORE_MATH_32)/cosh/coshf.c \ + $(CORE_MATH_32)/tanh/tanhf.c \ + $(CORE_MATH_32)/asinh/asinhf.c \ + $(CORE_MATH_32)/acosh/acoshf.c \ + $(CORE_MATH_32)/atanh/atanhf.c \ + $(CORE_MATH_32)/exp/expf.c \ + $(CORE_MATH_32)/log/logf.c \ + $(CORE_MATH_32)/log10/log10f.c \ + $(CORE_MATH_32)/log2/log2f.c \ + $(CORE_MATH_32)/pow/powf.c \ + $(CORE_MATH_32)/hypot/hypotf.c \ + $(CORE_MATH_32)/log1p/log1pf.c \ + $(CORE_MATH_32)/expm1/expm1f.c \ + $(CORE_MATH_32)/sincos/sincosf.c + +CORE_MATH_SRCS = $(CORE64_SRCS) $(CORE32_SRCS) + endif ifeq ($(filter 2% 3%, $(shell $(CC) -dumpversion)),) ===================================== src/lisp/GNUmakefile ===================================== @@ -36,7 +36,7 @@ SRCS = lisp.c coreparse.c alloc.c monitor.c print.c interr.c \ dynbind.c breakpoint.c regnames.c backtrace.c save.c purify.c \ runprog.c time.c case-mapping.c exec-init.c \ irrat.c \ - ${CORE64_SRCS} \ + ${CORE_MATH_SRCS} \ ${FDLIBM} ${ARCH_SRC} ${ASSEM_SRC} ${OS_SRC} ${GC_SRC} ===================================== src/lisp/irrat.c ===================================== @@ -32,6 +32,28 @@ extern double cr_hypot(double, double); extern double cr_log1p(double); extern double cr_expm1(double); extern void cr_sincos(double, double *, double *); + +extern float cr_sinf(float); +extern float cr_cosf(float); +extern float cr_tanf(float); +extern float cr_atanf(float); +extern float cr_atan2f(float, float); +extern float cr_asinf(float); +extern float cr_acosf(float); +extern float cr_sinhf(float); +extern float cr_coshf(float); +extern float cr_tanhf(float); +extern float cr_asinhf(float); +extern float cr_acoshf(float); +extern float cr_atanhf(float); +extern float cr_expf(float); +extern float cr_logf(float); +extern float cr_log10f(float); +extern float cr_powf(float, float); +extern float cr_hypotf(float, float); +extern float cr_log1pf(float); +extern float cr_expm1f(float); +extern void cr_sincosf(float, float *, float *); #endif @@ -141,6 +163,8 @@ double lisp_cosh(double x) { #ifdef FEATURE_CORE_MATH + MAYBE_SIGNAL_OVERFLOW(fabs(x)) + return cr_cosh(x); #else return __ieee754_cosh(x); @@ -284,6 +308,10 @@ double lisp_expm1(double x) { #ifdef FEATURE_CORE_MATH + if (isinf(x) == 1) { + return fdlibm_setexception(x, FDLIBM_OVERFLOW); + } + return cr_expm1(x); #else return fdlibm_expm1(x); @@ -297,7 +325,7 @@ lisp_scalbn(double x, int n) } void -lisp_sincos (double x, double *s, double *c) +lisp_sincos(double x, double *s, double *c) { #ifdef FEATURE_CORE_MATH cr_sincos(x, s, c); @@ -307,3 +335,236 @@ lisp_sincos (double x, double *s, double *c) cmucl_sincos(x, s, c); #endif } + +/* + * The single-float versions of the special functions. When core-math + * is set, we use the single-float core-math functions. Otherwise, we + * use the double-float versions from fdlibm, with appropriate + * coercions. + */ +float +lisp_sinf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_sinf(x); +#else + return (float) fdlibm_sin((double) x); +#endif +} + +float +lisp_cosf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_cosf(x); +#else + return (float) fdlibm_cos((double) x); +#endif +} + +float +lisp_tanf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_tanf(x); +#else + return (float) fdlibm_tan((double) x); +#endif +} + +float +lisp_atanf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_atanf(x); +#else + return (float) fdlibm_atan((double) x); +#endif +} + +float +lisp_atan2f(float y, float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_atan2f(y, x); +#else + return (float) __ieee754_atan2((double) y, (double) x); +#endif +} + +float +lisp_asinf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_asinf(x); +#else + return (float) __ieee754_asin((double) x); +#endif +} + +float +lisp_acosf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_acosf(x); +#else + return (float) __ieee754_acos((double) x); +#endif +} + +float +lisp_sinhf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_sinhf(x); +#else + return (float) __ieee754_sinh((double) x); +#endif +} + +float +lisp_coshf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_coshf(x); +#else + return (float) __ieee754_cosh((double) x); +#endif +} + +float +lisp_tanhf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_tanhf(x); +#else + return (float) fdlibm_tanh((double) x); +#endif +} + +float +lisp_asinhf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_asinhf(x); +#else + return (float) fdlibm_asinh((double) x); +#endif +} + +float +lisp_acoshf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_acoshf(x); +#else + return (float) __ieee754_acosh((double) x); +#endif +} + +float +lisp_atanhf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_atanhf(x); +#else + return (float) __ieee754_atanh((double) x); +#endif +} + +float +lisp_expf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_expf(x); +#else + return (float) __ieee754_exp((double) x); +#endif +} + +float +lisp_logf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_logf(x); +#else + return (float) __ieee754_log((double) x); +#endif +} + +float +lisp_log10f(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_log10f(x); +#else + return (float) __ieee754_log10((double) x); +#endif +} + +float +lisp_powf(float x, float y) +{ +#ifdef FEATURE_CORE_MATH + /* + * cr_pow when compiled with older versions of gcc or clang can + * cause failures in the ansi-tests [#469]. Ubuntu 25.10 and Fedora 41 + * (gcc only) are known to have compilers that work well enough + * that the ansi-tests pass. + */ + return cr_powf(x, y); +#else + /* + * cr_pow seems causes ansi-tests to fail in test WRITE.1 among + * others. Somewhere an invalid operation is occurring. Thus + * just use fdlibm for now until we can figure out what's causing + * the failure. + */ + return (float) __ieee754_pow((double) x, (double) y); +#endif +} + +float +lisp_hypotf(float x, float y) +{ +#ifdef FEATURE_CORE_MATH + return cr_hypotf(x, y); +#else + return (float) __ieee754_hypot((double) x, (double) y); +#endif +} + +float +lisp_log1pf(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_log1pf(x); +#else + return (float) fdlibm_log1p((double) x); +#endif +} + +float +lisp_expm1f(float x) +{ +#ifdef FEATURE_CORE_MATH + return cr_expm1f(x); +#else + return (float) fdlibm_expm1((double) x); +#endif +} + +void +lisp_sincosf(float x, float *s, float *c) +{ +#ifdef FEATURE_CORE_MATH + cr_sincosf(x, s, c); +#else + extern void cmucl_sincos(double, double*, double*); + double ds, dc; + + cmucl_sincos((double) x, &ds, &dc); + *s = (float) ds; + *c = (float) dc; +#endif +} View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/1b1e639bf08e9e6c9b45553... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/1b1e639bf08e9e6c9b45553... You're receiving this email because of your account on gitlab.common-lisp.net.