Skip to content

Commit

Permalink
Optimized efficiency with a pointer cast
Browse files Browse the repository at this point in the history
  • Loading branch information
basilicon committed Aug 5, 2024
1 parent 425906e commit f05fe69
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions scene/resources/bit_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,15 @@ Ref<BitMap> BitMap::bitwise_and(const Ref<BitMap> &p_other) const {
const uint8_t *d2 = p_other->bitmask.ptr();
uint8_t *w = new_bitmap->bitmask.ptrw();

for (int i = 0; i < ds; i++) {
const uint64_t *d_u64 = (uint64_t*) d;
const uint64_t *d2_u64 = (uint64_t*) d2;
uint64_t *w_u64 = (uint64_t*) w;

for (int i = 0; i < (ds >> 3); i++) {
w_u64[i] = d_u64[i] & d2_u64[i];
}

for (int i = ds & ~0b111; i < ds; i++) {
w[i] = d[i] & d2[i];
}

Expand All @@ -735,7 +743,14 @@ Ref<BitMap> BitMap::bitwise_not() const {
const uint8_t *d = bitmask.ptr();
uint8_t *w = new_bitmap->bitmask.ptrw();

for (int i = 0; i < ds; i++) {
const uint64_t *d_u64 = (uint64_t*) d;
uint64_t *w_u64 = (uint64_t*) w;

for (int i = 0; i < (ds >> 3); i++) {
w_u64[i] = ~d_u64[i];
}

for (int i = ds & ~0b111; i < ds; i++) {
w[i] = ~d[i];
}

Expand Down Expand Up @@ -763,7 +778,15 @@ Ref<BitMap> BitMap::bitwise_or(const Ref<BitMap> &p_other) const {
const uint8_t *d2 = p_other->bitmask.ptr();
uint8_t *w = new_bitmap->bitmask.ptrw();

for (int i = 0; i < ds; i++) {
const uint64_t *d_u64 = (uint64_t*) d;
const uint64_t *d2_u64 = (uint64_t*) d2;
uint64_t *w_u64 = (uint64_t*) w;

for (int i = 0; i < (ds >> 3); i++) {
w_u64[i] = d_u64[i] | d2_u64[i];
}

for (int i = ds & ~0b111; i < ds; i++) {
w[i] = d[i] | d2[i];
}

Expand All @@ -785,7 +808,15 @@ Ref<BitMap> BitMap::bitwise_xor(const Ref<BitMap> &p_other) const {
const uint8_t *d2 = p_other->bitmask.ptr();
uint8_t *w = new_bitmap->bitmask.ptrw();

for (int i = 0; i < ds; i++) {
const uint64_t *d_u64 = (uint64_t*) d;
const uint64_t *d2_u64 = (uint64_t*) d2;
uint64_t *w_u64 = (uint64_t*) w;

for (int i = 0; i < (ds >> 3); i++) {
w_u64[i] = d_u64[i] ^ d2_u64[i];
}

for (int i = ds & ~0b111; i < ds; i++) {
w[i] = d[i] ^ d2[i];
}

Expand Down

0 comments on commit f05fe69

Please sign in to comment.