-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsmall.cc
More file actions
50 lines (39 loc) · 1.4 KB
/
small.cc
File metadata and controls
50 lines (39 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// -*- mode: c++; coding: utf-8 -*-
// ra-ra/examples - Small arrays
// Daniel Llorens - 2015
// Adapted from blitz++/examples/tiny.cpp
// The point of this example is to show the assembly; I will when it's not awful :-/
// $CXX -o small.s -S -O3 -DRA_CHECK=0 -std=c++14 -Wall -Werror -Wno-unknown-pragmas -Wno-parentheses -Wno-error=strict-overflow -march=native -I.. small.cc -funroll-loops -ffast-math -fno-exceptions
#include "ra/ra.hh"
#include <iostream>
using std::cout, std::endl, std::flush;
void
add_vectors(ra::Small<double, 4> & c, ra::Small<double, 4> const & a, ra::Small<double, 4> const & b)
{
c = a+b;
}
void
reflect(ra::Small<double, 3> & reflection, ra::Small<double, 3> const & ray, ra::Small<double, 3> const & surfaceNormal)
{
// The surface normal must be unit length to use this equation.
reflection = ray - 2.7 * dot(ray, surfaceNormal) * surfaceNormal;
}
int main()
{
{
ra::Small<double, 3> x, y, z;
// y will be the incident ray
y = { 1, 0, -1 };
// z is the surface normal
z = { 0, 0, 1 };
reflect(x, y, z);
cout << "Reflected ray is: [ " << x[0] << " " << x[1] << " " << x[2]
<< " ]" << endl;
}
{
ra::Small<double, 4> x, y { 1, 2, 3, 4 }, z { 10, 11, 12, 13 };
add_vectors(x, y, z);
cout << "x(" << x << ") = y (" << y << ") + z (" << z << ")" << endl;
}
return 0;
}