Added abs, max, min and parity functions
This commit is contained in:
@@ -70,3 +70,25 @@ pub popc:
|
||||
add r4, r4, r2
|
||||
and r1, r4, 0xFF ; mask out end result in lowest byte
|
||||
jmp r13
|
||||
|
||||
; Calculates the parity of the value provided in the r1 register
|
||||
; i.e. 0 means even bits set, 1 means odd bits set
|
||||
; Based on Stanford's BitHacks
|
||||
; Clobbers r2
|
||||
pub parity:
|
||||
; v ^= v >> 16;
|
||||
lsr r2, r1, 16
|
||||
xor r1, r1, r2
|
||||
; v ^= v >> 8;
|
||||
lsr r2, r1, 8
|
||||
xor r1, r1, r2
|
||||
; v ^= v >> 4;
|
||||
lsr r2, r1, 4
|
||||
xor r1, r1, r2
|
||||
; v &= 0xf;
|
||||
and r1, r1, 0x0F
|
||||
; return (0x6996 >> v) & 1;
|
||||
mov r2, 0x6996
|
||||
lsr r1, r2, r1
|
||||
and r1, r1, 0x01
|
||||
jmp r13
|
||||
Reference in New Issue
Block a user