js/src/jit/arm/Architecture-arm.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "jit/arm/Architecture-arm.h"
michael@0 8
michael@0 9 #ifndef JS_ARM_SIMULATOR
michael@0 10 #include <elf.h>
michael@0 11 #endif
michael@0 12
michael@0 13 #include <fcntl.h>
michael@0 14 #include <unistd.h>
michael@0 15
michael@0 16 #include "jit/arm/Assembler-arm.h"
michael@0 17
michael@0 18 #define HWCAP_USE_HARDFP_ABI (1 << 28)
michael@0 19
michael@0 20 #if !(defined(ANDROID) || defined(MOZ_B2G)) && !defined(JS_ARM_SIMULATOR)
michael@0 21 #define HWCAP_ARMv7 (1 << 29)
michael@0 22 #include <asm/hwcap.h>
michael@0 23 #else
michael@0 24 #define HWCAP_VFP (1<<0)
michael@0 25 #define HWCAP_VFPv3 (1<<1)
michael@0 26 #define HWCAP_VFPv3D16 (1<<2)
michael@0 27 #define HWCAP_VFPv4 (1<<3)
michael@0 28 #define HWCAP_IDIVA (1<<4)
michael@0 29 #define HWCAP_IDIVT (1<<5)
michael@0 30 #define HWCAP_NEON (1<<6)
michael@0 31 #define HWCAP_ARMv7 (1<<7)
michael@0 32 #endif
michael@0 33
michael@0 34 namespace js {
michael@0 35 namespace jit {
michael@0 36
michael@0 37 uint32_t GetARMFlags()
michael@0 38 {
michael@0 39 static bool isSet = false;
michael@0 40 static uint32_t flags = 0;
michael@0 41 if (isSet)
michael@0 42 return flags;
michael@0 43
michael@0 44 #ifdef JS_CODEGEN_ARM_HARDFP
michael@0 45 flags |= HWCAP_USE_HARDFP_ABI;
michael@0 46 #endif
michael@0 47
michael@0 48 static const char *env = getenv("ARMHWCAP");
michael@0 49
michael@0 50 if (env && env[0]) {
michael@0 51 if (strstr(env, "help")) {
michael@0 52 fflush(NULL);
michael@0 53 printf(
michael@0 54 "\n"
michael@0 55 "usage: ARMHWCAP=option,option,option,... where options can be:\n"
michael@0 56 "\n"
michael@0 57 " armv7 \n"
michael@0 58 " vfp \n"
michael@0 59 " neon \n"
michael@0 60 " vfpv3 \n"
michael@0 61 " vfpv3d16 \n"
michael@0 62 " vfpv4 \n"
michael@0 63 " idiva \n"
michael@0 64 " idivt \n"
michael@0 65 #if defined(JS_ARM_SIMULATOR)
michael@0 66 " hardfp \n"
michael@0 67 #endif
michael@0 68 "\n"
michael@0 69 );
michael@0 70 exit(0);
michael@0 71 /*NOTREACHED*/
michael@0 72 } else {
michael@0 73 // Canonicalize each token to have a leading and trailing space.
michael@0 74 const char *start = env; // Token start.
michael@0 75 for (;;) {
michael@0 76 char ch = *start;
michael@0 77 if (!ch) {
michael@0 78 // End of string.
michael@0 79 break;
michael@0 80 }
michael@0 81 if (ch == ' ' || ch == ',') {
michael@0 82 // Skip separator characters.
michael@0 83 start++;
michael@0 84 continue;
michael@0 85 }
michael@0 86 // Find the end of the token.
michael@0 87 const char *end = start + 1;
michael@0 88 for (; ; end++) {
michael@0 89 ch = *end;
michael@0 90 if (!ch || ch == ' ' || ch == ',')
michael@0 91 break;
michael@0 92 }
michael@0 93 size_t count = end - start;
michael@0 94 if (count == 3 && strncmp(start, "vfp", 3) == 0)
michael@0 95 flags |= HWCAP_VFP;
michael@0 96 else if (count == 5 && strncmp(start, "vfpv3", 5) == 0)
michael@0 97 flags |= HWCAP_VFPv3;
michael@0 98 else if (count == 8 && strncmp(start, "vfpv3d16", 8) == 0)
michael@0 99 flags |= HWCAP_VFPv3D16;
michael@0 100 else if (count == 5 && strncmp(start, "vfpv4", 5) == 0)
michael@0 101 flags |= HWCAP_VFPv4;
michael@0 102 else if (count == 5 && strncmp(start, "idiva", 5) == 0)
michael@0 103 flags |= HWCAP_IDIVA;
michael@0 104 else if (count == 5 && strncmp(start, "idivt", 5) == 0)
michael@0 105 flags |= HWCAP_IDIVT;
michael@0 106 else if (count == 4 && strncmp(start, "neon", 4) == 0)
michael@0 107 flags |= HWCAP_NEON;
michael@0 108 else if (count == 5 && strncmp(start, "armv7", 5) == 0)
michael@0 109 flags |= HWCAP_ARMv7;
michael@0 110 #if defined(JS_ARM_SIMULATOR)
michael@0 111 else if (count == 6 && strncmp(start, "hardfp", 6) == 0)
michael@0 112 flags |= HWCAP_USE_HARDFP_ABI;
michael@0 113 #endif
michael@0 114 else
michael@0 115 fprintf(stderr, "Warning: unexpected ARMHWCAP flag at: %s\n", start);
michael@0 116 start = end;
michael@0 117 }
michael@0 118 #ifdef DEBUG
michael@0 119 IonSpew(IonSpew_Codegen, "ARMHWCAP: '%s'\n flags: 0x%x\n", env, flags);
michael@0 120 #endif
michael@0 121 isSet = true;
michael@0 122 return flags;
michael@0 123 }
michael@0 124 }
michael@0 125
michael@0 126 #ifdef JS_ARM_SIMULATOR
michael@0 127 isSet = true;
michael@0 128 flags = HWCAP_ARMv7 | HWCAP_VFP | HWCAP_VFPv3 | HWCAP_VFPv4 | HWCAP_NEON;
michael@0 129 return flags;
michael@0 130 #else
michael@0 131
michael@0 132 #if WTF_OS_LINUX
michael@0 133 int fd = open("/proc/self/auxv", O_RDONLY);
michael@0 134 if (fd > 0) {
michael@0 135 Elf32_auxv_t aux;
michael@0 136 while (read(fd, &aux, sizeof(Elf32_auxv_t))) {
michael@0 137 if (aux.a_type == AT_HWCAP) {
michael@0 138 close(fd);
michael@0 139 flags = aux.a_un.a_val;
michael@0 140 isSet = true;
michael@0 141 #if defined(__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__)
michael@0 142 // this should really be detected at runtime, but
michael@0 143 // /proc/*/auxv doesn't seem to carry the ISA
michael@0 144 // I could look in /proc/cpuinfo as well, but
michael@0 145 // the chances that it will be different from this
michael@0 146 // are low.
michael@0 147 flags |= HWCAP_ARMv7;
michael@0 148 #endif
michael@0 149 return flags;
michael@0 150 }
michael@0 151 }
michael@0 152 close(fd);
michael@0 153 }
michael@0 154
michael@0 155 #if defined(__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__)
michael@0 156 flags = HWCAP_ARMv7;
michael@0 157 #endif
michael@0 158 isSet = true;
michael@0 159 return flags;
michael@0 160
michael@0 161 #elif defined(WTF_OS_ANDROID) || defined(MOZ_B2G)
michael@0 162 FILE *fp = fopen("/proc/cpuinfo", "r");
michael@0 163 if (!fp)
michael@0 164 return false;
michael@0 165
michael@0 166 char buf[1024];
michael@0 167 memset(buf, 0, sizeof(buf));
michael@0 168 size_t len = fread(buf, sizeof(char), sizeof(buf) - 2, fp);
michael@0 169 fclose(fp);
michael@0 170 // Canonicalize each token to have a leading and trailing space.
michael@0 171 buf[len] = ' ';
michael@0 172 buf[len + 1] = '\0';
michael@0 173 for (size_t i = 0; i < len; i++) {
michael@0 174 char ch = buf[i];
michael@0 175 if (!ch)
michael@0 176 break;
michael@0 177 else if (ch == '\n')
michael@0 178 buf[i] = 0x20;
michael@0 179 else
michael@0 180 buf[i] = ch;
michael@0 181 }
michael@0 182
michael@0 183 if (strstr(buf, " vfp "))
michael@0 184 flags |= HWCAP_VFP;
michael@0 185
michael@0 186 if (strstr(buf, " vfpv3 "))
michael@0 187 flags |= HWCAP_VFPv3;
michael@0 188
michael@0 189 if (strstr(buf, " vfpv3d16 "))
michael@0 190 flags |= HWCAP_VFPv3D16;
michael@0 191
michael@0 192 if (strstr(buf, " vfpv4 "))
michael@0 193 flags |= HWCAP_VFPv4;
michael@0 194
michael@0 195 if (strstr(buf, " idiva "))
michael@0 196 flags |= HWCAP_IDIVA;
michael@0 197
michael@0 198 if (strstr(buf, " idivt "))
michael@0 199 flags |= HWCAP_IDIVT;
michael@0 200
michael@0 201 if (strstr(buf, " neon "))
michael@0 202 flags |= HWCAP_NEON;
michael@0 203
michael@0 204 // not part of the HWCAP flag, but I need to know this, and we're not using
michael@0 205 // that bit, so... I'm using it
michael@0 206 if (strstr(buf, "ARMv7"))
michael@0 207 flags |= HWCAP_ARMv7;
michael@0 208
michael@0 209 #ifdef DEBUG
michael@0 210 IonSpew(IonSpew_Codegen, "ARMHWCAP: '%s'\n flags: 0x%x\n", buf, flags);
michael@0 211 #endif
michael@0 212
michael@0 213 isSet = true;
michael@0 214 return flags;
michael@0 215 #endif
michael@0 216
michael@0 217 return 0;
michael@0 218 #endif // JS_ARM_SIMULATOR
michael@0 219 }
michael@0 220
michael@0 221 bool hasMOVWT()
michael@0 222 {
michael@0 223 return GetARMFlags() & HWCAP_ARMv7;
michael@0 224 }
michael@0 225 bool hasVFPv3()
michael@0 226 {
michael@0 227 return GetARMFlags() & HWCAP_VFPv3;
michael@0 228 }
michael@0 229 bool hasVFP()
michael@0 230 {
michael@0 231 return GetARMFlags() & HWCAP_VFP;
michael@0 232 }
michael@0 233
michael@0 234 bool has32DP()
michael@0 235 {
michael@0 236 return !(GetARMFlags() & HWCAP_VFPv3D16 && !(GetARMFlags() & HWCAP_NEON));
michael@0 237 }
michael@0 238 bool useConvReg()
michael@0 239 {
michael@0 240 return has32DP();
michael@0 241 }
michael@0 242
michael@0 243 bool hasIDIV()
michael@0 244 {
michael@0 245 #if defined HWCAP_IDIVA
michael@0 246 return GetARMFlags() & HWCAP_IDIVA;
michael@0 247 #else
michael@0 248 return false;
michael@0 249 #endif
michael@0 250 }
michael@0 251
michael@0 252 // This is defined in the header and inlined when not using the simulator.
michael@0 253 #if defined(JS_ARM_SIMULATOR)
michael@0 254 bool useHardFpABI()
michael@0 255 {
michael@0 256 return GetARMFlags() & HWCAP_USE_HARDFP_ABI;
michael@0 257 }
michael@0 258 #endif
michael@0 259
michael@0 260 Registers::Code
michael@0 261 Registers::FromName(const char *name)
michael@0 262 {
michael@0 263 // Check for some register aliases first.
michael@0 264 if (strcmp(name, "ip") == 0)
michael@0 265 return ip;
michael@0 266 if (strcmp(name, "r13") == 0)
michael@0 267 return r13;
michael@0 268 if (strcmp(name, "lr") == 0)
michael@0 269 return lr;
michael@0 270 if (strcmp(name, "r15") == 0)
michael@0 271 return r15;
michael@0 272
michael@0 273 for (size_t i = 0; i < Total; i++) {
michael@0 274 if (strcmp(GetName(i), name) == 0)
michael@0 275 return Code(i);
michael@0 276 }
michael@0 277
michael@0 278 return Invalid;
michael@0 279 }
michael@0 280
michael@0 281 FloatRegisters::Code
michael@0 282 FloatRegisters::FromName(const char *name)
michael@0 283 {
michael@0 284 for (size_t i = 0; i < Total; i++) {
michael@0 285 if (strcmp(GetName(i), name) == 0)
michael@0 286 return Code(i);
michael@0 287 }
michael@0 288
michael@0 289 return Invalid;
michael@0 290 }
michael@0 291
michael@0 292 } // namespace jit
michael@0 293 } // namespace js

mercurial