确定我的处理器字长 [英] Determine word size of my processor

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

问题描述

我如何确定我的CPU的字长?如果我理解正确的 INT 应该是正确的一个词?我不知道我是否正确。

How do I determine the word size of my CPU? If I understand correct an int should be one word right? I'm not sure if I am correct.

所以应该只打印的sizeof(INT)将足以确定我的处理器的字长?

So should just printing sizeof(int) would be enough to determine the word size of my processor?

推荐答案

您的假设有关的sizeof(int)的是不真实的;看到这个

Your assumption about sizeof(int) is untrue; see this.

因为你必须知道在编译时的处理器,操作系统和编译器,字的大小可以通过使用$ P $推断pdefined 架构/ OS /编译器宏通过编译器提供的。

Since you must know the processor, OS and compiler at compilation time, the word size can be inferred using predefined architecture/OS/compiler macros provided by the compiler.

然而同时简单和最RISC处理器,字的大小,总线宽度,寄存器的大小和存储器组织往往持续一个值,这可能不是真的,使其与各种尺寸的更复杂的CISC和DSP架构为浮点寄存器,累加器,总线宽度,宽度缓存,通用寄存器等。

However while on simpler and most RISC processors, word size, bus width, register size and memory organisation are often consistently one value, this may not be true to more complex CISC and DSP architectures with various sizes for floating point registers, accumulators, bus width, cache width, general purpose registers etc.

当然,这引出了一个问题,为什么你可能需要知道这一点?通常你会用适当的应用程序类型,并相信编译器提供任何优化。如果优化是什么,你认为你需要这些信息,那么你很可能是最好使用 C99快类型。如果需要,以优化特定的算法,实现它为若干类型和轮廓它

Of course it begs the question why you might need to know this? Generally you would use the type appropriate to the application, and trust the compiler to provide any optimisation. If optimisation is what you think you need this information for, then you would probably be better off using the C99 'fast' types. If you need to optimise a specific algorithm, implement it for a number of types and profile it.

这篇关于确定我的处理器字长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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