# Zynq Ultrascale MPSoC task floating point corruption

**URL:** <https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121>\
**Category:** Kernel\
**Created:** [March 2, 2020, 9:11pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121 "2020-03-02T21:11:27Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![wat](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wat/32/4351_2.png) [@wat](https://forums.freertos.org/u/wat)\
**Post date:** [February 9, 2022, 3:54pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/21 "2022-02-09T15:54:44Z")

</div>

I added codes for saving and restoring floating point registers to _FreeRTOS\_IRQ\_Handler_. I just copied them from _portSAVE\_CONTEXT_ in same file. Then, I don’t see any floating point corruption finally! Thank you for your advices!

But still I have one unknown point.  
At first, I added codes only for registers v16-v31 but floating point corruption was still seen. Adding v8-v31 was also same. Finally, I added codes for all registers v0-v31 and there is no floating point corruption.  
I am not sure why v0-v15 are needed to be saved and restored. And I am not sure it is allowable by ABI and FreeRTOS. Could you give me hints or advices?

> 16 large registers is quite an overhead.

Do you mean time overhead or stack space overhead or both of them? I cannot measure actual time overhead. In this case, time overhead can be estimated based on CPU clock and assembly code?

> are you performing a complex floating point operation, or just simple arithmetic?

My floating point operations in interrupts are not many. All of them are enough simple. I can replace them to integer operations if I try.  
But I would like to change all interrupts to “FPU safe” because of corruption risk in future. New floating point operation may be introduced in interrupt without any notice in future.  
Now I understand I should compare this risk and overhead of FPU safe handling. Do you think overhead is larger than future risks in general?  
Thank you for your support.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 9, 2022, 7:03pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/22 "2022-02-09T19:03:13Z")

</div>

The overhead is both in time and stack usage - whether that is an issue for you is very much dependent on the application you are writing. These devices can have a lot of RAM.

It is unexpected that you need to save all the floating point registers on interrupt entry - I would expect it on a context switch. I need to compile some code to see what it is doing. We have a Zynq project that uses Vitis and runs in QEMU now too - although its not merged into the mainline yet (still in the PR). That will make it easier to see what is going on.

---

<div class="post-metadata">

**Author:** ![wat](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wat/32/4351_2.png) [@wat](https://forums.freertos.org/u/wat)\
**Post date:** [February 13, 2022, 1:51pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/23 "2022-02-13T13:51:59Z")

</div>

I’m sorry for late response. I couldn’t reply for this topic. Then, I started the following new topic.

# [Zynq Ultrascale MPSoC task floating point corruption 2](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption-2/14458)

I’m sorry for separated topics. Thank you for your support.

[RTEL EDIT: Pasting the post from the other thread below to combine threads. I also upped your privileges so you can continue to post in this thread:]

> The overhead is both in time and stack usage - whether that is an issue for you is very much dependent on the application you are writing. These devices can have a lot of RAM.

Yes, my device has enough RAM. It means stack usage is not problem. I will estimate time overhead.

> It is unexpected that you need to save all the floating point registers on interrupt entry

I analyzed disassembled code for my floating point operations in interrupt. I found that s0, s1 and s2 registers are used in those operations. Does it mean v0-v2 require to be saved on IRQ entry?

> I need to compile some code to see what it is doing. We have a Zynq project that uses Vitis and runs in QEMU now too

Thank you very much for an investigation on your side. I am using Xilinx SDK 2019.1 instead of Vitis. Compiler is GCC which is built in Xilinx SDK. Maybe it is almost same as compiler in Vitis. Thank you for your support!

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 13, 2022, 4:30pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/24 "2022-02-13T16:30:08Z")

</div>

> [@wat](#):
>
> I analyzed disassembled code for my floating point operations in interrupt. I found that s0, s1 and s2 registers are used in those operations. Does it mean v0-v2 require to be saved on IRQ entry?

Could you also look at the assembly code where the function that uses those registers is called. Ideally if you can post the assembly here.

---

<div class="post-metadata">

**Author:** ![wat](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wat/32/4351_2.png) [@wat](https://forums.freertos.org/u/wat)\
**Post date:** [February 15, 2022, 2:15pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/25 "2022-02-15T14:15:20Z")

</div>

Thank you for combining threads and updating my account.

> Could you also look at the assembly code where the function that uses those registers is called.

I checked all assembly codes which are executed in interrupt.  
_FreeRTOS\_IRQ\_Handler_ → _vApplicationIRQHandler_ → My interrupt function -\>…-\> Goes back to _FreeRTOS\_IRQ\_Handler_.  
In this sequence, floating point registers are found only in the steps for my floating point calculation corresponding to C language code. No floating point register(_v_,_q_,_d_,_s_,_h_ or _b_) is saved or restored in the sequence.  
unfortunately, I cannot post assembly code directly because of the rules of my side. I’m sorry.

In a microsoft document [Overview of ARM64 ABI conventions](https://docs.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#floating-pointsimd-registers), v0-v7 are explained as not only “parameters” but also “volatile” and “scratch registers”. v8-v15 are Non-volatile only for low 64bit. So, I guess it means most of registers should be saved on IRQ entry. Could you give me your advice?  
Thank you for your support.

---

<div class="post-metadata">

**Author:** ![wat](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wat/32/4351_2.png) [@wat](https://forums.freertos.org/u/wat)\
**Post date:** [February 28, 2022, 2:25pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/26 "2022-02-28T14:25:43Z")

</div>

I have one question.  
If an overhead for saving “all” floating point registers is acceptable, is there any other problem for saving “all” floating point registers?

I have measured overhead for saving all floating point registers. It is 50ns. I think it is acceptable for my system. I measured time between external interrupt signal and GPIO signal generated by firmware in interrupt function by using an oscilloscope.  
Result is  
Time with saving “no” floating point registers: 450ns  
Time with saving “all” floating point registers: 500ns

I would like to choose this solution even if some registers don’t need to be saved actually. Could you tell me your opinion?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 28, 2022, 3:02pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/27 "2022-02-28T15:02:59Z")

</div>

The only impact would be the additional RAM used and interrupt entry time.

---

<div class="post-metadata">

**Author:** ![wat](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wat/32/4351_2.png) [@wat](https://forums.freertos.org/u/wat)\
**Post date:** [March 1, 2022, 2:04pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/28 "2022-03-01T14:04:28Z")

</div>

Thank you for a quick response. Impacts of RAM usage and entry time are acceptable for my system. My problem is solved because of your help. Thank you again!

---

<div class="post-metadata">

**Author:** ![dykeagdrs](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@dykeagdrs](https://forums.freertos.org/u/dykeagdrs)\
**Post date:** [October 30, 2023, 8:07pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/29 "2023-10-30T20:07:44Z")

</div>

We believe that we are having the same problem our Ultrascale A53. Rather that re-inventing the wheel, would you mind sharing the code changes?

---

<div class="post-metadata">

**Author:** ![wat](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/wat/32/4351_2.png) [@wat](https://forums.freertos.org/u/wat)\
**Post date:** [February 3, 2024, 4:18pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/30 "2024-02-03T16:18:30Z")

</div>

Sorry for the late reply.  
I found that this problem has been modified in the newest version of FreeRTOS A53 port.  
I have never tested it but it seems to be almost same modification as this topic.  
You can find “savefloatregisters” in “FreeRTOS\_IRQ\_Handler”.

portASM.S

> <https://github.com/Xilinx/embeddedsw/blob/xlnx_rel_v2023.2/ThirdParty/bsp/freertos10_xilinx/src/Source/portable/GCC/ARM_CA53/portASM.S>

---

<div class="post-metadata">

**Author:** ![StefanBa](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/stefanba/32/1341_2.png) [@StefanBa](https://forums.freertos.org/u/StefanBa)\
**Post date:** [May 2, 2024, 5:25pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/31 "2024-05-02T17:25:52Z")

</div>

Sorry for another late reply.  
I opened a pull request that will partially resolve this issue by adding `configUSE_TASK_FPU_SUPPORT ` to the AARCH64 port:  
[https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/1048](https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/1048)

For a full fix the FPU registers need to be saved/restored for interrupts like in the Xilinx `portASM.S` posted by @wat above.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 8, 2024, 3:08pm UTC](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121/32 "2024-05-08T15:08:10Z")

</div>

Thank you for your contribution!

[Previous page](https://forums.freertos.org/t/zynq-ultrascale-mpsoc-task-floating-point-corruption/9121.md?page=1)
