Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
improve gen_shift_n
Browse files Browse the repository at this point in the history
  • Loading branch information
zrr1999 committed Sep 2, 2023
1 parent 3df470d commit 5a8701e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sot/opcode_translator/executor/pycode_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,12 @@ def gen_shift_n(self, s: int, n: int):
"""
if s == 0 or n <= 1:
return

# NOTE(zrr1999): right shift s steps is equal to left shift n-s steps
if abs(s) > n // 2:
new_s = s - n if s > 0 else s + n
self.gen_shift_n(new_s, n)
return
if s > 0:
# NOTE: s=1, n=3 [1,2,3,4,5] -> [1,2,5,3,4]
# s=2, n=3 [1,2,3,4,5] -> [1,2,4,5,3]
Expand Down

0 comments on commit 5a8701e

Please sign in to comment.