DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
src/gui/ptrop.cpp
00001 
00002 #include <stdio.h> /* NULL */
00003 #include <assert.h>
00004 
00005 #include "ptrop.h"
00006 
00007 namespace ptrop {
00008 
00009 void self_test(void) {
00010     // DEBUG
00011     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)0 ) == true,  "whoops" );
00012     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)1 ) == false, "whoops" );
00013     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)2 ) == false, "whoops" );
00014     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)3 ) == false, "whoops" );
00015     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)4 ) == false, "whoops" );
00016     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)6 ) == false, "whoops" );
00017     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)7 ) == false, "whoops" );
00018     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)8 ) == true,  "whoops" );
00019     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)9 ) == false, "whoops" );
00020     static_assert( ptrop::isaligned<uint64_t>((uintptr_t)10) == false, "whoops" );
00021 
00022     static_assert( ptrop::isaligned((uintptr_t)0, (uintptr_t)8) == true,  "whoops" );
00023     static_assert( ptrop::isaligned((uintptr_t)1, (uintptr_t)8) == false, "whoops" );
00024     static_assert( ptrop::isaligned((uintptr_t)2, (uintptr_t)8) == false, "whoops" );
00025     static_assert( ptrop::isaligned((uintptr_t)3, (uintptr_t)8) == false, "whoops" );
00026     static_assert( ptrop::isaligned((uintptr_t)4, (uintptr_t)8) == false, "whoops" );
00027     static_assert( ptrop::isaligned((uintptr_t)6, (uintptr_t)8) == false, "whoops" );
00028     static_assert( ptrop::isaligned((uintptr_t)7, (uintptr_t)8) == false, "whoops" );
00029     static_assert( ptrop::isaligned((uintptr_t)8, (uintptr_t)8) == true,  "whoops" );
00030     static_assert( ptrop::isaligned((uintptr_t)9, (uintptr_t)8) == false, "whoops" );
00031     static_assert( ptrop::isaligned((uintptr_t)10,(uintptr_t)8) == false, "whoops" );
00032 
00033     static_assert( ptrop::isaligned<8>((uintptr_t)0 ) == true,  "whoops" );
00034     static_assert( ptrop::isaligned<8>((uintptr_t)1 ) == false, "whoops" );
00035     static_assert( ptrop::isaligned<8>((uintptr_t)2 ) == false, "whoops" );
00036     static_assert( ptrop::isaligned<8>((uintptr_t)3 ) == false, "whoops" );
00037     static_assert( ptrop::isaligned<8>((uintptr_t)4 ) == false, "whoops" );
00038     static_assert( ptrop::isaligned<8>((uintptr_t)6 ) == false, "whoops" );
00039     static_assert( ptrop::isaligned<8>((uintptr_t)7 ) == false, "whoops" );
00040     static_assert( ptrop::isaligned<8>((uintptr_t)8 ) == true,  "whoops" );
00041     static_assert( ptrop::isaligned<8>((uintptr_t)9 ) == false, "whoops" );
00042     static_assert( ptrop::isaligned<8>((uintptr_t)10) == false, "whoops" );
00043 
00044 
00045     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)0 ) == (uintptr_t)0,  "whoops" );
00046     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)1 ) == (uintptr_t)1,  "whoops" );
00047     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)2 ) == (uintptr_t)2,  "whoops" );
00048     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)3 ) == (uintptr_t)3,  "whoops" );
00049     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)4 ) == (uintptr_t)4,  "whoops" );
00050     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)5 ) == (uintptr_t)5,  "whoops" );
00051     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)6 ) == (uintptr_t)6,  "whoops" );
00052     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)7 ) == (uintptr_t)7,  "whoops" );
00053     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)8 ) == (uintptr_t)0,  "whoops" );
00054     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)9 ) == (uintptr_t)1,  "whoops" );
00055     static_assert( ptrop::misalignment<uint64_t>((uintptr_t)10) == (uintptr_t)2,  "whoops" );
00056 
00057     static_assert( ptrop::misalignment<8>((uintptr_t)0 ) == (uintptr_t)0,  "whoops" );
00058     static_assert( ptrop::misalignment<8>((uintptr_t)1 ) == (uintptr_t)1,  "whoops" );
00059     static_assert( ptrop::misalignment<8>((uintptr_t)2 ) == (uintptr_t)2,  "whoops" );
00060     static_assert( ptrop::misalignment<8>((uintptr_t)3 ) == (uintptr_t)3,  "whoops" );
00061     static_assert( ptrop::misalignment<8>((uintptr_t)4 ) == (uintptr_t)4,  "whoops" );
00062     static_assert( ptrop::misalignment<8>((uintptr_t)5 ) == (uintptr_t)5,  "whoops" );
00063     static_assert( ptrop::misalignment<8>((uintptr_t)6 ) == (uintptr_t)6,  "whoops" );
00064     static_assert( ptrop::misalignment<8>((uintptr_t)7 ) == (uintptr_t)7,  "whoops" );
00065     static_assert( ptrop::misalignment<8>((uintptr_t)8 ) == (uintptr_t)0,  "whoops" );
00066     static_assert( ptrop::misalignment<8>((uintptr_t)9 ) == (uintptr_t)1,  "whoops" );
00067     static_assert( ptrop::misalignment<8>((uintptr_t)10) == (uintptr_t)2,  "whoops" );
00068 
00069     static_assert( ptrop::misalignment((uintptr_t)0, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00070     static_assert( ptrop::misalignment((uintptr_t)1, (uintptr_t)8) == (uintptr_t)1,  "whoops" );
00071     static_assert( ptrop::misalignment((uintptr_t)2, (uintptr_t)8) == (uintptr_t)2,  "whoops" );
00072     static_assert( ptrop::misalignment((uintptr_t)3, (uintptr_t)8) == (uintptr_t)3,  "whoops" );
00073     static_assert( ptrop::misalignment((uintptr_t)4, (uintptr_t)8) == (uintptr_t)4,  "whoops" );
00074     static_assert( ptrop::misalignment((uintptr_t)5, (uintptr_t)8) == (uintptr_t)5,  "whoops" );
00075     static_assert( ptrop::misalignment((uintptr_t)6, (uintptr_t)8) == (uintptr_t)6,  "whoops" );
00076     static_assert( ptrop::misalignment((uintptr_t)7, (uintptr_t)8) == (uintptr_t)7,  "whoops" );
00077     static_assert( ptrop::misalignment((uintptr_t)8, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00078     static_assert( ptrop::misalignment((uintptr_t)9, (uintptr_t)8) == (uintptr_t)1,  "whoops" );
00079     static_assert( ptrop::misalignment((uintptr_t)10,(uintptr_t)8) == (uintptr_t)2,  "whoops" );
00080 
00081 
00082     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)0 ) == (uintptr_t)0,  "whoops" );
00083     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)1 ) == (uintptr_t)0,  "whoops" );
00084     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)2 ) == (uintptr_t)0,  "whoops" );
00085     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)3 ) == (uintptr_t)0,  "whoops" );
00086     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)4 ) == (uintptr_t)0,  "whoops" );
00087     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)5 ) == (uintptr_t)0,  "whoops" );
00088     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)6 ) == (uintptr_t)0,  "whoops" );
00089     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)7 ) == (uintptr_t)0,  "whoops" );
00090     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)8 ) == (uintptr_t)8,  "whoops" );
00091     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)9 ) == (uintptr_t)8,  "whoops" );
00092     static_assert( ptrop::aligndown<uint64_t>((uintptr_t)10) == (uintptr_t)8,  "whoops" );
00093 
00094     static_assert( ptrop::aligndown<8>((uintptr_t)0 ) == (uintptr_t)0,  "whoops" );
00095     static_assert( ptrop::aligndown<8>((uintptr_t)1 ) == (uintptr_t)0,  "whoops" );
00096     static_assert( ptrop::aligndown<8>((uintptr_t)2 ) == (uintptr_t)0,  "whoops" );
00097     static_assert( ptrop::aligndown<8>((uintptr_t)3 ) == (uintptr_t)0,  "whoops" );
00098     static_assert( ptrop::aligndown<8>((uintptr_t)4 ) == (uintptr_t)0,  "whoops" );
00099     static_assert( ptrop::aligndown<8>((uintptr_t)5 ) == (uintptr_t)0,  "whoops" );
00100     static_assert( ptrop::aligndown<8>((uintptr_t)6 ) == (uintptr_t)0,  "whoops" );
00101     static_assert( ptrop::aligndown<8>((uintptr_t)7 ) == (uintptr_t)0,  "whoops" );
00102     static_assert( ptrop::aligndown<8>((uintptr_t)8 ) == (uintptr_t)8,  "whoops" );
00103     static_assert( ptrop::aligndown<8>((uintptr_t)9 ) == (uintptr_t)8,  "whoops" );
00104     static_assert( ptrop::aligndown<8>((uintptr_t)10) == (uintptr_t)8,  "whoops" );
00105 
00106     static_assert( ptrop::aligndown((uintptr_t)0, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00107     static_assert( ptrop::aligndown((uintptr_t)1, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00108     static_assert( ptrop::aligndown((uintptr_t)2, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00109     static_assert( ptrop::aligndown((uintptr_t)3, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00110     static_assert( ptrop::aligndown((uintptr_t)4, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00111     static_assert( ptrop::aligndown((uintptr_t)5, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00112     static_assert( ptrop::aligndown((uintptr_t)6, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00113     static_assert( ptrop::aligndown((uintptr_t)7, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00114     static_assert( ptrop::aligndown((uintptr_t)8, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00115     static_assert( ptrop::aligndown((uintptr_t)9, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00116     static_assert( ptrop::aligndown((uintptr_t)10,(uintptr_t)8) == (uintptr_t)8,  "whoops" );
00117 
00118 
00119     static_assert( ptrop::alignup<uint64_t>((uintptr_t)0 ) == (uintptr_t)0,  "whoops" );
00120     static_assert( ptrop::alignup<uint64_t>((uintptr_t)1 ) == (uintptr_t)8,  "whoops" );
00121     static_assert( ptrop::alignup<uint64_t>((uintptr_t)2 ) == (uintptr_t)8,  "whoops" );
00122     static_assert( ptrop::alignup<uint64_t>((uintptr_t)3 ) == (uintptr_t)8,  "whoops" );
00123     static_assert( ptrop::alignup<uint64_t>((uintptr_t)4 ) == (uintptr_t)8,  "whoops" );
00124     static_assert( ptrop::alignup<uint64_t>((uintptr_t)5 ) == (uintptr_t)8,  "whoops" );
00125     static_assert( ptrop::alignup<uint64_t>((uintptr_t)6 ) == (uintptr_t)8,  "whoops" );
00126     static_assert( ptrop::alignup<uint64_t>((uintptr_t)7 ) == (uintptr_t)8,  "whoops" );
00127     static_assert( ptrop::alignup<uint64_t>((uintptr_t)8 ) == (uintptr_t)8,  "whoops" );
00128     static_assert( ptrop::alignup<uint64_t>((uintptr_t)9 ) == (uintptr_t)16, "whoops" );
00129     static_assert( ptrop::alignup<uint64_t>((uintptr_t)10) == (uintptr_t)16, "whoops" );
00130 
00131     static_assert( ptrop::alignup<8>((uintptr_t)0 ) == (uintptr_t)0,  "whoops" );
00132     static_assert( ptrop::alignup<8>((uintptr_t)1 ) == (uintptr_t)8,  "whoops" );
00133     static_assert( ptrop::alignup<8>((uintptr_t)2 ) == (uintptr_t)8,  "whoops" );
00134     static_assert( ptrop::alignup<8>((uintptr_t)3 ) == (uintptr_t)8,  "whoops" );
00135     static_assert( ptrop::alignup<8>((uintptr_t)4 ) == (uintptr_t)8,  "whoops" );
00136     static_assert( ptrop::alignup<8>((uintptr_t)5 ) == (uintptr_t)8,  "whoops" );
00137     static_assert( ptrop::alignup<8>((uintptr_t)6 ) == (uintptr_t)8,  "whoops" );
00138     static_assert( ptrop::alignup<8>((uintptr_t)7 ) == (uintptr_t)8,  "whoops" );
00139     static_assert( ptrop::alignup<8>((uintptr_t)8 ) == (uintptr_t)8,  "whoops" );
00140     static_assert( ptrop::alignup<8>((uintptr_t)9 ) == (uintptr_t)16, "whoops" );
00141     static_assert( ptrop::alignup<8>((uintptr_t)10) == (uintptr_t)16, "whoops" );
00142 
00143     static_assert( ptrop::alignup((uintptr_t)0, (uintptr_t)8) == (uintptr_t)0,  "whoops" );
00144     static_assert( ptrop::alignup((uintptr_t)1, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00145     static_assert( ptrop::alignup((uintptr_t)2, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00146     static_assert( ptrop::alignup((uintptr_t)3, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00147     static_assert( ptrop::alignup((uintptr_t)4, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00148     static_assert( ptrop::alignup((uintptr_t)5, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00149     static_assert( ptrop::alignup((uintptr_t)6, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00150     static_assert( ptrop::alignup((uintptr_t)7, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00151     static_assert( ptrop::alignup((uintptr_t)8, (uintptr_t)8) == (uintptr_t)8,  "whoops" );
00152     static_assert( ptrop::alignup((uintptr_t)9, (uintptr_t)8) == (uintptr_t)16, "whoops" );
00153     static_assert( ptrop::alignup((uintptr_t)10,(uintptr_t)8) == (uintptr_t)16, "whoops" );
00154 }
00155 
00156 }
00157