annotate python/ppci/bitfun.py @ 346:3bb7dcfe5529

expanded arm target
author Windel Bouwman
date Fri, 07 Mar 2014 17:05:32 +0100
parents
children 98ff43cfdd36
rev   line source
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
1
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
2
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
3 def rotate_right(v, n):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
4 """ bit-wise Rotate right n times """
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
5 mask = (2**n) - 1
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
6 mask_bits = v & mask
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
7 return (v >> n) | (mask_bits << (32 - n))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
8
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
9 def rotate_left(v, n):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
10 assert n >= 0
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
11 assert n < 32
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
12 return rotate_right(v, 32 - n)
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
13
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents:
diff changeset
14