[Numpy-discussion] Changeset 6557

Charles R Harris charlesr.harris@gmail....
Sat Mar 7 12:42:27 CST 2009


On Sat, Mar 7, 2009 at 11:20 AM, Charles R Harris <charlesr.harris@gmail.com
> wrote:

>
>
> On Sat, Mar 7, 2009 at 11:02 AM, David Cournapeau <cournape@gmail.com>wrote:
>
>> On Sun, Mar 8, 2009 at 2:52 AM, Charles R Harris
>> <charlesr.harris@gmail.com> wrote:
>> >
>> >
>> > On Sat, Mar 7, 2009 at 11:41 AM, David Cournapeau <cournape@gmail.com>
>> > wrote:
>> >>
>> >> On Sat, Mar 7, 2009 at 6:01 AM, Charles R Harris
>> >> <charlesr.harris@gmail.com> wrote:
>> >> > Hi David,
>> >> >
>> >> > Currently,
>> >> >
>> >> > bint.i = __STR2INTCST("ABCD");
>> >> >
>> >> > It is probably more portable to just initialize the union
>> >> >
>> >> >     union {
>> >> >         char c[4];
>> >> >         npy_uint32 i;
>> >> >     } bint = {'A','B','C','D'};
>> >> >
>> >
>> > Yes, but look at the second version. It does essentially what your macro
>> > does, only uses 1,2,3,4 instead of 'A','B','C','D'.
>>
>> Yes, it is the same thing, so I don't see the point of changing :)
>
>
> The macro is ugly, unneeded, and obfuscating. Why construct a number from
> characters and shifts when you can just *write it down*?
>
>
>> The
>> const union does not help, BTW.
>
>
> True, it is initialized here:
>
>         movl    $16909060, -8(%ebp)
>
> contrast that with the macro.
>

And here is the optimized code (-O2) to print out the byte values in order:

main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $20, %esp
        movl    $4, 4(%esp)
        movl    $.LC0, (%esp)
        call    printf
        movl    $3, 4(%esp)
        movl    $.LC0, (%esp)
        call    printf
        movl    $2, 4(%esp)
        movl    $.LC0, (%esp)
        call    printf
        movl    $1, 4(%esp)
        movl    $.LC0, (%esp)
        call    printf
        ...

 Note the compiler *knows* the byte values, the union never appears.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090307/31431ab6/attachment.html 


More information about the Numpy-discussion mailing list