Make numerous improvements

- Python static hello world now 1.8mb
- Python static fully loaded now 10mb
- Python HTTPS client now uses MbedTLS
- Python REPL now completes import stmts
- Increase stack size for Python for now
- Begin synthesizing posixpath and ntpath
- Restore Python \N{UNICODE NAME} support
- Restore Python NFKD symbol normalization
- Add optimized code path for Intel SHA-NI
- Get more Python unit tests passing faster
- Get Python help() pagination working on NT
- Python hashlib now supports MbedTLS PBKDF2
- Make memcpy/memmove/memcmp/bcmp/etc. faster
- Add Mersenne Twister and Vigna to LIBC_RAND
- Provide privileged __printf() for error code
- Fix zipos opendir() so that it reports ENOTDIR
- Add basic chmod() implementation for Windows NT
- Add Cosmo's best functions to Python cosmo module
- Pin function trace indent depth to that of caller
- Show memory diagram on invalid access in MODE=dbg
- Differentiate stack overflow on crash in MODE=dbg
- Add stb_truetype and tools for analyzing font files
- Upgrade to UNICODE 13 and reduce its binary footprint
- COMPILE.COM now logs resource usage of build commands
- Start implementing basic poll() support on bare metal
- Set getauxval(AT_EXECFN) to GetModuleFileName() on NT
- Add descriptions to strerror() in non-TINY build modes
- Add COUNTBRANCH() macro to help with micro-optimizations
- Make error / backtrace / asan / memory code more unbreakable
- Add fast perfect C implementation of μ-Law and a-Law audio codecs
- Make strtol() functions consistent with other libc implementations
- Improve Linenoise implementation (see also github.com/jart/bestline)
- COMPILE.COM now suppresses stdout/stderr of successful build commands
This commit is contained in:
Justine Tunney 2021-09-27 22:58:51 -07:00
parent fa7b4f5bd1
commit 39bf41f4eb
806 changed files with 77494 additions and 63859 deletions

View file

@ -16,40 +16,75 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/intrin/asan.internal.h"
#include "libc/rand/rand.h"
#include "libc/rand/xorshift.h"
#include "libc/str/str.h"
#include "libc/stdio/stdio.h"
/**
* Fills memory with random bytes, e.g.
*
* char buf[1024];
* rngset(buf, sizeof(buf), rand64, -1);
* char buf[512];
* rngset(buf, sizeof(buf), 0, 0);
*
* If reseed is zero then the internal PRNG is disabled and bytes are
* simply copied in little-endian order from the seed function. If seed
* is NULL then the reseed parameter is used as the seed value for the
* internal PRNG. If seed!=NULL and reseed>8 then reseed is the number
* of bytes after which the seed() function should be called again, to
* freshen up the PRNG.
*
* The main advantage of this generator is that it produces data at 13
* gigabytes per second since Vigna's Algorithm vectorizes better than
* alternatives, going even faster than xorshift.
*
* @param seed can be rand64() and is always called at least once
* @param reseed is bytes between seed() calls and -1 disables it
* @return original buf
*/
void *rngset(void *buf, size_t size, uint64_t seed(void), size_t reseed) {
unsigned char *p;
uint64_t i, x, state;
p = buf;
state = seed();
for (i = 0; size - i >= sizeof(x); i += sizeof(x)) {
x = MarsagliaXorshift64(&state);
memcpy(p + i, &x, sizeof(x));
if (i >= reseed) {
state = seed();
p += i;
size -= i;
i = 0;
void *rngset(void *b, size_t n, uint64_t seed(void), size_t reseed) {
size_t m;
uint64_t i, x, t = 0;
unsigned char *p = b;
if (!seed) {
t = reseed;
reseed = -1;
} else if (reseed < 8) {
reseed = 8;
}
while (n) {
if (seed) t = seed();
if (!seed || reseed > 8) {
n -= (m = reseed < n ? reseed : n);
while (m >= 8) {
x = (t += 0x9e3779b97f4a7c15);
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
x = (x ^ (x >> 31));
__builtin_memcpy(p, &x, 8);
p += 8;
m -= 8;
}
while (m--) {
*p++ = t;
t >>= 8;
}
} else if (n >= 8) {
p[0] = (0x00000000000000FF & t) >> 000;
p[1] = (0x000000000000FF00 & t) >> 010;
p[2] = (0x0000000000FF0000 & t) >> 020;
p[3] = (0x00000000FF000000 & t) >> 030;
p[4] = (0x000000FF00000000 & t) >> 040;
p[5] = (0x0000FF0000000000 & t) >> 050;
p[6] = (0x00FF000000000000 & t) >> 060;
p[7] = (0xFF00000000000000 & t) >> 070;
p += 8;
n -= 8;
} else {
while (n) {
*p++ = t;
t >>= 8;
--n;
}
}
}
if (i < size) {
x = MarsagliaXorshift64(&state);
for (; i < size; ++i, x >>= 8) {
p[i] = x & 0xff;
}
}
return buf;
return b;
}