c# - C# Get Label Address For Lookup Table?
问题描述
I'm trying to optimize an algorithm I've been working on in C#. I have a while loop that will continue as long as a couple of variables are not 0. I was hoping to potentially replace this with some binary arithmetic & lookup table to avoid conditional branching.
while(a != 0 && b != 0 ) {
// DO WORK
}
I was hoping I might be able to do something like this:
var lookup_table = [next_iteration, done];
next_iteration:
// DO WORK
goto lookup_table[<< a&b? 0 : 1 >>];
done:
Replacing the << a&b? 0 : 1 >>
with binary arithmetic. Probably folding all the bits to the 1s place in a & b, and then masking out other bits in the final AND operation. Perhaps there's a better technique.
Of course, this level of optimization may just be beyond the capabilities of C#/Managed Languages without dropping into IL (which could be a valid solution). In which case I can drop down to C/C++. I'm curious to see if I can't get it to work in C# though.
解决方案
推荐阅读
- c++ - 连接两个类型化的可变参数模板包
- powershell - 如何使用 PowerShell 编辑快捷方式文件的“注释”部分?
- system-verilog - 在 SystemVerilog 类中定义的任务的 DPI-C 导出
- asp.net - SqlException:在删除级联不工作 ASP.NET
- javascript - 尝试将 JSON 对象转换为 JavaScript 以显示,但未显示
- javascript - React + ES6:Dash.js,MediaPlayer 不是函数
- node.js - 如何在 MongoDB 中使用数组对嵌套对象进行排序?
- python - VS Code Python Intellisense 和 pylint 无法正常工作
- python - AttributeError:“DictCursor”对象没有“执行”属性
- laravel - 在 laravel 8.12 中安装和使用 npm 时出错