Boost logo

Boost Users :

From: Erik Thiele (erik.thiele_at_[hidden])
Date: 2019-05-24 13:41:21


I assume that time_duration is implemented as an integer. Some values
of this integer are then reserved for special values like
not_a_date_time.

this can be seen here:

https://github.com/boostorg/date_time/blob/develop/include/boost/date_time/int_adapter.hpp

this should have the consequence that when studying the assembler code
for comparing two time_durations, all that happens is the assembler
code of "less than compare" for integer type. if additional comparisons
and branchings take place, then I assume the code is not meeting the
design criteria of being optimized.

Well... this is what I did, copy paste this code to justcompare.cpp:

#include <boost/date_time/posix_time/ptime.hpp>

using namespace boost::posix_time;

bool compare_time_duration(time_duration a, time_duration b)
{
  return a < b;
}

bool compare_int(int a, int b)
{
  return a < b;
}

EOF

g++ -Wall -O2 -c justcompare.cpp
objdump -S --demangle justcompare.o

justcompare.o: file format elf64-x86-64

Disassembly of section .text:

0000000000000000
<compare_time_duration(boost::posix_time::time_duration, boost::posix_time::time_duration)>:
   0: 48 8b 17 mov (%rdi),%rdx
   3: 48 b9 ff ff ff ff ff movabs $0x7fffffffffffffff,%rcx
   a: ff ff 7f
   d: 48 8d 04 0a lea (%rdx,%rcx,1),%rax
  11: 48 83 f8 fd cmp $0xfffffffffffffffd,%rax
  15: 77 29 ja 40
  17: 48 bf fe ff ff ff ff movabs $0x7ffffffffffffffe,%rdi
  1e: ff ff 7f
  21: 31 c0 xor %eax,%eax
  23: 48 39 fa cmp %rdi,%rdx
  26: 74 60 je 88
  28: 48 8b 36 mov (%rsi),%rsi
  2b: 48 01 f1 add %rsi,%rcx
  2e: 48 83 f9 fd cmp $0xfffffffffffffffd,%rcx
  32: 77 20 ja 54
  34: 48 39 fe cmp %rdi,%rsi
  37: 74 0a je 43
  39: 48 39 f2 cmp %rsi,%rdx
  3c: 0f 9c c0 setl %al
  3f: c3 retq
  40: 48 8b 36 mov (%rsi),%rsi
  43: 48 b9 fe ff ff ff ff movabs $0x7ffffffffffffffe,%rcx
  4a: ff ff 7f
  4d: 31 c0 xor %eax,%eax
  4f: 48 39 ce cmp %rcx,%rsi
  52: 74 3c je 90
  54: 48 bf 00 00 00 00 00 movabs $0x8000000000000000,%rdi
  5b: 00 00 80
  5e: 48 39 fa cmp %rdi,%rdx
  61: 74 35 je 98
  63: 48 b9 ff ff ff ff ff movabs $0x7fffffffffffffff,%rcx
  6a: ff ff 7f
  6d: 48 39 ce cmp %rcx,%rsi
  70: 0f 94 c0 sete %al
  73: 48 39 ca cmp %rcx,%rdx
  76: 41 0f 95 c0 setne %r8b
  7a: 44 20 c0 and %r8b,%al
  7d: 74 21 je a0
  7f: f3 c3 repz retq
  81: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
  88: f3 c3 repz retq
  8a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
  90: f3 c3 repz retq
  92: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
  98: 48 39 d6 cmp %rdx,%rsi
  9b: 0f 95 c0 setne %al
  9e: c3 retq
  9f: 90 nop
  a0: 48 39 ca cmp %rcx,%rdx
  a3: 74 da je 7f
  a5: 48 39 fe cmp %rdi,%rsi
  a8: 75 8f jne 39
  aa: f3 c3 repz retq
  ac: 0f 1f 40 00 nopl 0x0(%rax)

00000000000000b0 <compare_int(int, int)>:
  b0: 39 f7 cmp %esi,%edi
  b2: 0f 9c c0 setl %al
  b5: c3 retq

(i removed the verbose jump target strings from the output to make the
email readable)

see the difference between compare_time_duration and compare_int...

I have a bad feeling in my stomach... sorry, something is going very
wrong here :-)

cya
erik


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net