0
我試圖創建一個基準ARM在隨後的指令循環(組裝),單獨和組合:浮點指令
- 整數加法
- 整數乘法
- 浮點加法
- 浮點乘法
這是我的整數運算代碼:
int additions_int(int n) {
int i, dummyValue = n;
__asm (
"MOV R0, #2\n"
"MOV R1, #6\n"
);
for (i = 0; i < n/LOOP_STEP; i++) {
__asm (
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
"ADD R0, R0, R1\n"
);
}
return dummyValue;
}
int multiplications_int(int n) {
int i, dummyValue=n;
__asm (
"MOV R0, #2\n"
"MOV R1, #6\n"
);
for (i = 0; i < n/LOOP_STEP; i++) {
__asm (
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
"MUL R0, R0, R1\n"
);
}
return dummyValue;
}
問題出在浮點運算上。我檢查this documentation,我已經tryed做這樣的事情:
arm-linux-gnueabi-gcc -static -march=armv7-a microbenchmark_arm.c -o microbenchmark_arm
我得到這個錯誤:
Error: selected processor does not support ARM mode `vmul.f32 R0,R0,R1'
Error: selected processor does not support ARM mode `vadd.f32 R0,R0,R1'
誰能說我
float multiplications_fp(int n) {
int i;
float fn=n, dummyValue = fn;
for (i = 0; i < n/LOOP_STEP; i++) {
__asm (
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
"VMUL.F32 R0, R0, R1\n"
);
}
return dummyValue;
}
float additions_fp(int n) {
int i;
float fn=n, dummyValue = fn;
for (i = 0; i < n/LOOP_STEP; i++) {
__asm (
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
"VADD.F32 R0, R0, R1\n"
);
}
return dummyValue;
}
與編譯我做錯了什麼?
任何人都可以向我展示一個用於ARM Cortex-A架構的浮點加法或乘法的例子嗎?
首先閱讀ARMv7A體系結構的參考手冊和目標CPU的數據表以及gcc手冊,該如何?供參考:循環是有問題的,因爲不確定。請先閱讀如何正確的基準。 – Olaf
我看到一個拼寫不同的例子[here](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491c/BABDEAGJ.html):'VMUL.F32 d0,d0 ,d0'。我沒有ARM FP的經驗,所以不能告訴你如何修正你的語法。 – anatolyg
順便說一句,關於「浮點加法或乘法的例子」,你可以通過反彙編編譯代碼來看到一個例子。 – anatolyg