Skip to content

Instantly share code, notes, and snippets.

@define-private-public
Last active August 1, 2024 22:55
Show Gist options
  • Select an option

  • Save define-private-public/73ab82890d63671095c8d050349a2ac2 to your computer and use it in GitHub Desktop.

Select an option

Save define-private-public/73ab82890d63671095c8d050349a2ac2 to your computer and use it in GitHub Desktop.

Revisions

  1. define-private-public revised this gist Aug 1, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Common.hpp
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #ifdef USE_FINAL
    #define FINAL final
    #ifdef USE_NOEXCEPT
    #define NOEXCEPT noexcept
    #else
    #define FINAL
    #define NOEXCEPT
    #endif
  2. define-private-public revised this gist Jul 31, 2024. 1 changed file with 40 additions and 0 deletions.
    40 changes: 40 additions & 0 deletions use_of_noexcept.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    // 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 {
  3. define-private-public revised this gist Jul 31, 2024. No changes.
  4. define-private-public revised this gist Jul 31, 2024. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Common.hpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    #ifdef USE_FINAL
    #define FINAL final
    #else
    #define FINAL
    #endif
  5. define-private-public revised this gist Jul 31, 2024. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions CMakeLists.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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()
  6. define-private-public revised this gist Jul 31, 2024. No changes.
  7. define-private-public revised this gist Jul 31, 2024. 1 changed file with 24 additions and 16 deletions.
    40 changes: 24 additions & 16 deletions find_index.cpp
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,26 @@
    // Doing this icky C preprocessor macro stuff guarentees thats that we have the same
    // funciton with and without the keyword on. Yes, I know there could be more of a
    // "C++ way" of doing this but that isn't important.
    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;
    }
    }

    #define MAKE_FIND_FUNCTION(FUNCTION_NAME, NOEXCEPT) \
    int FUNCTION_NAME(const vector<int> &numbers, const int x) NOEXCEPT \
    { \
    for (int i = 0; i < numbers.size(); i++) \
    { \
    if (numbers[i] == x) \
    { \
    return i; \
    } \
    } \
    return -1; \
    return -1;
    }
    MAKE_FIND_FUNCTION(find_index_plain, )
    MAKE_FIND_FUNCTION(find_index_noexcept, noexcept)


    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;
    }
  8. define-private-public revised this gist Jul 30, 2024. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions find_index.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    // Doing this icky C preprocessor macro stuff guarentees thats that we have the same
    // funciton with and without the keyword on. Yes, I know there could be more of a
    // "C++ way" of doing this but that isn't important.

    #define MAKE_FIND_FUNCTION(FUNCTION_NAME, NOEXCEPT) \
    int FUNCTION_NAME(const vector<int> &numbers, const int x) NOEXCEPT \
    { \
    for (int i = 0; i < numbers.size(); i++) \
    { \
    if (numbers[i] == x) \
    { \
    return i; \
    } \
    } \
    return -1; \
    }
    MAKE_FIND_FUNCTION(find_index_plain, )
    MAKE_FIND_FUNCTION(find_index_noexcept, noexcept)
  9. define-private-public revised this gist Jul 30, 2024. 3 changed files with 42 additions and 1 deletion.
    1 change: 0 additions & 1 deletion asdf.txt
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    asdf
    21 changes: 21 additions & 0 deletions find_index_noexcept.asm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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
    21 changes: 21 additions & 0 deletions find_index_plain.asm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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
  10. define-private-public created this gist Jul 26, 2024.
    1 change: 1 addition & 0 deletions asdf.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    asdf