Closed Bug 489419 Opened 15 years ago Closed 15 years ago

Get rid of STRING_BUFFER_OK, add bool return values to JSStringBuffer functions, make them methods of a class, etc.

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla1.9.2a1

People

(Reporter: brendan, Assigned: brendan)

Details

See bug 489089 comment 22 and previous comments.

/be
(In reply to bug 489089 comment #23)
> the prefetched path is the fast path and without PGO. Would GCC do that
> if you wrote out if (!s->add('X')) return false; if (!s->add('Y') return false;
> etc.?

With updated example GCC still produces the same nice pattern. I.e. given:

@watson~/s> cat x.cpp
struct S {
    char *buffer;
    char *end;

    bool grow();

    bool add(char c)
    {
        if (buffer == end && !grow())
            return false;
        *buffer++ = c;
        return true;
    }
};

bool test(S *s)
{
    if (!s->add('X'))
        return false;
    if (!s->add('Y'))
        return false;
    if (!s->add('Z'))
        return false;
    return true;
}

gcc-4.2.4 -O3 generates a code similar to:

    if (s->buffer == s->end) goto grow1;
  fast_add_1: 
    *s->buffer++ = 'X';

    if (s->buffer == s->end) goto grow2;
  fast_add_2: 
    *s->buffer++ = 'Y';

    if (s->buffer == s->end) goto grow3;
  fast_add_3: 
    *s->buffer++ = 'Z';
    return true;

  grow1:
    if (!s->grow()) return false;
    goto fast_add_1;

  grow2:
    if (!s->grow()) return false;
    goto fast_add_2;

  grow3:
    if (!s->grow()) return false;
    goto fast_add_3;


Here is i386 assembly for test's body:

        movl    8(%ebp), %ebx
        movl    (%ebx), %eax
        cmpl    4(%ebx), %eax
        je      .L13
.L2:
        movb    $88, (%eax)
        addl    $1, %eax
        cmpl    4(%ebx), %eax
        movl    %eax, (%ebx)
        je      .L5
.L6:
        movl    (%ebx), %eax
        movb    $89, (%eax)
        addl    $1, %eax
        cmpl    4(%ebx), %eax
        movl    %eax, (%ebx)
        je      .L7
.L8:
        movl    (%ebx), %eax
        movb    $90, (%eax)
        addl    $1, %eax
        movl    %eax, (%ebx)
        movl    $1, %eax
.L9:
        addl    $4, %esp
        popl    %ebx
        popl    %ebp
        ret
.L13:
        movl    %ebx, (%esp)
        call    _ZN1S4growEv
        testb   %al, %al
        je      .L4
        movl    (%ebx), %eax
        .p2align 4,,2
        jmp     .L2
.L5:
        movl    %ebx, (%esp)
        .p2align 4,,5
        call    _ZN1S4growEv
        testb   %al, %al
        .p2align 4,,2
        jne     .L6
.L4:
        xorl    %eax, %eax
        .p2align 4,,2
        jmp     .L9
.L7:
        movl    %ebx, (%esp)
        .p2align 4,,5
        call    _ZN1S4growEv
        testb   %al, %al
        .p2align 4,,2
        jne     .L8
        xorl    %eax, %eax
        .p2align 4,,2
        jmp     .L9
Nice, I take back three mean things I've said about gcc :-P.

/be
Priority: -- → P3
Luke got rid of STRING_BUFFER_OK, etc., in bug 503952.

/be
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.