Skip to content

Commit

Permalink
add BITREV aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
jamchamb committed May 8, 2024
1 parent a634045 commit 47ba4cd
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
67 changes: 67 additions & 0 deletions data/languages/nanomips.sinc
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,73 @@ addiupc48_offs: display_offs is
}


# BITREVB rt, rs (alias for ROTX rt, rs, 7, 8, 1)
:BITREVB rt, rs is
hi_pool10_6 = 0b100000 & rt & rs;
lo_pool12_4 = 0b1101 & lo_pool11_1 = 0b0 & shiftx_raw = (8 >> 1) & stripe = 1 & lo_pool5_1 = 0b0 & shift = 7
{
# Reverse bits in bytes
local byte0:4 = zext(rs[24,8]);
local byte1:4 = zext(rs[16,8]);
local byte2:4 = zext(rs[8,8]);
local byte3:4 = zext(rs[0,8]);

local byte0_rev:4 = ((byte0 >> 7 & 1) << 0) | ((byte0 >> 6 & 1) << 1) | ((byte0 >> 5 & 1) << 2) | ((byte0 >> 4 & 1) << 3) | ((byte0 >> 3 & 1) << 4) |
((byte0 >> 2 & 1) << 5) | ((byte0 >> 1 & 1) << 6) | ((byte0 >> 0 & 1) << 7);

local byte1_rev:4 = ((byte1 >> 7 & 1) << 0) | ((byte1 >> 6 & 1) << 1) | ((byte1 >> 5 & 1) << 2) | ((byte1 >> 4 & 1) << 3) | ((byte1 >> 3 & 1) << 4) |
((byte1 >> 2 & 1) << 5) | ((byte1 >> 1 & 1) << 6) | ((byte1 >> 0 & 1) << 7);

local byte2_rev:4 = ((byte2 >> 7 & 1) << 0) | ((byte2 >> 6 & 1) << 1) | ((byte2 >> 5 & 1) << 2) | ((byte2 >> 4 & 1) << 3) | ((byte2 >> 3 & 1) << 4) |
((byte2 >> 2 & 1) << 5) | ((byte2 >> 1 & 1) << 6) | ((byte2 >> 0 & 1) << 7);

local byte3_rev:4 = ((byte3 >> 7 & 1) << 0) | ((byte3 >> 6 & 1) << 1) | ((byte3 >> 5 & 1) << 2) | ((byte3 >> 4 & 1) << 3) | ((byte3 >> 3 & 1) << 4) |
((byte3 >> 2 & 1) << 5) | ((byte3 >> 1 & 1) << 6) | ((byte3 >> 0 & 1) << 7);

rt = (byte0_rev << 24) | (byte1_rev << 16) | (byte2_rev << 8) | byte3_rev;
}


# BITREVH rt, rs (alias for ROTX rt, rs, 15, 16)
:BITREVH rt, rs is
hi_pool10_6 = 0b100000 & rt & rs;
lo_pool12_4 = 0b1101 & lo_pool11_1 = 0b0 & shiftx_raw = (16 >> 1) & stripe = 0 & lo_pool5_1 = 0b0 & shift = 15
{
# Reverse bits in halfwords
local upper:4 = zext(rs[16,16]);
local lower:4 = zext(rs[0,16]);

local upper_rev:4 = ((upper >> 15 & 1) << 0) | ((upper >> 14 & 1) << 1) | ((upper >> 13 & 1) << 2) | ((upper >> 12 & 1) << 3) | ((upper >> 11 & 1) << 4) |
((upper >> 10 & 1) << 5) | ((upper >> 9 & 1) << 6) | ((upper >> 8 & 1) << 7) | ((upper >> 7 & 1) << 8) |
((upper >> 6 & 1) << 9) | ((upper >> 5 & 1) << 10) | ((upper >> 4 & 1) << 11) | ((upper >> 3 & 1) << 12) |
((upper >> 2 & 1) << 13) | ((upper >> 1 & 1) << 14) | ((upper >> 0 & 1) << 15);

local lower_rev:4 = ((lower >> 15 & 1) << 0) | ((lower >> 14 & 1) << 1) | ((lower >> 13 & 1) << 2) | ((lower >> 12 & 1) << 3) | ((lower >> 11 & 1) << 4) |
((lower >> 10 & 1) << 5) | ((lower >> 9 & 1) << 6) | ((lower >> 8 & 1) << 7) | ((lower >> 7 & 1) << 8) |
((lower >> 6 & 1) << 9) | ((lower >> 5 & 1) << 10) | ((lower >> 4 & 1) << 11) | ((lower >> 3 & 1) << 12) |
((lower >> 2 & 1) << 13) | ((lower >> 1 & 1) << 14) | ((lower >> 0 & 1) << 15);

rt = (upper << 16) | lower;
}


# BITREVW rt, rs (alias for ROTX rt, rs, 31, 0)
:BITREVW rt, rs is
hi_pool10_6 = 0b100000 & rt & rs;
lo_pool12_4 = 0b1101 & lo_pool11_1 = 0b0 & shiftx_raw = 0 & stripe = 0 & lo_pool5_1 = 0b0 & shift = 31
{
# Reverse all bits
rt = ((rs >> 31 & 1) << 0) | ((rs >> 30 & 1) << 1) | ((rs >> 29 & 1) << 2) | ((rs >> 28 & 1) << 3) | ((rs >> 27 & 1) << 4) |
((rs >> 26 & 1) << 5) | ((rs >> 25 & 1) << 6) | ((rs >> 24 & 1) << 7) | ((rs >> 23 & 1) << 8) |
((rs >> 22 & 1) << 9) | ((rs >> 21 & 1) << 10) | ((rs >> 20 & 1) << 11) | ((rs >> 19 & 1) << 12) |
((rs >> 18 & 1) << 13) | ((rs >> 17 & 1) << 14) | ((rs >> 16 & 1) << 15) | ((rs >> 15 & 1) << 16) |
((rs >> 14 & 1) << 17) | ((rs >> 13 & 1) << 18) | ((rs >> 12 & 1) << 19) | ((rs >> 11 & 1) << 20) |
((rs >> 10 & 1) << 21) | ((rs >> 9 & 1) << 22) | ((rs >> 8 & 1) << 23) | ((rs >> 7 & 1) << 24) |
((rs >> 6 & 1) << 25) | ((rs >> 5 & 1) << 26) | ((rs >> 4 & 1) << 27) | ((rs >> 3 & 1) << 28) |
((rs >> 2 & 1) << 29) | ((rs >> 1 & 1) << 30) | ((rs >> 0 & 1) << 31);
}


# BLTC rs, rt, address
:BLTC rs, rt, lo_saddr15 is
hi_pool10_6 = 0b101010 & rt & rs;
Expand Down
19 changes: 19 additions & 0 deletions data/sleigh_scripts/bitrevb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

# Reverse all bits
bit_str = ''

width = 8

for i in range(width):
swap_i = (width - 1) - i

bit_str += f'((rs >> {swap_i} & 1) << {i})'

if i < (width - 1):
bit_str += ' | '

if i > 1 and i % 4 == 0:
bit_str += '\n\t'

print(f'replaceme = {bit_str};')
19 changes: 19 additions & 0 deletions data/sleigh_scripts/bitrevh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

# Reverse all bits
bit_str = ''

width = 16

for i in range(width):
swap_i = (width - 1) - i

bit_str += f'((rs >> {swap_i} & 1) << {i})'

if i < (width - 1):
bit_str += ' | '

if i > 1 and i % 4 == 0:
bit_str += '\n\t'

print(f'replaceme = {bit_str};')
17 changes: 17 additions & 0 deletions data/sleigh_scripts/bitrevw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

# Reverse all bits
bit_str = ''

for i in range(32):
swap_i = 31 - i

bit_str += f'((rs >> {swap_i} & 1) << {i})'

if i < 31:
bit_str += ' | '

if i > 1 and i % 4 == 0:
bit_str += '\n\t'

print(f'rt = {bit_str};')

0 comments on commit 47ba4cd

Please sign in to comment.