if setting_mode and mask is not None and not (mask & bit):
setting_mode = False # masked out, stop setting
if setting_mode:
+ RT |= bit # inclusively set bit in RT
if RA & bit: # found a bit in rs1: stop setting RT
setting_mode = False
- RT |= bit
i += 1
return RT
bit = 1<<i
if not setting_mode and mask is not None and (mask & bit):
setting_mode = True # back into "setting" mode
- found = False
+ found = False # start finding first
if setting_mode:
if mask is not None and not (mask & bit):
setting_mode = False
- elif RA & bit: # found a bit in rs1: stop setting RT
- if not found:
- found = True
- RT |= bit
+ elif RA & bit and not found: # found a bit: set if not found
+ RT |= bit
+ found = True # don't set another bit
i += 1
return RT