mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 09:18:31 +00:00
parent
a988896048
commit
f317a47cd8
15 changed files with 315 additions and 253 deletions
|
@ -20,7 +20,7 @@
|
|||
#include "libc/bits/asmflag.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/calls/asan.internal.h"
|
||||
#include "libc/calls/clock_gettime.h"
|
||||
#include "libc/calls/clock_gettime.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
|
|
|
@ -7,8 +7,8 @@ COSMOPOLITAN_C_START_
|
|||
typedef int clock_gettime_f(int, struct timespec *);
|
||||
|
||||
extern clock_gettime_f *__clock_gettime;
|
||||
hidden clock_gettime_f __clock_gettime_init;
|
||||
hidden clock_gettime_f *__clock_gettime_get(bool *);
|
||||
clock_gettime_f *__clock_gettime_get(bool *) hidden;
|
||||
int __clock_gettime_init(int, struct timespec *) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/clock_gettime.h"
|
||||
#include "libc/calls/clock_gettime.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
|
|
|
@ -50,14 +50,18 @@ int64_t TimeValToWindowsTime(struct timeval) libcesque nosideeffect;
|
|||
struct timeval WindowsDurationToTimeVal(int64_t) libcesque nosideeffect;
|
||||
struct timespec WindowsDurationToTimeSpec(int64_t) libcesque nosideeffect;
|
||||
|
||||
static inline struct NtFileTime MakeFileTime(int64_t x) {
|
||||
return (struct NtFileTime){(uint32_t)x, (uint32_t)(x >> 32)};
|
||||
}
|
||||
#define MakeFileTime(x) \
|
||||
({ \
|
||||
int64_t __x = x; \
|
||||
(struct NtFileTime){(uint32_t)__x, (uint32_t)(__x >> 32)}; \
|
||||
})
|
||||
|
||||
static inline int64_t ReadFileTime(struct NtFileTime t) {
|
||||
uint64_t x = t.dwHighDateTime;
|
||||
return x << 32 | t.dwLowDateTime;
|
||||
}
|
||||
#define ReadFileTime(t) \
|
||||
({ \
|
||||
struct NtFileTime __t = t; \
|
||||
uint64_t x = __t.dwHighDateTime; \
|
||||
(int64_t)(x << 32 | __t.dwLowDateTime); \
|
||||
})
|
||||
|
||||
#define FileTimeToTimeSpec(x) WindowsTimeToTimeSpec(ReadFileTime(x))
|
||||
#define FileTimeToTimeVal(x) WindowsTimeToTimeVal(ReadFileTime(x))
|
||||
|
|
|
@ -9,13 +9,14 @@ bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);
|
|||
|
||||
#if defined(__GCC_ASM_FLAG_OUTPUTS__) && !defined(__STRICT_ANSI__)
|
||||
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
|
||||
static pureconst inline unsigned char GetNtMajorVersion(void) {
|
||||
uintptr_t _x;
|
||||
asm("mov\t%%gs:96,%q0\r\n"
|
||||
"mov\t280(%q0),%b0"
|
||||
: "=q"(_x));
|
||||
return _x;
|
||||
}
|
||||
#define GetNtMajorVersion() \
|
||||
({ \
|
||||
uintptr_t __x; \
|
||||
asm("mov\t%%gs:96,%q0\r\n" \
|
||||
"mov\t280(%q0),%b0" \
|
||||
: "=q"(__x)); \
|
||||
(unsigned char)__x; \
|
||||
})
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -4,14 +4,17 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
forceinline bool SlicesEqual(const char *a, size_t n, const char *b, size_t m) {
|
||||
return n == m && !memcmp(a, b, n);
|
||||
}
|
||||
#define SlicesEqual(a, n, b, m) \
|
||||
({ \
|
||||
size_t __n = (n); \
|
||||
__n == (m) && !memcmp(a, b, __n); \
|
||||
})
|
||||
|
||||
forceinline bool SlicesEqualCase(const void *a, size_t n, const void *b,
|
||||
size_t m) {
|
||||
return n == m && !memcasecmp(a, b, n);
|
||||
}
|
||||
#define SlicesEqualCase(a, n, b, m) \
|
||||
({ \
|
||||
size_t __n = (n); \
|
||||
__n == (m) && !memcasecmp(a, b, __n); \
|
||||
})
|
||||
|
||||
int CompareSlices(const char *, size_t, const char *, size_t);
|
||||
int CompareSlicesCase(const char *, size_t, const char *, size_t);
|
||||
|
|
|
@ -9,9 +9,12 @@
|
|||
* @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
|
||||
* @see fmod()
|
||||
*/
|
||||
static inline double emod(double x, double y) {
|
||||
return x - fabs(y) * floor(x / fabs(y));
|
||||
}
|
||||
#define emod(x, y) \
|
||||
({ \
|
||||
double __x = x; \
|
||||
double __y = y; \
|
||||
__x - fabs(__y) * floor(__x / fabs(__y)); \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_EMOD_H_ */
|
||||
|
|
|
@ -9,9 +9,12 @@
|
|||
* @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
|
||||
* @see fmodl()
|
||||
*/
|
||||
static inline long double emodl(long double x, long double y) {
|
||||
return x - fabsl(y) * floorl(x / fabsl(y));
|
||||
}
|
||||
#define emodl(x, y) \
|
||||
({ \
|
||||
long double __x = x; \
|
||||
long double __y = y; \
|
||||
__x - fabsl(__y) * floorl(__x / fabsl(__y)); \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue