在Android中进行上下文切换时保存ARM NEON寄存器

时间:2015-06-25 17:58:57

标签: android multithreading arm neon context-switching

在上下文切换时,Android将所有ARM通用寄存器保存在堆栈上并在之后恢复。

Android OS是否在堆栈中存储NEON寄存器?

如果没有,如何在多线程和多任务环境中安全使用NEON?

2 个答案:

答案 0 :(得分:2)

If the kernel is built with NEON/VFP support then it will indeed preserve the NEON state for a task along with the rest as part of the context switch (provided that the task has actually touched NEON/VFP beforehand, so there is some state to preserve).

If the kernel doesn't have NEON/VFP support, then as you guess there is simply no safe way of using it - any task could freely corrupt any other task as they'd all be sharing the same registers. Fortunately that problem doesn't exist in practice because a kernel which isn't aware of NEON also won't enable access to the hardware in the first place. In that case any NEON instructions would be treated as undefined, and signals sent back to the task as appropriate.

The fact that there are tons of Android applications out there with NEON code in them should be a hint as to which of those configurations is relevant here ;)

答案 1 :(得分:0)

如果您能够在Android中使用Neon指令,这意味着您的内核已启用VFP并将负责切换部分(如果内核未启用Neon / VFP,您将获得指令中止) 。此外,ARM VFP和NEON共享同一组寄存器。因此,您的上下文很可能会被保存恢复。一些操作系统有智能通过采用惰性切换技术来减少切换时间,但寄存器将保持无腐蚀