Thank you for your interest in contributing to libloong! This document provides guidelines for contributing to the project.
Be respectful, professional, and constructive in all interactions.
- Fork the repository
- Clone your fork:
git clone https://github.com/your-username/libloong.git cd libloong - Create a branch for your changes:
git checkout -b feature/your-feature-name
- CMake 3.5+
- C++20 compatible compiler (GCC 10+, Clang 12+)
- Git
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)cd build
ctest --output-on-failureFollow these guidelines:
- Use 4 spaces for indentation (no tabs)
- Maximum line length: 100 characters
- Use
snake_casefor functions and variables - Use
PascalCasefor types and classes - Use
UPPER_CASEfor constants and macros
Example:
namespace loongarch {
class MyClass {
public:
void my_method(int parameter_name);
private:
int m_member_variable;
};
}- Private members:
m_prefix (e.g.,m_counter) - Constants: ALL_CAPS with underscores (e.g.,
MAX_SIZE) - Template parameters: Single capital letter or PascalCase (e.g.,
W,AddressType)
- Header files:
.hppextension - Implementation files:
.cppextension - Headers in
lib/libloong/ - Implementations in
lib/libloong/
Document all public APIs with comments:
/// @brief Simulates the machine for a specified number of instructions
/// @param max_instructions Maximum number of instructions to execute
/// @param counter Starting instruction counter value
/// @return Returns true if stopped normally, false if timeout
template <bool Throw = true>
bool simulate(uint64_t max_instructions = UINT64_MAX, uint64_t counter = 0);- Create an issue describing the bug
- Reference the issue in your PR
- Include a test case if possible
- Discuss the feature in an issue first
- Break large features into smaller PRs
- Update documentation
- Add tests for new functionality
- Update relevant
.mdfiles indocs/ - Update code comments
- Add examples if appropriate
- Include benchmarks showing improvement
- Ensure correctness is maintained
- Document any trade-offs
Follow conventional commits format:
type(scope): subject
body (optional)
footer (optional)
Types:
feat: New featurefix: Bug fixdocs: Documentationstyle: Formatting, no code changerefactor: Code restructuringperf: Performance improvementtest: Adding testschore: Maintenance
Examples:
feat(cpu): add support for atomic instructions
Implements LL/SC and AMO instructions for LA64.
Closes #123
fix(memory): correct page alignment calculation
The previous calculation could cause misaligned memory access
for certain page sizes.
- Keep commits atomic and focused
- Write descriptive commit messages
- Reference issues when applicable
- Sign your commits if possible
- Ensure code compiles without warnings
- Run all tests and ensure they pass
- Update documentation if needed
- Add tests for new functionality
- Rebase on latest main branch
Include:
- What changes were made
- Why the changes were necessary
- How to test the changes
- Related issues
Example:
## Description
Adds support for LoongArch atomic instructions (LL/SC, AMO).
## Motivation
Needed for multi-threaded guest programs.
## Testing
- Added unit tests in `tests/test_atomics.cpp`
- Tested with atomic counter benchmark
## Related Issues
Closes #123- Maintainer will review your PR
- Address any feedback
- Once approved, maintainer will merge
Add tests in tests/ directory:
#include <catch2/catch.hpp>
#include <libloong/machine.hpp>
TEST_CASE("CPU can execute ADD instruction", "[cpu]") {
loongarch::Machine<loongarch::LA64> machine { /* ... */ };
// Setup test
machine.cpu.reg(1) = 10;
machine.cpu.reg(2) = 20;
// Execute ADD instruction
// ...
// Verify result
REQUIRE(machine.cpu.reg(3) == 30);
}cd build
./tests/test_suite --test-case="CPU can execute ADD instruction"libloong/
├── lib/ # Core library
│ ├── libloong/ # Headers and implementation
│ │ ├── cpu.hpp/.cpp
│ │ ├── machine.hpp/.cpp
│ │ ├── memory.hpp/.cpp
│ │ ├── linux/ # Linux syscalls
│ │ └── posix/ # POSIX support
│ └── CMakeLists.txt
├── emulator/ # Standalone emulator
│ └── src/main.cpp
├── examples/ # Example programs
├── docs/ # Documentation
├── tests/ # Unit tests
└── README.md
Current priorities:
- Instruction Implementation: Many LoongArch instructions not yet implemented
- Floating-Point Support: Complete FP instruction set
- Vector Extensions: LSX/LASX support
- Binary Translation: Performance optimization
- Test Coverage: More comprehensive tests
- Documentation: Examples and tutorials
- Performance: Optimization opportunities
- Open an issue for questions
- Check existing issues and PRs
- Read the documentation in
docs/
By contributing, you agree that your contributions will be licensed under the MIT License.
libloong is based on the design of libriscv by fwsGonzo.
Thank you for contributing! 🎉