public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* reasoning beehind prohibiting VFP/NEON on AArch32
@ 2018-05-12 21:11 Michael Zimmermann
  2018-05-13  7:32 ` Ard Biesheuvel
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Zimmermann @ 2018-05-12 21:11 UTC (permalink / raw)
  To: edk2-devel-01; +Cc: Leif Lindholm, Ard Biesheuvel

For AArch32 the spec says in 2.3.5.3:
> Floating point, SIMD, vector operations and other instruction set
extensions must not
be used.

For AArch64 the spec says in 2.3.6.4:
> Floating point and SIMD instructions may be used.

So is there a reason why AArch32 is not allowed to use Floating point
operations?
I'd understand if this restriction was limited to runtime services only but
I don't see how it makes sense for boot services.

I've written a patch which adds NEON support to FrameBufferBltLib to
increase the rendering performance(by a lot actually) for 24bit displays
and thought about sending it to the mailing list - that's why the question
came up.

Thanks
Michael


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reasoning beehind prohibiting VFP/NEON on AArch32
  2018-05-12 21:11 reasoning beehind prohibiting VFP/NEON on AArch32 Michael Zimmermann
@ 2018-05-13  7:32 ` Ard Biesheuvel
  2018-05-13  9:48   ` Michael Zimmermann
  0 siblings, 1 reply; 7+ messages in thread
From: Ard Biesheuvel @ 2018-05-13  7:32 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel-01, Leif Lindholm

On 12 May 2018 at 23:11, Michael Zimmermann <sigmaepsilon92@gmail.com> wrote:
> For AArch32 the spec says in 2.3.5.3:
>> Floating point, SIMD, vector operations and other instruction set
> extensions must not
> be used.
>
> For AArch64 the spec says in 2.3.6.4:
>> Floating point and SIMD instructions may be used.
>
> So is there a reason why AArch32 is not allowed to use Floating point
> operations?
> I'd understand if this restriction was limited to runtime services only but
> I don't see how it makes sense for boot services.
>
> I've written a patch which adds NEON support to FrameBufferBltLib to
> increase the rendering performance(by a lot actually) for 24bit displays
> and thought about sending it to the mailing list - that's why the question
> came up.
>

The reason for the difference between AArch64 and the other EFI
architectures is that AArch64 does not have a softfloat ABI, so it is
impossible to compile floating point code [portably] without enabling
VFP/NEON. This is why AArch64 is the exception here.

Currently, the AArch32 CPU context structure [EFI_SYSTEM_CONTEXT_ARM]
does not cover VFP/NEON registers, and so they are not
preserved/restored when an interrupt is taken. This means you cannot
use VFP/NEON registers in an event handler or you will corrupt the
VFP/NEON state of the interrupted context.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reasoning beehind prohibiting VFP/NEON on AArch32
  2018-05-13  7:32 ` Ard Biesheuvel
@ 2018-05-13  9:48   ` Michael Zimmermann
  2018-05-13 10:16     ` Ard Biesheuvel
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Zimmermann @ 2018-05-13  9:48 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

So basically using them should be safe as long as you're in
EfiGetCurrentTpl() < TPL_HIGH_LEVEL, right?
Also, it'd probably be trivial to add  VFP/NEON regs to
EFI_SYSTEM_CONTEXT_ARM though that wouldn't help when writing apps for
existing uefi platforms.
On Sun, May 13, 2018 at 9:32 AM Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 12 May 2018 at 23:11, Michael Zimmermann <sigmaepsilon92@gmail.com>
wrote:
> > For AArch32 the spec says in 2.3.5.3:
> >> Floating point, SIMD, vector operations and other instruction set
> > extensions must not
> > be used.
> >
> > For AArch64 the spec says in 2.3.6.4:
> >> Floating point and SIMD instructions may be used.
> >
> > So is there a reason why AArch32 is not allowed to use Floating point
> > operations?
> > I'd understand if this restriction was limited to runtime services only
but
> > I don't see how it makes sense for boot services.
> >
> > I've written a patch which adds NEON support to FrameBufferBltLib to
> > increase the rendering performance(by a lot actually) for 24bit displays
> > and thought about sending it to the mailing list - that's why the
question
> > came up.
> >

> The reason for the difference between AArch64 and the other EFI
> architectures is that AArch64 does not have a softfloat ABI, so it is
> impossible to compile floating point code [portably] without enabling
> VFP/NEON. This is why AArch64 is the exception here.

> Currently, the AArch32 CPU context structure [EFI_SYSTEM_CONTEXT_ARM]
> does not cover VFP/NEON registers, and so they are not
> preserved/restored when an interrupt is taken. This means you cannot
> use VFP/NEON registers in an event handler or you will corrupt the
> VFP/NEON state of the interrupted context.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reasoning beehind prohibiting VFP/NEON on AArch32
  2018-05-13  9:48   ` Michael Zimmermann
@ 2018-05-13 10:16     ` Ard Biesheuvel
  2018-05-13 10:58       ` Michael Zimmermann
  0 siblings, 1 reply; 7+ messages in thread
From: Ard Biesheuvel @ 2018-05-13 10:16 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 13 May 2018 at 11:48, Michael Zimmermann <sigmaepsilon92@gmail.com> wrote:
> So basically using them should be safe as long as you're in
> EfiGetCurrentTpl() < TPL_HIGH_LEVEL, right?

No, the other way around. You should raise the TPL to TPL_HIGH_LEVEL
to prevent being interrupted by something that may corrupt the NEON
registers.

> Also, it'd probably be trivial to add  VFP/NEON regs to
> EFI_SYSTEM_CONTEXT_ARM though that wouldn't help when writing apps for
> existing uefi platforms.

EFI_SYSTEM_CONTEXT_ARM is covered by the UEFI spec, so that is not
going to change.

> On Sun, May 13, 2018 at 9:32 AM Ard Biesheuvel <ard.biesheuvel@linaro.org>
> wrote:
>
>> On 12 May 2018 at 23:11, Michael Zimmermann <sigmaepsilon92@gmail.com>
> wrote:
>> > For AArch32 the spec says in 2.3.5.3:
>> >> Floating point, SIMD, vector operations and other instruction set
>> > extensions must not
>> > be used.
>> >
>> > For AArch64 the spec says in 2.3.6.4:
>> >> Floating point and SIMD instructions may be used.
>> >
>> > So is there a reason why AArch32 is not allowed to use Floating point
>> > operations?
>> > I'd understand if this restriction was limited to runtime services only
> but
>> > I don't see how it makes sense for boot services.
>> >
>> > I've written a patch which adds NEON support to FrameBufferBltLib to
>> > increase the rendering performance(by a lot actually) for 24bit displays
>> > and thought about sending it to the mailing list - that's why the
> question
>> > came up.
>> >
>
>> The reason for the difference between AArch64 and the other EFI
>> architectures is that AArch64 does not have a softfloat ABI, so it is
>> impossible to compile floating point code [portably] without enabling
>> VFP/NEON. This is why AArch64 is the exception here.
>
>> Currently, the AArch32 CPU context structure [EFI_SYSTEM_CONTEXT_ARM]
>> does not cover VFP/NEON registers, and so they are not
>> preserved/restored when an interrupt is taken. This means you cannot
>> use VFP/NEON registers in an event handler or you will corrupt the
>> VFP/NEON state of the interrupted context.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reasoning beehind prohibiting VFP/NEON on AArch32
  2018-05-13 10:16     ` Ard Biesheuvel
@ 2018-05-13 10:58       ` Michael Zimmermann
  2018-05-13 11:39         ` Ard Biesheuvel
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Zimmermann @ 2018-05-13 10:58 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

> No, the other way around. You should raise the TPL to TPL_HIGH_LEVEL
> to prevent being interrupted by something that may corrupt the NEON
> registers.
But isn't that only necessary if you assume that interrupt-handlers use VFP
registers?
afaik on ARM <TPL_HIGH_LEVEL events are never called from the timer
interrupt handler so basically if you're going to be interrupted during VFP
operations no other <TPL_HIGH_LEVEL code should ever run.

Please correct me if I'm misunderstanding something.
On Sun, May 13, 2018 at 12:16 PM Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 13 May 2018 at 11:48, Michael Zimmermann <sigmaepsilon92@gmail.com>
wrote:
> > So basically using them should be safe as long as you're in
> > EfiGetCurrentTpl() < TPL_HIGH_LEVEL, right?

> No, the other way around. You should raise the TPL to TPL_HIGH_LEVEL
> to prevent being interrupted by something that may corrupt the NEON
> registers.

> > Also, it'd probably be trivial to add  VFP/NEON regs to
> > EFI_SYSTEM_CONTEXT_ARM though that wouldn't help when writing apps for
> > existing uefi platforms.

> EFI_SYSTEM_CONTEXT_ARM is covered by the UEFI spec, so that is not
> going to change.

> > On Sun, May 13, 2018 at 9:32 AM Ard Biesheuvel <
ard.biesheuvel@linaro.org>
> > wrote:
> >
> >> On 12 May 2018 at 23:11, Michael Zimmermann <sigmaepsilon92@gmail.com>
> > wrote:
> >> > For AArch32 the spec says in 2.3.5.3:
> >> >> Floating point, SIMD, vector operations and other instruction set
> >> > extensions must not
> >> > be used.
> >> >
> >> > For AArch64 the spec says in 2.3.6.4:
> >> >> Floating point and SIMD instructions may be used.
> >> >
> >> > So is there a reason why AArch32 is not allowed to use Floating point
> >> > operations?
> >> > I'd understand if this restriction was limited to runtime services
only
> > but
> >> > I don't see how it makes sense for boot services.
> >> >
> >> > I've written a patch which adds NEON support to FrameBufferBltLib to
> >> > increase the rendering performance(by a lot actually) for 24bit
displays
> >> > and thought about sending it to the mailing list - that's why the
> > question
> >> > came up.
> >> >
> >
> >> The reason for the difference between AArch64 and the other EFI
> >> architectures is that AArch64 does not have a softfloat ABI, so it is
> >> impossible to compile floating point code [portably] without enabling
> >> VFP/NEON. This is why AArch64 is the exception here.
> >
> >> Currently, the AArch32 CPU context structure [EFI_SYSTEM_CONTEXT_ARM]
> >> does not cover VFP/NEON registers, and so they are not
> >> preserved/restored when an interrupt is taken. This means you cannot
> >> use VFP/NEON registers in an event handler or you will corrupt the
> >> VFP/NEON state of the interrupted context.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reasoning beehind prohibiting VFP/NEON on AArch32
  2018-05-13 10:58       ` Michael Zimmermann
@ 2018-05-13 11:39         ` Ard Biesheuvel
  2018-05-13 12:49           ` Michael Zimmermann
  0 siblings, 1 reply; 7+ messages in thread
From: Ard Biesheuvel @ 2018-05-13 11:39 UTC (permalink / raw)
  To: Michael Zimmermann; +Cc: edk2-devel@lists.01.org, Leif Lindholm

On 13 May 2018 at 12:58, Michael Zimmermann <sigmaepsilon92@gmail.com> wrote:
>> No, the other way around. You should raise the TPL to TPL_HIGH_LEVEL
>> to prevent being interrupted by something that may corrupt the NEON
>> registers.
> But isn't that only necessary if you assume that interrupt-handlers use VFP
> registers?

Event handlers are called from the timer interrupt handler. So unless
you want to restrict use of the NEON to non-event handler context
(which is not generally possible for libraries), you will need to
raise the TPL to avoid any interruptions.

> afaik on ARM <TPL_HIGH_LEVEL events are never called from the timer
> interrupt handler so basically if you're going to be interrupted during VFP
> operations no other <TPL_HIGH_LEVEL code should ever run.
>
> Please correct me if I'm misunderstanding something.

I don't follow. Your NEON code running at TPL_APPLICATION may be
interrupted at any time by event handlers running at higher TPL
levels. If such code uses the NEON, it will corrupt your register
file.



> On Sun, May 13, 2018 at 12:16 PM Ard Biesheuvel <ard.biesheuvel@linaro.org>
> wrote:
>
>> On 13 May 2018 at 11:48, Michael Zimmermann <sigmaepsilon92@gmail.com>
> wrote:
>> > So basically using them should be safe as long as you're in
>> > EfiGetCurrentTpl() < TPL_HIGH_LEVEL, right?
>
>> No, the other way around. You should raise the TPL to TPL_HIGH_LEVEL
>> to prevent being interrupted by something that may corrupt the NEON
>> registers.
>
>> > Also, it'd probably be trivial to add  VFP/NEON regs to
>> > EFI_SYSTEM_CONTEXT_ARM though that wouldn't help when writing apps for
>> > existing uefi platforms.
>
>> EFI_SYSTEM_CONTEXT_ARM is covered by the UEFI spec, so that is not
>> going to change.
>
>> > On Sun, May 13, 2018 at 9:32 AM Ard Biesheuvel <
> ard.biesheuvel@linaro.org>
>> > wrote:
>> >
>> >> On 12 May 2018 at 23:11, Michael Zimmermann <sigmaepsilon92@gmail.com>
>> > wrote:
>> >> > For AArch32 the spec says in 2.3.5.3:
>> >> >> Floating point, SIMD, vector operations and other instruction set
>> >> > extensions must not
>> >> > be used.
>> >> >
>> >> > For AArch64 the spec says in 2.3.6.4:
>> >> >> Floating point and SIMD instructions may be used.
>> >> >
>> >> > So is there a reason why AArch32 is not allowed to use Floating point
>> >> > operations?
>> >> > I'd understand if this restriction was limited to runtime services
> only
>> > but
>> >> > I don't see how it makes sense for boot services.
>> >> >
>> >> > I've written a patch which adds NEON support to FrameBufferBltLib to
>> >> > increase the rendering performance(by a lot actually) for 24bit
> displays
>> >> > and thought about sending it to the mailing list - that's why the
>> > question
>> >> > came up.
>> >> >
>> >
>> >> The reason for the difference between AArch64 and the other EFI
>> >> architectures is that AArch64 does not have a softfloat ABI, so it is
>> >> impossible to compile floating point code [portably] without enabling
>> >> VFP/NEON. This is why AArch64 is the exception here.
>> >
>> >> Currently, the AArch32 CPU context structure [EFI_SYSTEM_CONTEXT_ARM]
>> >> does not cover VFP/NEON registers, and so they are not
>> >> preserved/restored when an interrupt is taken. This means you cannot
>> >> use VFP/NEON registers in an event handler or you will corrupt the
>> >> VFP/NEON state of the interrupted context.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: reasoning beehind prohibiting VFP/NEON on AArch32
  2018-05-13 11:39         ` Ard Biesheuvel
@ 2018-05-13 12:49           ` Michael Zimmermann
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Zimmermann @ 2018-05-13 12:49 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel@lists.01.org, Leif Lindholm

I looked at ARMs TimerDxe and saw that mTimerNotifyFunction is called with
TPL_HIGH_LEVEL but didn't realize that RestoreTPL would call all pending
events.

Thank you for your help.
On Sun, May 13, 2018 at 1:39 PM Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> On 13 May 2018 at 12:58, Michael Zimmermann <sigmaepsilon92@gmail.com>
wrote:
> >> No, the other way around. You should raise the TPL to TPL_HIGH_LEVEL
> >> to prevent being interrupted by something that may corrupt the NEON
> >> registers.
> > But isn't that only necessary if you assume that interrupt-handlers use
VFP
> > registers?

> Event handlers are called from the timer interrupt handler. So unless
> you want to restrict use of the NEON to non-event handler context
> (which is not generally possible for libraries), you will need to
> raise the TPL to avoid any interruptions.

> > afaik on ARM <TPL_HIGH_LEVEL events are never called from the timer
> > interrupt handler so basically if you're going to be interrupted during
VFP
> > operations no other <TPL_HIGH_LEVEL code should ever run.
> >
> > Please correct me if I'm misunderstanding something.

> I don't follow. Your NEON code running at TPL_APPLICATION may be
> interrupted at any time by event handlers running at higher TPL
> levels. If such code uses the NEON, it will corrupt your register
> file.



> > On Sun, May 13, 2018 at 12:16 PM Ard Biesheuvel <
ard.biesheuvel@linaro.org>
> > wrote:
> >
> >> On 13 May 2018 at 11:48, Michael Zimmermann <sigmaepsilon92@gmail.com>
> > wrote:
> >> > So basically using them should be safe as long as you're in
> >> > EfiGetCurrentTpl() < TPL_HIGH_LEVEL, right?
> >
> >> No, the other way around. You should raise the TPL to TPL_HIGH_LEVEL
> >> to prevent being interrupted by something that may corrupt the NEON
> >> registers.
> >
> >> > Also, it'd probably be trivial to add  VFP/NEON regs to
> >> > EFI_SYSTEM_CONTEXT_ARM though that wouldn't help when writing apps
for
> >> > existing uefi platforms.
> >
> >> EFI_SYSTEM_CONTEXT_ARM is covered by the UEFI spec, so that is not
> >> going to change.
> >
> >> > On Sun, May 13, 2018 at 9:32 AM Ard Biesheuvel <
> > ard.biesheuvel@linaro.org>
> >> > wrote:
> >> >
> >> >> On 12 May 2018 at 23:11, Michael Zimmermann <
sigmaepsilon92@gmail.com>
> >> > wrote:
> >> >> > For AArch32 the spec says in 2.3.5.3:
> >> >> >> Floating point, SIMD, vector operations and other instruction set
> >> >> > extensions must not
> >> >> > be used.
> >> >> >
> >> >> > For AArch64 the spec says in 2.3.6.4:
> >> >> >> Floating point and SIMD instructions may be used.
> >> >> >
> >> >> > So is there a reason why AArch32 is not allowed to use Floating
point
> >> >> > operations?
> >> >> > I'd understand if this restriction was limited to runtime services
> > only
> >> > but
> >> >> > I don't see how it makes sense for boot services.
> >> >> >
> >> >> > I've written a patch which adds NEON support to FrameBufferBltLib
to
> >> >> > increase the rendering performance(by a lot actually) for 24bit
> > displays
> >> >> > and thought about sending it to the mailing list - that's why the
> >> > question
> >> >> > came up.
> >> >> >
> >> >
> >> >> The reason for the difference between AArch64 and the other EFI
> >> >> architectures is that AArch64 does not have a softfloat ABI, so it
is
> >> >> impossible to compile floating point code [portably] without
enabling
> >> >> VFP/NEON. This is why AArch64 is the exception here.
> >> >
> >> >> Currently, the AArch32 CPU context structure
[EFI_SYSTEM_CONTEXT_ARM]
> >> >> does not cover VFP/NEON registers, and so they are not
> >> >> preserved/restored when an interrupt is taken. This means you cannot
> >> >> use VFP/NEON registers in an event handler or you will corrupt the
> >> >> VFP/NEON state of the interrupted context.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-05-13 12:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-12 21:11 reasoning beehind prohibiting VFP/NEON on AArch32 Michael Zimmermann
2018-05-13  7:32 ` Ard Biesheuvel
2018-05-13  9:48   ` Michael Zimmermann
2018-05-13 10:16     ` Ard Biesheuvel
2018-05-13 10:58       ` Michael Zimmermann
2018-05-13 11:39         ` Ard Biesheuvel
2018-05-13 12:49           ` Michael Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox