Commit 671df871 authored by Mao Minkai's avatar Mao Minkai Committed by guzitao
Browse files

sw64: bpf: fix ebpf jit compiler

Sunway inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5PNGJ



--------------------------------

This patch makes following changes to ebpf jit compiler:
   * implement proper XADD instructions
   * implement 32-bit ARSH instructions
   * implement DIV and MOD instructions using helper functions
   * reorganize header file to make it easier to read
   * optimize load immediate helper functions
   * make sure ILLEGAL_INSN will throw instruction fault
   * make sure fields in jited instrctions won't overflow
   * restore GP register when exit
   * make sure 32-bit alu functions are unsigned
   * make sure 32-bit results are zero extended to 64 bits
   * make sure function addr are stored in $27 so callee can calculate
     GP correctly
   * track free temporary registers to make sure we won't accidentally
     clobber useful data
   * fix register mapping
   * fix host to be algorithm
   * fix offset calculation of branch instructions
   * fix tail call

Result of "test_bpf.ko": 378 PASSED, 0 FAILED, [366/366 JIT'ed]

Signed-off-by: default avatarMao Minkai <maominkai@wxiat.com>
Signed-off-by: default avatarGu Zitao <guzitao@wxiat.com>
parent 552045fb
Loading
Loading
Loading
Loading
+161 −136
Original line number Diff line number Diff line
@@ -21,80 +21,82 @@
#ifndef _SW64_BPF_JIT_H
#define _SW64_BPF_JIT_H

/* SW64 instruction field shift */
#define SW64_BPF_OPCODE_OFFSET		26
#define SW64_BPF_RA_OFFSET		21
#define SW64_BPF_RB_OFFSET		16
#define SW64_BPF_SIMPLE_ALU_IMM_OFFSET	13
#define SW64_BPF_SIMPLE_ALU_FUNC_OFFSET	5
#define SW64_BPF_SIMPLE_ALU_RC_OFFSET	0
#define SW64_BPF_LS_FUNC_OFFSET		12

#define SW64_BPF_OPCODE_BR_CALL		0x01
#define SW64_BPF_OPCODE_BR_RET		0x02
#define SW64_BPF_OPCODE_BR_JMP		0x03
#define SW64_BPF_OPCODE_BR_BR		0x04
#define SW64_BPF_OPCODE_BR_BSR		0x05
#define SW64_BPF_OPCODE_BR_BEQ		0x30
#define SW64_BPF_OPCODE_BR_BNE		0x31
#define SW64_BPF_OPCODE_BR_BLT		0x32
#define SW64_BPF_OPCODE_BR_BLE		0x33
#define SW64_BPF_OPCODE_BR_BGT		0x34
#define SW64_BPF_OPCODE_BR_BGE		0x35
#define SW64_BPF_OPCODE_BR_BLBC		0x36
#define SW64_BPF_OPCODE_BR_BLBS		0x37

#define SW64_BPF_OPCODE_LS_LDBU		0x20
#define SW64_BPF_OPCODE_LS_LDHU		0x21
#define SW64_BPF_OPCODE_LS_LDW		0x22
#define SW64_BPF_OPCODE_LS_LDL		0x23
#define SW64_BPF_OPCODE_LS_STB		0x28
#define SW64_BPF_OPCODE_LS_STH		0x29
#define SW64_BPF_OPCODE_LS_STW		0x2A
#define SW64_BPF_OPCODE_LS_STL		0x2B
#define SW64_BPF_OPCODE_LS_LDI		0x3E
#define SW64_BPF_OPCODE_LS_LDIH		0x3F

/* SW64 instruction opcodes */
#define SW64_BPF_OPCODE_CALL		0x01
#define SW64_BPF_OPCODE_RET		0x02
#define SW64_BPF_OPCODE_JMP		0x03
#define SW64_BPF_OPCODE_BR		0x04
#define SW64_BPF_OPCODE_BSR		0x05
#define SW64_BPF_OPCODE_MISC		0x06
#define SW64_BPF_OPCODE_LOCK		0x08
#define SW64_BPF_OPCODE_ALU_REG		0x10
#define SW64_BPF_OPCODE_ALU_IMM		0x12
#define SW64_BPF_OPCODE_LDBU		0x20
#define SW64_BPF_OPCODE_LDHU		0x21
#define SW64_BPF_OPCODE_LDW		0x22
#define SW64_BPF_OPCODE_LDL		0x23
#define SW64_BPF_OPCODE_STB		0x28
#define SW64_BPF_OPCODE_STH		0x29
#define SW64_BPF_OPCODE_STW		0x2A
#define SW64_BPF_OPCODE_STL		0x2B
#define SW64_BPF_OPCODE_BEQ		0x30
#define SW64_BPF_OPCODE_BNE		0x31
#define SW64_BPF_OPCODE_BLT		0x32
#define SW64_BPF_OPCODE_BLE		0x33
#define SW64_BPF_OPCODE_BGT		0x34
#define SW64_BPF_OPCODE_BGE		0x35
#define SW64_BPF_OPCODE_BLBC		0x36
#define SW64_BPF_OPCODE_BLBS		0x37
#define SW64_BPF_OPCODE_LDI		0x3E
#define SW64_BPF_OPCODE_LDIH		0x3F

/* SW64 MISC instructions function codes */
#define SW64_BPF_FUNC_MISC_RD_F		0x1000
#define SW64_BPF_FUNC_MISC_WR_F		0x1020

/* SW64 LOCK instructions function codes */
#define SW64_BPF_FUNC_LOCK_LLDW		0x0
#define SW64_BPF_FUNC_LOCK_LLDL		0x1
#define SW64_BPF_FUNC_LOCK_LSTW		0x8
#define SW64_BPF_FUNC_LOCK_LSTL		0x9

/* SW64 ALU instructions function codes */
#define SW64_BPF_FUNC_ALU_ADDW		0x00
#define SW64_BPF_FUNC_ALU_SUBW		0x01
#define SW64_BPF_FUNC_ALU_ADDL		0x08
#define SW64_BPF_FUNC_ALU_SUBL		0x09
#define SW64_BPF_FUNC_ALU_MULW		0x10
#define SW64_BPF_FUNC_ALU_MULL		0x18
#define SW64_BPF_FUNC_ALU_CMPEQ		0x28
#define SW64_BPF_FUNC_ALU_CMPLT		0x29
#define SW64_BPF_FUNC_ALU_CMPLE		0x2A
#define SW64_BPF_FUNC_ALU_CMPULT	0x2B
#define SW64_BPF_FUNC_ALU_CMPULE	0x2C
#define SW64_BPF_FUNC_ALU_AND		0x38
#define SW64_BPF_FUNC_ALU_BIC		0x39
#define SW64_BPF_FUNC_ALU_BIS		0x3A
#define SW64_BPF_FUNC_ALU_ORNOT		0x3B
#define SW64_BPF_FUNC_ALU_XOR		0x3C
#define SW64_BPF_FUNC_ALU_EQV		0x3D
#define SW64_BPF_FUNC_ALU_SLL		0x48
#define SW64_BPF_FUNC_ALU_SRL		0x49
#define SW64_BPF_FUNC_ALU_SRA		0x4A
#define SW64_BPF_FUNC_ALU_ZAP		0x68
#define SW64_BPF_FUNC_ALU_ZAPNOT	0x69
#define SW64_BPF_FUNC_ALU_SEXTB		0x6A
#define SW64_BPF_FUNC_ALU_SEXTH		0x6B

#define SW64_BPF_OPCODE_BS_REG		0x10
#define SW64_BPF_OPCODE_BS_IMM		0x12

#define SW64_BPF_FUNC_BS_SLL		0x48
#define SW64_BPF_FUNC_BS_SRL		0x49
#define SW64_BPF_FUNC_BS_SRA		0x4A

#define SW64_BPF_OPCODE_LOGIC_REG	0x10
#define SW64_BPF_OPCODE_LOGIC_IMM	0x12

#define SW64_BPF_FUNC_LOGIC_AND		0x38
#define SW64_BPF_FUNC_LOGIC_BIC		0x39
#define SW64_BPF_FUNC_LOGIC_BIS		0x3A
#define SW64_BPF_FUNC_LOGIC_ORNOT	0x3B
#define SW64_BPF_FUNC_LOGIC_XOR		0x3C
#define SW64_BPF_FUNC_LOGIC_EQV		0x3D

#define SW64_BPF_OPCODE_CMP_REG		0x10
#define SW64_BPF_OPCODE_CMP_IMM		0x12

#define SW64_BPF_FUNC_CMP_EQ		0x28
#define SW64_BPF_FUNC_CMP_LT		0x29
#define SW64_BPF_FUNC_CMP_LE		0x2A
#define SW64_BPF_FUNC_CMP_ULT		0x2B
#define SW64_BPF_FUNC_CMP_ULE		0x2C

/* special instuction used in jit_fill_hole() */
#define SW64_BPF_ILLEGAL_INSN	((1 << 25) | 0x80)
#define SW64_BPF_ILLEGAL_INSN	(0x1bff1000)	/* rd_f $31 */

enum sw64_bpf_registers {
	SW64_BPF_REG_V0		= 0,	/* keep return value */
@@ -135,25 +137,45 @@ enum sw64_bpf_registers {

/* SW64 load and store instructions */
#define SW64_BPF_LDBU(dst, rb, offset16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_LDBU, dst, rb, offset16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LDBU, dst, rb, offset16)
#define SW64_BPF_LDHU(dst, rb, offset16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_LDHU, dst, rb, offset16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LDHU, dst, rb, offset16)
#define SW64_BPF_LDW(dst, rb, offset16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_LDW, dst, rb, offset16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LDW, dst, rb, offset16)
#define SW64_BPF_LDL(dst, rb, offset16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_LDL, dst, rb, offset16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LDL, dst, rb, offset16)
#define SW64_BPF_STB(src, rb, offset16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_STB, src, rb, offset16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_STB, src, rb, offset16)
#define SW64_BPF_STH(src, rb, offset16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_STH, src, rb, offset16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_STH, src, rb, offset16)
#define SW64_BPF_STW(src, rb, offset16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_STW, src, rb, offset16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_STW, src, rb, offset16)
#define SW64_BPF_STL(src, rb, offset16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_STL, src, rb, offset16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_STL, src, rb, offset16)
#define SW64_BPF_LDI(dst, rb, imm16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_LDI, dst, rb, imm16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LDI, dst, rb, imm16)
#define SW64_BPF_LDIH(dst, rb, imm16) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LS_LDIH, dst, rb, imm16)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_LDIH, dst, rb, imm16)

/* SW64 lock instructions */
#define SW64_BPF_LLDW(ra, rb, offset16) \
	sw64_bpf_gen_format_ls_func(SW64_BPF_OPCODE_LOCK, \
			ra, rb, offset16, SW64_BPF_FUNC_LOCK_LLDW)
#define SW64_BPF_LLDL(ra, rb, offset16) \
	sw64_bpf_gen_format_ls_func(SW64_BPF_OPCODE_LOCK, \
			ra, rb, offset16, SW64_BPF_FUNC_LOCK_LLDL)
#define SW64_BPF_LSTW(ra, rb, offset16) \
	sw64_bpf_gen_format_ls_func(SW64_BPF_OPCODE_LOCK, \
			ra, rb, offset16, SW64_BPF_FUNC_LOCK_LSTW)
#define SW64_BPF_LSTL(ra, rb, offset16) \
	sw64_bpf_gen_format_ls_func(SW64_BPF_OPCODE_LOCK, \
			ra, rb, offset16, SW64_BPF_FUNC_LOCK_LSTL)
#define SW64_BPF_RD_F(ra) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_MISC, \
			ra, SW64_BPF_REG_ZR, SW64_BPF_FUNC_MISC_RD_F)
#define SW64_BPF_WR_F(ra) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_MISC, \
			ra, SW64_BPF_REG_ZR, SW64_BPF_FUNC_MISC_WR_F)

/* SW64 ALU instructions REG format */
#define SW64_BPF_ADDW_REG(ra, rb, dst) \
@@ -182,10 +204,10 @@ enum sw64_bpf_registers {
			ra, rb, dst, SW64_BPF_FUNC_ALU_ZAPNOT)
#define SW64_BPF_SEXTB_REG(rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			0, rb, dst, SW64_BPF_FUNC_ALU_SEXTB)
			SW64_BPF_REG_ZR, rb, dst, SW64_BPF_FUNC_ALU_SEXTB)
#define SW64_BPF_SEXTH_REG(rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			0, rb, dst, SW64_BPF_FUNC_ALU_SEXTH)
			SW64_BPF_REG_ZR, rb, dst, SW64_BPF_FUNC_ALU_SEXTH)

/* SW64 ALU instructions IMM format */
#define SW64_BPF_ADDW_IMM(ra, imm8, dst) \
@@ -214,130 +236,133 @@ enum sw64_bpf_registers {
			ra, imm8, dst, SW64_BPF_FUNC_ALU_ZAPNOT)
#define SW64_BPF_SEXTB_IMM(imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			0, imm8, dst, SW64_BPF_FUNC_ALU_SEXTB)
			SW64_BPF_REG_ZR, imm8, dst, SW64_BPF_FUNC_ALU_SEXTB)
#define SW64_BPF_SEXTH_IMM(imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			SW64_BPF_REG_ZR, imm8, dst, SW64_BPF_FUNC_ALU_SEXTH)

/* SW64 bit shift instructions REG format */
#define SW64_BPF_SLL_REG(src, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_BS_REG, \
			src, rb, dst, SW64_BPF_FUNC_BS_SLL)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			src, rb, dst, SW64_BPF_FUNC_ALU_SLL)
#define SW64_BPF_SRL_REG(src, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_BS_REG, \
			src, rb, dst, SW64_BPF_FUNC_BS_SRL)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			src, rb, dst, SW64_BPF_FUNC_ALU_SRL)
#define SW64_BPF_SRA_REG(src, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_BS_REG, \
			src, rb, dst, SW64_BPF_FUNC_BS_SRA)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			src, rb, dst, SW64_BPF_FUNC_ALU_SRA)

/* SW64 bit shift instructions IMM format */
#define SW64_BPF_SLL_IMM(src, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_BS_IMM, \
			src, imm8, dst, SW64_BPF_FUNC_BS_SLL)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			src, imm8, dst, SW64_BPF_FUNC_ALU_SLL)
#define SW64_BPF_SRL_IMM(src, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_BS_IMM, \
			src, imm8, dst, SW64_BPF_FUNC_BS_SRL)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			src, imm8, dst, SW64_BPF_FUNC_ALU_SRL)
#define SW64_BPF_SRA_IMM(src, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_BS_IMM, \
			src, imm8, dst, SW64_BPF_FUNC_BS_SRA)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			src, imm8, dst, SW64_BPF_FUNC_ALU_SRA)

/* SW64 control instructions */
#define SW64_BPF_CALL(ra, rb) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_BR_CALL, ra, rb, 0)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_CALL, ra, rb, 0)
#define SW64_BPF_RET(rb) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_BR_RET, SW64_BPF_REG_ZR, rb, 0)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_RET, SW64_BPF_REG_ZR, rb, 0)
#define SW64_BPF_JMP(ra, rb) \
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_BR_JMP, ra, rb, 0)
	sw64_bpf_gen_format_ls(SW64_BPF_OPCODE_JMP, ra, rb, 0)
#define SW64_BPF_BR(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BR, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR, ra, offset)
#define SW64_BPF_BSR(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BSR, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BSR, ra, offset)
#define SW64_BPF_BEQ(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BEQ, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BEQ, ra, offset)
#define SW64_BPF_BNE(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BNE, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BNE, ra, offset)
#define SW64_BPF_BLT(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BLT, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BLT, ra, offset)
#define SW64_BPF_BLE(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BLE, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BLE, ra, offset)
#define SW64_BPF_BGT(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BGT, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BGT, ra, offset)
#define SW64_BPF_BGE(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BGE, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BGE, ra, offset)
#define SW64_BPF_BLBC(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BLBC, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BLBC, ra, offset)
#define SW64_BPF_BLBS(ra, offset) \
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BR_BLBS, ra, offset)
	sw64_bpf_gen_format_br(SW64_BPF_OPCODE_BLBS, ra, offset)

/* SW64 bit logic instructions REG format */
#define SW64_BPF_AND_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_LOGIC_REG, \
			ra, rb, dst, SW64_BPF_FUNC_LOGIC_AND)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_AND)
#define SW64_BPF_ANDNOT_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_LOGIC_REG, \
			ra, rb, dst, SW64_BPF_FUNC_LOGIC_BIC)
#define SW64_BPF_OR_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_LOGIC_REG, \
			ra, rb, dst, SW64_BPF_FUNC_LOGIC_BIS)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_BIC)
#define SW64_BPF_BIS_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_BIS)
#define SW64_BPF_ORNOT_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_LOGIC_REG, \
			ra, rb, dst, SW64_BPF_FUNC_LOGIC_ORNOT)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_ORNOT)
#define SW64_BPF_XOR_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_LOGIC_REG, \
			ra, rb, dst, SW64_BPF_FUNC_LOGIC_XOR)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_XOR)
#define SW64_BPF_EQV_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_LOGIC_REG, \
			ra, rb, dst, SW64_BPF_FUNC_LOGIC_EQV)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_EQV)

/* SW64 bit logic instructions IMM format */
#define SW64_BPF_AND_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_LOGIC_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_LOGIC_AND)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_AND)
#define SW64_BPF_ANDNOT_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_LOGIC_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_LOGIC_BIC)
#define SW64_BPF_OR_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_LOGIC_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_LOGIC_BIS)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_BIC)
#define SW64_BPF_BIS_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_BIS)
#define SW64_BPF_ORNOT_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_LOGIC_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_LOGIC_ORNOT)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_ORNOT)
#define SW64_BPF_XOR_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_LOGIC_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_LOGIC_XOR)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_XOR)
#define SW64_BPF_EQV_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_LOGIC_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_LOGIC_EQV)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_EQV)

/* SW64 compare instructions REG format */
#define SW64_BPF_CMPEQ_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_CMP_REG, \
			ra, rb, dst, SW64_BPF_FUNC_CMP_EQ)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_CMPEQ)
#define SW64_BPF_CMPLT_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_CMP_REG, \
			ra, rb, dst, SW64_BPF_FUNC_CMP_LT)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_CMPLT)
#define SW64_BPF_CMPLE_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_CMP_REG, \
			ra, rb, dst, SW64_BPF_FUNC_CMP_LE)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_CMPLE)
#define SW64_BPF_CMPULT_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_CMP_REG, \
			ra, rb, dst, SW64_BPF_FUNC_CMP_ULT)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_CMPULT)
#define SW64_BPF_CMPULE_REG(ra, rb, dst) \
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_CMP_REG, \
			ra, rb, dst, SW64_BPF_FUNC_CMP_ULE)
	sw64_bpf_gen_format_simple_alu_reg(SW64_BPF_OPCODE_ALU_REG, \
			ra, rb, dst, SW64_BPF_FUNC_ALU_CMPULE)

/* SW64 compare instructions imm format */
#define SW64_BPF_CMPEQ_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_CMP_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_CMP_EQ)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_CMPEQ)
#define SW64_BPF_CMPLT_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_CMP_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_CMP_LT)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_CMPLT)
#define SW64_BPF_CMPLE_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_CMP_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_CMP_LE)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_CMPLE)
#define SW64_BPF_CMPULT_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_CMP_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_CMP_ULT)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_CMPULT)
#define SW64_BPF_CMPULE_IMM(ra, imm8, dst) \
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_CMP_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_CMP_ULE)
	sw64_bpf_gen_format_simple_alu_imm(SW64_BPF_OPCODE_ALU_IMM, \
			ra, imm8, dst, SW64_BPF_FUNC_ALU_CMPULE)

#endif /* _SW64_BPF_JIT_H */
+710 −297

File changed.

Preview size limit exceeded, changes collapsed.