在C#中_BitScanForward? [英] _BitScanForward in C#?

查看:374
本文介绍了在C#中_BitScanForward?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我翻译写在C ++到C#程序,我所遇到的一个内部函数,我不能变通解决。在C ++中,这就是所谓的:

I am translating a program written in C++ to C#, and I have come across an intrinsic function that I cannot work around. In C++ this is known as:

unsigned char _BitScanForward(unsigned long * Index, unsigned long Mask);

如果我只知道DLL,如果有的话,内在功能都在,我可以使用的P / Invoke。因为我不知道,我所期望的是在.NET框架的替代品,但我已经拿出空手而归。

If I only knew what DLL, if any, the intrinsic functions were in, I could use P/Invoke. Since I do not know, I looked for alternatives in the .NET framework, but I have come up empty handed.

有谁知道如何使用的P / Invoke的_BitScanForward,或做同样的事情的.NET方法?

Does anyone know how use P/Invoke on _BitScanForward, or an .NET method that does the same thing?

任何帮助是AP preciated,谢谢你。

Any help is appreciated, thank you.

推荐答案

内在功能都没有任何图书馆,他们在CPU内部实现,编译器发射的机code 该CPU识别为唤起这种特殊的行为。

Intrinsic functions aren't in any library, they're implemented inside the CPU, the compiler emits the machine code which the CPU recognizes as evoking this particular behavior.

他们要访问的指令的方式,没有一个简单的C当量。

They're a way of getting access to instructions that don't have a simple C equivalent.

直到.NET优化变得足够聪明,能够识别它们(例如,单声道JIT识别一些SIMD指令,连接$ C $光盘MSIL作为调用特定类的功能,同样的.NET JIT取代调用System.Math方法与浮点运算),你的C#code,是注定要运行幅度比原来的C ++慢一个数量级。

Until the .NET optimizer becomes smart enough to recognize them (for example, the Mono JIT recognizes some SIMD instructions, encoded in MSIL as calls to functions of a particular class, similarly the .NET JIT replaces calls to System.Math methods with floating-point operations), your C# code is doomed to run an order of magnitude slower than the original C++.

这篇关于在C#中_BitScanForward?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆