mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-02-07 14:40:12 +00:00
cpufeatures: Add separator to CpuFeatures_StringView_HasWord
This commit is contained in:
parent
4121efa0d2
commit
80fc676995
@ -87,7 +87,8 @@ void CpuFeatures_StringView_CopyString(const StringView src, char* dst,
|
|||||||
|
|
||||||
// Checks if line contains the specified whitespace separated word.
|
// Checks if line contains the specified whitespace separated word.
|
||||||
bool CpuFeatures_StringView_HasWord(const StringView line,
|
bool CpuFeatures_StringView_HasWord(const StringView line,
|
||||||
const char* const word);
|
const char* const word,
|
||||||
|
const char separator);
|
||||||
|
|
||||||
// Get key/value from line. key and value are separated by ": ".
|
// Get key/value from line. key and value are separated by ": ".
|
||||||
// key and value are cleaned up from leading and trailing whitespaces.
|
// key and value are cleaned up from leading and trailing whitespaces.
|
||||||
|
@ -107,8 +107,8 @@ static bool HandleAarch64Line(const LineResult result,
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < AARCH64_LAST_; ++i)
|
for (size_t i = 0; i < AARCH64_LAST_; ++i)
|
||||||
{
|
{
|
||||||
kSetters[i](&info->features,
|
kSetters[i](&info->features, CpuFeatures_StringView_HasWord(
|
||||||
CpuFeatures_StringView_HasWord(value, kCpuInfoFlags[i]));
|
value, kCpuInfoFlags[i], ' '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer")))
|
else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer")))
|
||||||
|
@ -71,8 +71,8 @@ static bool HandleArmLine(const LineResult result, ArmInfo* const info,
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < ARM_LAST_; ++i)
|
for (size_t i = 0; i < ARM_LAST_; ++i)
|
||||||
{
|
{
|
||||||
kSetters[i](&info->features,
|
kSetters[i](&info->features, CpuFeatures_StringView_HasWord(
|
||||||
CpuFeatures_StringView_HasWord(value, kCpuInfoFlags[i]));
|
value, kCpuInfoFlags[i], ' '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer")))
|
else if (CpuFeatures_StringView_IsEquals(key, str("CPU implementer")))
|
||||||
|
@ -28,8 +28,8 @@ static bool HandleMipsLine(const LineResult result,
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < MIPS_LAST_; ++i)
|
for (size_t i = 0; i < MIPS_LAST_; ++i)
|
||||||
{
|
{
|
||||||
kSetters[i](features,
|
kSetters[i](features, CpuFeatures_StringView_HasWord(
|
||||||
CpuFeatures_StringView_HasWord(value, kCpuInfoFlags[i]));
|
value, kCpuInfoFlags[i], ' '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ static bool HandlePPCLine(const LineResult result,
|
|||||||
StringView key, value;
|
StringView key, value;
|
||||||
if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value))
|
if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value))
|
||||||
{
|
{
|
||||||
if (CpuFeatures_StringView_HasWord(key, "platform"))
|
if (CpuFeatures_StringView_HasWord(key, "platform", ' '))
|
||||||
{
|
{
|
||||||
CpuFeatures_StringView_CopyString(value, strings->platform,
|
CpuFeatures_StringView_CopyString(value, strings->platform,
|
||||||
sizeof(strings->platform));
|
sizeof(strings->platform));
|
||||||
|
@ -1371,41 +1371,33 @@ static void ParseCpuId(const uint32_t max_cpuid_leaf, X86Info* info,
|
|||||||
{
|
{
|
||||||
StackLineReader reader;
|
StackLineReader reader;
|
||||||
StackLineReader_Initialize(&reader, fd);
|
StackLineReader_Initialize(&reader, fd);
|
||||||
for (;;)
|
for (bool stop = false; !stop;)
|
||||||
{
|
{
|
||||||
const LineResult result = StackLineReader_NextLine(&reader);
|
const LineResult result = StackLineReader_NextLine(&reader);
|
||||||
|
if (result.eof) stop = true;
|
||||||
const StringView line = result.line;
|
const StringView line = result.line;
|
||||||
const bool is_feature =
|
if (!CpuFeatures_StringView_StartsWith(line, str(" Features")))
|
||||||
CpuFeatures_StringView_StartsWith(line, str(" Features="));
|
continue;
|
||||||
const bool is_feature2 =
|
|
||||||
CpuFeatures_StringView_StartsWith(line, str(" Features2="));
|
|
||||||
if (is_feature || is_feature2)
|
|
||||||
{
|
|
||||||
// Lines of interests are of the following form:
|
// Lines of interests are of the following form:
|
||||||
// " Features=0x1783fbff<PSE36,MMX,FXSR,SSE,SSE2,HTT>"
|
// " Features=0x1783fbff<PSE36,MMX,FXSR,SSE,SSE2,HTT>"
|
||||||
// We replace '<', '>' and ',' with space so we can search by
|
// We first extract the comma separated values between angle brackets.
|
||||||
// whitespace separated word.
|
StringView csv = result.line;
|
||||||
// TODO: Fix CpuFeatures_StringView_HasWord to allow for different
|
int index = CpuFeatures_StringView_IndexOfChar(csv, '<');
|
||||||
// separators.
|
if (index >= 0) csv = CpuFeatures_StringView_PopFront(csv, index + 1);
|
||||||
for (size_t i = 0; i < line.size; ++i)
|
if (csv.size > 0 && CpuFeatures_StringView_Back(csv) == '>')
|
||||||
{
|
csv = CpuFeatures_StringView_PopBack(csv, 1);
|
||||||
char* c = (char*)(&(line.ptr[i]));
|
if (CpuFeatures_StringView_HasWord(csv, "SSE", ','))
|
||||||
if (*c == '<' || *c == '>' || *c == ',') *c = ' ';
|
features->sse = true;
|
||||||
}
|
if (CpuFeatures_StringView_HasWord(csv, "SSE2", ','))
|
||||||
if (is_feature)
|
features->sse2 = true;
|
||||||
{
|
if (CpuFeatures_StringView_HasWord(csv, "SSE3", ','))
|
||||||
features->sse = CpuFeatures_StringView_HasWord(line, "SSE");
|
features->sse3 = true;
|
||||||
features->sse2 = CpuFeatures_StringView_HasWord(line, "SSE2");
|
if (CpuFeatures_StringView_HasWord(csv, "SSSE3", ','))
|
||||||
}
|
features->ssse3 = true;
|
||||||
if (is_feature2)
|
if (CpuFeatures_StringView_HasWord(csv, "SSE4.1", ','))
|
||||||
{
|
features->sse4_1 = true;
|
||||||
features->sse3 = CpuFeatures_StringView_HasWord(line, "SSE3");
|
if (CpuFeatures_StringView_HasWord(csv, "SSE4.2", ','))
|
||||||
features->ssse3 = CpuFeatures_StringView_HasWord(line, "SSSE3");
|
features->sse4_2 = true;
|
||||||
features->sse4_1 = CpuFeatures_StringView_HasWord(line, "SSE4.1");
|
|
||||||
features->sse4_2 = CpuFeatures_StringView_HasWord(line, "SSE4.2");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result.eof) break;
|
|
||||||
}
|
}
|
||||||
CpuFeatures_CloseFile(fd);
|
CpuFeatures_CloseFile(fd);
|
||||||
}
|
}
|
||||||
@ -1416,26 +1408,23 @@ static void ParseCpuId(const uint32_t max_cpuid_leaf, X86Info* info,
|
|||||||
{
|
{
|
||||||
StackLineReader reader;
|
StackLineReader reader;
|
||||||
StackLineReader_Initialize(&reader, fd);
|
StackLineReader_Initialize(&reader, fd);
|
||||||
for (;;)
|
for (bool stop = false; !stop;)
|
||||||
{
|
{
|
||||||
const LineResult result = StackLineReader_NextLine(&reader);
|
const LineResult result = StackLineReader_NextLine(&reader);
|
||||||
|
if (result.eof) stop = true;
|
||||||
const StringView line = result.line;
|
const StringView line = result.line;
|
||||||
StringView key, value;
|
StringView key, value;
|
||||||
if (CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value))
|
if (!CpuFeatures_StringView_GetAttributeKeyValue(line, &key, &value))
|
||||||
{
|
continue;
|
||||||
if (CpuFeatures_StringView_IsEquals(key, str("flags")))
|
if (!CpuFeatures_StringView_IsEquals(key, str("flags"))) continue;
|
||||||
{
|
features->sse = CpuFeatures_StringView_HasWord(value, "sse", ' ');
|
||||||
features->sse = CpuFeatures_StringView_HasWord(value, "sse");
|
features->sse2 = CpuFeatures_StringView_HasWord(value, "sse2", ' ');
|
||||||
features->sse2 = CpuFeatures_StringView_HasWord(value, "sse2");
|
features->sse3 = CpuFeatures_StringView_HasWord(value, "sse3", ' ');
|
||||||
features->sse3 = CpuFeatures_StringView_HasWord(value, "sse3");
|
features->ssse3 = CpuFeatures_StringView_HasWord(value, "ssse3", ' ');
|
||||||
features->ssse3 = CpuFeatures_StringView_HasWord(value, "ssse3");
|
features->sse4_1 = CpuFeatures_StringView_HasWord(value, "sse4_1", ' ');
|
||||||
features->sse4_1 = CpuFeatures_StringView_HasWord(value, "sse4_1");
|
features->sse4_2 = CpuFeatures_StringView_HasWord(value, "sse4_2", ' ');
|
||||||
features->sse4_2 = CpuFeatures_StringView_HasWord(value, "sse4_2");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (result.eof) break;
|
|
||||||
}
|
|
||||||
CpuFeatures_CloseFile(fd);
|
CpuFeatures_CloseFile(fd);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -158,7 +158,8 @@ void CpuFeatures_StringView_CopyString(const StringView src, char* dst,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CpuFeatures_StringView_HasWord(const StringView line,
|
bool CpuFeatures_StringView_HasWord(const StringView line,
|
||||||
const char* const word_str)
|
const char* const word_str,
|
||||||
|
const char separator)
|
||||||
{
|
{
|
||||||
const StringView word = str(word_str);
|
const StringView word = str(word_str);
|
||||||
StringView remainder = line;
|
StringView remainder = line;
|
||||||
@ -176,9 +177,9 @@ bool CpuFeatures_StringView_HasWord(const StringView line,
|
|||||||
const StringView after =
|
const StringView after =
|
||||||
CpuFeatures_StringView_PopFront(line, index_of_word + word.size);
|
CpuFeatures_StringView_PopFront(line, index_of_word + word.size);
|
||||||
const bool valid_before =
|
const bool valid_before =
|
||||||
before.size == 0 || CpuFeatures_StringView_Back(before) == ' ';
|
before.size == 0 || CpuFeatures_StringView_Back(before) == separator;
|
||||||
const bool valid_after =
|
const bool valid_after =
|
||||||
after.size == 0 || CpuFeatures_StringView_Front(after) == ' ';
|
after.size == 0 || CpuFeatures_StringView_Front(after) == separator;
|
||||||
if (valid_before && valid_after) return true;
|
if (valid_before && valid_after) return true;
|
||||||
remainder =
|
remainder =
|
||||||
CpuFeatures_StringView_PopFront(remainder, index_of_word + word.size);
|
CpuFeatures_StringView_PopFront(remainder, index_of_word + word.size);
|
||||||
|
@ -167,15 +167,25 @@ TEST(StringViewTest, CpuFeatures_StringView_HasWord)
|
|||||||
{
|
{
|
||||||
// Find flags at beginning, middle and end.
|
// Find flags at beginning, middle and end.
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
CpuFeatures_StringView_HasWord(str("first middle last"), "first"));
|
CpuFeatures_StringView_HasWord(str("first middle last"), "first", ' '));
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
CpuFeatures_StringView_HasWord(str("first middle last"), "middle"));
|
CpuFeatures_StringView_HasWord(str("first middle last"), "middle", ' '));
|
||||||
EXPECT_TRUE(CpuFeatures_StringView_HasWord(str("first middle last"), "last"));
|
EXPECT_TRUE(
|
||||||
|
CpuFeatures_StringView_HasWord(str("first middle last"), "last", ' '));
|
||||||
|
// Find flags at beginning, middle and end with a different separator
|
||||||
|
EXPECT_TRUE(
|
||||||
|
CpuFeatures_StringView_HasWord(str("first-middle-last"), "first", '-'));
|
||||||
|
EXPECT_TRUE(
|
||||||
|
CpuFeatures_StringView_HasWord(str("first-middle-last"), "middle", '-'));
|
||||||
|
EXPECT_TRUE(
|
||||||
|
CpuFeatures_StringView_HasWord(str("first-middle-last"), "last", '-'));
|
||||||
// Do not match partial flags
|
// Do not match partial flags
|
||||||
EXPECT_FALSE(
|
EXPECT_FALSE(
|
||||||
CpuFeatures_StringView_HasWord(str("first middle last"), "irst"));
|
CpuFeatures_StringView_HasWord(str("first middle last"), "irst", ' '));
|
||||||
EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "mid"));
|
EXPECT_FALSE(
|
||||||
EXPECT_FALSE(CpuFeatures_StringView_HasWord(str("first middle last"), "las"));
|
CpuFeatures_StringView_HasWord(str("first middle last"), "mid", ' '));
|
||||||
|
EXPECT_FALSE(
|
||||||
|
CpuFeatures_StringView_HasWord(str("first middle last"), "las", ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StringViewTest, CpuFeatures_StringView_GetAttributeKeyValue)
|
TEST(StringViewTest, CpuFeatures_StringView_GetAttributeKeyValue)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user