mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-29 05:50:27 +00:00
Brush up some more code
This commit is contained in:
parent
ee6566a152
commit
a2d269dc38
32 changed files with 251 additions and 335 deletions
|
@ -743,7 +743,7 @@ static void __asan_report_memory_origin_image(intptr_t a, int z) {
|
|||
r = n = st->count;
|
||||
k = a - st->addr_base;
|
||||
while (l < r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (st->symbols[m].y < k) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/midpoint.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
|
||||
noasan unsigned FindMemoryInterval(const struct MemoryIntervals *mm, int x) {
|
||||
|
@ -25,7 +24,7 @@ noasan unsigned FindMemoryInterval(const struct MemoryIntervals *mm, int x) {
|
|||
l = 0;
|
||||
r = mm->i;
|
||||
while (l < r) {
|
||||
m = _midpoint(l, r);
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (mm->p[m].y < x) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
|
|
|
@ -161,7 +161,7 @@ privileged static bool kismapped(int x) {
|
|||
if (kismemtrackhosed()) return false;
|
||||
r = _weaken(_mmi)->i;
|
||||
while (l < r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (_weaken(_mmi)->p[m].y < x) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_MIDPOINT_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_MIDPOINT_H_
|
||||
#include "libc/assert.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
|
||||
/**
|
||||
* Computes `(a + b) / 2` assuming unsigned.
|
||||
*
|
||||
* This implementation is the fastest on AMD Zen architecture.
|
||||
*/
|
||||
#define _midpoint(a, b) \
|
||||
({ \
|
||||
typeof((a) + (b)) a_ = (a); \
|
||||
typeof(a_) b_ = (b); \
|
||||
_unassert(a_ >= 0); \
|
||||
_unassert(b_ >= 0); \
|
||||
asm("add\t%1,%0\n\t" \
|
||||
"rcr\t%0" \
|
||||
: "+r"(a_) \
|
||||
: "r"(b_)); \
|
||||
a_; \
|
||||
})
|
||||
#else
|
||||
/**
|
||||
* Computes `(a + b) / 2` assuming unsigned.
|
||||
*/
|
||||
#define _midpoint(a, b) (((a) & (b)) + ((a) ^ (b)) / 2)
|
||||
#endif /* __GNUC__ && !__STRICT_ANSI__ && x86 */
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_MIDPOINT_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue