Skip to content

feat: Add likely/unlikely hints to to some branches #974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, do_debug> {
const auto qe = solve_intersection(ray, mask, trf);

switch (qe.solutions()) {
case 1:
sfi = build_candidate<surface_descr_t>(
ray, mask, trf, qe.smaller(), mask_tolerance,
mask_tol_scalor, overstep_tol);
break;
case 0:
sfi.status = false;
[[likely]] case 1
: sfi = build_candidate<surface_descr_t>(
ray, mask, trf, qe.smaller(), mask_tolerance,
mask_tol_scalor, overstep_tol);
break;
[[unlikely]] case 0 : sfi.status = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,23 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
const auto qe = this->solve_intersection(ray, mask, trf);

// Find the closest valid intersection
if (qe.solutions() > 0) {

// Only the closest intersection that is outside the overstepping
// tolerance is needed
scalar_type t = qe.smaller();
if ((qe.smaller() < overstep_tol) && (qe.solutions() == 2u)) {
t = qe.larger();
if (qe.solutions() > 0)
[[likely]] {

// Only the closest intersection that is outside the
// overstepping tolerance is needed
scalar_type t = qe.smaller();
if ((qe.smaller() < overstep_tol) && (qe.solutions() == 2u)) {
t = qe.larger();
}

is = this->template build_candidate<surface_descr_t>(
ray, mask, trf, t, mask_tolerance, mask_tol_scalor,
overstep_tol);
is.sf_desc = sf;
}

is = this->template build_candidate<surface_descr_t>(
ray, mask, trf, t, mask_tolerance, mask_tol_scalor,
overstep_tol);
is.sf_desc = sf;
} else {
is.status = false;
}
else
[[unlikely]] { is.status = false; }

return is;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,32 @@ struct ray_intersector_impl<cartesian2D<algebra_t>, algebra_t, do_debug> {
const vector3_type &rd = ray.dir();
const scalar_type denom = vector::dot(rd, sn);
// this is dangerous
if (denom != 0.f) {
is.path = vector::dot(sn, st - ro) / denom;

// Intersection is valid for navigation - continue
if (is.path >= overstep_tol) {

const point3_type p3 = ro + is.path * rd;
const auto loc{mask_t::to_local_frame(trf, p3, rd)};
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
is.local = loc;
if (denom != 0.f)
[[likely]] {
is.path = vector::dot(sn, st - ro) / denom;

// Intersection is valid for navigation - continue
if (is.path >= overstep_tol) {

const point3_type p3 = ro + is.path * rd;
const auto loc{mask_t::to_local_frame(trf, p3, rd)};
if constexpr (intersection_type<
surface_descr_t>::is_debug()) {
is.local = loc;
}
// Tolerance: per mille of the distance
is.status = mask.is_inside(
loc, math::max(mask_tolerance[0],
math::min(mask_tolerance[1],
mask_tol_scalor *
math::fabs(is.path))));
is.sf_desc = sf;
is.direction = !detail::signbit(is.path);
is.volume_link = mask.volume_link();
}
// Tolerance: per mille of the distance
is.status = mask.is_inside(
loc, math::max(
mask_tolerance[0],
math::min(mask_tolerance[1],
mask_tol_scalor * math::fabs(is.path))));
is.sf_desc = sf;
is.direction = !detail::signbit(is.path);
is.volume_link = mask.volume_link();
}
} else {
is.status = false;
}
else
[[unlikely]] { is.status = false; }

return is;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,

// None of the cylinders has a valid intersection
if (detray::detail::all_of(qe.solutions() <= 0) ||
detray::detail::all_of(qe.larger() <= overstep_tol)) {
is.status = decltype(is.status)(false);
return is;
}
detray::detail::all_of(qe.larger() <= overstep_tol))
[[unlikely]] {
is.status = decltype(is.status)(false);
return is;
}

// Only the closest intersection that is outside the overstepping
// tolerance is needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ struct ray_intersector_impl<line2D<algebra_t>, algebra_t, do_debug> {
const scalar_type denom = 1.f - (zd * zd);

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

// vector from track position to line center
const vector3_type t2l = st - ro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,34 @@ struct ray_intersector_impl<cartesian2D<algebra_t>, algebra_t, do_debug> {

// Check if we divided by zero
const auto check_sum = is.path.sum();
if (!std::isnan(check_sum) && !std::isinf(check_sum)) {

const point3_type p3 = ro + is.path * rd;
const auto loc = mask_t::to_local_frame(trf, p3, rd);
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
is.local = loc;
}
is.status = mask.is_inside(
loc,
math::max(mask_tolerance[0],
math::min(mask_tolerance[1],
mask_tol_scalor * math::fabs(is.path))));

// Early return, if no intersection was found
if (detray::detail::none_of(is.status)) {
return is;
if (!std::isnan(check_sum) && !std::isinf(check_sum))
[[likely]] {

const point3_type p3 = ro + is.path * rd;
const auto loc = mask_t::to_local_frame(trf, p3, rd);
if constexpr (intersection_type<surface_descr_t>::is_debug()) {
is.local = loc;
}
is.status = mask.is_inside(
loc, math::max(
mask_tolerance[0],
math::min(mask_tolerance[1],
mask_tol_scalor * math::fabs(is.path))));

// Early return, if no intersection was found
if (detray::detail::none_of(is.status)) {
return is;
}

is.sf_desc = sf;
is.direction = !math::signbit(is.path);
is.volume_link = mask.volume_link();

// Mask the values where the overstepping tolerance was not met
is.status &= (is.path >= overstep_tol);
}

is.sf_desc = sf;
is.direction = !math::signbit(is.path);
is.volume_link = mask.volume_link();

// Mask the values where the overstepping tolerance was not met
is.status &= (is.path >= overstep_tol);
} else {
is.status = decltype(is.status)(false);
}
else
[[unlikely]] { is.status = decltype(is.status)(false); }

return is;
}
Expand Down
Loading
Loading