linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Documentation/CodingStyle: Add guidelines for inline assembly
@ 2012-02-02 22:33 Josh Triplett
  2012-03-20 20:46 ` Randy Dunlap
  0 siblings, 1 reply; 2+ messages in thread
From: Josh Triplett @ 2012-02-02 22:33 UTC (permalink / raw)
  To: linux-kernel, linux-doc; +Cc: Randy Dunlap, Linus Torvalds, Joe Perches

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---
 Documentation/CodingStyle |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index 2b90d32..c58b236 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -793,6 +793,35 @@ own custom mode, or may have some other magic method for making indentation
 work correctly.
 
 
+		Chapter 19:  Inline assembly
+
+In architecture-specific code, you may need to use inline assembly to interface
+with CPU or platform functionality.  Don't hesitate to do so when necessary.
+However, don't use inline assembly gratuitously when C can do the job.  You can
+and should poke hardware from C when possible.
+
+Consider writing simple helper functions that wrap common bits of inline
+assembly, rather than repeatedly writing them with slight variations.  Remember
+that inline assembly can use C parameters.
+
+Large, non-trivial assembly functions should go in .S files, with corresponding
+C prototypes defined in C header files.  The C prototypes for assembly
+functions should use "asmlinkage".
+
+You may need to mark your asm statement as volatile, to prevent GCC from
+removing it if GCC doesn't notice any side effects.  You don't always need to
+do so, though, and doing so unnecessarily can limit optimization.
+
+When writing a single inline assembly statement containing multiple
+instructions, put each instruction on a separate line in a separate quoted
+string, and end each string except the last with \n\t to properly indent the
+next instruction in the assembly output:
+
+	asm ("magic %reg1, #42\n\t"
+	     "more_magic %reg2, %reg3"
+	     : /* outputs */ : /* inputs */ : /* clobbers */);
+
+
 
 		Appendix I: References
 
-- 
1.7.9


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

* Re: [PATCH] Documentation/CodingStyle: Add guidelines for inline assembly
  2012-02-02 22:33 [PATCH] Documentation/CodingStyle: Add guidelines for inline assembly Josh Triplett
@ 2012-03-20 20:46 ` Randy Dunlap
  0 siblings, 0 replies; 2+ messages in thread
From: Randy Dunlap @ 2012-03-20 20:46 UTC (permalink / raw)
  To: Josh Triplett; +Cc: linux-kernel, linux-doc, Linus Torvalds, Joe Perches

On 02/02/2012 02:33 PM, Josh Triplett wrote:

> Signed-off-by: Josh Triplett <josh@joshtriplett.org>



Applied.  Thanks.


> ---
>  Documentation/CodingStyle |   29 +++++++++++++++++++++++++++++
>  1 files changed, 29 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
> index 2b90d32..c58b236 100644
> --- a/Documentation/CodingStyle
> +++ b/Documentation/CodingStyle
> @@ -793,6 +793,35 @@ own custom mode, or may have some other magic method for making indentation
>  work correctly.
>  
>  
> +		Chapter 19:  Inline assembly
> +
> +In architecture-specific code, you may need to use inline assembly to interface
> +with CPU or platform functionality.  Don't hesitate to do so when necessary.
> +However, don't use inline assembly gratuitously when C can do the job.  You can
> +and should poke hardware from C when possible.
> +
> +Consider writing simple helper functions that wrap common bits of inline
> +assembly, rather than repeatedly writing them with slight variations.  Remember
> +that inline assembly can use C parameters.
> +
> +Large, non-trivial assembly functions should go in .S files, with corresponding
> +C prototypes defined in C header files.  The C prototypes for assembly
> +functions should use "asmlinkage".
> +
> +You may need to mark your asm statement as volatile, to prevent GCC from
> +removing it if GCC doesn't notice any side effects.  You don't always need to
> +do so, though, and doing so unnecessarily can limit optimization.
> +
> +When writing a single inline assembly statement containing multiple
> +instructions, put each instruction on a separate line in a separate quoted
> +string, and end each string except the last with \n\t to properly indent the
> +next instruction in the assembly output:
> +
> +	asm ("magic %reg1, #42\n\t"
> +	     "more_magic %reg2, %reg3"
> +	     : /* outputs */ : /* inputs */ : /* clobbers */);
> +
> +
>  
>  		Appendix I: References
>  



-- 
~Randy

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

end of thread, other threads:[~2012-03-20 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-02 22:33 [PATCH] Documentation/CodingStyle: Add guidelines for inline assembly Josh Triplett
2012-03-20 20:46 ` Randy Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).