__asm__至__asm [英] __asm__ to __asm

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

问题描述

我有一个用__asm__关键字用纯C语言编写的代码.我需要将gcc可以识别的汇编语句转换为Visual C ++编译器可以识别的汇编语句.在Microsoft的C ++编译器中,使用__asm关键字(而不是__asm__)调用汇编指令,并且该指令应括在大括号{}中而不是括号内.
我不是汇编编码器,请帮助:)

这是我需要翻译为Visual C ++的代码:

I have a code written in pure C that uses the __asm__ keyword. I need to translate the assembly statements from something the gcc recognises into something the Visual C++ compiler will recognise. In Microsoft''s C++ compiler, assembly instructions are invoked using the __asm keyword (not __asm__) and the instructions should be enclosed in curly braces {} not parentheses.
I''m not an assembler coder, please help :)

Here is the code I need to translate to Visual C++ :

#    define FASTDIV(a,b) \
    ({\
        int ret,dmy;\
        __asm__ volatile(\
            "mull %3"\
            :"=d"(ret),"=a"(dmy)\
            :"1"(a),"g"(ff_inverse[b])\
            );\
        ret;\
    })





#define MASK_ABS(mask, level)\
            __asm__ volatile(\
                "cltd                   \n\t"\
                "xorl %1, %0            \n\t"\
                "subl %1, %0            \n\t"\
                : "+a" (level), "=&d" (mask)\
            );





uint32_t a, d;
__asm__ volatile("rdtsc\n\t" : "=a" (a), "=d" (d));
return ((uint64_t)d << 32) + a;



我敢肯定,对于那些具有汇编编码经验的人来说,这将是一个简单的答案.



I''m sure it will be an easy answer for someone who has more experience in assembly coding. Thanks in advance!

推荐答案

在这里对英国感到困惑,如何用汇编器编写的东西才能纯C"?

我建议做的第一件事是将装箱器完全装箱并让编译器生成代码.例如,第二个函数看起来像一个异或加减abs函数. VC ++使用完全相同的指令流来实现Abs(如果我正确使用了略微弯曲的gcc汇编器语法).

干杯,



PS:只要您在一段代码中看到内联汇编程序,就尝试用C重写.对于像这样的微优化,编译器通常可以像人类程序员一样出色地完成工作.因此,请确保您使用的代码比编译器生成的代码更好.

PPS:一个有趣的事实是,在编译器的代码流中注入手动优化的程序集通常会关闭编译器的优化器,因此生成的代码通常较慢.我在几年前(实际上是10个)就看到了这一点,当时优化"的strcpy实际上比编译器慢20%.尽管副本进行了优化,但使用它的所有内容并非如此.如果我不是程序员,我会怎么笑.
Confused of England here, how can you have "pure C" with things written in assembler?

The first thing I''d suggest doing is binning the assembler entirely and letting the compiler generate the code. For example the second one looks like a xor and subtract abs function. VC++ implements abs using exactly the same instruction stream (if I''ve got the slightly bent gcc assembler syntax correct).

Cheers,

Ash

PS: Whenever you see inline assembler in a piece of code try rewriting it in C. For micro-optimisations like that the compiler can often do as good a job as a human programmer. So make sure what you''re using is better than the compiler generated code.

PPS: One interesting fact is that hand optimised assembly injected in a compiler''s code stream usually turns off the compiler''s optimiser so the generated code is often slower. I saw this a couple (er, 10 actually) years ago when an "optimised" strcpy was actually 20% slower than the compilers. While the copy was optimised everything that used it wasn''t. How I would have laughed had I not been the programmer.


我知道,但是不幸的是,这段代码不是我的.这就是为什么它处于这种状态.我确实需要此代码,因此可以在MSVC环境中使用它.

期待包含MSVC代码的答案. :)
I know that but unfortunately this code is not mine. That is why it is in such condition. I really need this code so I can use it in MSVC environment.

Looking forward for an answer that contains MSVC code. :)


这篇关于__asm__至__asm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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