Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding aliases to MIPS inline encoder. #1847

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

nicolasnoble
Copy link
Member

Also adding a couple of aliases to the disassembler.

Also adding a couple of aliases to the disassembler.
Copy link
Contributor

coderabbitai bot commented Jan 19, 2025

Walkthrough

The pull request introduces several enhancements to the MIPS assembly instruction handling across multiple files. The changes primarily focus on optimizing instruction generation by adding new method overloads in the Mips::Encoder namespace, simplifying branch and arithmetic instructions, and introducing new pseudo-instructions. These modifications aim to provide more concise and flexible ways of generating assembly code, with improvements in the disassembly process and instruction encoding.

Changes

File Change Summary
src/core/disr3000a.cc Enhanced conditional logic in disBEQ and disBNE functions to handle cases with zero registers, generating optimized beqz and bnez instructions
src/mips/common/util/encoder.hh Added numerous method overloads and new pseudo-instructions in Mips::Encoder namespace, allowing simplified function calls and more flexible instruction generation
src/mips/psyqo/src/kernel.cpp Replaced addiu instructions with li for loading immediate values into registers
src/mips/tests/cop0/exceptions.cpp Simplified assembly instruction handling by using more direct loading of immediate values
src/supportpsx/ps1-packer.cc Optimized assembly instruction generation, replacing complex instructions with simpler alternatives

Sequence Diagram

sequenceDiagram
    participant Encoder as Mips::Encoder
    participant Disassembler as Disassembler
    
    Encoder->>Encoder: Add method overloads
    Encoder->>Encoder: Introduce pseudo-instructions
    Disassembler->>Disassembler: Optimize branch instructions
    
    Note over Encoder, Disassembler: Simplified instruction generation and handling
Loading

Possibly related PRs

Poem

🐰 Hop, skip, and a MIPS jump away,
Encoding magic on a coder's play!
Registers dance with newfound grace,
Pseudo-instructions set the pace.
A rabbit's code, both swift and bright! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06fdac5 and ee5c53b.

📒 Files selected for processing (5)
  • src/core/disr3000a.cc (2 hunks)
  • src/mips/common/util/encoder.hh (2 hunks)
  • src/mips/psyqo/src/kernel.cpp (1 hunks)
  • src/mips/tests/cop0/exceptions.cpp (1 hunks)
  • src/supportpsx/ps1-packer.cc (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: aur-build
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: coverage
  • GitHub Check: asan
  • GitHub Check: build
  • GitHub Check: cross-arm64
  • GitHub Check: toolchain
  • GitHub Check: build-openbios
🔇 Additional comments (8)
src/mips/common/util/encoder.hh (3)

50-103: Well-structured addition of ALU instruction aliases!

The new overloads provide convenient shortcuts for common assembly patterns where the destination register is also used as the first source operand. This improves code readability and reduces the likelihood of errors.


107-117: Consistent addition of shift instruction aliases!

The shift instruction aliases follow the same pattern as the ALU instructions, providing a cleaner syntax for self-shifts.


246-256: Excellent addition of standard MIPS pseudo-instructions!

The added pseudo-instructions are well-chosen and correctly implemented:

  • li/liu for loading immediate values
  • move for register-to-register moves
  • nott/neg for bitwise and arithmetic negation
  • b/beqz/bnez/bal for common branch patterns

These additions will make the assembly code more idiomatic and easier to read.

src/mips/tests/cop0/exceptions.cpp (1)

52-52: Good use of the new li pseudo-instruction!

The changes simplify the code by replacing ori with the more idiomatic li instruction, making the intent clearer.

Also applies to: 54-54

src/mips/psyqo/src/kernel.cpp (1)

152-152: Appropriate use of the new li pseudo-instruction!

The changes replace addiu with the more idiomatic li instruction, improving code clarity without affecting functionality.

Also applies to: 158-158

src/supportpsx/ps1-packer.cc (1)

148-155: Excellent adoption of the new MIPS instruction aliases!

The changes throughout the file make good use of the new pseudo-instructions and aliases:

  • bal for branch-and-link
  • li for loading immediate values
  • move for register moves
  • Other simplified instruction forms

This improves code readability while maintaining the same functionality.

Also applies to: 199-203, 240-242, 249-249, 252-252, 259-259, 263-263, 274-274, 278-281, 286-286, 290-294, 296-296, 302-302, 311-313, 318-318, 321-321, 354-359, 364-364, 368-368, 379-379, 411-411, 433-433

src/core/disr3000a.cc (2)

785-792: LGTM! Good optimization for zero register comparison.

The addition of beqz pseudo-instruction when either source register is zero improves readability of the disassembled code.


802-815: LGTM! Good optimization for zero register comparison.

The addition of bnez pseudo-instruction when either source register is zero improves readability of the disassembled code.

Finishing Touches

  • 📝 CodeRabbit is generating docstrings... (♻️ Check again to generate again)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

coderabbitai bot commented Jan 19, 2025

Caution

An unexpected error occurred while opening a pull request: Not Found - https://docs.github.com/rest/git/refs#get-a-reference

@nicolasnoble nicolasnoble merged commit d989f49 into grumpycoders:main Jan 20, 2025
19 checks passed
@nicolasnoble nicolasnoble deleted the encoder-aliases branch January 20, 2025 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant