PowerPC - Trying to understand the rlwinm instruction
#1
I have another question about something I wanted to add to the PowerPC For Dummies guide.

I've been trying to learn how the rlwinm instruction works and oh man, let me tell you. 
It's a lot harder than I thought it would be. I can't even begin to describe the headaches I got from trying to figure it out. 
Yes, I got an actual headache from this. 
I thought it was only one big instruction, but it turns out to be the substitute for 4 different ones.

I spent about 4 hours testing many things with it, I put together a very brief simplification of it.

Code:
rlwinm = (Rotate Left Word Immediate With AND Mask) = An instruction that has the functions of the slwi, srwi, clrlwi, and clrrwi instructions.



rlwinm rA, rB, SH, MB, ME

# There isn't a definition I can give for any of these because their usage changes based on what operation is being done.
RA = Destination Register
RB = Source Register
SH = Shift Amount
MB = Mask Value
ME = End Mask

# clrlwi Operation
# You will get this if the "Shift Amount" is 0 and the Mask Value is 0
# The amount of bits cleared depends on what the End Mask Value is
# Assume the register holds the value 0x81234567
0 =         80000000
8 =         81000000
11 - 15 =   81200000
16 =        81230000
17 - 23 =   81234000
24 =        81234500
27 - 29 =   81234560


# clrrwi Operation
# You will get this if the "Shift Amount" is 0 and the End Mask is 31
# The amount of bits cleared depends on what the Mask Value is
# Assume the register holds the value 0x81234567
1 =         01234567
8 =         00234567
11 - 15 =   00034567
16 =        00004567
17 - 23 =   00000567
24 =        00000067
27 - 29 =   00000007



# slwi Operation
# You will get this if the Mask Value is 0 and the End Mask is the amount of bits you want to shift.
# If the End Mask is 31, the code will shift portions of the same value into the new space (I don't know any other way to word this).

# EXAMPLE :
# Assume the register holds the value 0x81234567
# rlwinm    r18,r18,16,0,31
# If the End Mask was 24, the register would have the value 0x45678100
# But since it's 31, The value becomes 0x45678123

# The amount of bits shifted depends on what the Shift Amount is
# Assume the register holds the value 0x81234567
8  = 23456700
16 = 45670000
24 = 67000000

That's as far as I managed to get before I quit because of the headache I got.

My question is....
Is any part of this correct? 
I want to know in advance before I add anything else to what I have.
Reply


Messages In This Thread
PowerPC - Trying to understand the rlwinm instruction - by JimmyKazakhstan - 06-26-2021, 01:18 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)