Last active
February 11, 2016 08:40
-
-
Save hgomersall/22a19f245559d55f1ff6 to your computer and use it in GitHub Desktop.
Problem code with Valgrind on ARM
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 <stdint.h> | |
| #define N_SUBVALS 4 | |
| #define BOUNDARY 4 | |
| int main() | |
| { | |
| // The code finds the next boundary alignment for each set of of 4 | |
| // values in the following list, and sums them all together. | |
| uint32_t vals[] = {10,10,13,13,13,12,13,14,15,16,17,18,19,20,21,22}; | |
| uint32_t counter = 0; | |
| uint32_t index = 0; | |
| for (uint32_t i=0; i < 4; ++i){ | |
| uint32_t max_subval = 0; | |
| for (uint32_t j=0; j < N_SUBVALS; ++j){ | |
| uint32_t val = vals[index]; | |
| if (val > max_subval){ | |
| max_subval = val; | |
| } | |
| index += 1; | |
| } | |
| // should get the next aligned value from the largest of the set | |
| // of N_SUBVALS subvalues | |
| // The max sub vals are: 13, 14, 18 and 22 | |
| // These align to: 16, 16, 20 and 24 | |
| uint32_t aligned_subval = (max_subval + | |
| (BOUNDARY - (max_subval % BOUNDARY)) % BOUNDARY); | |
| // 16 + 16 + 20 + 24 = 76 | |
| counter += aligned_subval; | |
| } | |
| // Should print 76 | |
| // | |
| if (counter != 76){ | |
| printf("wrong final counter: %d\n", counter); | |
| } else { | |
| printf("correct final counter: %d\n", counter); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run and tested with the following shell script: