-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic_op.c
58 lines (50 loc) · 1.47 KB
/
logic_op.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "defines.h"
#include "internal.h"
/* Logical opcodes: */
OPCODE( and ) {
REGARG( 0 ) = REGARG( 1 ) & REGARG( 2 );
checkZeroFlag( REGARG( 0 ) );
}
OPCODE( and_const ) {
REGARG( 0 ) = REGARG( 1 ) & curopc.args[ 2 ];
checkZeroFlag( REGARG( 0 ) );
}
OPCODE( or ) {
REGARG( 0 ) = REGARG( 1 ) | REGARG( 2 );
checkZeroFlag( REGARG( 0 ) );
}
OPCODE( or_const ) {
REGARG( 0 ) = REGARG( 1 ) | curopc.args[ 2 ];
checkZeroFlag( REGARG( 0 ) );
}
OPCODE( xor ) {
REGARG( 0 ) = REGARG( 1 ) ^ REGARG( 2 );
checkZeroFlag( REGARG( 0 ) );
}
OPCODE( xor_const ) {
REGARG( 0 ) = REGARG( 1 ) ^ curopc.args[ 2 ];
checkZeroFlag( REGARG( 0 ) );
}
OPCODE( shl_const ) {
proc.flags = ( proc.flags & ~OF ) | ( OF * !!( (uint32) curopc.args[ 2 ] > 32 ) ); // Too far shift.
proc.flags = ( proc.flags & ~CF ) | ( CF * !!( REGARG( 1 ) & ( 1 << (UINT32_MAX - curopc.args[ 2 ] - 1) ) ) ); // Save last shifted bit.
REGARG( 0 ) = REGARG( 1 ) << curopc.args[ 2 ];
checkZeroFlag( REGARG( 0 ) );
}
OPCODE( shl ) {
curopc.args[ 2 ] = REGARG( 2 );
op_shl_const();
}
OPCODE( shr_const ) {
proc.flags = ( proc.flags & ~OF ) | ( OF * !!( (uint32) curopc.args[ 2 ] > 32 ) ); // Too far shift.
proc.flags = ( proc.flags & ~CF ) | ( CF * !!( REGARG( 1 ) & ( 1 << (curopc.args[ 2 ] - 1) ) ) ); // Save last shifted bit.
REGARG( 0 ) = REGARG( 1 ) >> curopc.args[ 2 ];
checkZeroFlag( REGARG( 0 ) );
}
OPCODE( shr ) {
curopc.args[ 2 ] = REGARG( 2 );
op_shr_const();
}
OPCODE( neg ) {
REGARG( 0 ) = ~REGARG( 0 );
}