Only restore FPCR if different from saved value.
Bug: 129131324
Change-Id: Id6db43e45d66d63a70a247d59ab355651420f897
diff --git a/src/arch/aarch64/hypervisor/exceptions.S b/src/arch/aarch64/hypervisor/exceptions.S
index bca781d..ea17ffa 100644
--- a/src/arch/aarch64/hypervisor/exceptions.S
+++ b/src/arch/aarch64/hypervisor/exceptions.S
@@ -386,9 +386,18 @@
ldp q30, q31, [x2, #32 * 15]!
ldp x3, x4, [x2, #32 * 1]
msr fpsr, x3
- /* TODO: Optimise by only performing expensive restore if changed. */
- msr fpcr, x4
+ /*
+ * Only restore FPCR if changed, to avoid expensive
+ * self-synchronising operation where possible.
+ */
+ mrs x5, fpcr
+ cmp x5, x4
+ b.eq vcpu_restore_lazy_and_run
+ msr fpcr, x4
+ /* Intentional fallthrough. */
+
+vcpu_restore_lazy_and_run:
/* Restore lazy registers. */
ldp x24, x25, [x0, #VCPU_LAZY + 16 * 0]
msr vmpidr_el2, x24