5

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

Anthony Blake
  • 5,328
  • 2
  • 25
  • 24
  • Ah, Silly question: What makes you think ARM Neon is supported on WP8?I haven't seen anything saying it's supported on WP8... – JustinAngel Nov 21 '12 at 08:39
  • armasm.exe complained about a few things, which I fixed, but it didn't raise any warnings about the NEON, and 95% of the insns were NEON – Anthony Blake Nov 21 '12 at 11:08
  • 1
    I don't know about WP8, but I've heard that WinRT supports only Thumb2 code (even if CPU accepts ARM). Why can't you assemble as Thumb2 though? – Igor Skochinsky Nov 21 '12 at 11:46
  • What instruction is generating the exception? Also, what does the return look like? When returning from a function you need to restore the mode. – Peter M Feb 13 '13 at 20:15

2 Answers2

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.

Docent
  • 11
  • 1
  • Yeah I ended up using intrinsics, but that code isn't as fast as the assembly, because I use insns like VSWP which don't map to intrinsics. – Anthony Blake Feb 25 '13 at 21:54
  • Also, the assembler didn't seem to assemble ARM code -- it seemed to be stuck on ARMCE mode, whatever that is. – Anthony Blake Feb 25 '13 at 21:55
0

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)

Jake 'Alquimista' LEE
  • 6,197
  • 2
  • 17
  • 25
  • Still curious? See [here](http://stackoverflow.com/questions/18344419/is-arm-not-thumb-supported-on-winphone8-at-all). Shortly, no. – Seva Alekseyev Sep 17 '13 at 21:42