Commit eebebf9f authored by yangguo@chromium.org's avatar yangguo@chromium.org

Add back ascii fast path for toupper/tolower

R=yangguo@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/11889007
Patch from Dan Carney <dcarney@google.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13376 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 89bef51a
...@@ -5804,7 +5804,9 @@ MUST_USE_RESULT static MaybeObject* ConvertCaseHelper( ...@@ -5804,7 +5804,9 @@ MUST_USE_RESULT static MaybeObject* ConvertCaseHelper(
namespace { namespace {
static const uintptr_t kOneInEveryByte = kUintptrAllBitsSet / 0xFF; static const uintptr_t kOneInEveryByte = kUintptrAllBitsSet / 0xFF;
#ifdef ENABLE_LATIN_1
static const uintptr_t kAsciiMask = kOneInEveryByte << 7;
#endif
// Given a word and two range boundaries returns a word with high bit // Given a word and two range boundaries returns a word with high bit
// set in every byte iff the corresponding input byte was strictly in // set in every byte iff the corresponding input byte was strictly in
...@@ -5818,7 +5820,10 @@ static inline uintptr_t AsciiRangeMask(uintptr_t w, char m, char n) { ...@@ -5818,7 +5820,10 @@ static inline uintptr_t AsciiRangeMask(uintptr_t w, char m, char n) {
ASSERT((w & (kOneInEveryByte * 0x7F)) == w); ASSERT((w & (kOneInEveryByte * 0x7F)) == w);
// Use strict inequalities since in edge cases the function could be // Use strict inequalities since in edge cases the function could be
// further simplified. // further simplified.
ASSERT(0 < m && m < n && n < 0x7F); ASSERT(0 < m && m < n);
#ifndef ENABLE_LATIN_1
ASSERT(n < 0x7F);
#endif
// Has high bit set in every w byte less than n. // Has high bit set in every w byte less than n.
uintptr_t tmp1 = kOneInEveryByte * (0x7F + n) - w; uintptr_t tmp1 = kOneInEveryByte * (0x7F + n) - w;
// Has high bit set in every w byte greater than m. // Has high bit set in every w byte greater than m.
...@@ -5835,7 +5840,11 @@ enum AsciiCaseConversion { ...@@ -5835,7 +5840,11 @@ enum AsciiCaseConversion {
template <AsciiCaseConversion dir> template <AsciiCaseConversion dir>
struct FastAsciiConverter { struct FastAsciiConverter {
#ifdef ENABLE_LATIN_1
static bool Convert(char* dst, char* src, int length, bool* changed_out) {
#else
static bool Convert(char* dst, char* src, int length) { static bool Convert(char* dst, char* src, int length) {
#endif
#ifdef DEBUG #ifdef DEBUG
char* saved_dst = dst; char* saved_dst = dst;
char* saved_src = src; char* saved_src = src;
...@@ -5847,12 +5856,18 @@ struct FastAsciiConverter { ...@@ -5847,12 +5856,18 @@ struct FastAsciiConverter {
const char lo = (dir == ASCII_TO_LOWER) ? 'A' - 1 : 'a' - 1; const char lo = (dir == ASCII_TO_LOWER) ? 'A' - 1 : 'a' - 1;
const char hi = (dir == ASCII_TO_LOWER) ? 'Z' + 1 : 'z' + 1; const char hi = (dir == ASCII_TO_LOWER) ? 'Z' + 1 : 'z' + 1;
bool changed = false; bool changed = false;
#ifdef ENABLE_LATIN_1
uintptr_t or_acc = 0;
#endif
char* const limit = src + length; char* const limit = src + length;
#ifdef V8_HOST_CAN_READ_UNALIGNED #ifdef V8_HOST_CAN_READ_UNALIGNED
// Process the prefix of the input that requires no conversion one // Process the prefix of the input that requires no conversion one
// (machine) word at a time. // (machine) word at a time.
while (src <= limit - sizeof(uintptr_t)) { while (src <= limit - sizeof(uintptr_t)) {
uintptr_t w = *reinterpret_cast<uintptr_t*>(src); uintptr_t w = *reinterpret_cast<uintptr_t*>(src);
#ifdef ENABLE_LATIN_1
or_acc |= w;
#endif
if (AsciiRangeMask(w, lo, hi) != 0) { if (AsciiRangeMask(w, lo, hi) != 0) {
changed = true; changed = true;
break; break;
...@@ -5865,6 +5880,9 @@ struct FastAsciiConverter { ...@@ -5865,6 +5880,9 @@ struct FastAsciiConverter {
// required one word at a time. // required one word at a time.
while (src <= limit - sizeof(uintptr_t)) { while (src <= limit - sizeof(uintptr_t)) {
uintptr_t w = *reinterpret_cast<uintptr_t*>(src); uintptr_t w = *reinterpret_cast<uintptr_t*>(src);
#ifdef ENABLE_LATIN_1
or_acc |= w;
#endif
uintptr_t m = AsciiRangeMask(w, lo, hi); uintptr_t m = AsciiRangeMask(w, lo, hi);
// The mask has high (7th) bit set in every byte that needs // The mask has high (7th) bit set in every byte that needs
// conversion and we know that the distance between cases is // conversion and we know that the distance between cases is
...@@ -5878,6 +5896,9 @@ struct FastAsciiConverter { ...@@ -5878,6 +5896,9 @@ struct FastAsciiConverter {
// unaligned access is not supported). // unaligned access is not supported).
while (src < limit) { while (src < limit) {
char c = *src; char c = *src;
#ifdef ENABLE_LATIN_1
or_acc |= c;
#endif
if (lo < c && c < hi) { if (lo < c && c < hi) {
c ^= (1 << 5); c ^= (1 << 5);
changed = true; changed = true;
...@@ -5886,10 +5907,20 @@ struct FastAsciiConverter { ...@@ -5886,10 +5907,20 @@ struct FastAsciiConverter {
++src; ++src;
++dst; ++dst;
} }
#ifdef ENABLE_LATIN_1
if ((or_acc & kAsciiMask) != 0) {
return false;
}
#endif
#ifdef DEBUG #ifdef DEBUG
CheckConvert(saved_dst, saved_src, length, changed); CheckConvert(saved_dst, saved_src, length, changed);
#endif #endif
#ifdef ENABLE_LATIN_1
*changed_out = changed;
return true;
#else
return changed; return changed;
#endif
} }
#ifdef DEBUG #ifdef DEBUG
...@@ -5942,7 +5973,6 @@ MUST_USE_RESULT static MaybeObject* ConvertCase( ...@@ -5942,7 +5973,6 @@ MUST_USE_RESULT static MaybeObject* ConvertCase(
// Assume that the string is not empty; we need this assumption later // Assume that the string is not empty; we need this assumption later
if (length == 0) return s; if (length == 0) return s;
#ifndef ENABLE_LATIN_1
// Simpler handling of ASCII strings. // Simpler handling of ASCII strings.
// //
// NOTE: This assumes that the upper/lower case of an ASCII // NOTE: This assumes that the upper/lower case of an ASCII
...@@ -5955,13 +5985,25 @@ MUST_USE_RESULT static MaybeObject* ConvertCase( ...@@ -5955,13 +5985,25 @@ MUST_USE_RESULT static MaybeObject* ConvertCase(
if (!maybe_o->ToObject(&o)) return maybe_o; if (!maybe_o->ToObject(&o)) return maybe_o;
} }
SeqOneByteString* result = SeqOneByteString::cast(o); SeqOneByteString* result = SeqOneByteString::cast(o);
#ifndef ENABLE_LATIN_1
bool has_changed_character = ConvertTraits::AsciiConverter::Convert( bool has_changed_character = ConvertTraits::AsciiConverter::Convert(
reinterpret_cast<char*>(result->GetChars()), reinterpret_cast<char*>(result->GetChars()),
reinterpret_cast<char*>(SeqOneByteString::cast(s)->GetChars()), reinterpret_cast<char*>(SeqOneByteString::cast(s)->GetChars()),
length); length);
return has_changed_character ? result : s; return has_changed_character ? result : s;
} #else
bool has_changed_character;
bool is_ascii = ConvertTraits::AsciiConverter::Convert(
reinterpret_cast<char*>(result->GetChars()),
reinterpret_cast<char*>(SeqOneByteString::cast(s)->GetChars()),
length,
&has_changed_character);
// If not ASCII, we discard the result and take the 2 byte path.
if (is_ascii) {
return has_changed_character ? result : s;
}
#endif #endif
}
Object* answer; Object* answer;
{ MaybeObject* maybe_answer = { MaybeObject* maybe_answer =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment