Last active
August 1, 2024 22:55
-
-
Save define-private-public/73ab82890d63671095c8d050349a2ac2 to your computer and use it in GitHub Desktop.
C++ `noexcept` keyword experiment with PSRayTracing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
option(WITH_NOEXCEPT "Use the `noexcept` annotation for various functions (faster?)" OFF) | |
# ... | |
if (WITH_NOEXCEPT) | |
message(STATUS "Using `noexcept` annotations (faster?)") | |
target_compile_definitions(PSRayTracing_StaticLibrary PUBLIC USE_NOEXCEPT) | |
else() | |
message(STATUS "Turned off use of `noexcept` (slower?)") | |
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef USE_NOEXCEPT | |
#define NOEXCEPT noexcept | |
#else | |
#define NOEXCEPT | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int find_index_plain(const vector<int> &numbers, const int x) | |
{ | |
for (int i = 0; i < numbers.size(); i++) | |
{ | |
if (numbers[i] == x) | |
{ | |
return i; | |
} | |
} | |
return -1; | |
} | |
int find_index_noexcept(const vector<int> &numbers, const int x) noexcept | |
{ | |
for (int i = 0; i < numbers.size(); i++) | |
{ | |
if (numbers[i] == x) | |
{ | |
return i; | |
} | |
} | |
return -1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_index_noexcept(std::vector<int, std::allocator<int> > const&, int): | |
mov rax, QWORD PTR [rdi+8] | |
mov rdx, QWORD PTR [rdi] | |
mov rcx, rax | |
sub rcx, rdx | |
sar rcx, 2 | |
cmp rax, rdx | |
je .L13 | |
xor eax, eax | |
jmp .L12 | |
.L15: | |
add rax, 1 | |
cmp rax, rcx | |
jnb .L13 | |
.L12: | |
cmp esi, DWORD PTR [rdx+rax*4] | |
jne .L15 | |
ret | |
.L13: | |
mov eax, -1 | |
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_index_plain(std::vector<int, std::allocator<int> > const&, int): | |
mov rax, QWORD PTR [rdi+8] | |
mov rdx, QWORD PTR [rdi] | |
mov rcx, rax | |
sub rcx, rdx | |
sar rcx, 2 | |
cmp rax, rdx | |
je .L5 | |
xor eax, eax | |
jmp .L4 | |
.L8: | |
add rax, 1 | |
cmp rax, rcx | |
jnb .L5 | |
.L4: | |
cmp DWORD PTR [rdx+rax*4], esi | |
jne .L8 | |
ret | |
.L5: | |
mov eax, -1 | |
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is merely a snippet. Doing a `rg NOEXCEPT | wc -l` yields at least 450 results. | |
Objects/Sphere.cpp | |
12:inline void sphere_get_uv(const Vec3 &p, rreal &u, rreal &v) NOEXCEPT { | |
21:Sphere::Sphere(const Vec3 &cen, const rreal r, const shared_ptr<IMaterial> &mat) NOEXCEPT : | |
27:shared_ptr<IHittable> Sphere::deep_copy() const NOEXCEPT { | |
40:) const NOEXCEPT { | |
122:) const NOEXCEPT { | |
128:rreal Sphere::pdf_value(RandomGenerator &rng, const Vec3 &origin, const Vec3 &v) const NOEXCEPT { | |
142:Vec3 Sphere::random(RandomGenerator &rng, const Vec3 &origin) const NOEXCEPT { | |
Objects/ConstantMedium.cpp | |
14:) NOEXCEPT : | |
24:) NOEXCEPT : | |
30:std::shared_ptr<IHittable> ConstantMedium::deep_copy() const NOEXCEPT { | |
38:bool ConstantMedium::hit(RandomGenerator &rng, const Ray &r, const rreal t_min, const rreal t_max, HitRecord &rec) const NOEXCEPT { | |
72:bool ConstantMedium::bounding_box(const rreal t0, const rreal t1, AABB &output_box) const NOEXCEPT { | |
Objects/Transform/FlipFace.cpp | |
6:shared_ptr<IHittable> FlipFace::deep_copy() const NOEXCEPT { | |
10:bool FlipFace::hit(RandomGenerator &rng, const Ray &r, const rreal t_min, const rreal t_max, HitRecord &rec) const NOEXCEPT { | |
18:bool FlipFace::bounding_box(const rreal t0, const rreal t1, AABB &output_box) const NOEXCEPT { | |
Objects/Transform/Translate.hpp | |
13: explicit Translate(const std::shared_ptr<IHittable> &obj, const Vec3 &displacement) NOEXCEPT; | |
15: std::shared_ptr<IHittable> deep_copy() const NOEXCEPT override; | |
17: bool hit(RandomGenerator &rng, const Ray &r, const rreal t_min, const rreal t_max, HitRecord &rec) const NOEXCEPT override; | |
18: bool bounding_box(const rreal t0, const rreal t1, AABB &output_box) const NOEXCEPT override; | |
24: ) const NOEXCEPT override { | |
31: ) const NOEXCEPT override { | |
Objects/HittableList.cpp | |
8:HittableList::HittableList(const shared_ptr<IHittable> &object) NOEXCEPT { | |
12:shared_ptr<IHittable> HittableList::deep_copy() const NOEXCEPT { | |
23:void HittableList::clear() NOEXCEPT { | |
27:void HittableList::add(const shared_ptr<IHittable> &object) NOEXCEPT { | |
31:bool HittableList::hit(RandomGenerator &rng, const Ray &r, const rreal t_min, const rreal t_max, HitRecord &rec) const NOEXCEPT { | |
53:) const NOEXCEPT { | |
73:rreal HittableList::pdf_value(RandomGenerator &rng, const Vec3 &origin, const Vec3 &v) const NOEXCEPT { | |
84:Vec3 HittableList::random(RandomGenerator &rng, const Vec3 &origin) const NOEXCEPT { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment