问题
I'm trying to call a function that is coded in ARM NEON assembly in an .s file that looks like this:
AREA myfunction, code, readonly, ARM
global fun
align 4
fun
push {r4, r5, r6, r7, lr}
add r7, sp, #12
push {r8, r10, r11}
sub r4, sp, #64
bic r4, r4, #15
mov sp, r4
vst1.64 {d8, d9, d10, d11}, [r4]!
vst1.64 {d12, d13, d14, d15}, [r4]
[....]
and I'm assembling it like this:
armasm.exe -32 func.s func.obj
Unfortunately this doesn't work, and I'm getting illegal instruction exception when I try and call the function. When I used dumpbin.exe to disassemble the .obj, it seem to be disassembling as though it was Thumb code, despite the ARM directive in the assembly (see code above).
I suspect the function is being called in Thumb mode, and that all functions are assumed to be in Thumb mode by default on Windows. Can't see to find any info on this though.
Does anyone know what is going on here?
EDIT: This happens on Microsoft Surface as well
回答1:
VS 2012 by default produces thumb code for both Windows RT and Windows Phone 8 so the error you got is probably caused by calling into arm code from thumb code. You have two options:
1. Switch from thumb mode to arm mode before calling your function (you can use BX asm instruction for it), or
2. You can try to rewrite your NEON code in C++ using ARM/NEON intrinsics - they are supported by VS 2012. Just include "arm_neon.h" and you're done.
For the ARM intrinsics reference check out the following link: http://msdn.microsoft.com/en-us/library/hh875058.aspx
For NEON intrinsics reference check out this link: http://infocenter.arm.com/help/topic/com.arm.doc.dui0491c/DUI0491C_arm_compiler_reference.pdf
These NEON intrinsics from the link above are generally supported by VS 2012, there might be some small differences though - if unsure, check the "arm_neon.h" include to find out.
回答2:
You could start your assembly code with a bx instruction in Thumb mode and simply branch to the ARM part in the same source file.
And you don't have to switch back to Thumb mode at the end since you'll finish the ARM function in bx or pop {pc} anyway which does the switching automatically.
My answer is WAAAAAAY late, but I'm really curious if it works on a WP. (I don't have any)
来源:https://stackoverflow.com/questions/13488620/arm-neon-assembly-on-windows-phone-8-not-working