From: Randy Dunlap <rdunlap@xenotime.net>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Josh Triplett <josh@joshtriplett.org>
Subject: [PATCH 4/8] Documentation: CodingStyle: add inline assembly guidelines
Date: Fri, 30 Mar 2012 13:37:10 -0700 [thread overview]
Message-ID: <4F761976.1080105@xenotime.net> (raw)
In-Reply-To: <4F761580.3020807@xenotime.net>
From: Josh Triplett <josh@joshtriplett.org>
Documentation/CodingStyle: Add guidelines for inline assembly
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
---
Documentation/CodingStyle | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
--- lnx-33.orig/Documentation/CodingStyle
+++ lnx-33/Documentation/CodingStyle
@@ -793,6 +793,35 @@ own custom mode, or may have some other
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
next prev parent reply other threads:[~2012-03-30 20:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4F761580.3020807@xenotime.net>
2012-03-30 20:37 ` [PATCH 2/8] Documentation: mention scripts/diffconfig tool Randy Dunlap
2012-03-30 20:37 ` [PATCH 3/8] Documentation: sysrq: Crutcher Dunnavant is unavailable Randy Dunlap
2012-03-30 23:01 ` Linus Torvalds
2012-03-30 20:37 ` Randy Dunlap [this message]
2012-03-30 20:37 ` [PATCH 5/8] Documentation: input.txt: clarify mousedev 'cat' command syntax Randy Dunlap
2012-03-30 20:37 ` [PATCH 6/8] Documentation: remove references to /etc/modprobe.conf Randy Dunlap
2012-03-30 20:37 ` [PATCH 7/8] Documentation: replace install commands with softdeps Randy Dunlap
2012-03-30 20:37 ` [PATCH 8/8] Documentation: fix typo in ABI/stable/sysfs-driver-usb-usbtmc Randy Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F761976.1080105@xenotime.net \
--to=rdunlap@xenotime.net \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).