Skip to content

Commit da13355

Browse files
committed
Add likely/unlikely hints to to some branches
1 parent 737247b commit da13355

8 files changed

+289
-266
lines changed

core/include/detray/navigation/intersection/ray_cylinder_intersector.hpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,12 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, do_debug> {
130130
const auto qe = solve_intersection(ray, mask, trf);
131131

132132
switch (qe.solutions()) {
133-
case 1:
134-
sfi = build_candidate<surface_descr_t>(
135-
ray, mask, trf, qe.smaller(), mask_tolerance,
136-
mask_tol_scalor, overstep_tol);
137-
break;
138-
case 0:
139-
sfi.status = false;
133+
[[likely]] case 1
134+
: sfi = build_candidate<surface_descr_t>(
135+
ray, mask, trf, qe.smaller(), mask_tolerance,
136+
mask_tol_scalor, overstep_tol);
137+
break;
138+
[[unlikely]] case 0 : sfi.status = false;
140139
}
141140
}
142141

core/include/detray/navigation/intersection/ray_cylinder_portal_intersector.hpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,23 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
8080
const auto qe = this->solve_intersection(ray, mask, trf);
8181

8282
// Find the closest valid intersection
83-
if (qe.solutions() > 0) {
84-
85-
// Only the closest intersection that is outside the overstepping
86-
// tolerance is needed
87-
scalar_type t = qe.smaller();
88-
if ((qe.smaller() < overstep_tol) && (qe.solutions() == 2u)) {
89-
t = qe.larger();
83+
if (qe.solutions() > 0)
84+
[[likely]] {
85+
86+
// Only the closest intersection that is outside the
87+
// overstepping tolerance is needed
88+
scalar_type t = qe.smaller();
89+
if ((qe.smaller() < overstep_tol) && (qe.solutions() == 2u)) {
90+
t = qe.larger();
91+
}
92+
93+
is = this->template build_candidate<surface_descr_t>(
94+
ray, mask, trf, t, mask_tolerance, mask_tol_scalor,
95+
overstep_tol);
96+
is.sf_desc = sf;
9097
}
91-
92-
is = this->template build_candidate<surface_descr_t>(
93-
ray, mask, trf, t, mask_tolerance, mask_tol_scalor,
94-
overstep_tol);
95-
is.sf_desc = sf;
96-
} else {
97-
is.status = false;
98-
}
98+
else
99+
[[unlikely]] { is.status = false; }
99100

100101
return is;
101102
}

core/include/detray/navigation/intersection/ray_plane_intersector.hpp

+24-22
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,32 @@ struct ray_intersector_impl<cartesian2D<algebra_t>, algebra_t, do_debug> {
7575
const vector3_type &rd = ray.dir();
7676
const scalar_type denom = vector::dot(rd, sn);
7777
// this is dangerous
78-
if (denom != 0.f) {
79-
is.path = vector::dot(sn, st - ro) / denom;
80-
81-
// Intersection is valid for navigation - continue
82-
if (is.path >= overstep_tol) {
83-
84-
const point3_type p3 = ro + is.path * rd;
85-
const auto loc{mask_t::to_local_frame(trf, p3, rd)};
86-
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
87-
is.local = loc;
78+
if (denom != 0.f)
79+
[[likely]] {
80+
is.path = vector::dot(sn, st - ro) / denom;
81+
82+
// Intersection is valid for navigation - continue
83+
if (is.path >= overstep_tol) {
84+
85+
const point3_type p3 = ro + is.path * rd;
86+
const auto loc{mask_t::to_local_frame(trf, p3, rd)};
87+
if constexpr (intersection_type<
88+
surface_descr_t>::is_debug()) {
89+
is.local = loc;
90+
}
91+
// Tolerance: per mille of the distance
92+
is.status = mask.is_inside(
93+
loc, math::max(mask_tolerance[0],
94+
math::min(mask_tolerance[1],
95+
mask_tol_scalor *
96+
math::fabs(is.path))));
97+
is.sf_desc = sf;
98+
is.direction = !detail::signbit(is.path);
99+
is.volume_link = mask.volume_link();
88100
}
89-
// Tolerance: per mille of the distance
90-
is.status = mask.is_inside(
91-
loc, math::max(
92-
mask_tolerance[0],
93-
math::min(mask_tolerance[1],
94-
mask_tol_scalor * math::fabs(is.path))));
95-
is.sf_desc = sf;
96-
is.direction = !detail::signbit(is.path);
97-
is.volume_link = mask.volume_link();
98101
}
99-
} else {
100-
is.status = false;
101-
}
102+
else
103+
[[unlikely]] { is.status = false; }
102104

103105
return is;
104106
}

core/include/detray/navigation/intersection/soa/ray_cylinder_portal_intersector.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
7373

7474
// None of the cylinders has a valid intersection
7575
if (detray::detail::all_of(qe.solutions() <= 0) ||
76-
detray::detail::all_of(qe.larger() <= overstep_tol)) {
77-
is.status = decltype(is.status)(false);
78-
return is;
79-
}
76+
detray::detail::all_of(qe.larger() <= overstep_tol))
77+
[[unlikely]] {
78+
is.status = decltype(is.status)(false);
79+
return is;
80+
}
8081

8182
// Only the closest intersection that is outside the overstepping
8283
// tolerance is needed

core/include/detray/navigation/intersection/soa/ray_line_intersector.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ struct ray_intersector_impl<line2D<algebra_t>, algebra_t, do_debug> {
8080
const scalar_type denom = 1.f - (zd * zd);
8181

8282
// Case for wire is parallel to track
83-
if (detray::detail::all_of(denom < 1e-5f)) {
84-
is.status = decltype(is.status)(false);
85-
return is;
86-
}
83+
if (detray::detail::all_of(denom < 1e-5f))
84+
[[unlikely]] {
85+
is.status = decltype(is.status)(false);
86+
return is;
87+
}
8788

8889
// vector from track position to line center
8990
const vector3_type t2l = st - ro;

core/include/detray/navigation/intersection/soa/ray_plane_intersector.hpp

+27-26
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,34 @@ struct ray_intersector_impl<cartesian2D<algebra_t>, algebra_t, do_debug> {
7979

8080
// Check if we divided by zero
8181
const auto check_sum = is.path.sum();
82-
if (!std::isnan(check_sum) && !std::isinf(check_sum)) {
83-
84-
const point3_type p3 = ro + is.path * rd;
85-
const auto loc = mask_t::to_local_frame(trf, p3, rd);
86-
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
87-
is.local = loc;
88-
}
89-
is.status = mask.is_inside(
90-
loc,
91-
math::max(mask_tolerance[0],
92-
math::min(mask_tolerance[1],
93-
mask_tol_scalor * math::fabs(is.path))));
94-
95-
// Early return, if no intersection was found
96-
if (detray::detail::none_of(is.status)) {
97-
return is;
82+
if (!std::isnan(check_sum) && !std::isinf(check_sum))
83+
[[likely]] {
84+
85+
const point3_type p3 = ro + is.path * rd;
86+
const auto loc = mask_t::to_local_frame(trf, p3, rd);
87+
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
88+
is.local = loc;
89+
}
90+
is.status = mask.is_inside(
91+
loc, math::max(
92+
mask_tolerance[0],
93+
math::min(mask_tolerance[1],
94+
mask_tol_scalor * math::fabs(is.path))));
95+
96+
// Early return, if no intersection was found
97+
if (detray::detail::none_of(is.status)) {
98+
return is;
99+
}
100+
101+
is.sf_desc = sf;
102+
is.direction = !math::signbit(is.path);
103+
is.volume_link = mask.volume_link();
104+
105+
// Mask the values where the overstepping tolerance was not met
106+
is.status &= (is.path >= overstep_tol);
98107
}
99-
100-
is.sf_desc = sf;
101-
is.direction = !math::signbit(is.path);
102-
is.volume_link = mask.volume_link();
103-
104-
// Mask the values where the overstepping tolerance was not met
105-
is.status &= (is.path >= overstep_tol);
106-
} else {
107-
is.status = decltype(is.status)(false);
108-
}
108+
else
109+
[[unlikely]] { is.status = decltype(is.status)(false); }
109110

110111
return is;
111112
}

0 commit comments

Comments
 (0)