[Bug c++/84525] GCC7: generate movaps instruction when assign to unaligned __int128*

2018-02-23 Thread buaa.zhaoc at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84525

--- Comment #6 from Zhao Chun  ---
(In reply to Jakub Jelinek from comment #5)
> I wrote it above.  memcpy or packed struct.  And there is no reason to think
> about memcpy as something inefficient, GCC will turn those single element
> memcpy calls into efficient unaligned loads or stores.

OK, Thanks!

[Bug c++/84525] GCC7: generate movaps instruction when assign to unaligned __int128*

2018-02-23 Thread buaa.zhaoc at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84525

--- Comment #4 from Zhao Chun  ---
(In reply to Jakub Jelinek from comment #3)
> (In reply to Zhao Chun from comment #2)
> > Thanks for you explain.
> > It looks some weird to me. 
> > If the type was int64_t or others, this can work.
> 
> No, it would be invalid too.  It may appear to work.
> 
> > Is there some specs to say that __int128 is 16-byte aligned?
> 
> Just check the __alignof__ (__int128) value?

Yes, you'er right.

Is there good way to assign value to unaligned int type except memcpy?

[Bug c++/84525] GCC7: generate movaps instruction when assign to unaligned __int128*

2018-02-23 Thread buaa.zhaoc at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84525

--- Comment #2 from Zhao Chun  ---
Thanks for you explain.
It looks some weird to me. 
If the type was int64_t or others, this can work.

Is there some specs to say that __int128 is 16-byte aligned?

[Bug c++/84525] New: GCC7: generate movaps instruction when assign to unaligned __int128*

2018-02-22 Thread buaa.zhaoc at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84525

Bug ID: 84525
   Summary: GCC7: generate movaps instruction when assign to
unaligned __int128*
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: buaa.zhaoc at gmail dot com
  Target Milestone: ---

compiling the following code. Run the binary will cause a segment fault. GCC
version is 7.3, Target: x86_64-pc-linux-gnu, Configure is
../gcc-7.3.0/configure CFLAGS=-O2 LDFLAGS=-static --enable-gold=yes
--enable-languages=c,c++ --enable-c99 --enable-threads=posix
--enable-__cxa_atexit --disable-multilib --disable-bootstrap

g++ -O3 a.cc b.cc

a.cc 
#include 

extern void set_to_max(char* abc);

int main() {
char* abc = new char[100];
set_to_max(abc + 1);
std::cout << (int64_t)(((*(__int128*)(abc+1))) >> 64) << std::endl;
delete[] abc;
return 0;
}

b.cc
void set_to_max(char* abc) {
*reinterpret_cast<__int128*>(abc) = ~((__int128)1 << 127);
}

when I execute following command
g++ -O3 -S b.cc

following asm code generated: 

.file   "b.cc"
.text
.p2align 4,,15
.globl  _Z10set_to_maxPc
.type   _Z10set_to_maxPc, @function
_Z10set_to_maxPc:
.LFB0:
.cfi_startproc
movdqa  .LC0(%rip), %xmm0
movaps  %xmm0, (%rdi)
ret
.cfi_endproc
.LFE0:
.size   _Z10set_to_maxPc, .-_Z10set_to_maxPc
.section.rodata.cst16,"aM",@progbits,16
.align 16
.LC0:
.quad   -1
.quad   9223372036854775807
.ident  "GCC: (GNU) 7.3.0"
.section.note.GNU-stack,"",@progbits

movaps instruction cause the Segmentation fault