diff options
author | Josh Triplett <josh@joshtriplett.org> | 2012-03-30 16:37:10 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-30 19:03:15 -0400 |
commit | 9a7c48b7c3d58835b3a91d86c55e0ae77d15ddd5 (patch) | |
tree | 9a7728d24c9721d7e9e5458b7f76d565265fa9ae /Documentation | |
parent | 21106b0114f75cff199d6834f676877c3edae928 (diff) |
Documentation: CodingStyle: add inline assembly guidelines
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/CodingStyle | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index 2b90d328b3ba..c58b236bbe04 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle | |||
@@ -793,6 +793,35 @@ own custom mode, or may have some other magic method for making indentation | |||
793 | work correctly. | 793 | work correctly. |
794 | 794 | ||
795 | 795 | ||
796 | Chapter 19: Inline assembly | ||
797 | |||
798 | In architecture-specific code, you may need to use inline assembly to interface | ||
799 | with CPU or platform functionality. Don't hesitate to do so when necessary. | ||
800 | However, don't use inline assembly gratuitously when C can do the job. You can | ||
801 | and should poke hardware from C when possible. | ||
802 | |||
803 | Consider writing simple helper functions that wrap common bits of inline | ||
804 | assembly, rather than repeatedly writing them with slight variations. Remember | ||
805 | that inline assembly can use C parameters. | ||
806 | |||
807 | Large, non-trivial assembly functions should go in .S files, with corresponding | ||
808 | C prototypes defined in C header files. The C prototypes for assembly | ||
809 | functions should use "asmlinkage". | ||
810 | |||
811 | You may need to mark your asm statement as volatile, to prevent GCC from | ||
812 | removing it if GCC doesn't notice any side effects. You don't always need to | ||
813 | do so, though, and doing so unnecessarily can limit optimization. | ||
814 | |||
815 | When writing a single inline assembly statement containing multiple | ||
816 | instructions, put each instruction on a separate line in a separate quoted | ||
817 | string, and end each string except the last with \n\t to properly indent the | ||
818 | next instruction in the assembly output: | ||
819 | |||
820 | asm ("magic %reg1, #42\n\t" | ||
821 | "more_magic %reg2, %reg3" | ||
822 | : /* outputs */ : /* inputs */ : /* clobbers */); | ||
823 | |||
824 | |||
796 | 825 | ||
797 | Appendix I: References | 826 | Appendix I: References |
798 | 827 | ||