そこで,fseekとfgetposを使ってファイルポインタの位置を調べることで
間接的にファイルサイズを取得するそうな.
fpos_t fpos; FILE *fp = fopen(fname, "rb"); fseek(fp, 0, SEEK_END); fgetpos(fp, &fpos); fclose(fp); fpos.__pos; // これがファイルサイズ
// Reference
ファイルサイズの取得方法
半年くらい前にはまったこと
標準C言語関数
fpos_t fpos; FILE *fp = fopen(fname, "rb"); fseek(fp, 0, SEEK_END); fgetpos(fp, &fpos); fclose(fp); fpos.__pos; // これがファイルサイズ
# eog *.png
int i = 0; while (1) { i++; if (unlikely(i > 100)) break; }上記の例では,ループを抜ける条件式の
[IA32_FIXED_CTR0(MSR_PERF_FIXED_CTR0)]
Register Address: 0x309
Performance Event: Inst_Retired.Any
実行した命令数をカウントする.
[IA32_FIXED_CTR1(MSR_PERF_FIXED_CTR1)]
Register Address: 0x30A
Performance Event: CPU_CLK_Unhalted.Core
CPUがHalt状態でない時のCPUサイクル数をカウントする.
[IA32_FIXED_CTR2(MSR_PERF_FIXED_CTR2)]
Register Address: 0x30B
Performance Event: CPU_CLK_Unhalted.Ref
CPUがHalt状態でない時のバスクロック数をカウントする.
[bit fields]
0-4: IA32_FIXED_CTR0の設定
0: EN0_OS(CPL=0の時にenable)
1: EN0_Usr(CPL>0の時にenable)
2: Reserved
3: EN0_PMI(カウンタがオーバーフローした時にPMIを発生)
4-7: IA32_FIXED_CTR1の設定,0-3と同様
8-11: IA32_FIXED_CTR2の設定,0-3と同様
#define EXPAND_MACRO(_MACRO) \ _MACRO(a) \ _MACRO(b) \ #define DEFINE(_X) int _X; #define FUNC(_X) do { func(_X); } while (0);
__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; }