xref: /aosp_15_r20/external/llvm/lib/Target/X86/README-MMX.txt (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===//
2*9880d681SAndroid Build Coastguard Worker// Random ideas for the X86 backend: MMX-specific stuff.
3*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===//
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===//
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard WorkerThis:
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker#include <mmintrin.h>
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker__v2si qux(int A) {
12*9880d681SAndroid Build Coastguard Worker  return (__v2si){ 0, A };
13*9880d681SAndroid Build Coastguard Worker}
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workeris compiled into:
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker_qux:
18*9880d681SAndroid Build Coastguard Worker        subl $28, %esp
19*9880d681SAndroid Build Coastguard Worker        movl 32(%esp), %eax
20*9880d681SAndroid Build Coastguard Worker        movd %eax, %mm0
21*9880d681SAndroid Build Coastguard Worker        movq %mm0, (%esp)
22*9880d681SAndroid Build Coastguard Worker        movl (%esp), %eax
23*9880d681SAndroid Build Coastguard Worker        movl %eax, 20(%esp)
24*9880d681SAndroid Build Coastguard Worker        movq %mm0, 8(%esp)
25*9880d681SAndroid Build Coastguard Worker        movl 12(%esp), %eax
26*9880d681SAndroid Build Coastguard Worker        movl %eax, 16(%esp)
27*9880d681SAndroid Build Coastguard Worker        movq 16(%esp), %mm0
28*9880d681SAndroid Build Coastguard Worker        addl $28, %esp
29*9880d681SAndroid Build Coastguard Worker        ret
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard WorkerYuck!
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard WorkerGCC gives us:
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Worker_qux:
36*9880d681SAndroid Build Coastguard Worker        subl    $12, %esp
37*9880d681SAndroid Build Coastguard Worker        movl    16(%esp), %eax
38*9880d681SAndroid Build Coastguard Worker        movl    20(%esp), %edx
39*9880d681SAndroid Build Coastguard Worker        movl    $0, (%eax)
40*9880d681SAndroid Build Coastguard Worker        movl    %edx, 4(%eax)
41*9880d681SAndroid Build Coastguard Worker        addl    $12, %esp
42*9880d681SAndroid Build Coastguard Worker        ret     $4
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker//===---------------------------------------------------------------------===//
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard WorkerWe generate crappy code for this:
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker__m64 t() {
49*9880d681SAndroid Build Coastguard Worker  return _mm_cvtsi32_si64(1);
50*9880d681SAndroid Build Coastguard Worker}
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker_t:
53*9880d681SAndroid Build Coastguard Worker	subl	$12, %esp
54*9880d681SAndroid Build Coastguard Worker	movl	$1, %eax
55*9880d681SAndroid Build Coastguard Worker	movd	%eax, %mm0
56*9880d681SAndroid Build Coastguard Worker	movq	%mm0, (%esp)
57*9880d681SAndroid Build Coastguard Worker	movl	(%esp), %eax
58*9880d681SAndroid Build Coastguard Worker	movl	4(%esp), %edx
59*9880d681SAndroid Build Coastguard Worker	addl	$12, %esp
60*9880d681SAndroid Build Coastguard Worker	ret
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard WorkerThe extra stack traffic is covered in the previous entry. But the other reason
63*9880d681SAndroid Build Coastguard Workeris we are not smart about materializing constants in MMX registers. With -m64
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker	movl	$1, %eax
66*9880d681SAndroid Build Coastguard Worker	movd	%eax, %mm0
67*9880d681SAndroid Build Coastguard Worker	movd	%mm0, %rax
68*9880d681SAndroid Build Coastguard Worker	ret
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard WorkerWe should be using a constantpool load instead:
71*9880d681SAndroid Build Coastguard Worker	movq	LC0(%rip), %rax
72