gmux
0.1.0
Linux on Cloudflare Workers
Loading...
Searching...
No Matches
src
gmux
katybug
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
16
extern
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)];
25
}
kb_exp_data
;
26
27
extern
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];
38
}
kb_log_data
;
39
40
extern
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];
47
}
kb_pow_log_data
;
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 */
53
enum
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 */
65
int
kb_libm_exp(
double
x,
int
flavor,
double
* out);
66
int
kb_libm_log(
double
x,
int
flavor,
double
* out);
67
int
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 */
69
int
kb_libm_ok(
void
);
70
71
#endif
kb_exp_data
Definition
libm.h:16
kb_log_data
Definition
libm.h:27
kb_pow_log_data
Definition
libm.h:40
Generated by
1.15.0