ec-vp8 perf: loop-filter kernels — chunked loads, conditional stores
Browse files at this commit289ae2c88caa97a690dc221f17b8e8a33f7b35ccParent: 1a98a0f1 changed file +111 -88
- crates/ec-vp8/src/loopfilter.rs +111 -88
crates/ec-vp8/src/loopfilter.rsmodified+111 -88
| @@ -401,39 +401,44 @@ fn filter_mb_v_edge( | |||
| 401 | hev: i32, | 401 | hev: i32, |
| 402 | size: usize, | 402 | size: usize, |
| 403 | ) { | 403 | ) { |
| 404 | + // Taps are contiguous around each anchor: one slice read per pixel; | ||
| 405 | + // most pixels fail the threshold, so stores stay conditional. | ||
| 404 | for row in 0..8 * size { | 406 | for row in 0..8 * size { |
| 405 | let a = anchor + row * stride; | 407 | let a = anchor + row * stride; |
| 406 | debug_assert!(a >= 4 && a + 3 < plane.len()); | 408 | debug_assert!(a >= 4 && a + 3 < plane.len()); |
| 407 | - let px = [ | 409 | + let mut px = [0u8; 8]; |
| 408 | - i32::from(plane[a - 4]), | 410 | + px.copy_from_slice(&plane[a - 4..a + 4]); |
| 409 | - i32::from(plane[a - 3]), | 411 | + let c = [ |
| 410 | - i32::from(plane[a - 2]), | 412 | + i32::from(px[0]), |
| 411 | - i32::from(plane[a - 1]), | 413 | + i32::from(px[1]), |
| 412 | - i32::from(plane[a]), | 414 | + i32::from(px[2]), |
| 413 | - i32::from(plane[a + 1]), | 415 | + i32::from(px[3]), |
| 414 | - i32::from(plane[a + 2]), | 416 | + i32::from(px[4]), |
| 415 | - i32::from(plane[a + 3]), | 417 | + i32::from(px[5]), |
| 418 | + i32::from(px[6]), | ||
| 419 | + i32::from(px[7]), | ||
| 416 | ]; | 420 | ]; |
| 417 | - if !normal_threshold(&px, center_limit, interior) { | 421 | + if !normal_threshold(&c, center_limit, interior) { |
| 418 | continue; | 422 | continue; |
| 419 | } | 423 | } |
| 420 | - let [_, p2, p1, p0, q0, q1, q2, _] = px; | 424 | + let [_, p2, p1, p0, q0, q1, q2, _] = c; |
| 421 | if high_edge_variance(p1, p0, q0, q1, hev) { | 425 | if high_edge_variance(p1, p0, q0, q1, hev) { |
| 422 | // dixie: filter_common with outer taps (p1/q1 unchanged). | 426 | // dixie: filter_common with outer taps (p1/q1 unchanged). |
| 423 | let f = filter_common(p1, p0, q0, q1, true); | 427 | let f = filter_common(p1, p0, q0, q1, true); |
| 424 | - plane[a - 2] = f[0] as u8; | 428 | + px[2] = f[0] as u8; |
| 425 | - plane[a - 1] = f[1] as u8; | 429 | + px[3] = f[1] as u8; |
| 426 | - plane[a] = f[2] as u8; | 430 | + px[4] = f[2] as u8; |
| 427 | - plane[a + 1] = f[3] as u8; | 431 | + px[5] = f[3] as u8; |
| 428 | } else { | 432 | } else { |
| 429 | let m = filter_mb_edge(p2, p1, p0, q0, q1, q2); | 433 | let m = filter_mb_edge(p2, p1, p0, q0, q1, q2); |
| 430 | - plane[a - 3] = m[0] as u8; | 434 | + px[1] = m[0] as u8; |
| 431 | - plane[a - 2] = m[1] as u8; | 435 | + px[2] = m[1] as u8; |
| 432 | - plane[a - 1] = m[2] as u8; | 436 | + px[3] = m[2] as u8; |
| 433 | - plane[a] = m[3] as u8; | 437 | + px[4] = m[3] as u8; |
| 434 | - plane[a + 1] = m[4] as u8; | 438 | + px[5] = m[4] as u8; |
| 435 | - plane[a + 2] = m[5] as u8; | 439 | + px[6] = m[5] as u8; |
| 436 | } | 440 | } |
| 441 | + plane[a - 3..a + 3].copy_from_slice(&px[1..7]); | ||
| 437 | } | 442 | } |
| 438 | } | 443 | } |
| 439 | 444 | ||
| @@ -450,19 +455,20 @@ fn filter_subblock_v_edge( | |||
| 450 | for row in 0..8 * size { | 455 | for row in 0..8 * size { |
| 451 | let a = anchor + row * stride; | 456 | let a = anchor + row * stride; |
| 452 | debug_assert!(a >= 4 && a + 3 < plane.len()); | 457 | debug_assert!(a >= 4 && a + 3 < plane.len()); |
| 453 | - let px = [ | 458 | + let px: [u8; 8] = plane[a - 4..a + 4].try_into().unwrap(); |
| 454 | - i32::from(plane[a - 4]), | 459 | + let c = [ |
| 455 | - i32::from(plane[a - 3]), | 460 | + i32::from(px[0]), |
| 456 | - i32::from(plane[a - 2]), | 461 | + i32::from(px[1]), |
| 457 | - i32::from(plane[a - 1]), | 462 | + i32::from(px[2]), |
| 458 | - i32::from(plane[a]), | 463 | + i32::from(px[3]), |
| 459 | - i32::from(plane[a + 1]), | 464 | + i32::from(px[4]), |
| 460 | - i32::from(plane[a + 2]), | 465 | + i32::from(px[5]), |
| 461 | - i32::from(plane[a + 3]), | 466 | + i32::from(px[6]), |
| 467 | + i32::from(px[7]), | ||
| 462 | ]; | 468 | ]; |
| 463 | - if normal_threshold(&px, center_limit, interior) { | 469 | + if normal_threshold(&c, center_limit, interior) { |
| 464 | - let outer = high_edge_variance(px[2], px[3], px[4], px[5], hev); | 470 | + let outer = high_edge_variance(c[2], c[3], c[4], c[5], hev); |
| 465 | - let f = filter_common(px[2], px[3], px[4], px[5], outer); | 471 | + let f = filter_common(c[2], c[3], c[4], c[5], outer); |
| 466 | plane[a - 2] = f[0] as u8; | 472 | plane[a - 2] = f[0] as u8; |
| 467 | plane[a - 1] = f[1] as u8; | 473 | plane[a - 1] = f[1] as u8; |
| 468 | plane[a] = f[2] as u8; | 474 | plane[a] = f[2] as u8; |
| @@ -481,37 +487,45 @@ fn filter_mb_h_edge( | |||
| 481 | hev: i32, | 487 | hev: i32, |
| 482 | size: usize, | 488 | size: usize, |
| 483 | ) { | 489 | ) { |
| 484 | - for i in 0..8 * size { | 490 | + // Columns are contiguous (anchor + i), taps sit `stride` apart: the |
| 485 | - let a = anchor + i; | 491 | + // tap rows are pulled in with one bounds-checked slice each (most |
| 486 | - debug_assert!(a >= 4 * stride && a + 3 * stride < plane.len()); | 492 | + // columns fail the threshold and need no store, so writes stay |
| 487 | - let px = [ | 493 | + // per-column). |
| 488 | - i32::from(plane[a - 4 * stride]), | 494 | + let n = 8 * size; |
| 489 | - i32::from(plane[a - 3 * stride]), | 495 | + let mut px = [[0u8; 64]; 8]; |
| 490 | - i32::from(plane[a - 2 * stride]), | 496 | + for (k, r) in px.iter_mut().enumerate() { |
| 491 | - i32::from(plane[a - stride]), | 497 | + let a = anchor - (4 - k) * stride; |
| 492 | - i32::from(plane[a]), | 498 | + r[..n].copy_from_slice(&plane[a..a + n]); |
| 493 | - i32::from(plane[a + stride]), | 499 | + } |
| 494 | - i32::from(plane[a + 2 * stride]), | 500 | + for i in 0..n { |
| 495 | - i32::from(plane[a + 3 * stride]), | 501 | + let c = [ |
| 502 | + i32::from(px[0][i]), | ||
| 503 | + i32::from(px[1][i]), | ||
| 504 | + i32::from(px[2][i]), | ||
| 505 | + i32::from(px[3][i]), | ||
| 506 | + i32::from(px[4][i]), | ||
| 507 | + i32::from(px[5][i]), | ||
| 508 | + i32::from(px[6][i]), | ||
| 509 | + i32::from(px[7][i]), | ||
| 496 | ]; | 510 | ]; |
| 497 | - if !normal_threshold(&px, center_limit, interior) { | 511 | + if !normal_threshold(&c, center_limit, interior) { |
| 498 | continue; | 512 | continue; |
| 499 | } | 513 | } |
| 500 | - let [_, p2, p1, p0, q0, q1, q2, _] = px; | 514 | + let [_, p2, p1, p0, q0, q1, q2, _] = c; |
| 501 | if high_edge_variance(p1, p0, q0, q1, hev) { | 515 | if high_edge_variance(p1, p0, q0, q1, hev) { |
| 502 | let f = filter_common(p1, p0, q0, q1, true); | 516 | let f = filter_common(p1, p0, q0, q1, true); |
| 503 | - plane[a - 2 * stride] = f[0] as u8; | 517 | + plane[anchor - 2 * stride + i] = f[0] as u8; |
| 504 | - plane[a - stride] = f[1] as u8; | 518 | + plane[anchor - stride + i] = f[1] as u8; |
| 505 | - plane[a] = f[2] as u8; | 519 | + plane[anchor + i] = f[2] as u8; |
| 506 | - plane[a + stride] = f[3] as u8; | 520 | + plane[anchor + stride + i] = f[3] as u8; |
| 507 | } else { | 521 | } else { |
| 508 | let m = filter_mb_edge(p2, p1, p0, q0, q1, q2); | 522 | let m = filter_mb_edge(p2, p1, p0, q0, q1, q2); |
| 509 | - plane[a - 3 * stride] = m[0] as u8; | 523 | + plane[anchor - 3 * stride + i] = m[0] as u8; |
| 510 | - plane[a - 2 * stride] = m[1] as u8; | 524 | + plane[anchor - 2 * stride + i] = m[1] as u8; |
| 511 | - plane[a - stride] = m[2] as u8; | 525 | + plane[anchor - stride + i] = m[2] as u8; |
| 512 | - plane[a] = m[3] as u8; | 526 | + plane[anchor + i] = m[3] as u8; |
| 513 | - plane[a + stride] = m[4] as u8; | 527 | + plane[anchor + stride + i] = m[4] as u8; |
| 514 | - plane[a + 2 * stride] = m[5] as u8; | 528 | + plane[anchor + 2 * stride + i] = m[5] as u8; |
| 515 | } | 529 | } |
| 516 | } | 530 | } |
| 517 | } | 531 | } |
| @@ -526,26 +540,30 @@ fn filter_subblock_h_edge( | |||
| 526 | hev: i32, | 540 | hev: i32, |
| 527 | size: usize, | 541 | size: usize, |
| 528 | ) { | 542 | ) { |
| 529 | - for i in 0..8 * size { | 543 | + let n = 8 * size; |
| 530 | - let a = anchor + i; | 544 | + let mut px = [[0u8; 64]; 8]; |
| 531 | - debug_assert!(a >= 4 * stride && a + 3 * stride < plane.len()); | 545 | + for (k, r) in px.iter_mut().enumerate() { |
| 532 | - let px = [ | 546 | + let a = anchor - (4 - k) * stride; |
| 533 | - i32::from(plane[a - 4 * stride]), | 547 | + r[..n].copy_from_slice(&plane[a..a + n]); |
| 534 | - i32::from(plane[a - 3 * stride]), | 548 | + } |
| 535 | - i32::from(plane[a - 2 * stride]), | 549 | + for i in 0..n { |
| 536 | - i32::from(plane[a - stride]), | 550 | + let c = [ |
| 537 | - i32::from(plane[a]), | 551 | + i32::from(px[0][i]), |
| 538 | - i32::from(plane[a + stride]), | 552 | + i32::from(px[1][i]), |
| 539 | - i32::from(plane[a + 2 * stride]), | 553 | + i32::from(px[2][i]), |
| 540 | - i32::from(plane[a + 3 * stride]), | 554 | + i32::from(px[3][i]), |
| 555 | + i32::from(px[4][i]), | ||
| 556 | + i32::from(px[5][i]), | ||
| 557 | + i32::from(px[6][i]), | ||
| 558 | + i32::from(px[7][i]), | ||
| 541 | ]; | 559 | ]; |
| 542 | - if normal_threshold(&px, center_limit, interior) { | 560 | + if normal_threshold(&c, center_limit, interior) { |
| 543 | - let outer = high_edge_variance(px[2], px[3], px[4], px[5], hev); | 561 | + let outer = high_edge_variance(c[2], c[3], c[4], c[5], hev); |
| 544 | - let f = filter_common(px[2], px[3], px[4], px[5], outer); | 562 | + let f = filter_common(c[2], c[3], c[4], c[5], outer); |
| 545 | - plane[a - 2 * stride] = f[0] as u8; | 563 | + plane[anchor - 2 * stride + i] = f[0] as u8; |
| 546 | - plane[a - stride] = f[1] as u8; | 564 | + plane[anchor - stride + i] = f[1] as u8; |
| 547 | - plane[a] = f[2] as u8; | 565 | + plane[anchor + i] = f[2] as u8; |
| 548 | - plane[a + stride] = f[3] as u8; | 566 | + plane[anchor + stride + i] = f[3] as u8; |
| 549 | } | 567 | } |
| 550 | } | 568 | } |
| 551 | } | 569 | } |
| @@ -556,10 +574,11 @@ fn filter_v_edge_simple(plane: &mut [u8], stride: usize, anchor: usize, limit: i | |||
| 556 | for row in 0..16 { | 574 | for row in 0..16 { |
| 557 | let a = anchor + row * stride; | 575 | let a = anchor + row * stride; |
| 558 | debug_assert!(a >= 2 && a + 1 < plane.len()); | 576 | debug_assert!(a >= 2 && a + 1 < plane.len()); |
| 559 | - let p1 = i32::from(plane[a - 2]); | 577 | + let px: [u8; 4] = plane[a - 2..a + 2].try_into().unwrap(); |
| 560 | - let p0 = i32::from(plane[a - 1]); | 578 | + let p1 = i32::from(px[0]); |
| 561 | - let q0 = i32::from(plane[a]); | 579 | + let p0 = i32::from(px[1]); |
| 562 | - let q1 = i32::from(plane[a + 1]); | 580 | + let q0 = i32::from(px[2]); |
| 581 | + let q1 = i32::from(px[3]); | ||
| 563 | if simple_threshold(p1, p0, q0, q1, limit) { | 582 | if simple_threshold(p1, p0, q0, q1, limit) { |
| 564 | let f = filter_common(p1, p0, q0, q1, true); | 583 | let f = filter_common(p1, p0, q0, q1, true); |
| 565 | plane[a - 1] = f[1] as u8; | 584 | plane[a - 1] = f[1] as u8; |
| @@ -570,17 +589,21 @@ fn filter_v_edge_simple(plane: &mut [u8], stride: usize, anchor: usize, limit: i | |||
| 570 | 589 | ||
| 571 | /// dixie `filter_h_edge_simple`: horizontal edge, simple filter. | 590 | /// dixie `filter_h_edge_simple`: horizontal edge, simple filter. |
| 572 | fn filter_h_edge_simple(plane: &mut [u8], stride: usize, anchor: usize, limit: i32) { | 591 | fn filter_h_edge_simple(plane: &mut [u8], stride: usize, anchor: usize, limit: i32) { |
| 592 | + // Contiguous columns, strided taps: chunked loads, conditional stores. | ||
| 593 | + let mut px = [[0u8; 16]; 4]; | ||
| 594 | + for (k, r) in px.iter_mut().enumerate() { | ||
| 595 | + let a = anchor - (2 - k) * stride; | ||
| 596 | + r.copy_from_slice(&plane[a..a + 16]); | ||
| 597 | + } | ||
| 573 | for i in 0..16 { | 598 | for i in 0..16 { |
| 574 | - let a = anchor + i; | 599 | + let p1 = i32::from(px[0][i]); |
| 575 | - debug_assert!(a >= 2 * stride && a + stride < plane.len()); | 600 | + let p0 = i32::from(px[1][i]); |
| 576 | - let p1 = i32::from(plane[a - 2 * stride]); | 601 | + let q0 = i32::from(px[2][i]); |
| 577 | - let p0 = i32::from(plane[a - stride]); | 602 | + let q1 = i32::from(px[3][i]); |
| 578 | - let q0 = i32::from(plane[a]); | ||
| 579 | - let q1 = i32::from(plane[a + stride]); | ||
| 580 | if simple_threshold(p1, p0, q0, q1, limit) { | 603 | if simple_threshold(p1, p0, q0, q1, limit) { |
| 581 | let f = filter_common(p1, p0, q0, q1, true); | 604 | let f = filter_common(p1, p0, q0, q1, true); |
| 582 | - plane[a - stride] = f[1] as u8; | 605 | + plane[anchor - stride + i] = f[1] as u8; |
| 583 | - plane[a] = f[2] as u8; | 606 | + plane[anchor + i] = f[2] as u8; |
| 584 | } | 607 | } |
| 585 | } | 608 | } |
| 586 | } | 609 | } |