avoid inlining hot functions

This commit is contained in:
Magnus Ulimoen 2019-11-14 18:18:50 +01:00
parent e0f3ed3fd8
commit 8b11cb74e4
1 changed files with 14 additions and 5 deletions

View File

@ -53,10 +53,11 @@ impl Upwind4 {
], ],
]; ];
#[inline(never)]
fn diff_simd(prev: &[f32], fut: &mut [f32]) { fn diff_simd(prev: &[f32], fut: &mut [f32]) {
use packed_simd::{f32x8, u32x8}; use packed_simd::{f32x8, u32x8};
assert_eq!(prev.len(), fut.len()); assert_eq!(prev.len(), fut.len());
assert!(prev.len() > 8); assert_eq!(prev.len() % 8, 0);
let nx = prev.len(); let nx = prev.len();
let dx = 1.0 / (nx - 1) as f32; let dx = 1.0 / (nx - 1) as f32;
let idx = 1.0 / dx; let idx = 1.0 / dx;
@ -144,9 +145,10 @@ impl Upwind4 {
} }
} }
#[inline(never)]
fn diffy_simd(prev: &[f32], fut: &mut [f32], nx: usize, ny: usize) { fn diffy_simd(prev: &[f32], fut: &mut [f32], nx: usize, ny: usize) {
use packed_simd::f32x4; use packed_simd::f32x4;
assert!(ny > 8); assert!(ny >= 8);
assert!(nx > 4); assert!(nx > 4);
assert!(nx % 4 == 0); assert!(nx % 4 == 0);
assert_eq!(prev.len(), fut.len()); assert_eq!(prev.len(), fut.len());
@ -228,10 +230,13 @@ impl Upwind4 {
fn diff(prev: ArrayView1<f32>, mut fut: ArrayViewMut1<f32>) { fn diff(prev: ArrayView1<f32>, mut fut: ArrayViewMut1<f32>) {
assert_eq!(prev.shape(), fut.shape()); assert_eq!(prev.shape(), fut.shape());
let nx = prev.shape()[0]; let nx = prev.shape()[0];
assert!(nx >= 8);
if let (Some(p), Some(f)) = (prev.as_slice(), fut.as_slice_mut()) { if nx % 8 == 0 {
Self::diff_simd(p, f); if let (Some(p), Some(f)) = (prev.as_slice(), fut.as_slice_mut()) {
return; Self::diff_simd(p, f);
return;
}
} }
let dx = 1.0 / (nx - 1) as f32; let dx = 1.0 / (nx - 1) as f32;
@ -355,12 +360,16 @@ fn upwind4_test() {
impl SbpOperator for Upwind4 { impl SbpOperator for Upwind4 {
fn diffx(prev: ArrayView2<f32>, mut fut: ArrayViewMut2<f32>) { fn diffx(prev: ArrayView2<f32>, mut fut: ArrayViewMut2<f32>) {
assert_eq!(prev.shape(), fut.shape());
assert!(prev.shape()[0] >= 8);
for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) { for (r0, r1) in prev.outer_iter().zip(fut.outer_iter_mut()) {
Self::diff(r0, r1) Self::diff(r0, r1)
} }
} }
fn diffy(prev: ArrayView2<f32>, mut fut: ArrayViewMut2<f32>) { fn diffy(prev: ArrayView2<f32>, mut fut: ArrayViewMut2<f32>) {
assert_eq!(prev.shape(), fut.shape());
assert!(prev.shape()[1] >= 8);
let nx = prev.shape()[1]; let nx = prev.shape()[1];
let ny = prev.shape()[0]; let ny = prev.shape()[0];
if nx >= 4 && nx % 4 == 0 { if nx >= 4 && nx % 4 == 0 {