All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] parisc: Prevent using same register as soure and target in extru/shr
@ 2022-05-17 12:49 Helge Deller
  2022-05-17 12:54 ` Helge Deller
  0 siblings, 1 reply; 5+ messages in thread
From: Helge Deller @ 2022-05-17 12:49 UTC (permalink / raw)
  To: linux-parisc, James Bottomley, John David Anglin

In 2004 Randolph added the shr() assembly macro and noted that the
source and target register could not be the same.

I did not find any confindence in the docs for this restriction. Maybe
it's related that on PA2.0 the upper bits may be clobbered?

Anyway, add a compile-time check for it now.

Signed-off-by: Helge Deller <deller@gmx.de>

diff --git a/arch/parisc/include/asm/assembly.h b/arch/parisc/include/asm/assembly.h
index ea0cb318b13d..ca1a12ae5ee7 100644
--- a/arch/parisc/include/asm/assembly.h
+++ b/arch/parisc/include/asm/assembly.h
@@ -146,6 +146,9 @@
 	/* Shift Right - note the r and t can NOT be the same! */
 	.macro shr r, sa, t
 	extru \r, 31-(\sa), 32-(\sa), \t
+.ifc \r,\t
+        .error "Can not used the same register (\r) in shr/extru as source and target register."
+.endif
 	.endm

 	/* pa20w version of shift right */

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

* Re: [PATCH] parisc: Prevent using same register as soure and target in extru/shr
  2022-05-17 12:49 [PATCH] parisc: Prevent using same register as soure and target in extru/shr Helge Deller
@ 2022-05-17 12:54 ` Helge Deller
  2022-05-17 13:41   ` John David Anglin
  2022-05-18  6:57   ` Sven Schnelle
  0 siblings, 2 replies; 5+ messages in thread
From: Helge Deller @ 2022-05-17 12:54 UTC (permalink / raw)
  To: linux-parisc, James Bottomley, John David Anglin

On 5/17/22 14:49, Helge Deller wrote:
> In 2004 Randolph added the shr() assembly macro and noted that the
> source and target register could not be the same.
>
> I did not find any confindence in the docs for this restriction. Maybe
> it's related that on PA2.0 the upper bits may be clobbered?

Looking at the generated kernel code from C-files, I'll find all over usages of
	extru source, x,y,  target
where source and target are the same register.
So, at least for 32-bit this restriction can't be true.

Any ideas why this restriction could have been added to the comments?

Helge


> Anyway, add a compile-time check for it now.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
>
> diff --git a/arch/parisc/include/asm/assembly.h b/arch/parisc/include/asm/assembly.h
> index ea0cb318b13d..ca1a12ae5ee7 100644
> --- a/arch/parisc/include/asm/assembly.h
> +++ b/arch/parisc/include/asm/assembly.h
> @@ -146,6 +146,9 @@
>  	/* Shift Right - note the r and t can NOT be the same! */
>  	.macro shr r, sa, t
>  	extru \r, 31-(\sa), 32-(\sa), \t
> +.ifc \r,\t
> +        .error "Can not used the same register (\r) in shr/extru as source and target register."
> +.endif
>  	.endm
>
>  	/* pa20w version of shift right */


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

* Re: [PATCH] parisc: Prevent using same register as soure and target in extru/shr
  2022-05-17 12:54 ` Helge Deller
@ 2022-05-17 13:41   ` John David Anglin
  2022-05-18  6:57   ` Sven Schnelle
  1 sibling, 0 replies; 5+ messages in thread
From: John David Anglin @ 2022-05-17 13:41 UTC (permalink / raw)
  To: Helge Deller, linux-parisc, James Bottomley

I'm not aware of any PA-RISC instructions where the source and target registers can't be the same.

In gcc asm statements, there are early clobber situations where the source and target can't be the same.
The same situation could occur in assembler macros but never when there's a single instruction.

The only thing unusual about the extru instruction is the most significant 32 bits in the target are undefined
on PA 2.0.  Thus, its use needs to be limited to 32-bit extracts.

Dave

On 2022-05-17 8:54 a.m., Helge Deller wrote:
> On 5/17/22 14:49, Helge Deller wrote:
>> In 2004 Randolph added the shr() assembly macro and noted that the
>> source and target register could not be the same.
>>
>> I did not find any confindence in the docs for this restriction. Maybe
>> it's related that on PA2.0 the upper bits may be clobbered?
> Looking at the generated kernel code from C-files, I'll find all over usages of
> 	extru source, x,y,  target
> where source and target are the same register.
> So, at least for 32-bit this restriction can't be true.
>
> Any ideas why this restriction could have been added to the comments?
>
> Helge
>
>
>> Anyway, add a compile-time check for it now.
>>
>> Signed-off-by: Helge Deller <deller@gmx.de>
>>
>> diff --git a/arch/parisc/include/asm/assembly.h b/arch/parisc/include/asm/assembly.h
>> index ea0cb318b13d..ca1a12ae5ee7 100644
>> --- a/arch/parisc/include/asm/assembly.h
>> +++ b/arch/parisc/include/asm/assembly.h
>> @@ -146,6 +146,9 @@
>>   	/* Shift Right - note the r and t can NOT be the same! */
>>   	.macro shr r, sa, t
>>   	extru \r, 31-(\sa), 32-(\sa), \t
>> +.ifc \r,\t
>> +        .error "Can not used the same register (\r) in shr/extru as source and target register."
>> +.endif
>>   	.endm
>>
>>   	/* pa20w version of shift right */


-- 
John David Anglin  dave.anglin@bell.net


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

* Re: [PATCH] parisc: Prevent using same register as soure and target in extru/shr
  2022-05-17 12:54 ` Helge Deller
  2022-05-17 13:41   ` John David Anglin
@ 2022-05-18  6:57   ` Sven Schnelle
  2022-05-18  7:10     ` Helge Deller
  1 sibling, 1 reply; 5+ messages in thread
From: Sven Schnelle @ 2022-05-18  6:57 UTC (permalink / raw)
  To: Helge Deller; +Cc: linux-parisc, James Bottomley, John David Anglin

Helge Deller <deller@gmx.de> writes:

> On 5/17/22 14:49, Helge Deller wrote:
>> In 2004 Randolph added the shr() assembly macro and noted that the
>> source and target register could not be the same.
>>
>> I did not find any confindence in the docs for this restriction. Maybe
>> it's related that on PA2.0 the upper bits may be clobbered?
>
> Looking at the generated kernel code from C-files, I'll find all over usages of
> 	extru source, x,y,  target
> where source and target are the same register.
> So, at least for 32-bit this restriction can't be true.

I did a quick objdump on the 64 bit HP-UX kernel and that one also uses
extrd/extrw where target and source are the same register. So i don't
think that restriction is true.

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

* Re: [PATCH] parisc: Prevent using same register as soure and target in extru/shr
  2022-05-18  6:57   ` Sven Schnelle
@ 2022-05-18  7:10     ` Helge Deller
  0 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2022-05-18  7:10 UTC (permalink / raw)
  To: Sven Schnelle; +Cc: linux-parisc, James Bottomley, John David Anglin

On 5/18/22 08:57, Sven Schnelle wrote:
> Helge Deller <deller@gmx.de> writes:
>
>> On 5/17/22 14:49, Helge Deller wrote:
>>> In 2004 Randolph added the shr() assembly macro and noted that the
>>> source and target register could not be the same.
>>>
>>> I did not find any confindence in the docs for this restriction. Maybe
>>> it's related that on PA2.0 the upper bits may be clobbered?
>>
>> Looking at the generated kernel code from C-files, I'll find all over usages of
>> 	extru source, x,y,  target
>> where source and target are the same register.
>> So, at least for 32-bit this restriction can't be true.
>
> I did a quick objdump on the 64 bit HP-UX kernel and that one also uses
> extrd/extrw where target and source are the same register. So i don't
> think that restriction is true.

Thanks for checking!
Maybe it's meant that it clobbers when running *32-bit* code on PA2.0?
Just a thought...

Helge

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

end of thread, other threads:[~2022-05-18  7:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17 12:49 [PATCH] parisc: Prevent using same register as soure and target in extru/shr Helge Deller
2022-05-17 12:54 ` Helge Deller
2022-05-17 13:41   ` John David Anglin
2022-05-18  6:57   ` Sven Schnelle
2022-05-18  7:10     ` Helge Deller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.