Skip to content

Commit

Permalink
optimize SteadyVector::operator[] by __builtin_clzll
Browse files Browse the repository at this point in the history
  • Loading branch information
lixinqi committed Jun 14, 2022
1 parent 3bf92e4 commit 4f3b775
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion oneflow/core/common/steady_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ class SteadyVector {
}

private:
static int GetGranularity(size_t index) { return std::log2(index + 1); }
#ifdef __GNUC__
#define LOG2(x) ((unsigned)(8 * sizeof(unsigned long long) - __builtin_clzll((x)) - 1))
#else
#define LOG2(x) std::log2(x)
#endif

static int GetGranularity(size_t index) { return LOG2(index + 1); }

#undef LOG2

std::atomic<size_t> size_;
std::mutex mutex_;
Expand Down

0 comments on commit 4f3b775

Please sign in to comment.