Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.4 KiB

  1. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All rights reserved.
  4. //
  5. // Module:
  6. // volcano/dll/vtune.c
  7. //
  8. // Description:
  9. // Runtime portion of the volcano tuning module
  10. //
  11. // Author:
  12. // hrowley
  13. //
  14. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  15. #include <stdio.h>
  16. #include <float.h>
  17. #include "common.h"
  18. #include "vtune.h"
  19. ///////////////////////////////////////
  20. //
  21. // VTuneZeroWeights
  22. //
  23. // Zero out an array of weights on scores
  24. //
  25. // Parameters:
  26. // pWeights: [out] Pointer to a weights array
  27. //
  28. // Return values:
  29. // None.
  30. //
  31. //////////////////////////////////////
  32. void VTuneZeroWeights(VOLCANO_WEIGHTS *pWeights)
  33. {
  34. int i;
  35. for (i = 0; i < VTUNE_NUM_WEIGHTS; i++)
  36. {
  37. pWeights->afl[i] = 0;
  38. }
  39. }
  40. ///////////////////////////////////////
  41. //
  42. // VTuneComputeScore
  43. //
  44. // Compute the weighted sum of the scores and return the result
  45. //
  46. // Parameters:
  47. // pWeights: [in] Pointer to a weights array
  48. // pScores: [in] Pointer to a scores array
  49. //
  50. // Return values:
  51. // Weighted sum of the scores.
  52. //
  53. //////////////////////////////////////
  54. float VTuneComputeScore(VOLCANO_WEIGHTS *pWeights, VOLCANO_WEIGHTS *pScores)
  55. {
  56. int i;
  57. float flTotal = 0.0;
  58. for (i = 0; i < VTUNE_NUM_WEIGHTS; i++)
  59. {
  60. flTotal += pWeights->afl[i] * pScores->afl[i];
  61. }
  62. return flTotal;
  63. }
  64. ///////////////////////////////////////
  65. //
  66. // VTuneComputeScoreNoLM
  67. //
  68. // Compute the weighted sum of the scores and return the result.
  69. // Unlike VTuneComputeScore, this version does not add in the
  70. // components of the score related to the language model.
  71. //
  72. // Parameters:
  73. // pWeights: [in] Pointer to a weights array
  74. // pScores: [in] Pointer to a scores array
  75. //
  76. // Return values:
  77. // Weighted sum of the scores.
  78. //
  79. //////////////////////////////////////
  80. float VTuneComputeScoreNoLM(VOLCANO_WEIGHTS *pWeights, VOLCANO_WEIGHTS *pScores)
  81. {
  82. int i;
  83. float flTotal = 0.0;
  84. for (i = 0; i < VTUNE_NUM_WEIGHTS; i++)
  85. {
  86. // Check th
  87. switch (i)
  88. {
  89. // Global language model
  90. case VTUNE_UNIGRAM:
  91. break;
  92. // String mode language model
  93. case VTUNE_STRING_SMOOTHING_UNIGRAM:
  94. case VTUNE_STRING_BIGRAM:
  95. case VTUNE_STRING_CLASS_BIGRAM:
  96. break;
  97. // Free mode langauge model
  98. case VTUNE_FREE_SMOOTHING_UNIGRAM:
  99. case VTUNE_FREE_BIGRAM:
  100. case VTUNE_FREE_CLASS_BIGRAM:
  101. break;
  102. // Otherwise, add in the score
  103. default:
  104. flTotal += pWeights->afl[i] * pScores->afl[i];
  105. break;
  106. }
  107. }
  108. return flTotal;
  109. }
  110. ///////////////////////////////////////
  111. //
  112. // VTuneCheckFileVersion
  113. //
  114. // Check the file header and version information in a tuning database
  115. //
  116. // Parameters:
  117. // pTune: [in] Tuning database to check
  118. //
  119. // Return values:
  120. // TRUE if file version is okay, FALSE otherwise
  121. //
  122. //////////////////////////////////////
  123. BOOL VTuneCheckFileVersion(VOLCANO_PARAMS *pTune)
  124. {
  125. ASSERT(pTune->dwFileType == VTUNE_FILE_TYPE);
  126. if (pTune->dwFileType != VTUNE_FILE_TYPE)
  127. {
  128. return FALSE;
  129. }
  130. ASSERT(pTune->iFileVer >= VTUNE_OLD_FILE_VERSION);
  131. ASSERT(pTune->iMinCodeVer <= VTUNE_CUR_FILE_VERSION);
  132. if (pTune->iFileVer >= VTUNE_OLD_FILE_VERSION &&
  133. pTune->iMinCodeVer <= VTUNE_CUR_FILE_VERSION)
  134. {
  135. return TRUE;
  136. }
  137. return FALSE;
  138. }
  139. ///////////////////////////////////////
  140. //
  141. // VTuneLoadRes
  142. //
  143. // Map a resource as the tuning parameter database
  144. //
  145. // Parameters:
  146. // pInfo: [out] Pointer to the database structure to fill in
  147. // hInst: [in] DLL to locate the resource in
  148. // nResID: [in] Resource ID
  149. // nType: [in] Resource type
  150. //
  151. // Return values:
  152. // TRUE if the mapping succeeds, FALSE if the mapping fails.
  153. //
  154. //////////////////////////////////////
  155. BOOL VTuneLoadRes(VOLCANO_PARAMS_INFO *pInfo, HINSTANCE hInst, int nResID, int nType)
  156. {
  157. pInfo->pTune = (VOLCANO_PARAMS *) DoLoadResource(&pInfo->info, hInst, nResID, nType);
  158. if (pInfo->pTune == NULL)
  159. {
  160. ASSERT(("Failed to locate resource for VTune database.\n", FALSE));
  161. return FALSE;
  162. }
  163. // Check the file version
  164. return VTuneCheckFileVersion(pInfo->pTune);
  165. }