Skip to content

Commit 0aac347

Browse files
ajkleinCommit Bot
authored andcommitted
Revert "Remove all custom CopyCharsUnsigned implementations"
This reverts commit 5d8c489. Reason for revert: Fails on UBSan bot: https://ci.chromium.org/p/v8/builders/ci/V8%20Linux64%20UBSan/7946 Original change's description: > Remove all custom CopyCharsUnsigned implementations > > It's unclear whether the custom implementation have any advantage over > the standard library one's. > Since we update our toolchain and standard library regularly, it might > well be the case that the custom implementations are slower by now. > > Thus this CL removes all {CopyCharsUnsigned} implementations and > implements {CopyChars} generically using {std::copy_n}. > > Note that this does not touch the {MemMove} and {MemCopy} functions > yet, as we have seen regressions when trying to remove them before > (https://crbug.com/v8/8675#c5). > > R=​leszeks@chromium.org > > Bug: v8:9396 > Change-Id: I97a183afebcccd2fbb567bdba02e827331475608 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1800577 > Commit-Queue: Clemens Hammacher <clemensh@chromium.org> > Reviewed-by: Leszek Swirski <leszeks@chromium.org> > Cr-Commit-Position: refs/heads/master@{#63808} TBR=leszeks@chromium.org,clemensh@chromium.org Change-Id: Ia16da942c7c28ba71076d1e3b0b8a6388a4ba359 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: v8:9396 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1806103 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Adam Klein <adamk@chromium.org> Cr-Commit-Position: refs/heads/master@{#63810}
1 parent c9fa0c5 commit 0aac347

6 files changed

Lines changed: 374 additions & 31 deletions

File tree

src/builtins/arm/builtins-arm.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,6 +3167,51 @@ void Builtins::Generate_MemCopyUint8Uint8(MacroAssembler* masm) {
31673167
__ Ret();
31683168
}
31693169

3170+
void Builtins::Generate_MemCopyUint16Uint8(MacroAssembler* masm) {
3171+
Register dest = r0;
3172+
Register src = r1;
3173+
Register chars = r2;
3174+
3175+
{
3176+
UseScratchRegisterScope temps(masm);
3177+
3178+
Register temp1 = r3;
3179+
Register temp2 = temps.Acquire();
3180+
Register temp3 = lr;
3181+
Register temp4 = r4;
3182+
Label loop;
3183+
Label not_two;
3184+
3185+
__ Push(lr, r4);
3186+
__ bic(temp2, chars, Operand(0x3));
3187+
__ add(temp2, dest, Operand(temp2, LSL, 1));
3188+
3189+
__ bind(&loop);
3190+
__ ldr(temp1, MemOperand(src, 4, PostIndex));
3191+
__ uxtb16(temp3, temp1);
3192+
__ uxtb16(temp4, temp1, 8);
3193+
__ pkhbt(temp1, temp3, Operand(temp4, LSL, 16));
3194+
__ str(temp1, MemOperand(dest));
3195+
__ pkhtb(temp1, temp4, Operand(temp3, ASR, 16));
3196+
__ str(temp1, MemOperand(dest, 4));
3197+
__ add(dest, dest, Operand(8));
3198+
__ cmp(dest, temp2);
3199+
__ b(&loop, ne);
3200+
3201+
__ mov(chars, Operand(chars, LSL, 31), SetCC); // bit0 => ne, bit1 => cs
3202+
__ b(&not_two, cc);
3203+
__ ldrh(temp1, MemOperand(src, 2, PostIndex));
3204+
__ uxtb(temp3, temp1, 8);
3205+
__ mov(temp3, Operand(temp3, LSL, 16));
3206+
__ uxtab(temp3, temp3, temp1);
3207+
__ str(temp3, MemOperand(dest, 4, PostIndex));
3208+
__ bind(&not_two);
3209+
__ ldrb(temp1, MemOperand(src), ne);
3210+
__ strh(temp1, MemOperand(dest), ne);
3211+
__ Pop(pc, r4);
3212+
}
3213+
}
3214+
31703215
#undef __
31713216

31723217
} // namespace internal

src/builtins/builtins-definitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ namespace internal {
11131113
TFS(SetProperty, kReceiver, kKey, kValue) \
11141114
TFS(SetPropertyInLiteral, kReceiver, kKey, kValue) \
11151115
ASM(MemCopyUint8Uint8, CCall) \
1116+
ASM(MemCopyUint16Uint8, CCall) \
11161117
ASM(MemMove, CCall) \
11171118
\
11181119
/* Trace */ \

src/builtins/builtins-internal-gen.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,12 @@ void Builtins::Generate_MemCopyUint8Uint8(MacroAssembler* masm) {
933933
}
934934
#endif // !defined(V8_TARGET_ARCH_ARM) && !defined(V8_TARGET_ARCH_MIPS)
935935

936+
#ifndef V8_TARGET_ARCH_ARM
937+
void Builtins::Generate_MemCopyUint16Uint8(MacroAssembler* masm) {
938+
masm->Call(BUILTIN_CODE(masm->isolate(), Illegal), RelocInfo::CODE_TARGET);
939+
}
940+
#endif // V8_TARGET_ARCH_ARM
941+
936942
#ifndef V8_TARGET_ARCH_IA32
937943
void Builtins::Generate_MemMove(MacroAssembler* masm) {
938944
masm->Call(BUILTIN_CODE(masm->isolate(), Illegal), RelocInfo::CODE_TARGET);

src/parsing/scanner-character-streams.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class BufferedCharacterStream : public Utf16CharacterStream {
265265
}
266266

267267
size_t length = Min(kBufferSize, range.length());
268-
i::CopyChars(buffer_, range.start, length);
268+
i::CopyCharsUnsigned(buffer_, range.start, length);
269269
buffer_end_ = &buffer_[length];
270270
return true;
271271
}

src/utils/memcopy.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ V8_EXPORT_PRIVATE void MemMove(void* dest, const void* src, size_t size) {
2525
(*memmove_function)(dest, src, size);
2626
}
2727
#elif V8_OS_POSIX && V8_HOST_ARCH_ARM
28+
void MemCopyUint16Uint8Wrapper(uint16_t* dest, const uint8_t* src,
29+
size_t chars) {
30+
uint16_t* limit = dest + chars;
31+
while (dest < limit) {
32+
*dest++ = static_cast<uint16_t>(*src++);
33+
}
34+
}
35+
2836
V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function =
2937
&MemCopyUint8Wrapper;
38+
MemCopyUint16Uint8Function memcopy_uint16_uint8_function =
39+
&MemCopyUint16Uint8Wrapper;
3040
#elif V8_OS_POSIX && V8_HOST_ARCH_MIPS
3141
V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function =
3242
&MemCopyUint8Wrapper;
@@ -44,6 +54,9 @@ void init_memcopy_functions() {
4454
EmbeddedData d = EmbeddedData::FromBlob();
4555
memcopy_uint8_function = reinterpret_cast<MemCopyUint8Function>(
4656
d.InstructionStartOfBuiltin(Builtins::kMemCopyUint8Uint8));
57+
memcopy_uint16_uint8_function =
58+
reinterpret_cast<MemCopyUint16Uint8Function>(
59+
d.InstructionStartOfBuiltin(Builtins::kMemCopyUint16Uint8));
4760
}
4861
#elif V8_OS_POSIX && V8_HOST_ARCH_MIPS
4962
if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) {

0 commit comments

Comments
 (0)