是专门用来编译1比1与位操作汇编指令的一个跨平台的方式有C函数和宏? [英] Are there C functions or macros specifically designed to compile 1 to 1 with assembly instructions for bit manipulations in a cross-platform manner?

查看:174
本文介绍了是专门用来编译1比1与位操作汇编指令的一个跨平台的方式有C函数和宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了包括仿真(如果你看看我的历史后,你会看到多远我来!)一个项目,我希望做伪二进制翻译使用C和与打优化和/或编译器使用C code,它编译我的switch语句内容到一个单一的汇编指令,主要用于非常标准的指令,例如 MOV S,添加 SR 等简单的位操作和算术指令。我希望能在同一时间为ARM和x86-64做到这一点,写少它在这两个组件成为可能。

I've got a project involving emulation (If you look at my post history, you'll see how far I've come!) and I'm looking to do pseudo-binary-translation using C and playing with the optimizers and/or compilers to use C code that compiles my switch statement contents to a single assembly instruction, primarily for very standard instructions such as movs, add, SR and other simple bit manipulations and arithmetic instructions. I'm hoping to do this for ARM and x86-64 at the same time, writing as little of it in both assemblies as possible.

如果我所描述的东西不存在,那么我想知道是否有某种汇编语言,我可以用它来写我的code,然后编译组装成的x86-64和ARM的。

If the thing I'm describing doesn't exist, then I wonder if there's some sort of "assembly language" that I can use to write my code and then compile that assembly into x86-64 and ARM.

推荐答案

要清楚地回答这一部分:

To clearly answer this part:

...然后我不知道是否有某种汇编语言的,我可以
  用它来写我的code,然后编译成汇编和X86-64
  ARM。

... then I wonder if there's some sort of "assembly language" that I can use to write my code and then compile that assembly into x86-64 and ARM.

这正是 LLVM IR 是目标定位。

该LLVM重新presentation目标是重量轻,低层次的,而
  作为前pressive,打字,并在同一时间可扩展的。它的目的是
  是各种各样的万能的IR,由是在足够低的水平
  高层次的想法,可以清晰地映射到它(类似于如何
  微处理器是万能IR的,这让很多源语言
  被映射到它们)。

The LLVM representation aims to be light-weight and low-level while being expressive, typed, and extensible at the same time. It aims to be a "universal IR" of sorts, by being at a low enough level that high-level ideas may be cleanly mapped to it (similar to how microprocessors are "universal IR’s", allowing many source languages to be mapped to them).

有关例如

您可以重新present这个C函数

You can represent this C function

int mul_add(int x, int y, int z) {
  return x * y + z;
}

本LLVM IR

with this LLVM IR

define i32 @mul_add(i32 %x, i32 %y, i32 %z) {
entry:
  %tmp = mul i32 %x, %y
  %tmp2 = add i32 %tmp, %z
  ret i32 %tmp2
}

这篇关于是专门用来编译1比1与位操作汇编指令的一个跨平台的方式有C函数和宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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