… | |
… | |
356 | #define ECB_STRINGIFY_(a) # a |
356 | #define ECB_STRINGIFY_(a) # a |
357 | #define ECB_STRINGIFY(a) ECB_STRINGIFY_(a) |
357 | #define ECB_STRINGIFY(a) ECB_STRINGIFY_(a) |
358 | #define ECB_STRINGIFY_EXPR(expr) ((expr), ECB_STRINGIFY_ (expr)) |
358 | #define ECB_STRINGIFY_EXPR(expr) ((expr), ECB_STRINGIFY_ (expr)) |
359 | |
359 | |
360 | /* This marks larger functions that do not neccessarily need to be inlined */ |
360 | /* This marks larger functions that do not neccessarily need to be inlined */ |
|
|
361 | /* The idea is to possibly compile the header twice, */ |
|
|
362 | /* once exposing only the declarations, another time to define external functions */ |
361 | /* TODO: popssibly static would be best for these at the moment? */ |
363 | /* TODO: possibly static would be best for these at the moment? */ |
362 | #define ecb_function_ ecb_inline |
364 | #define ecb_function_ ecb_inline |
363 | |
365 | |
364 | #if ECB_GCC_VERSION(3,1) || ECB_CLANG_VERSION(2,8) |
366 | #if ECB_GCC_VERSION(3,1) || ECB_CLANG_VERSION(2,8) |
365 | #define ecb_attribute(attrlist) __attribute__ (attrlist) |
367 | #define ecb_attribute(attrlist) __attribute__ (attrlist) |
366 | #else |
368 | #else |
… | |
… | |
1033 | /*****************************************************************************/ |
1035 | /*****************************************************************************/ |
1034 | /* 2d hilbert curves */ |
1036 | /* 2d hilbert curves */ |
1035 | |
1037 | |
1036 | /* algorithm from the book Hacker's Delight, modified to not */ |
1038 | /* algorithm from the book Hacker's Delight, modified to not */ |
1037 | /* run into undefined behaviour for n==16 */ |
1039 | /* run into undefined behaviour for n==16 */ |
1038 | static uint32_t |
1040 | static uint32_t ecb_hilbert2d_index_to_coord32 (int n, uint32_t s); |
1039 | ecb_hilbert2d_index_to_coord32 (int n, uint32_t s) |
1041 | static uint32_t ecb_hilbert2d_index_to_coord32 (int n, uint32_t s) |
1040 | { |
1042 | { |
1041 | uint32_t comp, swap, cs, t, sr; |
1043 | uint32_t comp, swap, cs, t, sr; |
1042 | |
1044 | |
1043 | /* pad s on the left (unused) bits with 01 (no change groups) */ |
1045 | /* pad s on the left (unused) bits with 01 (no change groups) */ |
1044 | s |= 0x55555555U << n << n; |
1046 | s |= 0x55555555U << n << n; |
… | |
… | |
1078 | /* now s contains two 16-bit coordinates */ |
1080 | /* now s contains two 16-bit coordinates */ |
1079 | return s; |
1081 | return s; |
1080 | } |
1082 | } |
1081 | |
1083 | |
1082 | /* 64 bit, a straightforward extension to the 32 bit case */ |
1084 | /* 64 bit, a straightforward extension to the 32 bit case */ |
1083 | static uint64_t |
1085 | static uint64_t ecb_hilbert2d_index_to_coord64 (int n, uint64_t s); |
1084 | ecb_hilbert2d_index_to_coord64 (int n, uint64_t s) |
1086 | static uint64_t ecb_hilbert2d_index_to_coord64 (int n, uint64_t s) |
1085 | { |
1087 | { |
1086 | uint64_t comp, swap, cs, t, sr; |
1088 | uint64_t comp, swap, cs, t, sr; |
1087 | |
1089 | |
1088 | /* pad s on the left (unused) bits with 01 (no change groups) */ |
1090 | /* pad s on the left (unused) bits with 01 (no change groups) */ |
1089 | s |= 0x5555555555555555U << n << n; |
1091 | s |= 0x5555555555555555U << n << n; |
… | |
… | |
1127 | } |
1129 | } |
1128 | |
1130 | |
1129 | /* algorithm from the book Hacker's Delight, but a similar algorithm*/ |
1131 | /* algorithm from the book Hacker's Delight, but a similar algorithm*/ |
1130 | /* is given in https://doi.org/10.1002/spe.4380160103 */ |
1132 | /* is given in https://doi.org/10.1002/spe.4380160103 */ |
1131 | /* this has been slightly improved over the original version */ |
1133 | /* this has been slightly improved over the original version */ |
1132 | ecb_function_ uint32_t |
1134 | ecb_function_ uint32_t ecb_hilbert2d_coord_to_index32 (int n, uint32_t xy); |
1133 | ecb_hilbert2d_coord_to_index32 (int n, uint32_t xy) |
1135 | ecb_function_ uint32_t ecb_hilbert2d_coord_to_index32 (int n, uint32_t xy) |
1134 | { |
1136 | { |
1135 | uint32_t row; |
1137 | uint32_t row; |
1136 | uint32_t state = 0; |
1138 | uint32_t state = 0; |
1137 | uint32_t s = 0; |
1139 | uint32_t s = 0; |
1138 | |
1140 | |
… | |
… | |
1152 | |
1154 | |
1153 | return s; |
1155 | return s; |
1154 | } |
1156 | } |
1155 | |
1157 | |
1156 | /* 64 bit, essentially the same as 32 bit */ |
1158 | /* 64 bit, essentially the same as 32 bit */ |
1157 | ecb_function_ uint64_t |
1159 | ecb_function_ uint64_t ecb_hilbert2d_coord_to_index64 (int n, uint64_t xy); |
1158 | ecb_hilbert2d_coord_to_index64 (int n, uint64_t xy) |
1160 | ecb_function_ uint64_t ecb_hilbert2d_coord_to_index64 (int n, uint64_t xy) |
1159 | { |
1161 | { |
1160 | uint32_t row; |
1162 | uint32_t row; |
1161 | uint32_t state = 0; |
1163 | uint32_t state = 0; |
1162 | uint64_t s = 0; |
1164 | uint64_t s = 0; |
1163 | |
1165 | |