mirror of https://github.com/inolen/redream.git
fixed overflows in bad comparison predicates
This commit is contained in:
parent
5ec4735c4a
commit
7ec14faed9
|
@ -68,13 +68,17 @@ static int interval_tree_cmp(const struct rb_node *rb_lhs,
|
|||
struct interval_node *lhs = rb_entry(rb_lhs, struct interval_node, base);
|
||||
struct interval_node *rhs = rb_entry(rb_rhs, struct interval_node, base);
|
||||
|
||||
int cmp = (int)(lhs->low - rhs->low);
|
||||
|
||||
if (!cmp) {
|
||||
cmp = (int)(lhs->high - rhs->high);
|
||||
if (lhs->low < rhs->low) {
|
||||
return -1;
|
||||
} else if (lhs->low > rhs->low) {
|
||||
return 1;
|
||||
} else if (lhs->high < rhs->high) {
|
||||
return -1;
|
||||
} else if (lhs->high > rhs->high) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return cmp;
|
||||
}
|
||||
|
||||
static int interval_tree_intersects(const struct interval_node *n,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "core/list.h"
|
||||
#include "core/assert.h"
|
||||
|
||||
int list_empty(struct list *list) {
|
||||
return !list->head;
|
||||
|
@ -65,7 +64,7 @@ void list_sort(struct list *list, list_node_cmp cmp) {
|
|||
struct list_node *tail = NULL;
|
||||
int k = 1;
|
||||
|
||||
while (true) {
|
||||
while (1) {
|
||||
int merges = 0;
|
||||
struct list_node *p = head;
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
#define align_down(v, alignment) (v & ~(alignment - 1))
|
||||
|
||||
#if PLATFORM_LINUX || PLATFORM_DARWIN
|
||||
|
||||
static inline int popcnt32(uint32_t v) {
|
||||
return __builtin_popcount(v);
|
||||
}
|
||||
static inline int clz32(uint32_t v) {
|
||||
return __builtin_clz(v);
|
||||
}
|
||||
|
@ -23,7 +27,14 @@ static inline int ctz32(uint32_t v) {
|
|||
static inline int ctz64(uint64_t v) {
|
||||
return __builtin_ctzll(v);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
static inline int popcnt32(uint32_t v) {
|
||||
return __popcnt(v);
|
||||
}
|
||||
static inline int clz32(uint32_t v) {
|
||||
unsigned long r = 0;
|
||||
_BitScanReverse(&r, v);
|
||||
|
@ -44,6 +55,7 @@ static inline int ctz64(uint64_t v) {
|
|||
_BitScanForward64(&r, v);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -100,10 +100,19 @@ static int tracer_texture_cmp(const struct rb_node *rb_lhs,
|
|||
const struct rb_node *rb_rhs) {
|
||||
const struct tracer_texture_entry *lhs =
|
||||
rb_entry(rb_lhs, const struct tracer_texture_entry, live_it);
|
||||
texture_key_t lhs_key = tr_texture_key(lhs->tsp, lhs->tcw);
|
||||
|
||||
const struct tracer_texture_entry *rhs =
|
||||
rb_entry(rb_rhs, const struct tracer_texture_entry, live_it);
|
||||
return (int)(tr_texture_key(lhs->tsp, lhs->tcw) -
|
||||
tr_texture_key(rhs->tsp, rhs->tcw));
|
||||
texture_key_t rhs_key = tr_texture_key(rhs->tsp, rhs->tcw);
|
||||
|
||||
if (lhs_key < rhs_key) {
|
||||
return -1;
|
||||
} else if (lhs_key > rhs_key) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static struct rb_callbacks tracer_texture_cb = {&tracer_texture_cmp, NULL,
|
||||
|
|
|
@ -48,7 +48,7 @@ struct ta {
|
|||
// texture cache entry pool. free entries are in a linked list, live entries
|
||||
// are in a tree ordered by texture key, textures queued for invalidation are
|
||||
// in the the invalid_entries linked list
|
||||
struct ta_texture_entry entries[1024];
|
||||
struct ta_texture_entry entries[8192];
|
||||
struct list free_entries;
|
||||
struct rb_tree live_entries;
|
||||
int num_invalidated;
|
||||
|
@ -101,17 +101,33 @@ static int ta_entry_cmp(const struct rb_node *rb_lhs,
|
|||
const struct rb_node *rb_rhs) {
|
||||
const struct ta_texture_entry *lhs =
|
||||
rb_entry(rb_lhs, const struct ta_texture_entry, live_it);
|
||||
texture_key_t lhs_key = tr_texture_key(lhs->tsp, lhs->tcw);
|
||||
|
||||
const struct ta_texture_entry *rhs =
|
||||
rb_entry(rb_rhs, const struct ta_texture_entry, live_it);
|
||||
return (int)(tr_texture_key(lhs->tsp, lhs->tcw) -
|
||||
tr_texture_key(rhs->tsp, rhs->tcw));
|
||||
texture_key_t rhs_key = tr_texture_key(rhs->tsp, rhs->tcw);
|
||||
|
||||
if (lhs_key < rhs_key) {
|
||||
return -1;
|
||||
} else if (lhs_key > rhs_key) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int ta_context_cmp(const struct rb_node *rb_lhs,
|
||||
const struct rb_node *rb_rhs) {
|
||||
const struct tile_ctx *lhs = rb_entry(rb_lhs, const struct tile_ctx, live_it);
|
||||
const struct tile_ctx *rhs = rb_entry(rb_rhs, const struct tile_ctx, live_it);
|
||||
return (int)(lhs->addr - rhs->addr);
|
||||
|
||||
if (lhs->addr < rhs->addr) {
|
||||
return -1;
|
||||
} else if (lhs->addr > rhs->addr) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static struct rb_callbacks ta_entry_cb = {&ta_entry_cmp, NULL, NULL};
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "ui/window.h"
|
||||
#include "video/backend.h"
|
||||
|
||||
#define MAX_TEXTURES 1024
|
||||
#define MAX_TEXTURES 8192
|
||||
|
||||
enum texture_map {
|
||||
MAP_DIFFUSE,
|
||||
|
|
Loading…
Reference in New Issue