mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Create ELF aliases for identical symbols
This change greatly reduces the number of modules that need to be compiled. The only issue right now is that sometimes when viewing symbol table entries, the aliased symbol is chosen.
This commit is contained in:
parent
e1b83399bd
commit
b8a6a989c0
191 changed files with 414 additions and 2190 deletions
|
@ -28,6 +28,7 @@
|
|||
#include "libc/intrin/aarch64/asmdefs.internal.h"
|
||||
|
||||
#define __strchr_aarch64 strchr
|
||||
#define __index_aarch64 index
|
||||
|
||||
.ident "\n\n\
|
||||
Optimized Routines (MIT License)\n\
|
||||
|
@ -77,6 +78,7 @@ Copyright 2022 ARM Limited\n"
|
|||
|
||||
/* Locals and temporaries. */
|
||||
|
||||
ENTRY_ALIAS (__strchr_aarch64, __index_aarch64)
|
||||
ENTRY (__strchr_aarch64)
|
||||
PTR_ARG (0)
|
||||
/* Magic constant 0xc0300c03 to allow us to identify which lane
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "libc/intrin/aarch64/asmdefs.internal.h"
|
||||
|
||||
#define __strrchr_aarch64 strrchr
|
||||
#define __rindex_aarch64 rindex
|
||||
|
||||
.ident "\n\n\
|
||||
Optimized Routines (MIT License)\n\
|
||||
|
@ -81,6 +82,7 @@ Copyright 2022 ARM Limited\n"
|
|||
in the original string a count_trailing_zeros() operation will
|
||||
identify exactly which byte is causing the termination, and why. */
|
||||
|
||||
ENTRY_ALIAS (__strrchr_aarch64, __rindex_aarch64)
|
||||
ENTRY (__strrchr_aarch64)
|
||||
PTR_ARG (0)
|
||||
/* Magic constant 0x40100401 to allow us to identify which lane
|
||||
|
|
|
@ -41,9 +41,5 @@ long labs(long x) {
|
|||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns absolute value of 𝑥.
|
||||
*/
|
||||
long long llabs(long long x) {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
__weak_reference(labs, llabs);
|
||||
__weak_reference(labs, imaxabs);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define COSMOPOLITAN_LIBC_BITS_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#ifdef COSMO
|
||||
|
||||
#define CheckUnsigned(x) ((x) / !((typeof(x))(-1) < 0))
|
||||
|
||||
|
@ -11,8 +12,6 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
extern const uint8_t kReverseBits[256];
|
||||
|
||||
uint32_t gray(uint32_t) pureconst;
|
||||
uint32_t ungray(uint32_t) pureconst;
|
||||
int _bitreverse8(int) libcesque pureconst;
|
||||
int _bitreverse16(int) libcesque pureconst;
|
||||
uint32_t _bitreverse32(uint32_t)
|
||||
|
@ -22,7 +21,6 @@ libcesque pureconst;
|
|||
unsigned long _roundup2pow(unsigned long) libcesque pureconst;
|
||||
unsigned long _roundup2log(unsigned long) libcesque pureconst;
|
||||
unsigned long _rounddown2pow(unsigned long) libcesque pureconst;
|
||||
unsigned long _hamming(unsigned long, unsigned long) pureconst;
|
||||
unsigned _bextra(const unsigned *, size_t, char);
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
|
@ -157,6 +155,7 @@ unsigned _bextra(const unsigned *, size_t, char);
|
|||
})
|
||||
|
||||
#endif /* __GNUC__ && !__STRICT_ANSI__ */
|
||||
#endif /* COSMO */
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_H_ */
|
||||
|
|
|
@ -60,23 +60,4 @@ int(_bsfl)(long x) {
|
|||
return _bsfl(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns position of first bit set.
|
||||
*
|
||||
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
|
||||
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
|
||||
* 0x00000000 wut 32 0 wut 32
|
||||
* 0x00000001 0 0 1 0 31
|
||||
* 0x80000001 0 0 1 31 0
|
||||
* 0x80000000 31 31 32 31 0
|
||||
* 0x00000010 4 4 5 4 27
|
||||
* 0x08000010 4 4 5 27 4
|
||||
* 0x08000000 27 27 28 27 4
|
||||
* 0xffffffff 0 0 1 31 0
|
||||
*
|
||||
* @param 𝑥 is a 64-bit integer
|
||||
* @return number in range 0..63 or undefined if 𝑥 is 0
|
||||
*/
|
||||
int(_bsfll)(long long x) {
|
||||
return _bsfll(x);
|
||||
}
|
||||
__weak_reference(_bsfl, _bsfll);
|
||||
|
|
|
@ -60,23 +60,4 @@ int(_bsrl)(long x) {
|
|||
return _bsrl(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns binary logarithm of 𝑥.
|
||||
*
|
||||
* ctz(𝑥) 31^clz(𝑥) clz(𝑥)
|
||||
* uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥)
|
||||
* 0x00000000 wut 32 0 wut 32
|
||||
* 0x00000001 0 0 1 0 31
|
||||
* 0x80000001 0 0 1 31 0
|
||||
* 0x80000000 31 31 32 31 0
|
||||
* 0x00000010 4 4 5 4 27
|
||||
* 0x08000010 4 4 5 27 4
|
||||
* 0x08000000 27 27 28 27 4
|
||||
* 0xffffffff 0 0 1 31 0
|
||||
*
|
||||
* @param x is a 64-bit integer
|
||||
* @return number in range 0..63 or undefined if 𝑥 is 0
|
||||
*/
|
||||
int(_bsrll)(long long x) {
|
||||
return _bsrll(x);
|
||||
}
|
||||
__weak_reference(_bsrl, _bsrll);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
|
@ -16,13 +16,32 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/bswap.h"
|
||||
#include "libc/intrin/newbie.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
||||
/**
|
||||
* Returns gray code for x.
|
||||
* @see https://en.wikipedia.org/wiki/Gray_code
|
||||
* @see ungray()
|
||||
*/
|
||||
uint32_t gray(uint32_t x) {
|
||||
return x ^ (x >> 1);
|
||||
uint16_t(bswap_16)(uint16_t x) {
|
||||
return (0x00ff & x) << 010 | (0xff00 & x) >> 010;
|
||||
}
|
||||
|
||||
__strong_reference(bswap_16, ntohs);
|
||||
__strong_reference(bswap_16, htons);
|
||||
|
||||
uint32_t(bswap_32)(uint32_t x) {
|
||||
return (0x000000ffu & x) << 030 | (0x0000ff00u & x) << 010 |
|
||||
(0x00ff0000u & x) >> 010 | (0xff000000u & x) >> 030;
|
||||
}
|
||||
|
||||
__strong_reference(bswap_32, ntohl);
|
||||
__strong_reference(bswap_32, htonl);
|
||||
|
||||
uint64_t(bswap_64)(uint64_t x) {
|
||||
return (0x00000000000000ffull & x) << 070 |
|
||||
(0x000000000000ff00ull & x) << 050 |
|
||||
(0x0000000000ff0000ull & x) << 030 |
|
||||
(0x00000000ff000000ull & x) << 010 |
|
||||
(0x000000ff00000000ull & x) >> 010 |
|
||||
(0x0000ff0000000000ull & x) >> 030 |
|
||||
(0x00ff000000000000ull & x) >> 050 |
|
||||
(0xff00000000000000ull & x) >> 070;
|
||||
}
|
|
@ -5,7 +5,7 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
uint16_t bswap_16(uint16_t) pureconst;
|
||||
uint32_t bswap_32(uint32_t) pureconst;
|
||||
uint32_t bswap_64(uint32_t) pureconst;
|
||||
uint64_t bswap_64(uint64_t) pureconst;
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#define bswap_16(x) __builtin_bswap16(x)
|
||||
|
|
|
@ -165,3 +165,5 @@ void bzero(void *p, size_t n) {
|
|||
bzero128(b, n);
|
||||
}
|
||||
}
|
||||
|
||||
__weak_reference(bzero, explicit_bzero);
|
||||
|
|
|
@ -91,3 +91,5 @@ wontreturn void _Exit(int exitcode) {
|
|||
unreachable;
|
||||
#endif
|
||||
}
|
||||
|
||||
__strong_reference(_Exit, _exit);
|
||||
|
|
|
@ -39,7 +39,9 @@
|
|||
// - `FE_INEXACT`
|
||||
// - `FE_ALL_EXCEPT` (all of the above)
|
||||
// @return 0 on success, or nonzero on error
|
||||
.ftrace1
|
||||
feclearexcept:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
// maintain exceptions in the sse mxcsr, clear x87 exceptions
|
||||
mov %edi,%ecx
|
||||
|
@ -79,6 +81,7 @@ feclearexcept:
|
|||
// volatile double x = 0, y = 1 / x;
|
||||
// assert(fetestexcept(FE_ALL_EXCEPT) == FE_DIVBYZERO);
|
||||
//
|
||||
.ftrace1
|
||||
// @param excepts may bitwise-or the following:
|
||||
// - `FE_INVALID`
|
||||
// - `FE_DIVBYZERO`
|
||||
|
@ -88,7 +91,9 @@ feclearexcept:
|
|||
// - `FE_ALL_EXCEPT` (all of the above)
|
||||
// @return mask of which exception status codes are currently set,
|
||||
// or zero if there aren't any floating point exceptions
|
||||
.ftrace1
|
||||
fetestexcept:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
and $0x3f,%edi
|
||||
push %rax
|
||||
|
@ -106,7 +111,9 @@ fetestexcept:
|
|||
#endif
|
||||
.endfn fetestexcept,globl
|
||||
|
||||
.ftrace1
|
||||
feraiseexcept:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
and $0x3f,%edi
|
||||
stmxcsr -8(%rsp)
|
||||
|
@ -124,7 +131,9 @@ feraiseexcept:
|
|||
#endif
|
||||
.endfn feraiseexcept,globl
|
||||
|
||||
.ftrace1
|
||||
__fesetround:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rax
|
||||
xor %eax,%eax
|
||||
|
@ -150,7 +159,9 @@ __fesetround:
|
|||
#endif
|
||||
.endfn __fesetround,globl,hidden
|
||||
|
||||
.ftrace1
|
||||
fegetround:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rax
|
||||
stmxcsr (%rsp)
|
||||
|
@ -165,7 +176,9 @@ fegetround:
|
|||
#endif
|
||||
.endfn fegetround,globl
|
||||
|
||||
.ftrace1
|
||||
fegetenv:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
xor %eax,%eax
|
||||
fnstenv (%rdi)
|
||||
|
@ -180,7 +193,9 @@ fegetenv:
|
|||
#endif
|
||||
.endfn fegetenv,globl
|
||||
|
||||
.ftrace1
|
||||
fesetenv:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
xor %eax,%eax
|
||||
inc %rdi
|
||||
|
|
|
@ -31,9 +31,4 @@ long ffsl(long x) {
|
|||
return __builtin_ffsl(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds lowest set bit in word.
|
||||
*/
|
||||
long long ffsll(long long x) {
|
||||
return __builtin_ffsll(x);
|
||||
}
|
||||
__weak_reference(ffsl, ffsll);
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/popcnt.h"
|
||||
|
||||
/**
|
||||
* Counts number of different bits.
|
||||
* @see https://en.wikipedia.org/wiki/Hamming_code
|
||||
*/
|
||||
unsigned long _hamming(unsigned long x, unsigned long y) {
|
||||
return popcnt(x ^ y);
|
||||
}
|
|
@ -2,10 +2,14 @@
|
|||
#define COSMOPOLITAN_LIBC_BITS_HILBERT_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#ifdef COSMO
|
||||
#define hilbert __hilbert
|
||||
#define unhilbert __unhilbert
|
||||
|
||||
long hilbert(long, long, long) pureconst;
|
||||
axdx_t unhilbert(long, long) pureconst;
|
||||
|
||||
#endif /* COSMO */
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_HILBERT_H_ */
|
||||
|
|
|
@ -1,8 +1,22 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
|
||||
#ifdef COSMO
|
||||
|
||||
#define kprintf __kprintf
|
||||
#define ksnprintf __ksnprintf
|
||||
#define kvprintf __kvprintf
|
||||
#define kvsnprintf __kvsnprintf
|
||||
#define kisdangerous __kisdangerous
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
void kprintf(const char *, ...);
|
||||
size_t ksnprintf(char *, size_t, const char *, ...);
|
||||
void kvprintf(const char *, va_list);
|
||||
size_t kvsnprintf(char *, size_t, const char *, va_list);
|
||||
bool kisdangerous(const void *);
|
||||
|
||||
void kprintf(const char *, ...);
|
||||
size_t ksnprintf(char *, size_t, const char *, ...);
|
||||
void kvprintf(const char *, va_list);
|
||||
|
@ -12,4 +26,5 @@ void _klog(const char *, size_t);
|
|||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMO */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_ */
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_LIKELY_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifdef COSMO
|
||||
|
||||
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
|
@ -17,5 +18,6 @@
|
|||
#define VERY_UNLIKELY(x) UNLIKELY(x)
|
||||
#endif
|
||||
|
||||
#endif /* COSMO */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_LIKELY_H_ */
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_LOCKXADD_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_LOCKXADD_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
intptr_t _lockxadd(void *, intptr_t, size_t);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
|
||||
#define _lockxadd(PTR, VAL) \
|
||||
({ \
|
||||
typeof(*(PTR)) Res; \
|
||||
typeof(Res) Val = (VAL); \
|
||||
asm volatile("lock xadd\t%0,%1" : "=r"(Res), "+m"(*(PTR)) : "0"(Val)); \
|
||||
Res; /* contains *PTR before addition cf. InterlockedAdd() */ \
|
||||
})
|
||||
#else
|
||||
#define _lockxadd(MEM, VAL) _lockxadd(MEM, (intptr_t)(VAL), sizeof(*(MEM)))
|
||||
#endif /* GNUC && !ANSI && x86 */
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_LOCKXADD_H_ */
|
|
@ -342,6 +342,6 @@ void *memmove(void *dst, const void *src, size_t n) {
|
|||
}
|
||||
}
|
||||
|
||||
__strong_reference(memmove, memcpy);
|
||||
__weak_reference(memmove, memcpy);
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
* @see https://en.wikipedia.org/wiki/Z-order_curve
|
||||
* @see unmorton()
|
||||
*/
|
||||
unsigned long(morton)(unsigned long y, unsigned long x) {
|
||||
unsigned long morton(unsigned long y, unsigned long x) {
|
||||
x = (x | x << 020) & 0x0000FFFF0000FFFF;
|
||||
x = (x | x << 010) & 0x00FF00FF00FF00FF;
|
||||
x = (x | x << 004) & 0x0F0F0F0F0F0F0F0F;
|
||||
|
|
|
@ -1,24 +1,16 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_MORTON_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_MORTON_H_
|
||||
#include "libc/intrin/pdep.h"
|
||||
#include "libc/intrin/pext.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#ifdef COSMO
|
||||
|
||||
#define morton __morton
|
||||
#define unmorton __unmorton
|
||||
|
||||
unsigned long morton(unsigned long, unsigned long) libcesque;
|
||||
axdx_t unmorton(unsigned long) libcesque;
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#define morton(Y, X) \
|
||||
(X86_NEED(BMI2) ? pdep(X, 0x5555555555555555) | pdep(Y, 0xAAAAAAAAAAAAAAAA) \
|
||||
: morton(Y, X))
|
||||
#define unmorton(I) \
|
||||
(X86_NEED(BMI2) \
|
||||
? (axdx_t){pext(I, 0xAAAAAAAAAAAAAAAA), pext(I, 0x5555555555555555)} \
|
||||
: unmorton(I))
|
||||
#endif
|
||||
|
||||
#endif /* COSMO */
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_MORTON_H_ */
|
||||
|
|
|
@ -2,11 +2,6 @@
|
|||
#define COSMOPOLITAN_LIBC_BITS_NEWBIE_H_
|
||||
#include "libc/intrin/bswap.h"
|
||||
|
||||
/*
|
||||
* Macros for newbies.
|
||||
* https://justine.lol/endian.html
|
||||
*/
|
||||
|
||||
#define BYTE_ORDER __BYTE_ORDER__
|
||||
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
|
||||
#define BIG_ENDIAN __ORDER_BIG_ENDIAN__
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define COSMOPOLITAN_LIBC_BITS_PUSHPOP_H_
|
||||
#include "libc/macros.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifdef COSMO
|
||||
|
||||
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__)
|
||||
#define pushpop(x) (x)
|
||||
|
@ -51,5 +52,6 @@
|
|||
})
|
||||
#endif
|
||||
|
||||
#endif /* COSMO */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_PUSHPOP_H_ */
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifdef COSMO
|
||||
|
||||
forceinline void repmovsb(void **dest, const void **src, size_t cx) {
|
||||
char *di = (char *)*dest;
|
||||
|
@ -22,5 +23,6 @@ forceinline void repmovsb(void **dest, const void **src, size_t cx) {
|
|||
})
|
||||
#endif
|
||||
|
||||
#endif /* COSMO */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_ */
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifdef COSMO
|
||||
|
||||
forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
|
||||
unsigned char *di = (unsigned char *)dest;
|
||||
|
@ -21,5 +22,6 @@ forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
|
|||
})
|
||||
#endif
|
||||
|
||||
#endif /* COSMO */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_ */
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#ifdef COSMO
|
||||
|
||||
/**
|
||||
* Reads scalar from memory, offset by segment.
|
||||
|
@ -20,6 +21,7 @@
|
|||
Pk; \
|
||||
})
|
||||
|
||||
#endif /* COSMO */
|
||||
#endif /* __GNUC__ && !__STRICT_ANSI__ */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ */
|
||||
|
|
|
@ -117,4 +117,6 @@ char *strchr(const char *s, int c) {
|
|||
#endif
|
||||
}
|
||||
|
||||
__strong_reference(strchr, index);
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
|
|
|
@ -31,4 +31,6 @@ char *strrchr(const char *s, int c) {
|
|||
return memrchr(s, c, strlen(s));
|
||||
}
|
||||
|
||||
__strong_reference(strrchr, rindex);
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
|
||||
// Invokes SYSCALL for libfatal forceinline asm() routines.
|
||||
//
|
||||
// @param rax is ordinal
|
||||
// @param rdi is arg1
|
||||
// @param rsi is arg2
|
||||
// @param rdx is arg3
|
||||
// @param rcx is arg4
|
||||
// @param r8 is arg5
|
||||
// @param r9 is arg6
|
||||
// @param rsp may contain more args
|
||||
// @return rdx:rax where rax holds -errno on error
|
||||
// @clob rax,rdx,memory,cc
|
||||
__syscall__:
|
||||
mov %rcx,.Lrcx(%rip)
|
||||
mov %rdi,.Lrdi(%rip)
|
||||
mov %rsi,.Lrsi(%rip)
|
||||
mov %r8,.Lr8(%rip)
|
||||
mov %r9,.Lr9(%rip)
|
||||
mov %r10,.Lr10(%rip)
|
||||
mov %r11,.Lr11(%rip)
|
||||
mov %rcx,%r10
|
||||
clc
|
||||
syscall
|
||||
jnc 1f
|
||||
neg %rax
|
||||
1: mov .Lrcx(%rip),%rcx
|
||||
mov .Lrdi(%rip),%rdi
|
||||
mov .Lrsi(%rip),%rsi
|
||||
mov .Lr8(%rip),%r8
|
||||
mov .Lr9(%rip),%r9
|
||||
mov .Lr10(%rip),%r10
|
||||
mov .Lr11(%rip),%r11
|
||||
ret
|
||||
.endfn __syscall__,globl,hidden
|
||||
|
||||
.bss
|
||||
.balign 8
|
||||
.Lrcx: .quad 0 // clobbered by syscall
|
||||
.Lrdi: .quad 0 // just in case
|
||||
.Lrsi: .quad 0 // just in case
|
||||
.Lr8: .quad 0 // freebsd bug?
|
||||
.Lr9: .quad 0 // just in case
|
||||
.Lr10: .quad 0 // just in case
|
||||
.Lr11: .quad 0 // clobbered by syscall
|
|
@ -1,33 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/bits.h"
|
||||
|
||||
/**
|
||||
* Decodes gray code.
|
||||
* @see https://en.wikipedia.org/wiki/Gray_code
|
||||
* @see gray()
|
||||
*/
|
||||
uint32_t ungray(uint32_t x) {
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
x ^= x >> 4;
|
||||
x ^= x >> 2;
|
||||
x ^= x >> 1;
|
||||
return x;
|
||||
}
|
|
@ -36,6 +36,6 @@ static unsigned long GetOddBits(unsigned long x) {
|
|||
* @see en.wikipedia.org/wiki/Z-order_curve
|
||||
* @see morton()
|
||||
*/
|
||||
axdx_t(unmorton)(unsigned long i) {
|
||||
axdx_t unmorton(unsigned long i) {
|
||||
return (axdx_t){GetOddBits(i >> 1), GetOddBits(i)};
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_XADD_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_XADD_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define _xadd(p, v) \
|
||||
({ \
|
||||
typeof(*(p)) Res; \
|
||||
autotype(Res) Val = (v); \
|
||||
asm volatile("xadd\t%0,%1" : "=r"(Res), "+m"(*(p)) : "0"(Val)); \
|
||||
Res + Val; \
|
||||
})
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_XADD_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue