Bug 857071 - Ionmonkey ARM: Support a HWCAP environment variable override. r=mjrosenb

This commit is contained in:
Douglas Crosher 2014-02-01 19:02:32 +11:00
parent d319eb321c
commit 2e3633b3f3

View File

@ -39,6 +39,77 @@ uint32_t GetARMFlags()
if (isSet)
return flags;
static const char *env = getenv("ARMHWCAP");
if (env && env[0]) {
if (strstr(env, "help")) {
fflush(NULL);
printf(
"\n"
"usage: ARMHWCAP=option,option,option,... where options can be:\n"
"\n"
" armv7 \n"
" vfp \n"
" neon \n"
" vfpv3 \n"
" vfpv3d16 \n"
" vfpv4 \n"
" idiva \n"
" idivt \n"
"\n"
);
exit(0);
/*NOTREACHED*/
} else {
// Canonicalize each token to have a leading and trailing space.
const char *start = env; // Token start.
for (;;) {
char ch = *start;
if (!ch) {
// End of string.
break;
}
if (ch == ' ' || ch == ',') {
// Skip separator characters.
start++;
continue;
}
// Find the end of the token.
const char *end = start + 1;
for (; ; end++) {
ch = *end;
if (!ch || ch == ' ' || ch == ',')
break;
}
size_t count = end - start;
if (count == 3 && strncmp(start, "vfp", 3) == 0)
flags |= HWCAP_VFP;
else if (count == 5 && strncmp(start, "vfpv3", 5) == 0)
flags |= HWCAP_VFPv3;
else if (count == 8 && strncmp(start, "vfpv3d16", 8) == 0)
flags |= HWCAP_VFPv3D16;
else if (count == 5 && strncmp(start, "vfpv4", 5) == 0)
flags |= HWCAP_VFPv4;
else if (count == 5 && strncmp(start, "idiva", 5) == 0)
flags |= HWCAP_IDIVA;
else if (count == 5 && strncmp(start, "idivt", 5) == 0)
flags |= HWCAP_IDIVT;
else if (count == 4 && strncmp(start, "neon", 4) == 0)
flags |= HWCAP_NEON;
else if (count == 5 && strncmp(start, "armv7", 5) == 0)
flags |= HWCAP_ARMv7;
else
fprintf(stderr, "Warning: unexpected ARMHWCAP flag at: %s\n", start);
start = end;
}
#ifdef DEBUG
IonSpew(IonSpew_Codegen, "ARMHWCAP: '%s'\n flags: 0x%x\n", env, flags);
#endif
isSet = true;
return flags;
}
}
#ifdef JS_ARM_SIMULATOR
isSet = true;
flags = HWCAP_ARMv7 | HWCAP_VFP | HWCAP_VFPv4 | HWCAP_NEON;
@ -81,27 +152,40 @@ uint32_t GetARMFlags()
char buf[1024];
memset(buf, 0, sizeof(buf));
fread(buf, sizeof(char), sizeof(buf)-1, fp);
size_t len = fread(buf, sizeof(char), sizeof(buf) - 2, fp);
fclose(fp);
if (strstr(buf, "vfp"))
// Canonicalize each token to have a leading and trailing space.
buf[len] = ' ';
buf[len + 1] = '\0';
for (size_t i = 0; i < len; i++) {
char ch = buf[i];
if (!ch)
break;
else if (ch == '\n')
buf[i] = 0x20;
else
buf[i] = ch;
}
if (strstr(buf, " vfp "))
flags |= HWCAP_VFP;
if (strstr(buf, "vfpv3"))
if (strstr(buf, " vfpv3 "))
flags |= HWCAP_VFPv3;
if (strstr(buf, "vfpv3d16"))
if (strstr(buf, " vfpv3d16 "))
flags |= HWCAP_VFPv3D16;
if (strstr(buf, "vfpv4"))
if (strstr(buf, " vfpv4 "))
flags |= HWCAP_VFPv4;
if (strstr(buf, "idiva"))
if (strstr(buf, " idiva "))
flags |= HWCAP_IDIVA;
if (strstr(buf, "idivt"))
if (strstr(buf, " idivt "))
flags |= HWCAP_IDIVT;
if (strstr(buf, "neon"))
if (strstr(buf, " neon "))
flags |= HWCAP_NEON;
// not part of the HWCAP flag, but I need to know this, and we're not using
@ -109,6 +193,10 @@ uint32_t GetARMFlags()
if (strstr(buf, "ARMv7"))
flags |= HWCAP_ARMv7;
#ifdef DEBUG
IonSpew(IonSpew_Codegen, "ARMHWCAP: '%s'\n flags: 0x%x\n", buf, flags);
#endif
isSet = true;
return flags;
#endif
@ -119,20 +207,20 @@ uint32_t GetARMFlags()
bool hasMOVWT()
{
return js::jit::GetARMFlags() & HWCAP_ARMv7;
return GetARMFlags() & HWCAP_ARMv7;
}
bool hasVFPv3()
{
return js::jit::GetARMFlags() & HWCAP_VFPv3;
return GetARMFlags() & HWCAP_VFPv3;
}
bool hasVFP()
{
return js::jit::GetARMFlags() & HWCAP_VFP;
return GetARMFlags() & HWCAP_VFP;
}
bool has32DP()
{
return !(js::jit::GetARMFlags() & HWCAP_VFPv3D16 && !(js::jit::GetARMFlags() & HWCAP_NEON));
return !(GetARMFlags() & HWCAP_VFPv3D16 && !(GetARMFlags() & HWCAP_NEON));
}
bool useConvReg()
{
@ -142,7 +230,7 @@ bool useConvReg()
bool hasIDIV()
{
#if defined HWCAP_IDIVA
return js::jit::GetARMFlags() & HWCAP_IDIVA;
return GetARMFlags() & HWCAP_IDIVA;
#else
return false;
#endif