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.