gmux 0.1.0
Linux on Cloudflare Workers
Loading...
Searching...
No Matches
libm.h
1#ifndef KB_LIBM_H
2#define KB_LIBM_H
3
4#include <stdint.h>
5
6#define EXP_TABLE_BITS 7
7#define EXP_POLY_ORDER 5
8#define EXP_USE_TOINT_NARROW 0
9#define EXP2_POLY_ORDER 5
10#define LOG_TABLE_BITS 7
11#define LOG_POLY_ORDER 6
12#define LOG_POLY1_ORDER 12
13#define POW_LOG_TABLE_BITS 7
14#define POW_LOG_POLY_ORDER 8
15
16extern const struct kb_exp_data {
17 double invln2N;
18 double shift;
19 double negln2hiN;
20 double negln2loN;
21 double poly[4];
22 double exp2_shift;
23 double exp2_poly[EXP2_POLY_ORDER];
24 uint64_t tab[2 * (1 << EXP_TABLE_BITS)];
26
27extern const struct kb_log_data {
28 double ln2hi;
29 double ln2lo;
30 double poly[LOG_POLY_ORDER - 1];
31 double poly1[LOG_POLY1_ORDER - 1];
32 struct {
33 double invc, logc;
34 } tab[1 << LOG_TABLE_BITS];
35 struct {
36 double chi, clo;
37 } tab2[1 << LOG_TABLE_BITS];
39
40extern const struct kb_pow_log_data {
41 double ln2hi;
42 double ln2lo;
43 double poly[POW_LOG_POLY_ORDER - 1];
44 struct {
45 double invc, pad, logc, logctail;
46 } tab[1 << POW_LOG_TABLE_BITS];
48
49/* how the guest's libm was compiled: without a fused multiply-add (x86-64),
50 * with one at the sites the source writes as fma (musl on AArch64, built with
51 * -ffp-contract=off), and glibc 2.36 on AArch64 (Debian 12), where gcc fused
52 * more than that and rounds a tie in the argument reduction away from zero */
53enum
54{
55 KB_LIBM_X86,
56 KB_LIBM_MUSL_A64,
57 KB_LIBM_GLIBC_A64
58};
59
60/* exp, log and pow as glibc and musl compute them in the normal cases. Each
61 * returns 1 with the value in *out, or 0 for an input or a result outside
62 * them (non-finite, zero, subnormal, a result that would set errno or raise
63 * underflow or overflow, an exact tie in the argument reduction except for
64 * KB_LIBM_GLIBC_A64), where the caller runs the guest's own code */
65int kb_libm_exp(double x, int flavor, double* out);
66int kb_libm_log(double x, int flavor, double* out);
67int kb_libm_pow(double x, double y, int flavor, double* out);
68/* 1 when a*b + c is rounded twice here, as the kernels need */
69int kb_libm_ok(void);
70
71#endif
Definition libm.h:16
Definition libm.h:27
Definition libm.h:40