Skip to content
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

added ray-bbox-intersection benchmark #372

Merged
merged 1 commit into from
Jan 31, 2025
Merged
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
126 changes: 126 additions & 0 deletions benchmarks/float/ray-bbox-intersection.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
## Ray intersection with an axis-aligned bounding box in 2D.
## The bounding box is given by coordinates of its two corners: (x_min, y_min) and (x_max, y_max)
## Ray is defined by its origin, direction (not necessarily unit length) and length t.

# ARGS: 1 2 3 4 0 0 1 1 100
@main (x_min: float,
y_min: float,
x_max: float,
y_max: float,
x_ray_origin: float,
y_ray_origin: float,
x_ray_direction: float,
y_ray_direction: float,
t: float){
call @ray_bbox_inter x_min y_min x_max y_max x_ray_origin y_ray_origin x_ray_direction y_ray_direction t;
}

@ray_bbox_inter(x_min: float,
y_min: float,
x_max: float,
y_max: float,
x_ray_origin: float,
y_ray_origin: float,
x_ray_direction: float,
y_ray_direction: float,
t: float) {

t_min: float = const 0;
t_max: float = id t;

t_x_min_num: float = fsub x_min x_ray_origin;
t_x_max_num: float = fsub x_max x_ray_origin;

t_x_min: float = fdiv t_x_min_num x_ray_direction;
t_x_max: float = fdiv t_x_max_num x_ray_direction;

cond1: bool = fgt t_x_min t_x_max;
br cond1 .case1 .case2;

.case1:
cond11: bool = fgt t_x_max t_min;
br cond11 .case11 .donothing11;
.case11:
t_min: float = id t_x_max;
jmp .endcase11;
.donothing11:
.endcase11:
cond12: bool = flt t_x_min t_max;
br cond12 .case12 .donothing12;
.case12:
t_max: float = id t_x_min;
jmp .endcase12;
.donothing12:
.endcase12:
jmp .endpart1;

.case2:
cond21: bool = fgt t_x_min t_min;
br cond21 .case21 .donothing21;
.case21:
t_min: float = id t_x_min;
jmp .endcase21;
.donothing21:
.endcase21:
cond22: bool = flt t_x_max t_max;
br cond22 .case22 .donothing22;
.case22:
t_max: float = id t_x_max;
jmp .endcase22;
.donothing22:
.endcase22:

.endpart1:
t_y_min_num: float = fsub y_min y_ray_origin;
t_y_max_num: float = fsub y_max y_ray_origin;

t_y_min: float = fdiv t_y_min_num y_ray_direction;
t_y_max: float = fdiv t_y_max_num y_ray_direction;

cond3: bool = fgt t_y_min t_y_max;
br cond3 .case3 .case4;
.case3:
cond31: bool = fgt t_y_max t_min;
br cond31 .case31 .donothing31;
.case31:
t_min: float = id t_y_max;
jmp .endcase31;
.donothing31:
.endcase31:
cond32: bool = flt t_y_min t_max;
br cond32 .case32 .donothing32;
.case32:
t_max: float = id t_y_min;
jmp .endcase32;
.donothing32:
.endcase32:
jmp .endpart2;

.case4:
cond41: bool = fgt t_y_min t_min;
br cond41 .case41 .donothing41;
.case41:
t_min: float = id t_y_min;
jmp .endcase41;
.donothing41:
.endcase41:
cond42: bool = flt t_y_max t_max;
br cond42 .case42 .donothing42;
.case42:
t_max: float = id t_y_max;
jmp .endcase42;
.donothing42:
.endcase42:

.endpart2:
finalcheck: bool = fgt t_min t_max;
br finalcheck .printfalse .printtrue;
.printfalse:
falsebool: bool = const false;
print falsebool;
jmp .exit;
.printtrue:
truebool: bool = const true;
print truebool;
.exit:
}
1 change: 1 addition & 0 deletions benchmarks/float/ray-bbox-intersection.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
1 change: 1 addition & 0 deletions benchmarks/float/ray-bbox-intersection.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 33
1 change: 1 addition & 0 deletions docs/tools/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The current benchmarks are:
* `quickselect`: Find the kth smallest element in an array using the quickselect algorithm.
* `quicksort`: [Quicksort using the Lomuto partition scheme][qsort].
* `quicksort-hoare`: Quicksort using [Hoare partioning][qsort-hoare] and median of three pivot selection.
* `ray-bbox-intersection`: Finds whether a ray intersects an axis-aligned bounding box.
* `recfact`: Compute *n!* using recursive function calls.
* `rectangles-area-difference`: Output the difference between the areas of rectangles (as a positive value) given their respective side lengths.
* `fitsinside`: Output whether or not a rectangle fits inside of another rectangle given the width and height lengths.
Expand Down
Loading