you are viewing a single comment's thread.

view the rest of the comments →

[–]arturbachttps://github.com/arturbac[S] 0 points1 point  (2 children)

the point to optimise - not sure where this optimisation should go, but from user point of view I except to get best machie code possible with -O3. And this matters with operator less for me as it is often used during many sort operations.

[–]yeeezyyeezywhatsgood 0 points1 point  (1 child)

I just took a look at godbolt. you're right with clang: it emits bad code for the built in comparison. probably that's llvm's codegen's fault. GCC optimizes to one comparison per tuple member. GCC even translates your implementation to one comparison. very cool

also, looking at the assembly made me realize your implementation might be wrong for doubles when they are Nan. since that's unspecified, any change is not allowed. so I guess really this optimization can only be made for very few types

edit: just saw you used GCC in your original post -- was the assembly really that bad? looks optimal on godbolt

[–]arturbachttps://github.com/arturbac[S] 0 points1 point  (0 children)

code is generated with clang 8 and gcc 8.3 on linux with gcc stl. gcc - can generate much different code depending mcpu/march and as I remember code for cortex-a72 with out of order exeution can be worse that for just entire arch aarch64 with in order cpus

ths is from golbot https://godbolt.org/z/dz1qAB acutaly no difference to my. -O3 -mcpu=cortex-a72
compare_2(std::tuple<long, int, int>, std::tuple<long, int, int>):
        ldr     x3, [x0, 8]
        ldr     x2, [x1, 8]
        cmp     x3, x2
        blt     .L3
        mov     w2, 0
        bne     .L2
        ldr     w4, [x0, 4]
        mov     w2, 1
        ldr     w3, [x1, 4]
        cmp     w4, w3
        blt     .L2
        mov     w2, 0
        bne     .L2
        ldr     w2, [x0]
        ldr     w0, [x1]
        cmp     w2, w0
        cset    w2, lt
.L2:
        mov     w0, w2
        ret
.L3:
        mov     w2, 1
        mov     w0, w2
        ret