tailieunhanh - REAL-TIME SYSTEMS DESIGN AND ANALYSIS phần 8
Sử dụng trong khi các vòng so với các vòng hoặc làm trong khi các vòng. Khi "cuộn" vòng, có nghĩa là, để thay thế xây dựng vòng lặp với mã lặp đi lặp lại (do đó tiết kiệm chi phí vòng lặp cũng như cung cấp các trình biên dịch cơ hội để hướng dẫn sử dụng chế độ nhanh hơn, trực tiếp hoặc gián tiếp duy nhất). | CODING STANDARDS 347 Other language constructs that may need to be considered include Use of while loops versus for loops or do-while loops. When to unroll loops that is to replace the looping construct with repetitive code thus saving the loop overhead as well as providing the compiler the opportunity to use faster direct or single indirect mode instructions . Comparison of variable types and their uses . when to use short integer in C versus Boolean when to use single precision versus double precision floating point and so forth . Use of in-line expansion of code via macros versus procedure calls. This is by no means an exhaustive list. While good compilers should provide optimization of the assembly language code output so as to in many cases make the decisions just listed it is important to discover what that optimization is doing to produce the resultant code. For example compiler output can be affected by optimization for speed memory and register usage jumps and so on which can lead to inefficient code timing problems or critical regions. Thus real-time systems engineers must be masters of their compilers. That is at all times the engineer must know what assembly language code will be output for a given high-order language statement. A full understanding of each compiler can only be accomplished by developing a set of test cases to exercise it. The conclusions suggested by these tests can be included in the set of coding standards to foster improved use of the language and ultimately improved system performance. When building real-time systems no matter which language bear in mind these rules of thumb Avoid recursion and other nondeterministic constructs where possible . Avoid unbounded while loops and other temporally unbounded structures. Avoid priority inversion situations. Avoid overengineering gold-plating. Know your compiler CODING STANDARDS Coding standards are different from language standards. A language standard for example ANSI C .
đang nạp các trang xem trước