あるオブジェクトがどのようにアライメントされるか,
または,ある型が通常必要とする最小アライメント値を調べることができる.
[Example]
__alignof__(int) == 4 __alignof__(double) == 8 struct test { int x; char y; } t; __alignof__(t) == 4;
[Reference]
Using and Porting GNU CC - C 言語ファミリに対する拡張
__alignof__(int) == 4 __alignof__(double) == 8 struct test { int x; char y; } t; __alignof__(t) == 4;
[Table 18-11. Core Specificity Encoding]
Bit 15:14
11B All cores
10B Reserved
01B This core
00B Reserved
Some microarchitectural conditions allow detection specificity only at the boundary of physical processors. Some bus events belong to this category, providing specificity between the originating physical processor (a bus agent) versus other agents on the bus. Sub-field encoding for agent specificity is shown in Table 18-12.
[Table 18-12. Agent Specificity Encoding]
Bit 13
0 This agent
1 Include all agents
Some microarchitectural conditions are detectable only from the originating core. In such cases, unit mask does not support core-specificity or agent-specificity encodings. These are referred to as core-only conditions. Some microarchitectural conditions allow detection specificity that includes or excludes the action of hardware prefetches. A two-bit encoding may be supported to qualify hardware prefetch actions. Typically, this applies only to some L2 or bus events. The sub-field encoding for hardware prefetch qualification is shown in Table 18-13.
[Table 18-13. HW Prefetch Qualification Encoding]
Bit 13:12
11B All inclusive
10B Reserved
01B Hardware prefetch only
00B Exclude hardware prefetch
[Table 18-14. MESI Qualification Definitions]
Bit Position 11:8
Bit 11 Counts modified state
Bit 10 Counts exclusive state
Bit 9 Counts shared state
Bit 8 Counts Invalid state
// よく使いそうな16進マスク
//--------------------------------------------------
[Table 18-11. Core Specificity Encoding]
0xc000: All cores
0x4000: This core
[Table 18-12. Agent Specificity Encoding]
0x0000 This agent
0x2000 Include all agents
[Table 18-13. HW Prefetch Qualification Encoding]
0x3000: All inclusive
0x1000: Hardware prefetch only
[Table 18-14. MESI Qualification Definitions]
0x0f00: 全部
#include#include #define BIT(x, bit) (((x) >> (bit)) & 0x00000001) int main() { unsigned int a, b, c, d; unsigned char eax_07_00, eax_15_08, eax_23_16, eax_31_24; unsigned char edx_04_00, edx_12_05; asm volatile ("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "a"(0x0a)); printf("CPUID(EAX=0AH): Architectural Performance Monitoring\n"); eax_07_00 = (unsigned char)(a & 0xff); eax_15_08 = (unsigned char)((a >> 8) & 0xff); eax_23_16 = (unsigned char)((a >> 16) & 0xff); eax_31_24 = (unsigned char)((a >> 24) & 0xff); printf(" Version ID of architectural PM: %d\n", eax_07_00); printf(" Number of general-purpose PMC per logical processor: %d\n", eax_15_08); printf(" Bit width of general-purpose PMC: %d\n", eax_23_16); printf(" Length of EBX bit vector: %d\n", eax_31_24); printf("\n"); printf(" Core cycle event not available: %d\n", BIT(b, 0)); printf(" Instruction retired event not available: %d\n", BIT(b, 1)); printf(" Reference cycles event not available: %d\n", BIT(b, 2)); printf(" Last-level cache reference event not available: %d\n", BIT(b, 3)); printf(" Last-level cache misses event not available: %d\n", BIT(b, 4)); printf(" Branch instrunction retired event not available: %d\n", BIT(b, 5)); printf(" Branch mispredict retired event not available: %d\n", BIT(b, 6)); printf("\n"); if (eax_07_00 > 1) { edx_04_00 = (unsigned char)(d & 0x1f); edx_12_05 = (unsigned char)((d >> 5) & 0xff); printf(" Number of fixed-function PCs: %d\n", edx_04_00); printf(" Bit width of fixed-function PCs: %d\n", edx_12_05); } return 0; }