Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions abis/linux/auxv.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#define AT_FPUCW 18
#define AT_SECURE 23
#define AT_RANDOM 25
#define AT_HWCAP2 26
#define AT_HWCAP3 29
#define AT_HWCAP4 30
#define AT_EXECFN 31
#define AT_SYSINFO_EHDR 33

Expand Down
3 changes: 2 additions & 1 deletion abis/linux/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extern "C" {

#if defined(__aarch64__) || defined(__i386__) || defined(__m68k__)
#define IPC_64 0x100
#elif defined(__x86_64__) || (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch64)
#elif defined(__x86_64__) || (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch64) \
|| defined(__powerpc64__)
#define IPC_64 0
#else
#error "Unsupported arch!"
Expand Down
12 changes: 12 additions & 0 deletions abis/linux/shm.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ struct shmid_ds {
unsigned long shm_nattch;
unsigned long __unused[2];
};
#elif defined(__powerpc64__)
struct shmid_ds {
struct ipc_perm shm_perm;
time_t shm_atime;
time_t shm_dtime;
time_t shm_ctime;
size_t shm_segsz;
pid_t shm_cpid;
pid_t shm_lpid;
unsigned long shm_nattch;
unsigned long __unused[2];
};
Comment on lines +81 to +91
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is correct - this seems to match the definition of shmid64_ds for ppc64, which is a different struct. I think the correct definition is the one above.

#else
#error "Missing architecture specific code."
#endif
Expand Down
47 changes: 47 additions & 0 deletions abis/linux/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <abi-bits/pid_t.h>
#include <abi-bits/sigevent.h>
#include <abi-bits/uid_t.h>
#include <asm/types.h>
#include <bits/size_t.h>
#include <stdint.h>
#include <time.h>
Expand Down Expand Up @@ -152,8 +153,14 @@ typedef struct {
#define SIGUNUSED SIGSYS
#define SIGCANCEL 32

#if defined(__powerpc64__)
#define MINSIGSTKSZ 8192
#define SIGSTKSZ 32768
#else
#define MINSIGSTKSZ 2048
#define SIGSTKSZ 8192
#endif

#define SS_ONSTACK 1
#define SS_DISABLE 2

Expand Down Expand Up @@ -621,6 +628,46 @@ typedef struct __ucontext {
mcontext_t uc_mcontext;
} ucontext_t;

#elif defined(__powerpc64__)

struct sigaltstack {
void *ss_sp;
int ss_flags;
size_t ss_size;
};

typedef unsigned long greg_t, gregset_t[48];
typedef double fpreg_t, fpregset_t[33];

typedef __vector128 vrreg_t;
typedef vrreg_t vrregset_t[34];

struct pt_regs {
greg_t gpr[32];
greg_t pc;
};

struct sigcontext {
unsigned long _unused[4];
int signal;
int _pad0;
unsigned long handler;
unsigned long oldmask;
struct pt_regs *regs;
gregset_t gp_regs;
fpregset_t fp_regs;
vrreg_t *v_regs;
long vmx_reserve[101];
};

typedef struct __ucontext {
unsigned long uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
sigset_t uc_sigmask;
struct sigcontext uc_mcontext;
} ucontext_t;

#else
#error "Missing architecture specific code."
#endif
Expand Down
21 changes: 21 additions & 0 deletions abis/linux/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ struct stat {
ino_t st_ino;
};

#elif defined(__powerpc64__)

struct stat {
unsigned long st_dev;
unsigned long st_ino;
unsigned long st_nlink;
mode_t st_mode;
uid_t st_uid;
gid_t st_gid;
unsigned long st_rdev;
long st_size;
unsigned long st_blksize;
unsigned long st_blocks;
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
unsigned long __unused4;
unsigned long __unused5;
unsigned long __unused6;
};

#endif

#define stat64 stat
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ if default_library_paths.length() == 0
'arm': 32,
'm68k': 32,
'loongarch64': 64,
'powerpc64': 64
}
if target_word_size.get(target_machine.cpu_family()) == 64
default_library_paths = ['/lib', '/lib64', '/usr/lib', '/usr/lib64']
Expand Down
15 changes: 15 additions & 0 deletions options/ansi/include/bits/ansi/fenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@
#define FE_UPWARD 0x200
#define FE_DOWNWARD 0x300

#elif defined(__powerpc64__)

#define FE_DIVBYZERO 0x4000000
#define FE_INEXACT 0x2000000
#define FE_INVALID 0x20000000
#define FE_OVERFLOW 0x10000000
#define FE_UNDERFLOW 0x8000000

#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)

#define FE_TONEAREST 0
#define FE_DOWNWARD 0b11
#define FE_TOWARDZERO 0b01
#define FE_UPWARD 0b10
Comment on lines +101 to +103
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binary literals are compiler extensions and should therefore not be used in public headers.


#else
#error Unknown architecture
#endif
Expand Down
18 changes: 18 additions & 0 deletions options/ansi/musl-generic-math/__fpclassifyl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@ int __fpclassifyl(long double x) {
return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE;
return FP_NORMAL;
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024
int __fpclassifyl(long double x) {
union ldshape u = {x};

if (isnan(u.i.hi))
return FP_NAN;
if (isinf(u.i.hi))
return FP_INFINITE;

if (u.i.hi == 0.0) {
if (u.i.lo == 0.0)
return FP_ZERO;
else
return fpclassify(u.i.lo);
}

return fpclassify(u.i.hi);
}
#endif
22 changes: 22 additions & 0 deletions options/ansi/musl-generic-math/exp10l.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ long double exp10l(long double x) {
}
return powl(10.0, x);
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024

#define M_LN10l 2.302585092994045684017991454684364208L

static const long double log10_high = 0x2.4d763776aaap+0L;
static const long double log10_low = 0x2.b05ba95b58ae0b4c28a38a3fb4p-48L;

long double exp10l(long double x) {
if (!isfinite(x))
return expl(x);
if (x < LDBL_MIN_10_EXP - LDBL_DIG - 10)
return LDBL_MIN * LDBL_MIN;
else if (x > LDBL_MAX_10_EXP + 1)
return LDBL_MAX * LDBL_MAX;
else if (fabsl(x) < 0x1p-109L)
return 1.0L;

union ldshape u = {x};
long double exp_hi = u.i.hi * log10_high;
long double exp_lo = u.i.hi * log10_low + u.i.lo * M_LN10l;
return expl(exp_hi) * expl(exp_lo);
}
#endif

weak_alias(exp10l, pow10l);
3 changes: 2 additions & 1 deletion options/ansi/musl-generic-math/expl.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ long double expl(long double x) {
x = 1.0 + 2.0 * x;
return scalbnl(x, k);
}
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
#elif (LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384) \
|| (LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024)
// TODO: broken implementation to make things compile
long double expl(long double x) { return exp(x); }
#endif
9 changes: 9 additions & 0 deletions options/ansi/musl-generic-math/fabsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ long double fabsl(long double x) {
u.i.se &= 0x7fff;
return u.f;
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024
long double fabsl(long double x) {
union ldshape u = {x};

u.i1.lo = u.i1.lo ^ (u.i1.hi & 0x8000000000000000LL);
u.i1.hi = u.i1.hi & 0x7fffffffffffffffLL;

return u.f;
}
#endif
29 changes: 29 additions & 0 deletions options/ansi/musl-generic-math/ilogbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,33 @@ int ilogbl(long double x) {
}
return e - 0x3fff;
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024
int ilogbl(long double x) {
union ldshape u = {x};

uint64_t hx = u.i1.hi & 0x7fffffffffffffffLL;
if (hx <= 0x0010000000000000LL) {
if (hx == 0) {
return FP_ILOGB0;
} else {
hx <<= 11;
int ix = 0;
for (ix = -1022; hx > 0; hx <<= 1)
ix -= 1;
return ix;
}
} else if (hx < 0x7ff0000000000000LL) {
int hexp = (hx >> 52) - 0x3ff;
if ((hx & 0x000fffffffffffffLL) == 0) {
if ((u.i1.hi ^ u.i1.lo) < 0 && (u.i1.lo & 0x7fffffffffffffffLL) != 0)
hexp--;
}
return hexp;
} else if (FP_ILOGBNAN != INT_MAX) {
if (hx == 0x7ff0000000000000LL)
return INT_MAX;
}

return FP_ILOGBNAN;
}
#endif
3 changes: 2 additions & 1 deletion options/ansi/musl-generic-math/lgammal.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ long double __lgammal_r(long double x, int *sg) {
r = nadj - r;
return r;
}
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
#elif (LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384) \
|| (LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024)
// TODO: broken implementation to make things compile
double __lgamma_r(double x, int *sg);

Expand Down
12 changes: 12 additions & 0 deletions options/ansi/musl-generic-math/libm.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ union ldshape {
uint64_t lo;
} i2;
};
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024 && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
union ldshape {
long double f;
struct {
double hi;
double lo;
} i;
struct {
uint64_t hi;
uint64_t lo;
} i1;
};
#else
#error Unsupported long double representation
#endif
Expand Down
3 changes: 3 additions & 0 deletions options/ansi/musl-generic-math/nextafterl.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ long double nextafterl(long double x, long double y) {
FORCE_EVAL(x * x + ux.f * ux.f);
return ux.f;
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024
// todo(localcc): broken implementation to make things compile
long double nextafterl(long double x, long double y) { return 0; }
#endif
3 changes: 3 additions & 0 deletions options/ansi/musl-generic-math/remquol.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,7 @@ long double remquol(long double x, long double y, int *quo) {
*quo = sx ^ sy ? -(int)q : (int)q;
return sx ? -x : x;
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024
// todo(localcc): broken implementation to make things compile
long double remquol(long double x, long double y, int *quo) { return 0; }
#endif
3 changes: 3 additions & 0 deletions options/ansi/musl-generic-math/rintl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ long double rintl(long double x) {
return 0 * x;
return y;
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024
// todo(localcc): broken implementation to make things compile
long double rintl(long double x) { return 0; }
#endif
3 changes: 3 additions & 0 deletions options/ansi/musl-generic-math/roundl.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ long double roundl(long double x) {
y = -y;
return y;
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024
// todo(localcc): broken implementation to make things compile
long double roundl(long double x) { return 0; }
#endif
5 changes: 4 additions & 1 deletion options/ansi/musl-generic-math/scalbnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ long double scalbnl(long double x, int n) {
}
}
u.f = 1.0;
u.i.se = 0x3fff + n;
u.i.se = exp_bias + n;
return x * u.f;
}
#elif LDBL_MANT_DIG == 106 && LDBL_MAX_EXP == 1024
// todo(localcc): broken implementation to make things compile
long double scalbnl(long double x, int n) { return 0; }
#endif
Loading