Changeset 22004 in vbox
- Timestamp:
- Aug 5, 2009 6:26:53 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 50739
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/asm.h
r21943 r22004 5053 5053 5054 5054 /** 5055 * Checks if a memory page is all zeros. 5056 * 5057 * @returns true / false. 5058 * 5059 * @param pvPage Pointer to the page. This must be naturally aligned if 5060 * not page aligned. 5061 */ 5062 DECLINLINE(bool) ASMMemIsZeroPage(void const *pvPage) 5063 { 5064 # if 0 /*RT_INLINE_ASM_GNU_STYLE - this is actually slower... */ 5065 union { RTCCUINTREG r; bool f; } uAX; 5066 RTCCUINTREG xCX, xDI; 5067 Assert(!((uintptr_t)pvPage & (sizeof(uintptr_t) - 1))); 5068 __asm__ __volatile__("repe; " 5069 # ifdef RT_ARCH_AMD64 5070 "scasq\n\t" 5071 # else 5072 "scasl\n\t" 5073 # endif 5074 "setnc %%al\n\t" 5075 : "=&c" (xCX), 5076 "=&D" (xDI), 5077 "=&a" (uAX.r) 5078 : "mr" (pvPage), 5079 # ifdef RT_ARCH_AMD64 5080 "0" (0x1000/8), 5081 # else 5082 "0" (0x1000/4), 5083 # endif 5084 "1" (pvPage), 5085 "2" (0)); 5086 return uAX.f; 5087 # else 5088 uintptr_t const *puPtr = (uintptr_t const *)pvPage; 5089 int cLeft = 0x1000 / sizeof(uintptr_t) / 8; 5090 Assert(!((uintptr_t)pvPage & (sizeof(uintptr_t) - 1))); 5091 for (;;) 5092 { 5093 if (puPtr[0]) return false; 5094 if (puPtr[4]) return false; 5095 5096 if (puPtr[2]) return false; 5097 if (puPtr[6]) return false; 5098 5099 if (puPtr[1]) return false; 5100 if (puPtr[5]) return false; 5101 5102 if (puPtr[3]) return false; 5103 if (puPtr[7]) return false; 5104 5105 if (!--cLeft) 5106 return true; 5107 puPtr += 8; 5108 } 5109 return true; 5110 # endif 5111 } 5112 5113 5114 /** 5055 5115 * Checks if a memory block is filled with the specified byte. 5056 5116 * -
trunk/src/VBox/Runtime/testcase/tstInlineAsm.cpp
r21451 r22004 38 38 #include <iprt/param.h> 39 39 #include <iprt/thread.h> 40 41 42 /******************************************************************************* 43 * Global Variables * 44 *******************************************************************************/ 45 /** Global error count. */ 46 static unsigned g_cErrors; 40 #include <iprt/test.h> 41 47 42 48 43 … … 55 50 if ((val) != (expect)) \ 56 51 { \ 57 g_cErrors++; \52 RTTestIErrorInc(); \ 58 53 RTPrintf("%s, %d: " #val ": expected " fmt " got " fmt "\n", __FUNCTION__, __LINE__, (expect), (val)); \ 59 54 } \ … … 66 61 if (val != (type)(expect)) \ 67 62 { \ 68 g_cErrors++; \63 RTTestIErrorInc(); \ 69 64 RTPrintf("%s, %d: " #op ": expected " fmt " got " fmt "\n", __FUNCTION__, __LINE__, (type)(expect), val); \ 70 65 } \ … … 693 688 { \ 694 689 RTPrintf("%s, %d: FAILURE: %s -> %d expected %d\n", __FUNCTION__, __LINE__, #op, i32Rc, rc); \ 695 g_cErrors++; \690 RTTestIErrorInc(); \ 696 691 } \ 697 692 if (i32 != (val)) \ 698 693 { \ 699 694 RTPrintf("%s, %d: FAILURE: %s => i32=%d expected %d\n", __FUNCTION__, __LINE__, #op, i32, val); \ 700 g_cErrors++; \695 RTTestIErrorInc(); \ 701 696 } \ 702 697 } while (0) … … 722 717 { \ 723 718 RTPrintf("%s, %d: FAILURE: %s -> %d expected %d\n", __FUNCTION__, __LINE__, #op, i32Rc, rc); \ 724 g_cErrors++; \719 RTTestIErrorInc(); \ 725 720 } \ 726 721 if (i32 != (rc)) \ 727 722 { \ 728 723 RTPrintf("%s, %d: FAILURE: %s => i32=%d expected %d\n", __FUNCTION__, __LINE__, #op, i32, rc); \ 729 g_cErrors++; \724 RTTestIErrorInc(); \ 730 725 } \ 731 726 } while (0) … … 817 812 { 818 813 RTPrintf("tstInlineAsm: ASMMemZeroPage violated one/both magic(s)!\n"); 819 g_cErrors++;814 RTTestIErrorInc(); 820 815 } 821 816 for (unsigned i = 0; i < sizeof(Buf1.abPage); i++) … … 823 818 { 824 819 RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i); 825 g_cErrors++;820 RTTestIErrorInc(); 826 821 } 827 822 for (unsigned i = 0; i < sizeof(Buf2.abPage); i++) … … 829 824 { 830 825 RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i); 831 g_cErrors++;826 RTTestIErrorInc(); 832 827 } 833 828 for (unsigned i = 0; i < sizeof(Buf3.abPage); i++) … … 835 830 { 836 831 RTPrintf("tstInlineAsm: ASMMemZeroPage didn't clear byte at offset %#x!\n", i); 837 g_cErrors++;832 RTTestIErrorInc(); 838 833 } 834 } 835 836 837 void tstASMMemIsZeroPage(RTTEST hTest) 838 { 839 RTTestSub(hTest, "ASMMemIsZeroPage"); 840 841 void *pvPage1 = RTTestGuardedAllocHead(hTest, PAGE_SIZE); 842 void *pvPage2 = RTTestGuardedAllocTail(hTest, PAGE_SIZE); 843 RTTESTI_CHECK_RETV(pvPage1 && pvPage2); 844 845 memset(pvPage1, 0, PAGE_SIZE); 846 memset(pvPage2, 0, PAGE_SIZE); 847 RTTESTI_CHECK(ASMMemIsZeroPage(pvPage1)); 848 RTTESTI_CHECK(ASMMemIsZeroPage(pvPage2)); 849 850 memset(pvPage1, 0xff, PAGE_SIZE); 851 memset(pvPage2, 0xff, PAGE_SIZE); 852 RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage1)); 853 RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage2)); 854 855 memset(pvPage1, 0, PAGE_SIZE); 856 memset(pvPage2, 0, PAGE_SIZE); 857 for (unsigned off = 0; off < PAGE_SIZE; off++) 858 { 859 ((uint8_t *)pvPage1)[off] = 1; 860 RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage1)); 861 ((uint8_t *)pvPage1)[off] = 0; 862 863 ((uint8_t *)pvPage2)[off] = 0x80; 864 RTTESTI_CHECK(!ASMMemIsZeroPage(pvPage2)); 865 ((uint8_t *)pvPage2)[off] = 0; 866 } 867 868 RTTestSubDone(hTest); 839 869 } 840 870 … … 869 899 { 870 900 RTPrintf("tstInlineAsm: ASMMemZero32 violated one/both magic(s)!\n"); 871 g_cErrors++;901 RTTestIErrorInc(); 872 902 } 873 903 for (unsigned i = 0; i < RT_ELEMENTS(Buf1.abPage); i++) … … 875 905 { 876 906 RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i); 877 g_cErrors++;907 RTTestIErrorInc(); 878 908 } 879 909 for (unsigned i = 0; i < RT_ELEMENTS(Buf2.abPage); i++) … … 881 911 { 882 912 RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i); 883 g_cErrors++;913 RTTestIErrorInc(); 884 914 } 885 915 for (unsigned i = 0; i < RT_ELEMENTS(Buf3.abPage); i++) … … 887 917 { 888 918 RTPrintf("tstInlineAsm: ASMMemZero32 didn't clear byte at offset %#x!\n", i); 889 g_cErrors++;919 RTTestIErrorInc(); 890 920 } 891 921 } … … 933 963 { 934 964 RTPrintf("tstInlineAsm: ASMMemFill32 violated one/both magic(s)!\n"); 935 g_cErrors++;965 RTTestIErrorInc(); 936 966 } 937 967 for (unsigned i = 0; i < RT_ELEMENTS(Buf1.au32Page); i++) … … 939 969 { 940 970 RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf1.au32Page[i], 0xdeadbeef); 941 g_cErrors++;971 RTTestIErrorInc(); 942 972 } 943 973 for (unsigned i = 0; i < RT_ELEMENTS(Buf2.au32Page); i++) … … 945 975 { 946 976 RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf2.au32Page[i], 0xcafeff01); 947 g_cErrors++;977 RTTestIErrorInc(); 948 978 } 949 979 for (unsigned i = 0; i < RT_ELEMENTS(Buf3.au32Page); i++) … … 951 981 { 952 982 RTPrintf("tstInlineAsm: ASMMemFill32 %#x: %#x exepcted %#x\n", i, Buf3.au32Page[i], 0xf00dd00f); 953 g_cErrors++;983 RTTestIErrorInc(); 954 984 } 955 985 } … … 1168 1198 int main(int argc, char *argv[]) 1169 1199 { 1170 RTR3Init(); 1171 RTPrintf("tstInlineAsm: TESTING\n"); 1200 RTTEST hTest; 1201 int rc = RTTestInitAndCreate("tstInlineAsm", &hTest); 1202 if (rc) 1203 return rc; 1204 RTTestBanner(hTest); 1172 1205 1173 1206 /* … … 1191 1224 tstASMAtomicAndOrU32(); 1192 1225 tstASMMemZeroPage(); 1226 tstASMMemIsZeroPage(hTest); 1193 1227 tstASMMemZero32(); 1194 1228 tstASMMemFill32(); 1195 1229 tstASMMath(); 1196 1230 tstASMByteSwap(); 1197 1198 1231 tstASMBench(); 1199 1232 … … 1201 1234 * Show the result. 1202 1235 */ 1203 if (!g_cErrors) 1204 RTPrintf("tstInlineAsm: SUCCESS\n", g_cErrors); 1205 else 1206 RTPrintf("tstInlineAsm: FAILURE - %d errors\n", g_cErrors); 1207 return !!g_cErrors; 1208 } 1209 1236 return RTTestSummaryAndDestroy(hTest); 1237 } 1238
Note:
See TracChangeset
for help on using the changeset viewer.