gpt4 book ai didi

java - 如何在 Java 中将 boolean 条件转换为整数类型而不在已编译的字节码和 JITed 机器码中进行分支或跳转

转载 作者:行者123 更新时间:2023-12-05 06:56:30 26 4
gpt4 key购买 nike

<分区>

如给出的示例 here对于 C/C++:

... This is due to a new technique described in "BlockQuicksort: How Branch Mispredictions don't affect Quicksort" by Stefan Edelkamp and Armin Weiss. In short, we bypass the branch predictor by using small buffers (entirely in L1 cache) of the indices of elements that need to be swapped. We fill these buffers in a branch-free way that's quite elegant (in pseudocode):

buffer_num = 0; buffer_max_size = 64;
for (int i = 0; i < buffer_max_size; ++i) {
// With branch:
if (elements[i] < pivot) { buffer[buffer_num] = i; buffer_num++; }
// Without:
buffer[buffer_num] = i; buffer_num += (elements[i] < pivot);
}

在没有分支或跳转的情况下,如何在 Java 中实现相同的功能?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com