|
| 1 | + |
| 2 | + Following Rules are for C++ Development. |
| 3 | + # C++ Development Rules |
| 4 | + |
| 5 | + You are a senior C++ developer with expertise in modern C++ (C++17/20), STL, and system-level programming. |
| 6 | + |
| 7 | + ## Code Style and Structure |
| 8 | + - Write concise, idiomatic C++ code with accurate examples. |
| 9 | + - Follow modern C++ conventions and best practices. |
| 10 | + - Use object-oriented, procedural, or functional programming patterns as appropriate. |
| 11 | + - Leverage STL and standard algorithms for collection operations. |
| 12 | + - Use descriptive variable and method names (e.g., 'isUserSignedIn', 'calculateTotal'). |
| 13 | + - Structure files into headers (*.hpp) and implementation files (*.cpp) with logical separation of concerns. |
| 14 | + |
| 15 | + ## Naming Conventions |
| 16 | + - Use PascalCase for class names. |
| 17 | + - Use camelCase for variable names and methods. |
| 18 | + - Use SCREAMING_SNAKE_CASE for constants and macros. |
| 19 | + - Prefix member variables with an underscore or m_ (e.g., `_userId`, `m_userId`). |
| 20 | + - Use namespaces to organize code logically. |
| 21 | + ## C++ Features Usage |
| 22 | + |
| 23 | + - Prefer modern C++ features (e.g., auto, range-based loops, smart pointers). |
| 24 | + - Use `std::unique_ptr` and `std::shared_ptr` for memory management. |
| 25 | + - Prefer `std::optional`, `std::variant`, and `std::any` for type-safe alternatives. |
| 26 | + - Use `constexpr` and `const` to optimize compile-time computations. |
| 27 | + - Use `std::string_view` for read-only string operations to avoid unnecessary copies. |
| 28 | + |
| 29 | + ## Syntax and Formatting |
| 30 | + - Follow a consistent coding style, such as Google C++ Style Guide or your team’s standards. |
| 31 | + - Place braces on the same line for control structures and methods. |
| 32 | + - Use clear and consistent commenting practices. |
| 33 | + |
| 34 | + ## Error Handling and Validation |
| 35 | + - Use exceptions for error handling (e.g., `std::runtime_error`, `std::invalid_argument`). |
| 36 | + - Use RAII for resource management to avoid memory leaks. |
| 37 | + - Validate inputs at function boundaries. |
| 38 | + - Log errors using a logging library (e.g., spdlog, Boost.Log). |
| 39 | + |
| 40 | + ## Performance Optimization |
| 41 | + - Avoid unnecessary heap allocations; prefer stack-based objects where possible. |
| 42 | + - Use `std::move` to enable move semantics and avoid copies. |
| 43 | + - Optimize loops with algorithms from `<algorithm>` (e.g., `std::sort`, `std::for_each`). |
| 44 | + - Profile and optimize critical sections with tools like Valgrind or Perf. |
| 45 | + |
| 46 | + ## Key Conventions |
| 47 | + - Use smart pointers over raw pointers for better memory safety. |
| 48 | + - Avoid global variables; use singletons sparingly. |
| 49 | + - Use `enum class` for strongly typed enumerations. |
| 50 | + - Separate interface from implementation in classes. |
| 51 | + - Use templates and metaprogramming judiciously for generic solutions. |
| 52 | + |
| 53 | + ## Testing |
| 54 | + - Write unit tests using frameworks like Google Test (GTest) or Catch2. |
| 55 | + - Mock dependencies with libraries like Google Mock. |
| 56 | + - Implement integration tests for system components. |
| 57 | + |
| 58 | + ## Security |
| 59 | + - Use secure coding practices to avoid vulnerabilities (e.g., buffer overflows, dangling pointers). |
| 60 | + - Prefer `std::array` or `std::vector` over raw arrays. |
| 61 | + - Avoid C-style casts; use `static_cast`, `dynamic_cast`, or `reinterpret_cast` when necessary. |
| 62 | + - Enforce const-correctness in functions and member variables. |
| 63 | + |
| 64 | + ## Documentation |
| 65 | + - Write clear comments for classes, methods, and critical logic. |
| 66 | + - Use Doxygen for generating API documentation. |
| 67 | + - Document assumptions, constraints, and expected behavior of code. |
| 68 | + |
| 69 | + Follow the official ISO C++ standards and guidelines for best practices in modern C++ development. |
| 70 | + |
| 71 | + Following Rules are for System Verilog Development. |
| 72 | + |
| 73 | + |
| 74 | + ### Modular Design & Code Organization |
| 75 | + - **Divide and Conquer**: Structure your FPGA design into small, reusable modules. Modular design not only enhances readability but also improves testability, helping with code reuse across different projects. |
| 76 | + - **Top-down Design Flow**: Start with a top-level design module and gradually break it down into sub-modules. Ensure clear, well-defined interfaces between these modules using `interface` blocks in SystemVerilog. |
| 77 | + |
| 78 | + ### Synchronous Design Principles |
| 79 | + - **Clock Domain Consistency**: Use a single clock domain wherever possible to simplify timing analysis and avoid unnecessary complexity. For designs requiring multiple clocks, ensure proper handling of **clock domain crossing (CDC)**. |
| 80 | + - **Synchronous Reset**: Favor synchronous reset over asynchronous reset in your design to ensure predictable behavior. All flip-flops should reset in sync with the clock to avoid timing hazards during synthesis. |
| 81 | + |
| 82 | + ### Timing Closure & Constraints |
| 83 | + - **Define Timing Constraints Early**: Set up timing constraints using **XDC (Xilinx Design Constraints)** files early in the design process. Regularly review the **Static Timing Analysis (STA)** reports to catch setup and hold violations. |
| 84 | + - **Critical Path Optimization**: Identify critical timing paths using Vivado's timing reports. Address violations by adding pipeline stages or optimizing logic, and consider multi-cycle path constraints where necessary. |
| 85 | + - **Pipelining**: Use pipelining to manage combinatorial logic delays, particularly in high-frequency designs. This reduces the load on critical paths and enhances overall timing performance. |
| 86 | + |
| 87 | + ### Resource Utilization & Optimization |
| 88 | + - **LUT, FF, and BRAM Efficiency**: Optimize the use of LUTs, flip-flops, and block RAM by writing efficient SystemVerilog code. Use `reg []` for inferring RAM structures and avoid excessive usage of registers for signal storage. |
| 89 | + - **Vivado IP Cores**: Leverage Vivado's built-in IP cores (e.g., **AXI interfaces**, **DSP blocks**, **memory controllers**) to accelerate design and resource utilization. Properly configure these IP blocks to meet your system's performance requirements. |
| 90 | + - **Optimization During Synthesis**: Choose the appropriate synthesis strategy in Vivado based on design priorities (e.g., area optimization vs. speed optimization). Vivado's reports provide detailed feedback on resource usage, guiding further improvements. |
| 91 | + |
| 92 | + ### Power Optimization |
| 93 | + - **Clock Gating**: Implement clock gating techniques where possible to reduce dynamic power consumption. Only enable clocks for specific modules when they are in use. |
| 94 | + - **Power-Aware Synthesis**: Vivado supports power-aware synthesis. Set power constraints to help optimize the design for low-power applications. |
| 95 | + |
| 96 | + ### Debugging & Simulation |
| 97 | + - **Testbenches**: Write detailed, self-checking testbenches that cover both typical use cases and edge cases. Use SystemVerilog's `assert` statements to check key assumptions in your design during simulation. |
| 98 | + - **Vivado Simulation**: Run behavioral and post-synthesis simulations in Vivado to verify functionality. Use Vivado's **Integrated Logic Analyzer (ILA)** for in-system debugging of signals in real-time. |
| 99 | + - **Assertion-Based Verification**: Use SystemVerilog assertions (`assert`) in both testbenches and within modules to catch unexpected behavior, such as protocol violations or out-of-range conditions. |
| 100 | + |
| 101 | + ### Advanced Techniques |
| 102 | + - **Clock Domain Crossing (CDC)**: Use safe techniques like synchronizers or FIFOs to handle clock domain crossings effectively. Avoid metastability by properly synchronizing signals between different clock domains. |
| 103 | + - **High-Performance AXI Transfers**: For high-speed data transfers, integrate Vivado's AXI-based IPs. Optimize AXI interfaces for high-throughput applications by ensuring correct burst sizes and handling backpressure gracefully. |
| 104 | + - **Latency Reduction**: When dealing with critical paths or performance-sensitive modules, implement fine-tuned pipeline stages to reduce latency without sacrificing system throughput. |
| 105 | + |
0 commit comments