PPC: net: bpf_jit_comp: add XOR instruction for BPF JIT
authorDaniel Borkmann <dxchgb@gmail.com>
Thu, 8 Nov 2012 11:39:41 +0000 (11:39 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sun, 18 Nov 2012 03:12:47 +0000 (22:12 -0500)
This patch is a follow-up for patch "filter: add XOR instruction for use
with X/K" that implements BPF PowerPC JIT parts for the BPF XOR operation.

Signed-off-by: Daniel Borkmann <daniel.borkmann@tik.ee.ethz.ch>
Cc: Matt Evans <matt@ozlabs.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/powerpc/include/asm/ppc-opcode.h
arch/powerpc/net/bpf_jit.h
arch/powerpc/net/bpf_jit_comp.c

index 5f73ce63fcaeb79a6a10d7d77b92d82ad26331db..42b1f43b943ba197ce766067d735c47397519382 100644 (file)
 #define PPC_INST_AND                   0x7c000038
 #define PPC_INST_ANDDOT                        0x7c000039
 #define PPC_INST_OR                    0x7c000378
+#define PPC_INST_XOR                   0x7c000278
 #define PPC_INST_ANDI                  0x70000000
 #define PPC_INST_ORI                   0x60000000
 #define PPC_INST_ORIS                  0x64000000
+#define PPC_INST_XORI                  0x68000000
+#define PPC_INST_XORIS                 0x6c000000
 #define PPC_INST_NEG                   0x7c0000d0
 #define PPC_INST_BRANCH                        0x48000000
 #define PPC_INST_BRANCH_COND           0x40800000
index 1fc8109bf2f94761d01c21eb1f9358d58668aeee..8a5dfaf5c6b73fc94c7ceab634d1bf679a4f06b1 100644 (file)
@@ -134,6 +134,12 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
                                     ___PPC_RS(a) | IMM_L(i))
 #define PPC_ORIS(d, a, i)      EMIT(PPC_INST_ORIS | ___PPC_RA(d) |           \
                                     ___PPC_RS(a) | IMM_L(i))
+#define PPC_XOR(d, a, b)       EMIT(PPC_INST_XOR | ___PPC_RA(d) |            \
+                                    ___PPC_RS(a) | ___PPC_RB(b))
+#define PPC_XORI(d, a, i)      EMIT(PPC_INST_XORI | ___PPC_RA(d) |           \
+                                    ___PPC_RS(a) | IMM_L(i))
+#define PPC_XORIS(d, a, i)     EMIT(PPC_INST_XORIS | ___PPC_RA(d) |          \
+                                    ___PPC_RS(a) | IMM_L(i))
 #define PPC_SLW(d, a, s)       EMIT(PPC_INST_SLW | ___PPC_RA(d) |            \
                                     ___PPC_RS(a) | ___PPC_RB(s))
 #define PPC_SRW(d, a, s)       EMIT(PPC_INST_SRW | ___PPC_RA(d) |            \
index dd1130642d0753b217e9a73c3e9404bb2aef2d0d..b9434de8222be190aeb2b6eb2dcf394cc2980232 100644 (file)
@@ -232,6 +232,17 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image,
                        if (K >= 65536)
                                PPC_ORIS(r_A, r_A, IMM_H(K));
                        break;
+               case BPF_S_ANC_ALU_XOR_X:
+               case BPF_S_ALU_XOR_X: /* A ^= X */
+                       ctx->seen |= SEEN_XREG;
+                       PPC_XOR(r_A, r_A, r_X);
+                       break;
+               case BPF_S_ALU_XOR_K: /* A ^= K */
+                       if (IMM_L(K))
+                               PPC_XORI(r_A, r_A, IMM_L(K));
+                       if (K >= 65536)
+                               PPC_XORIS(r_A, r_A, IMM_H(K));
+                       break;
                case BPF_S_ALU_LSH_X: /* A <<= X; */
                        ctx->seen |= SEEN_XREG;
                        PPC_SLW(r_A, r_A, r_X);