关于大小和数据类型的排列在不同的平台安全的假设? [英] Safe assumption regarding size and alignment of datatypes on different platforms?

查看:165
本文介绍了关于大小和数据类型的排列在不同的平台安全的假设?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我将只使用类型有明确的宽度,如没有INT但INT32,UINT16,等...它是安全的假设:

Let's say I will only be using types with explicit width, e.g. no int but int32, uint16, etc... is it safe to assume that:

A byte will always take 8 bits and will be 8 bit aligned
A short will always take 16 bits and will be 16 bit aligned
An int will always take 32 bits and will be 32 bit aligned
A long int will always take 64 bits and will be 64 bit aligned
A float will always take 32 bits and will be 32 bit aligned
A double will always take 64 bits and will be 64 bit aligned

---也可选择这三个将最好的工作,如果:

--- and also optionally those three will best work if:

A 64bit SIMD datatype will always be 8 byte aligned    
A 128bit SIMD datatype will always be 16 byte aligned
A 256bit SIMD datatype will always be 32 byte aligned

---而最后:

--- and lastly:

A cache page will always be multiple of 32 bytes  // e.g. 32 or 64 bytes

当然,我不意味的每个的硬件平台,在那里,我只关心的x86 / x64和ARM V7 / V8

Naturally, I do not imply EVERY hardware platform out there, I am only concerned with x86/x64 and ARM v7/v8

推荐答案

我会说有保证只要是有保证的,这里是我的意思是:

I'd say there is guarantee only if there is a guarantee, and here is what I mean:

typedef qint8
Typedef for signed char. This type is guaranteed to be 8-bit on all platforms supported by Qt.

typedef qint16
Typedef for signed short. This type is guaranteed to be 16-bit on all platforms supported by Qt.

typedef qint32
Typedef for signed int. This type is guaranteed to be 32-bit on all platforms supported by Qt.

typedef qint64
Typedef for long long int (__int64 on Windows). This type is guaranteed to be 64-bit on all platforms supported by Qt.

typedef quint8
Typedef for unsigned char. This type is guaranteed to be 8-bit on all platforms supported by Qt.

typedef quint16
Typedef for unsigned short. This type is guaranteed to be 16-bit on all platforms supported by Qt.

typedef quint32
Typedef for unsigned int. This type is guaranteed to be 32-bit on all platforms supported by Qt.

typedef quint64
Typedef for unsigned long long int (unsigned __int64 on Windows). This type is guaranteed to be 64-bit on all platforms supported by Qt.

这是从Qt文档。话虽这么说,有这保证数据类型的宽度其他图书馆,例如Apache可移植运行库,这是更精简的使用Qt。两者都支持x86和ARM架构。有可能是其他人了。

This is taken from the Qt documentation. That being said, there are other libraries which guarantee datatype width, for example the Apache Portable Runtime library, which is more streamlined that Qt. Both support x86 and ARM architectures. There are probably others too.

的比对以进行SIMD操作似乎是那些,建议以获得最佳性能。高速缓存行的大小也似乎是正确的,因为x86处理器有64字节的缓存行,ARM V7有32个字节和V8向上移动64个字节为好。所以我说,你使用某种类型库从而保证宽度你是安全的,只要 - 而不是最小像标准的要求,但绝对宽度

The alignments for SIMD operations seem to be the ones, recommended for optimal performance. The cache line size also seems to be the right one, since x86 processors have 64 byte cache lines, ARM v7 has 32 byte and v8 moves up to 64 bytes as well. So I'd say you are safe as long as you use some kind of library which guarantees width - not the minimum like the standard requires but the absolute width.

这篇关于关于大小和数据类型的排列在不同的平台安全的假设?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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