void _mm_clflush(void const*_P)
Posted rtoax
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了void _mm_clflush(void const*_P)相关的知识,希望对你有一定的参考价值。
/**
* File: _mm_clflush.c
* Author: Rong Tao <rongtao@????.cn>
* Date: 2022.05.06
*
* _mm_clflush() will flush cacheline if vars in cache.
*
* Refs:
* https://www.codenong.com/52525886/
* https://zhuanlan.zhihu.com/p/242740319
*/
#include <stdio.h>
#include <stdint.h>
#if defined(__x86_64__)
#include <mmintrin.h>
#include <x86intrin.h>
#else
# error "Not support"
#endif
#ifndef FLUSH
# warning "Define FLUSH test _mm_clflush."
#endif
#define LINE_SIZE 64
#define L1_WAYS 16
#define L1_SETS 64
#define L1_LINES 512
extern void _mm_clflush(void const*_P);
uint8_t data[L1_LINES*LINE_SIZE];
int main(int argc, char *argv[])
volatile uint8_t *addr;
register uint64_t i;
unsigned int junk = 0;
register uint64_t t1, t2;
printf("data: %p\\n", data);
_mm_clflush(data);
printf("accessing 16 bytes in a cache line:\\n");
for (i = 0; i < 16; i++)
t1 = __rdtscp(&junk);
addr = &data[i];
junk = *addr;
t2 = __rdtscp(&junk) - t1;
#ifdef FLUSH
/* Flush */
_mm_clflush(data);
#endif
printf("i = %2ld, cycles: %ld\\n", i, t2);
return 0;
测试:
[rongtao@localhost mmintrin]$ gcc _mm_clflush.c
_mm_clflush.c:23:3: warning: #warning "Define FLUSH test _mm_clflush." [-Wcpp]
23 | # warning "Define FLUSH test _mm_clflush."
| ^~~~~~~
[rongtao@localhost mmintrin]$ ./a.out
data: 0x404060
accessing 16 bytes in a cache line:
i = 0, cycles: 142
i = 1, cycles: 14
i = 2, cycles: 13
i = 3, cycles: 12
i = 4, cycles: 12
i = 5, cycles: 14
i = 6, cycles: 12
i = 7, cycles: 14
i = 8, cycles: 14
i = 9, cycles: 14
i = 10, cycles: 12
i = 11, cycles: 14
i = 12, cycles: 14
i = 13, cycles: 14
i = 14, cycles: 14
i = 15, cycles: 12
[rongtao@localhost mmintrin]$ gcc _mm_clflush.c -DFLUSH
[rongtao@localhost mmintrin]$ ./a.out
data: 0x404060
accessing 16 bytes in a cache line:
i = 0, cycles: 126
i = 1, cycles: 124
i = 2, cycles: 134
i = 3, cycles: 136
i = 4, cycles: 120
i = 5, cycles: 136
i = 6, cycles: 142
i = 7, cycles: 126
i = 8, cycles: 124
i = 9, cycles: 126
i = 10, cycles: 156
i = 11, cycles: 138
i = 12, cycles: 126
i = 13, cycles: 122
i = 14, cycles: 163
i = 15, cycles: 124
以上是关于void _mm_clflush(void const*_P)的主要内容,如果未能解决你的问题,请参考以下文章
无法转换类型“(_)-> Void?”的值到预期的参数类型'(() - > Void)?
从类型 (_,_,_) throws -> Void 到非抛出函数类型 (NSData?, NSURLResponse?, NSError?) -> Void 的无效转换
typedef void (*funcptr)(void) typedef void (*PFV)(); typedef int32_t (*PFI)();
LNK2019:函数“void __cdecl mainfunc(void)”中引用的未解析外部符号 _kiss_fftr_alloc