mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Get more Python tests passing (#141)
This commit is contained in:
parent
916f19eea1
commit
59e1c245d1
141 changed files with 3536 additions and 1203 deletions
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/runtime/clktck.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
|
||||
|
@ -36,7 +37,9 @@ static noinline int __clk_tck_init(void) {
|
|||
int cmd[2];
|
||||
size_t len;
|
||||
struct clockinfo_netbsd clock;
|
||||
if (IsXnu() || IsOpenbsd()) {
|
||||
if (IsWindows()) {
|
||||
x = HECTONANOSECONDS;
|
||||
} else if (IsXnu() || IsOpenbsd()) {
|
||||
x = 100;
|
||||
} else if (IsFreebsd()) {
|
||||
x = 128;
|
||||
|
|
|
@ -33,6 +33,51 @@
|
|||
#define HW_NCPUONLINE_NETBSD 16
|
||||
#define ALL_PROCESSOR_GROUPS 0xffff
|
||||
|
||||
static unsigned GetCpuCountLinux(void) {
|
||||
uint64_t s[16];
|
||||
unsigned i, c, n;
|
||||
if ((n = sched_getaffinity(0, sizeof(s), s)) > 0) {
|
||||
assert(!(n & 7));
|
||||
for (n >>= 3, c = i = 0; i < n; ++i) {
|
||||
c += popcnt(s[i]);
|
||||
}
|
||||
return c;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned GetCpuCountBsd(void) {
|
||||
size_t n;
|
||||
int c, cmd[2];
|
||||
n = sizeof(c);
|
||||
cmd[0] = CTL_HW;
|
||||
if (IsOpenbsd()) {
|
||||
cmd[1] = HW_NCPUONLINE_OPENBSD;
|
||||
} else if (IsNetbsd()) {
|
||||
cmd[1] = HW_NCPUONLINE_NETBSD;
|
||||
} else {
|
||||
cmd[1] = HW_NCPU;
|
||||
}
|
||||
if (!sysctl(cmd, 2, &c, &n, 0, 0)) {
|
||||
return c;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static textwindows unsigned GetCpuCountWindows(void) {
|
||||
struct NtSystemInfo si;
|
||||
uint32_t (*f)(uint16_t);
|
||||
if ((f = GetProcAddress(GetModuleHandle("KERNEL32"),
|
||||
"GetMaximumProcessorCount"))) {
|
||||
return f(ALL_PROCESSOR_GROUPS);
|
||||
} else {
|
||||
GetSystemInfo(&si);
|
||||
return si.dwNumberOfProcessors;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of CPUs in system.
|
||||
*
|
||||
|
@ -42,43 +87,13 @@
|
|||
* @return cpu count or 0 if it couldn't be determined
|
||||
*/
|
||||
unsigned GetCpuCount(void) {
|
||||
size_t len;
|
||||
int i, c, n, cmd[2];
|
||||
uint64_t cpuset[16];
|
||||
uint32_t (*f)(uint16_t);
|
||||
struct NtSystemInfo sysinfo;
|
||||
if (IsWindows()) {
|
||||
if ((f = GetProcAddress(GetModuleHandle("KERNEL32"),
|
||||
"GetMaximumProcessorCount"))) {
|
||||
return f(ALL_PROCESSOR_GROUPS);
|
||||
if (!IsWindows()) {
|
||||
if (!IsBsd()) {
|
||||
return GetCpuCountLinux();
|
||||
} else {
|
||||
GetSystemInfo(&sysinfo);
|
||||
return sysinfo.dwNumberOfProcessors;
|
||||
}
|
||||
} else if (IsBsd()) {
|
||||
len = sizeof(c);
|
||||
cmd[0] = CTL_HW;
|
||||
if (IsOpenbsd()) {
|
||||
cmd[1] = HW_NCPUONLINE_OPENBSD;
|
||||
} else if (IsNetbsd()) {
|
||||
cmd[1] = HW_NCPUONLINE_NETBSD;
|
||||
} else {
|
||||
cmd[1] = HW_NCPU;
|
||||
}
|
||||
if (!sysctl(cmd, 2, &c, &len, 0, 0)) {
|
||||
return c;
|
||||
} else {
|
||||
return 0;
|
||||
return GetCpuCountBsd();
|
||||
}
|
||||
} else {
|
||||
if ((n = sched_getaffinity(0, sizeof(cpuset), cpuset)) > 0) {
|
||||
assert(!(n & 7));
|
||||
for (n >>= 3, c = i = 0; i < ARRAYLEN(cpuset); ++i) {
|
||||
c += popcnt(cpuset[i]);
|
||||
}
|
||||
return c;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return GetCpuCountWindows();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue