Improve documentation

The Cosmo API documentation page is pretty good now
https://justine.lol/cosmopolitan/documentation.html
This commit is contained in:
Justine Tunney 2020-12-27 07:02:35 -08:00
parent 13437dd19b
commit 1bc3a25505
367 changed files with 2542 additions and 26178 deletions

View file

@ -19,6 +19,23 @@
*/
#include "libc/nexgen32e/bsf.h"
/**
* 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 x is a 32-bit integer
* @return number in range 0..31 or undefined if 𝑥 is 0
*/
int(bsf)(int x) {
return bsf(x);
}

View file

@ -19,6 +19,23 @@
*/
#include "libc/nexgen32e/bsf.h"
/**
* 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(bsfl)(long x) {
return bsfl(x);
}

View file

@ -19,6 +19,23 @@
*/
#include "libc/nexgen32e/bsf.h"
/**
* 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);
}

View file

@ -19,6 +19,23 @@
*/
#include "libc/nexgen32e/bsr.h"
/**
* 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 32-bit integer
* @return number in range 0..31 or undefined if 𝑥 is 0
*/
int(bsr)(int x) {
return bsr(x);
}

View file

@ -19,6 +19,23 @@
*/
#include "libc/nexgen32e/bsr.h"
/**
* 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(bsrl)(long x) {
return bsrl(x);
}

View file

@ -19,6 +19,23 @@
*/
#include "libc/nexgen32e/bsr.h"
/**
* 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);
}

View file

@ -21,20 +21,19 @@
/ Returns binary logarithm of integer 𝑥.
/
/ 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 rsi:rdi is 128-bit unsigned 𝑥 value
/ @return eax number in range [0,128) or undef if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
/
/ 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
/
bsrmax: .leafprologue
.profilable
bsr %rsi,%rax

View file

@ -19,11 +19,12 @@
*/
#include "libc/nexgen32e/crc32.h"
extern const uint32_t kCrc32cTab[256];
/**
* Computes Castagnoli CRC-32 on old computers.
*/
uint32_t crc32c$pure(uint32_t init, const void *data, size_t size) {
extern const uint32_t kCrc32cTab[256];
const unsigned char *p = data;
uint32_t h = init ^ 0xffffffff;
unsigned i;

View file

@ -21,16 +21,16 @@
/ Generates lookup table for computing CRC-32 byte-by-byte.
/
/ void crc32init(uint32_t table[256], uint32_t polynomial) {
/ uint32_t d, i, r;
/ for (d = 0; d < 256; ++d) {
/ r = d;
/ for (i = 0; i < 8; ++i) {
/ r = r >> 1 ^ (r & 1 ? polynomial : 0);
/ void crc32init(uint32_t table[256], uint32_t polynomial) {
/ uint32_t d, i, r;
/ for (d = 0; d < 256; ++d) {
/ r = d;
/ for (i = 0; i < 8; ++i) {
/ r = r >> 1 ^ (r & 1 ? polynomial : 0);
/ }
/ table[d] = r;
/ }
/ table[d] = r;
/ }
/ }
/
/ @param rdi is pointer to uint32_t[256] array
/ @param esi 32-bit binary polynomial config

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/safemacros.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/x86feature.h"

View file

@ -21,10 +21,6 @@
/ Finds lowest set bit in word.
/
/ @param edi is the input number
/ @return number in range [1,32] or 0 if no bits set
/ @see also treasure trove of nearly identical functions
/
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
/ 0x00000000 wut 32 0 wut 32
/ 0x00000001 0 0 1 0 31
@ -35,6 +31,9 @@
/ 0x08000000 27 27 28 27 4
/ 0xffffffff 0 0 1 31 0
/
/ @param edi is the input number
/ @return number in range [1,32] or 0 if no bits set
/ @see also treasure trove of nearly identical functions
/ @asyncsignalsafe
ffs: .leafprologue
.profilable

View file

@ -21,10 +21,6 @@
/ Finds lowest set bit in word.
/
/ @param rdi is the input number
/ @return number in range [1,64] or 0 if no bits set
/ @see also treasure trove of nearly identical functions
/
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
/ 0x00000000 wut 32 0 wut 32
/ 0x00000001 0 0 1 0 31
@ -35,6 +31,9 @@
/ 0x08000000 27 27 28 27 4
/ 0xffffffff 0 0 1 31 0
/
/ @param rdi is the input number
/ @return number in range [1,64] or 0 if no bits set
/ @see also treasure trove of nearly identical functions
/ @asyncsignalsafe
ffsl: .leafprologue
.profilable

View file

@ -24,38 +24,38 @@
/ ibm cp437 unicode table w/ string literal safety
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/ THERE WILL BE BLOCKS march 01 2017
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/ THERE WILL BE BLOCKS march 01 2017
/
/ @see libc/str/str.h
/ @see kCp437i[]

View file

@ -20,8 +20,6 @@
#include "libc/macros.h"
/ Signal mask constant w/ no signal bits set.
/
/ @see kSigsetFull,sigemptyset(),sigprocmask(),sigaction()
.initbss 300,_init_kSigsetEmpty
kSigsetEmpty:
.rept NSIG / 64

View file

@ -20,8 +20,6 @@
#include "libc/macros.h"
/ Signal mask constant w/ every signal bit set.
/
/ @see kSigsetEmpty,sigemptyset(),sigprocmask(),sigaction()
.initbss 300,_init_kSigsetFull
kSigsetFull:
.rept NSIG / 64

View file

@ -20,7 +20,9 @@
#include "libc/macros.h"
/ Stores CPU Timestamp Counter at startup.
/
/ It can be useful as an added source of seeding information.
/
/ @note rdtsc is a 25 cycle instruction
.initbss 200,_init_kStartTsc
kStartTsc:

View file

@ -21,10 +21,6 @@
/ Finds leading bits in 𝑥.
/
/ @param edi is 32-bit unsigned 𝑥 value
/ @return eax number in range [0,32) or 32 if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
/
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
/ 0x00000000 wut 32 0 wut 32
/ 0x00000001 0 0 1 0 31
@ -35,6 +31,9 @@
/ 0x08000000 27 27 28 27 4
/ 0xffffffff 0 0 1 31 0
/
/ @param edi is 32-bit unsigned 𝑥 value
/ @return eax number in range [0,32) or 32 if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
lzcnt: .leafprologue
.profilable
mov $31,%eax

View file

@ -21,10 +21,6 @@
/ Finds leading bits in 𝑥.
/
/ @param rdi is 64-bit unsigned 𝑥 value
/ @return rax number in range [0,64) or 64 if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
/
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
/ 0x00000000 wut 32 0 wut 32
/ 0x00000001 0 0 1 0 31
@ -35,6 +31,9 @@
/ 0x08000000 27 27 28 27 4
/ 0xffffffff 0 0 1 31 0
/
/ @param rdi is 64-bit unsigned 𝑥 value
/ @return rax number in range [0,64) or 64 if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
lzcntl: .leafprologue
.profilable
mov $31,%eax

View file

@ -21,12 +21,7 @@
#include "libc/nexgen32e/pcmpstr.inc"
#include "libc/nexgen32e/strstr.inc"
/ Searches for substring.
/
/ @param rdi is NUL-terminated haystack string
/ @param rsi is NUL-terminated needle string (16-byte aligned)
/ @return rax is pointer to substring or NULL
/ @asyncsignalsafe
/ TODO(jart): Fix me.
strstr$sse42:
.leafprologue
mov %rdi,%rax

View file

@ -21,12 +21,7 @@
#include "libc/nexgen32e/pcmpstr.inc"
#include "libc/nexgen32e/strstr.inc"
/ Searches for substring w/ char16_t.
/
/ @param rdi is NUL-terminated haystack string
/ @param rsi is NUL-terminated needle string (16-byte aligned)
/ @return rax is pointer to substring or NULL
/ @asyncsignalsafe
/ TODO(jart): Fix me.
strstr16$sse42:
.strstr .Lequalorder16
.endfn strstr16$sse42,globl,hidden

View file

@ -22,10 +22,6 @@
/ Finds lowest set bit in 𝑥.
/
/ @param edi is 32-bit unsigned 𝑥 value
/ @return eax number in range [0,32) or 32 if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
/
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
/ 0x00000000 wut 32 0 wut 32
/ 0x00000001 0 0 1 0 31
@ -36,6 +32,9 @@
/ 0x08000000 27 27 28 27 4
/ 0xffffffff 0 0 1 31 0
/
/ @param edi is 32-bit unsigned 𝑥 value
/ @return eax number in range [0,32) or 32 if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
tzcnt: .leafprologue
.profilable
mov $32,%esi

View file

@ -21,10 +21,6 @@
/ Finds lowest set bit in 𝑥.
/
/ @param rdi is 64-bit unsigned 𝑥 value
/ @return rax number in range [0,64) or 64 if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
/
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
/ 0x00000000 wut 32 0 wut 32
/ 0x00000001 0 0 1 0 31
@ -35,6 +31,9 @@
/ 0x08000000 27 27 28 27 4
/ 0xffffffff 0 0 1 31 0
/
/ @param rdi is 64-bit unsigned 𝑥 value
/ @return rax number in range [0,64) or 64 if 𝑥 is 0
/ @see also treasure trove of nearly identical functions
tzcntl: .leafprologue
.profilable
mov $64,%esi