comparison python/ppci/bitfun.py @ 365:98ff43cfdd36

Nasty bug in adr instruction
author Windel Bouwman
date Wed, 19 Mar 2014 22:32:04 +0100
parents 3bb7dcfe5529
children
comparison
equal deleted inserted replaced
364:c49459768aaa 365:98ff43cfdd36
9 def rotate_left(v, n): 9 def rotate_left(v, n):
10 assert n >= 0 10 assert n >= 0
11 assert n < 32 11 assert n < 32
12 return rotate_right(v, 32 - n) 12 return rotate_right(v, 32 - n)
13 13
14 def encode_imm32(v):
15 """ Bundle 32 bit value into 4 bits rotation and 8 bits value
16 """
17 for i in range(0, 16):
18 v2 = rotate_left(v, i*2)
19 if (v2 & 0xFFFFFF00) == 0:
20 rotation = i
21 val = v2 & 0xFF
22 x = (rotation << 8) | val
23 return x
24 raise Exception("Invalid value {}".format(v))
14 25