diff options
author | Heiko Carstens <heiko.carstens@de.ibm.com> | 2012-08-28 09:36:14 -0400 |
---|---|---|
committer | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2012-09-26 09:44:49 -0400 |
commit | 68d9884dbc4215b6693c108eb35a02bd78f7956e (patch) | |
tree | 6f54b348e87adcaad0d03a4897734635ea919750 /arch/s390 | |
parent | c10302efe569bfd646b4c22df29577a4595b4580 (diff) |
s390/bpf,jit: improve code generation
Make use of new immediate instructions that came with the
extended immediate and general instruction extension facilities.
Reviewed-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'arch/s390')
-rw-r--r-- | arch/s390/net/bpf_jit_comp.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index b07aa3dc5eed..f57f0c335b1d 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/filter.h> | 10 | #include <linux/filter.h> |
11 | #include <asm/cacheflush.h> | 11 | #include <asm/cacheflush.h> |
12 | #include <asm/processor.h> | 12 | #include <asm/processor.h> |
13 | #include <asm/facility.h> | ||
13 | 14 | ||
14 | /* | 15 | /* |
15 | * Conventions: | 16 | * Conventions: |
@@ -114,6 +115,12 @@ struct bpf_jit { | |||
114 | EMIT6(op1 | __disp, op2); \ | 115 | EMIT6(op1 | __disp, op2); \ |
115 | }) | 116 | }) |
116 | 117 | ||
118 | #define EMIT6_IMM(op, imm) \ | ||
119 | ({ \ | ||
120 | unsigned int __imm = (imm); \ | ||
121 | EMIT6(op | (__imm >> 16), __imm & 0xffff); \ | ||
122 | }) | ||
123 | |||
117 | #define EMIT_CONST(val) \ | 124 | #define EMIT_CONST(val) \ |
118 | ({ \ | 125 | ({ \ |
119 | unsigned int ret; \ | 126 | unsigned int ret; \ |
@@ -276,6 +283,9 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
276 | if (K <= 16383) | 283 | if (K <= 16383) |
277 | /* ahi %r5,<K> */ | 284 | /* ahi %r5,<K> */ |
278 | EMIT4_IMM(0xa75a0000, K); | 285 | EMIT4_IMM(0xa75a0000, K); |
286 | else if (test_facility(21)) | ||
287 | /* alfi %r5,<K> */ | ||
288 | EMIT6_IMM(0xc25b0000, K); | ||
279 | else | 289 | else |
280 | /* a %r5,<d(K)>(%r13) */ | 290 | /* a %r5,<d(K)>(%r13) */ |
281 | EMIT4_DISP(0x5a50d000, EMIT_CONST(K)); | 291 | EMIT4_DISP(0x5a50d000, EMIT_CONST(K)); |
@@ -291,6 +301,9 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
291 | if (K <= 16384) | 301 | if (K <= 16384) |
292 | /* ahi %r5,-K */ | 302 | /* ahi %r5,-K */ |
293 | EMIT4_IMM(0xa75a0000, -K); | 303 | EMIT4_IMM(0xa75a0000, -K); |
304 | else if (test_facility(21)) | ||
305 | /* alfi %r5,-K */ | ||
306 | EMIT6_IMM(0xc25b0000, -K); | ||
294 | else | 307 | else |
295 | /* s %r5,<d(K)>(%r13) */ | 308 | /* s %r5,<d(K)>(%r13) */ |
296 | EMIT4_DISP(0x5b50d000, EMIT_CONST(K)); | 309 | EMIT4_DISP(0x5b50d000, EMIT_CONST(K)); |
@@ -304,6 +317,9 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
304 | if (K <= 16383) | 317 | if (K <= 16383) |
305 | /* mhi %r5,K */ | 318 | /* mhi %r5,K */ |
306 | EMIT4_IMM(0xa75c0000, K); | 319 | EMIT4_IMM(0xa75c0000, K); |
320 | else if (test_facility(34)) | ||
321 | /* msfi %r5,<K> */ | ||
322 | EMIT6_IMM(0xc2510000, K); | ||
307 | else | 323 | else |
308 | /* ms %r5,<d(K)>(%r13) */ | 324 | /* ms %r5,<d(K)>(%r13) */ |
309 | EMIT4_DISP(0x7150d000, EMIT_CONST(K)); | 325 | EMIT4_DISP(0x7150d000, EMIT_CONST(K)); |
@@ -331,8 +347,12 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
331 | EMIT2(0x145c); | 347 | EMIT2(0x145c); |
332 | break; | 348 | break; |
333 | case BPF_S_ALU_AND_K: /* A &= K */ | 349 | case BPF_S_ALU_AND_K: /* A &= K */ |
334 | /* n %r5,<d(K)>(%r13) */ | 350 | if (test_facility(21)) |
335 | EMIT4_DISP(0x5450d000, EMIT_CONST(K)); | 351 | /* nilf %r5,<K> */ |
352 | EMIT6_IMM(0xc05b0000, K); | ||
353 | else | ||
354 | /* n %r5,<d(K)>(%r13) */ | ||
355 | EMIT4_DISP(0x5450d000, EMIT_CONST(K)); | ||
336 | break; | 356 | break; |
337 | case BPF_S_ALU_OR_X: /* A |= X */ | 357 | case BPF_S_ALU_OR_X: /* A |= X */ |
338 | jit->seen |= SEEN_XREG; | 358 | jit->seen |= SEEN_XREG; |
@@ -340,8 +360,12 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
340 | EMIT2(0x165c); | 360 | EMIT2(0x165c); |
341 | break; | 361 | break; |
342 | case BPF_S_ALU_OR_K: /* A |= K */ | 362 | case BPF_S_ALU_OR_K: /* A |= K */ |
343 | /* o %r5,<d(K)>(%r13) */ | 363 | if (test_facility(21)) |
344 | EMIT4_DISP(0x5650d000, EMIT_CONST(K)); | 364 | /* oilf %r5,<K> */ |
365 | EMIT6_IMM(0xc05d0000, K); | ||
366 | else | ||
367 | /* o %r5,<d(K)>(%r13) */ | ||
368 | EMIT4_DISP(0x5650d000, EMIT_CONST(K)); | ||
345 | break; | 369 | break; |
346 | case BPF_S_ALU_LSH_X: /* A <<= X; */ | 370 | case BPF_S_ALU_LSH_X: /* A <<= X; */ |
347 | jit->seen |= SEEN_XREG; | 371 | jit->seen |= SEEN_XREG; |
@@ -386,6 +410,9 @@ kbranch: /* Emit compare if the branch targets are different */ | |||
386 | if (K <= 16383) | 410 | if (K <= 16383) |
387 | /* chi %r5,<K> */ | 411 | /* chi %r5,<K> */ |
388 | EMIT4_IMM(0xa75e0000, K); | 412 | EMIT4_IMM(0xa75e0000, K); |
413 | else if (test_facility(21)) | ||
414 | /* clfi %r5,<K> */ | ||
415 | EMIT6_IMM(0xc25f0000, K); | ||
389 | else | 416 | else |
390 | /* c %r5,<d(K)>(%r13) */ | 417 | /* c %r5,<d(K)>(%r13) */ |
391 | EMIT4_DISP(0x5950d000, EMIT_CONST(K)); | 418 | EMIT4_DISP(0x5950d000, EMIT_CONST(K)); |
@@ -508,6 +535,9 @@ call_fn: /* lg %r1,<d(function)>(%r13) */ | |||
508 | if (K <= 16383) | 535 | if (K <= 16383) |
509 | /* lhi %r5,K */ | 536 | /* lhi %r5,K */ |
510 | EMIT4_IMM(0xa7580000, K); | 537 | EMIT4_IMM(0xa7580000, K); |
538 | else if (test_facility(21)) | ||
539 | /* llilf %r5,<K> */ | ||
540 | EMIT6_IMM(0xc05f0000, K); | ||
511 | else | 541 | else |
512 | /* l %r5,<d(K)>(%r13) */ | 542 | /* l %r5,<d(K)>(%r13) */ |
513 | EMIT4_DISP(0x5850d000, EMIT_CONST(K)); | 543 | EMIT4_DISP(0x5850d000, EMIT_CONST(K)); |
@@ -517,6 +547,9 @@ call_fn: /* lg %r1,<d(function)>(%r13) */ | |||
517 | if (K <= 16383) | 547 | if (K <= 16383) |
518 | /* lhi %r12,<K> */ | 548 | /* lhi %r12,<K> */ |
519 | EMIT4_IMM(0xa7c80000, K); | 549 | EMIT4_IMM(0xa7c80000, K); |
550 | else if (test_facility(21)) | ||
551 | /* llilf %r12,<K> */ | ||
552 | EMIT6_IMM(0xc0cf0000, K); | ||
520 | else | 553 | else |
521 | /* l %r12,<d(K)>(%r13) */ | 554 | /* l %r12,<d(K)>(%r13) */ |
522 | EMIT4_DISP(0x58c0d000, EMIT_CONST(K)); | 555 | EMIT4_DISP(0x58c0d000, EMIT_CONST(K)); |