Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARM NEON assembly on Windows Phone 8 not working

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

like image 241
Anthony Blake Avatar asked Nov 12 '22 17:11

Anthony Blake


1 Answers

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.

like image 91
Docent Avatar answered Nov 15 '22 07:11

Docent