This file contains hidden or 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
| void simple_memory_copy(char *restrict destination, char const *restrict source, unsigned int length) { | |
| for (unsigned int i = 0; i < length; i++) { | |
| destination[i] = source[i]; | |
| } | |
| } |
This file contains hidden or 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
| void nonoptimizable_accumulate(int *accumulator, int const *array, int length) { | |
| for (int i = 0; i < length; i++) { | |
| *accumulator += array[i]; | |
| } | |
| } | |
| void optimizable_accumulate(int *restrict accumulator, int const *restrict array, int length) { | |
| for (int i = 0; i < length; i++) { | |
| *accumulator += array[i]; | |
| } |
This file contains hidden or 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
| static int compute_triangle_number(int base) { | |
| int base_incremented = base + 1; | |
| int numerator = base * base_incremented; | |
| return numerator/2; | |
| } | |
| long simple_bonus_threshold(unsigned int number) { | |
| int triangle_number = compute_triangle_number(number); | |
| return 3 * triangle_number; | |
| } |
This file contains hidden or 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
| #include <string.h> | |
| void simple_string_copy_without_restrict(char *destination, char const *source) { | |
| for (unsigned int i = 0; i <= strlen(source); i++) { | |
| destination[i] = source[i]; | |
| } | |
| } | |
| void simple_string_copy_with_restrict(char *restrict destination, char const *restrict source) { | |
| for (unsigned int i = 0; i <= strlen(source); i++) { |
This file contains hidden or 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
| #include <string.h> | |
| size_t strlen(char const *string) [[unsequenced]]; // may help in the future | |
| void simple_string_copy(char *restrict destination, char const *restrict source) { | |
| for (unsigned int i = 0; i < strlen(source); i++) { | |
| destination[i] = source[i]; | |
| } | |
| } |
This file contains hidden or 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
| void migration(int *destination, int const *source, int factor, int limit) { | |
| for (int i = 0; i < limit; i++) { | |
| destination[factor * limit + i] = source[i]; | |
| } | |
| } |
This file contains hidden or 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
| double average_neighbors(double const *matrix, unsigned int const neighbors[]); | |
| double no_cse(unsigned int i, unsigned int j, unsigned int width, double values[][width]) { | |
| unsigned int neighbors[4]; | |
| neighbors[0] = (i-1) * width + j; // values[i-1][j] | |
| neighbors[1] = (i+1) * width + j; // values[i+1][j] | |
| neighbors[2] = i * width + (j-1); // values[i][j-1] | |
| neighbors[3] = i * width + (j+1); // values[i][j+1] | |
| return average_neighbors((double const *) values, neighbors); | |
| } |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <time.h> | |
| #define RANGE 16384 | |
| int src1[RANGE][RANGE]; | |
| int src2[RANGE][RANGE]; | |
| int dest[RANGE][RANGE]; | |
| int main() { |
This file contains hidden or 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
| #include <stdio.h> | |
| int main() { | |
| long l = 1L; | |
| printf("Address: %p\n", &l); | |
| return 0; | |
| } |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <signal.h> | |
| void count_loop_iterations(int ignored) ; | |
| void catch_all(int signal); | |
| int main() { | |
| sigaction(SIGINT, &((struct sigaction) {.sa_handler = alarm_handler}), nullptr); | |
| sigaction(SIGVTALRM, &((struct sigaction) {.sa_handler = alarm_handler}), nullptr); | |
| count_loop_iterations(2000); |