summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-12-31 09:39:48 +0100
committerTyge Løvset <[email protected]>2020-12-31 09:39:48 +0100
commit5c86a9ec884598c1ceb6f4b564248de99d6e05d7 (patch)
treef448a2d9c00660b76bdbf9aebb29a55cf61b8c94
parent3a01dac7e392da596c007cd69d089865daf4c50c (diff)
downloadSTC-modified-5c86a9ec884598c1ceb6f4b564248de99d6e05d7.tar.gz
STC-modified-5c86a9ec884598c1ceb6f4b564248de99d6e05d7.zip
Some minor touches.
-rw-r--r--README.md4
-rw-r--r--benchmarks/crand_benchmark.cpp6
-rw-r--r--docs/cdeq_api.md4
-rw-r--r--stc/crand.h18
4 files changed, 14 insertions, 18 deletions
diff --git a/README.md b/README.md
index 61c814fb..e6dc7a34 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-STC - Standard Template library for C
-=====================================
+STC - Standard Template Containers for C99
+==========================================
Introduction
------------
diff --git a/benchmarks/crand_benchmark.cpp b/benchmarks/crand_benchmark.cpp
index 70a3bb45..3d42c62b 100644
--- a/benchmarks/crand_benchmark.cpp
+++ b/benchmarks/crand_benchmark.cpp
@@ -84,7 +84,7 @@ using namespace std;
int main(void)
{
- enum {N = 1000000000};
+ enum {N = 800000000};
uint64_t* recipient = new uint64_t[N];
static stc64_t rng;
init_state(rng.state, 12345123);
@@ -115,7 +115,7 @@ int main(void)
for (size_t i = 0; i < N; i++)
recipient[i] = stc64_rand(&rng);
end = clock();
- cout << "stc-crand:\t"
+ cout << "stc64:\t\t"
<< (float(end - beg) / CLOCKS_PER_SEC)
<< " s: " << recipient[312] << endl;
@@ -160,7 +160,7 @@ int main(void)
for (size_t i = 0; i < N; i++)
s += stc64_rand(&rng);
end = clock();
- cout << "stc-crand:\t"
+ cout << "stc64:\t\t"
<< ((float) end - beg) / CLOCKS_PER_SEC
<< " s: " << s << endl;
diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md
index 9f72406f..259d02b1 100644
--- a/docs/cdeq_api.md
+++ b/docs/cdeq_api.md
@@ -37,10 +37,6 @@ using_cdeq(str, cstr_t, cstr_del, cstr_compare_raw, const char*, cstr_to_raw, cs
| Name | Purpose |
|:---------------------------|:---------------------|
| `cdeq_inits` | Initializer constant |
-| `cdeq_empty(vec)` | true if vec is empty |
-| `cdeq_size(vec)` | return vec length |
-| `cdeq_capacity(vec)` | return vec capacity |
-
## Header file
diff --git a/stc/crand.h b/stc/crand.h
index d58c0681..3d010eb2 100644
--- a/stc/crand.h
+++ b/stc/crand.h
@@ -49,29 +49,28 @@ typedef struct {double lower, range;} stc64_uniformf_t;
typedef struct {double mean, stddev, next; bool has_next;} stc64_normalf_t;
-/* int random number generator, range [0, 2^64). PRNG copyright Tyge Løvset, NORCE Research, 2020 */
+/* Stc64: random number generator, range [0, 2^64). PRNG copyright Tyge Løvset, NORCE Research, 2020 */
STC_API stc64_t stc64_init(uint64_t seed);
STC_API stc64_t stc64_with_seq(uint64_t seed, uint64_t seq);
STC_INLINE uint64_t stc64_rand(stc64_t* rng) {
- enum {LROT = 24, RSHIFT = 11, LSHIFT = 3};
uint64_t *s = rng->state;
const uint64_t b = s[1], result = s[0] ^ (s[2] += s[3]|1);
- s[0] = (b + (b << LSHIFT)) ^ (b >> RSHIFT);
- s[1] = ((b << LROT) | (b >> (64 - LROT))) + result;
+ s[0] = (b + (b << 3)) ^ (b >> 11);
+ s[1] = ((b << 24) | (b >> (64 - 24))) + result;
return result;
}
-/* double random number in range [low, high). */
+/* Float64 random number in range [low, high). */
STC_INLINE double stc64_randf(stc64_t* rng) {
union {uint64_t i; double f;} u = {0x3FF0000000000000ull | (stc64_rand(rng) >> 12)};
return u.f - 1.0;
}
-/* integer uniform distributed RNG, range [low, high]. */
+/* Int64 uniform distributed RNG, range [low, high]. */
STC_API stc64_uniform_t stc64_uniform_init(int64_t low, int64_t high);
-/* double uniform distributed RNG, range [low, high). */
+/* Float64 uniform distributed RNG, range [low, high). */
STC_INLINE stc64_uniformf_t stc64_uniformf_init(double low, double high) {
stc64_uniformf_t dist = {low, high - low}; return dist;
}
@@ -92,13 +91,14 @@ STC_INLINE double stc64_uniformf(stc64_t* rng, stc64_uniformf_t* dist) {
: [lhs] "0" (a), [rhs] "rm" (b))
#endif
+/* Unbiased bounded uniform distribution. */
STC_INLINE int64_t stc64_uniform(stc64_t* rng, stc64_uniform_t* d) {
uint64_t lo, hi;
do { cmul128(stc64_rand(rng), d->range, &lo, &hi); } while (lo < d->threshold);
return d->lower + hi;
}
-/* double normal distributed RNG. */
+/* Normal distributed RNG, Float64. */
STC_INLINE stc64_normalf_t stc64_normalf_init(double mean, double stddev) {
stc64_normalf_t dist = {mean, stddev, 0.0, false}; return dist;
}
@@ -109,7 +109,7 @@ STC_API double stc64_normalf(stc64_t* rng, stc64_normalf_t* dist);
/* PRNG crand: by Tyge Løvset, NORCE Research, 2020.
* Extremely fast PRNG suited for parallel usage with Weyl-sequence parameter.
- * Faster than sfc64, wyhash64, and almost 50% faster than xoshiro256** on gcc.
+ * Faster than sfc64, wyhash64, and xoshiro256** on most platforms.
* 256bit state, updates only 192bit per rng.
* 2^63 unique threads with a minimum 2^64 period lengths each.
* 2^127 minimum period length for single thread (double loop).