I did the following source from fabriceo's original code, and then compiled different versions.
I have attached the project and the two interesting results in two external directories, containing ..map.txt and .s and .xi files. Just download and do a compare.
I am not able to analyse the build files. But I see the for the
safe version it does an out of range check of the pointer.
Might the not-unsafe pointer of 4*3 bytes contain the pointer plus full range (low and high)?
The .xi files just shows the difference in what's compiled.
The .s files are vastly different. I don't know the assembler, so I would be blank. I always get impressed by these files!
The ..map.txt files are equal except for one value: 000400f4 00000000 .text $d.46 or $d.59
I took out the printing for these builds, to hold that code away.
And I wanted to just do something (increment) to make sure(?) that the functions were not optimized away.
The code looks like this. I have stored away for TEST_SAFE 1 only and TEST_UNSAFE 1 only.
Code: Select all
#include <stdio.h> // printf
// ---
// Control printing
// See https://stackoverflow.com/questions/1644868/define-macro-for-debug-printing-in-c
// ---
#define DEBUG_PRINT_TEST 0
#define debug_print(fmt, ...) do { if(DEBUG_PRINT_TEST) printf(fmt, __VA_ARGS__); } while (0)
// See Fabriceo 10Apr2020 at https://xcore.com/viewtopic.php?f=26&t=7886#top
#define TEST_SAFE 0
#define TEST_UNSAFE 1
#if (TEST_SAFE == 1)
void test_ptr (int *ptr) {
debug_print ("sizeof ptr = %d\n",sizeof(ptr));
*ptr++; // Just do something
}
#endif
#if (TEST_UNSAFE == 1)
void test_unsafe_ptr (int * unsafe ptr) {
debug_print ("sizeof unsafe ptr = %d\n",sizeof(ptr));
unsafe {
*ptr++; // Just do something
}
}
#endif
// === Prints ===
// sizeof ptr = 12
// sizeof unsafe ptr = 4
void task1 () {
int x_val = 0;
#if (TEST_SAFE == 1)
test_ptr (&x_val);
#endif
#if (TEST_UNSAFE == 1)
unsafe {
test_unsafe_ptr (&x_val);
}
#endif
}
// xTIMEcomposer 14.4.1
// DEBUG_PRINT_TEST
// TEST_SAFE
// TEST_UNSUAFE
// 0 1 1 Constraints: C:8/1 T:10/1 C:32/0 M:2768 S:348 C:1972 D:448
// 1 1 1 Constraints: C:8/1 T:10/1 C:32/0 M:8320 S:596 C:7104 D:620
// 0 1 0 Constraints: C:8/1 T:10/1 C:32/0 M:2768 S:348 C:1972 D:448 strange
// 0 0 1 Constraints: C:8/1 T:10/1 C:32/0 M:2768 S:348 C:1972 D:448 strange
// 0 0 0 Constraints: C:8/1 T:10/1 C:32/0 M:880 S:348 C:456 D:76
// This costs no extra code, as compared to just making task1 the main
// But it looks more idiomatic XC:
int main() {
par {
task1 ();
}
return 0;
}
You do not have the required permissions to view the files attached to this post.