Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

CodeStyleGuide

Zhongwei Yao edited this page · 6 revisions

Ne10 Code Style

C

Besides the style defined below, Ne10 C generally follows Linux kernel coding style: https://www.kernel.org/doc/Documentation/CodingStyle

"if" statement

Each single file must use a consistent formatting style. Currently used in NE10 C files and recommended formatting style looks as follows:

   1     if (a > 5)
   2     {
   3         int b = a * a;
   4         c = c > b ? c : b + 1;
   5     }
   6     else if (abs (a) < 5)
   7     {
   8         c--;
   9     }
  10     else
  11     {
  12         printf ("a=%d is far to negative\n", a);
  13     }

Comment

/* This is a comment. */
void main (void)
{
    int i; // This is a comment.
}

Macro

#define FOO
#define NE10_ADD1(X) ((X) + 1)
#define NE10_CPX_ADD(Z,A,B) \
    do { \
        Z.r = A.r + B.r; \
        Z.i = A.i + B.i; \
    } while (0)

Pointers

TODO(PhilWang) There are two place we can put the "const". I prefer this one.
    const ne10_fft_cpx_float32 *Fin = NULL;

Assembly

Each single file must use a consistent formatting style. Currently used in NE10 assembly files and recommended formatting style looks as follows:

  • comments: /**/, both single line and multi-line
  • file description: no indent
  • function description: 8-space indent
  • directive: 8-space indent, lowercase
  • marco name: upper case
  • register alias: 8-space indent, lowercase
  • instruction: 8-space indent, lowercase, the width of instruction is 16 character.
  • label: 1 blank line before the label, no indent, lowercase and '_' mixed
/*
 * file description
 * 
 */
        .text
        .syntax unified

        /**
         * function description
         */

        .align 4
        .global
        .thumb
        .thumb_func
        .equ BITS, 0x16

ne10_vresize_neon:
        push {r4-r6,lr}

        /*ARM Registers*/
        src .req r0
        beta .req r1

        /*NEON variale Declaration*/
        d_beta0 .dn d0

        ldr             beta, [src]
        vmov.s32        d_beta0, beta

vresize_end:
        /*Return From Function*/
        pop     {r4-r6,pc}

        /*ARM Registers*/
        .unreq src
        .unreq beta

        /*NEON variale Declaration*/
        .unreq d_beta0

Misc

  • Filenames are written in lower-case letters with upper-case prefix "NE10".
  • Headers have .h extension.
  • Implementation files have .c, .neon.c, .neon.s, .asm.s, extension
  • Every file includes apache license in the beginning
  • Do not use tabulation. Indentation is 4 spaces. Lines should not be much longer than ~100 characters.
  • Keep consistent formatting style in each particular source file (especially if you modify the existing code).
  • Only English should be used in comments and string literals.
  • External function names and data type names are written in mixed case. functions start with "NE10". External macros are written in upper case.
  • Use EXTERN_C macro within external functions.
  • Provide documentation for your code
Something went wrong with that request. Please try again.