annotate python/ppci/bitfun.py @ 348:442fb043d149

Added log option to zcc
author Windel Bouwman
date Sat, 08 Mar 2014 15:32:33 +0100
parents 3bb7dcfe5529
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