Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5933575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:59:32+00:00 2026-05-22T14:59:32+00:00

In JavaScript, with my own emulator implementation, getting the value of register field RA

  • 0

In JavaScript, with my own emulator implementation, getting the value of register field RA from a 32-bit instruction i is often represented as:

this.gpr.u32[(i >> 16) & 0x1f]

However, having the above expression many times in a function is ugly and hard to follow and edit. I have avoided defining a variable ra with that expression and using it because I thought that it would be stored in memory, and fetching it would be costly. Should I be worried about this or do modern JavaScript engines ‘inline’ the value of the variable into the statements that follow the definition? Though using a variable makes the code much cleaner, I don’t really want to use it if it will slow down the execution time in a performance-sensitive environment such as an emulator.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:59:33+00:00Added an answer on May 22, 2026 at 2:59 pm

    There are a lot of “it depends” in an answer. First of all it depends on the javascript interpreter how good it can optimize.

    Nevertheless, if I understand you correctly your code is something like

    .... this.gpr.u32[(i >> 16) & 0x1f] ...
    .... this.gpr.u32[(i >> 16) & 0x1f] ...
    .... this.gpr.u32[(i >> 16) & 0x1f] ...
    

    instead of

    ra = this.gpr.u32[(i >> 16) & 0x1f];
    .... ra ....
    .... ra ....
    .... ra ....
    

    In this case I suppose any javascript engine will execute the latter much faster. It is true that you have an additional variable ra in memory. But access to ra should not be slower than access to i plus shift and mask plus access to this.gpr.u32.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement my own clustering algorithm using this Virtual Earth javascript API:
Aside from the framework, is jQuery worth using rather than creating your own javascript?
When troubleshooting my own javascript, I see console messages from my installed chrome extensions.
I'm creating my own JavaScript Array-like object and I have methods that call closures.
I recently made my own Javascript library and I initially used the following pattern:
I have just started writing my own JavaScript Framework (just for the learning experience),
How do I programatically get my own Firefox extension's version number with Javascript? My
how can I open a modal window using javascript only. I can't use own
Javascript: The Good Parts is a great book. Often I find myself reading passages
Is it possible to use your own javascript engine in place of the browser's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.