Register constraint in NEG instructions
Hello.
The neg (and neg32) instructions are documented to use (and encode) both src and dst register operands in standarization/instruction-set.rst:
BPF_NEG 0x80 dst = -src
However, in llvm's BPFAsmParser::PreMatchCheck, it is checked that both source and destination registers refer to the same register. If they are not, an error is raised.
Is this to speed up JIT to different architectures, some like x86 featuring NEG reg' and others like aarch64 featuring NEG reg1,reg2'?
Should I send a patch for instruction-set.rst documenting the requirement?
Thanks.
I see this in the verifier (bpf-next):
if (opcode == BPF_NEG) {
if (BPF_SRC(insn->code) != BPF_K ||
insn->src_reg != BPF_REG_0 ||
insn->off != 0 || insn->imm != 0) {
verbose(env, "BPF_NEG uses reserved fields\n");
return -EINVAL;}
And along this llvm assembler test:
|
v // CHECK: 84 01 00 00 00 00 00 00 w1 = -w1
w1 = -w1
Is enough evidence that NEG is supposed to use only dst and not src. I am sending a fix for standarization/instruction-set.rst.
Quoted 18 lines
Hello.
The neg (and neg32) instructions are documented to use (and encode) both src and dst register operands in
standarization/instruction-set.rst:
BPF_NEG0x80dst = -srcHowever, in llvm's
BPFAsmParser::PreMatchCheck, it is checked that both source and destination registers refer to the same register. If they are not, an error is raised.Is this to speed up JIT to different architectures, some like x86 featuring
NEG reg' and others like aarch64 featuringNEG reg1,reg2'?Should I send a patch for
instruction-set.rstdocumenting the requirement?Thanks.
Quoted 21 lines
-----Original Message-----
From: Jose E. Marchesi <[email protected]>
Sent: Wednesday, July 26, 2023 2:17 AM
To: [email protected]
Cc: Yonghong Song <[email protected]>; Eduard Zingerman <[email protected]>
Subject: Re: Register constraint in NEG instructionsI see this in the verifier (bpf-next):
if (opcode == BPF_NEG) { if (BPF_SRC(insn->code) != BPF_K || insn->src_reg != BPF_REG_0 || insn->off != 0 || insn->imm != 0) { verbose(env, "BPF_NEG uses reserved fields\n"); return -EINVAL; }And along this llvm assembler test:
Quoted 26 lines
| v// CHECK: 84 01 00 00 00 00 00 00 w1 = -w1
w1 = -w1Is enough evidence that NEG is supposed to use only dst and not src. I am sending a fix for
standarization/instruction-set.rst.Quoted 18 lines
Hello.
The neg (and neg32) instructions are documented to use (and encode) both src and dst register operands in
standarization/instruction-set.rst:
BPF_NEG0x80dst = -srcHowever, in llvm's
BPFAsmParser::PreMatchCheck, it is checked that both source and destination registers refer to the same register. If they are not, an error is raised.Is this to speed up JIT to different architectures, some like x86 featuring
NEG reg' and others like aarch64 featuringNEG reg1,reg2'?Should I send a patch for
instruction-set.rstdocumenting the requirement?Thanks.
I am adding [email protected] to this thread, for context.
Dave
Yonghong Song
reviewerQuoted 11 lines · Jose E. Marchesi
I see this in the verifier (bpf-next):
if (opcode == BPF_NEG) { if (BPF_SRC(insn->code) != BPF_K || insn->src_reg != BPF_REG_0 || insn->off != 0 || insn->imm != 0) { verbose(env, "BPF_NEG uses reserved fields\n"); return -EINVAL; }
Quoted 8 lines
And along this llvm assembler test:
| v// CHECK: 84 01 00 00 00 00 00 00 w1 = -w1
w1 = -w1Is enough evidence that NEG is supposed to use only dst and not src. I
Yes, in llvm (BPFInstrInfo.td),
class NEG_RR<BPFOpClass Class, BPFArithOp Opc,
dag outs, dag ins, string asmstr, list<dag> pattern>
: TYPE_ALU_JMP<Opc.Value, 0, outs, ins, asmstr, pattern> {
bits<4> dst;
let Inst{51-48} = dst;
let BPFClass = Class;
}
You can see only dst register is used. The further evidence is from the above kernel check.
Quoted 20 lines
am sending a fix for
standarization/instruction-set.rst.Quoted 18 lines
Hello.
The neg (and neg32) instructions are documented to use (and encode) both src and dst register operands in
standarization/instruction-set.rst:BPF_NEG 0x80 dst = -srcHowever, in llvm's
BPFAsmParser::PreMatchCheck, it is checked that both source and destination registers refer to the same register. If they are not, an error is raised.Is this to speed up JIT to different architectures, some like x86 featuring
NEG reg' and others like aarch64 featuringNEG reg1,reg2'?Should I send a patch for
instruction-set.rstdocumenting the requirement?Thanks.