help.syntax kernel math sequences ;
IN: cpu.x86.assembler
+HELP: (MOV-I)
+{ $values { "dst" "destination" } { "src" "immediate value" } }
+{ $description "MOV where 'src' is immediate. If dst is a 64-bit register and the 'src' value fits in 32 bits, then zero extension is taken advantage of by downgrading 'dst' to a 32-bit register. That way, the instruction gets a shorter encoding." } ;
+
HELP: 1-operand
{ $values { "operand" "operand" } { "reg,rex.w,opcode" sequence } }
{ $description "Used for encoding some instructions with one operand." } ;
{ $values { "dst" "destination" "src" "source" } }
{ $description "Moves a value from one place to another." } ;
-HELP: (MOV-I)
-{ $values { "dst" "destination" } { "src" "immediate value" } }
-{ $description "MOV where 'src' is immediate. If dst is a 64-bit register and the 'src' value fits in 32 bits, then zero extension is taken advantage of by downgrading 'dst' to a 32-bit register. That way, the instruction gets a shorter encoding." } ;
+HELP: immediate-1/4
+{ $values { "dst" "dst" } { "imm" "imm" } { "reg,rex.w,opcode" } }
+{ $description "If imm is a byte, compile the opcode and the byte. Otherwise, set the 8-bit operand flag in the opcode, and compile the cell. The 'reg' is not really a register, but a value for the 'reg' field of the mod-r/m byte." } ;
HELP: zero-extendable?
{ $values { "imm" integer } { "?" boolean } }
over integer? [ first3 0b10 opcode-or 3array ] when ;
: immediate-1/4 ( dst imm reg,rex.w,opcode -- )
- ! If imm is a byte, compile the opcode and the byte.
- ! Otherwise, set the 8-bit operand flag in the opcode, and
- ! compile the cell. The 'reg' is not really a register, but
- ! a value for the 'reg' field of the mod-r/m byte.
over fits-in-byte? [
immediate-fits-in-size-bit immediate-1
] [
M: operand SBB 0o030 2-operand ;
GENERIC: AND ( dst src -- )
-M: immediate AND { 0b100 t 0x80 } immediate-1/4 ;
+M: immediate AND ( dst src -- )
+ dup zero-extendable? [ [ 32-bit-version-of ] dip ] when
+ { 0b100 t 0x80 } immediate-1/4 ;
M: operand AND 0o040 2-operand ;
GENERIC: SUB ( dst src -- )
M: operand XOR 0o060 2-operand ;
GENERIC: CMP ( dst src -- )
-M: immediate CMP { 0b111 t 0x80 } immediate-1/4 ;
+M: immediate CMP ( dst src -- )
+ { 0b111 t 0x80 } immediate-1/4 ;
M: operand CMP 0o070 2-operand ;
GENERIC: TEST ( dst src -- )