machine.m4 3.4 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1 2 3
C OFFSET(i)
C Expands to 4*i, or to the empty string if i is zero
define(<OFFSET>, <ifelse($1,0,,eval(4*$1))>)
4

Niels Möller's avatar
Niels Möller committed
5 6 7 8
C OFFSET64(i)
C Expands to 8*i, or to the empty string if i is zero
define(<OFFSET64>, <ifelse($1,0,,eval(8*$1))>)

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
dnl LREG(reg) gives the 8-bit register corresponding to the given 64-bit register.
define(<LREG>,<ifelse(
	$1, %rax, %al,
	$1, %rbx, %bl,
	$1, %rcx, %cl,
	$1, %rdx, %dl,
	$1, %rsi, %sil,
	$1, %rdi, %dil,
	$1, %rbp, %bpl,
	$1, %r8, %r8b,
	$1, %r9, %r9b,
	$1, %r10, %r10b,
	$1, %r11, %r11b,
	$1, %r12, %r12b,
	$1, %r13, %r13b,
	$1, %r14, %r14b,
	$1, %r15, %r15b)>)dnl

define(<HREG>,<ifelse(
	$1, %rax, %ah,
	$1, %rbx, %bh,
	$1, %rcx, %ch,
	$1, %rdx, %dh)>)dnl

Niels Möller's avatar
Niels Möller committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
define(<WREG>,<ifelse(
	$1, %rax, %ax,
	$1, %rbx, %bx,
	$1, %rcx, %cx,
	$1, %rdx, %dx,
	$1, %rsi, %si,
	$1, %rdi, %di,
	$1, %rbp, %bp,
	$1, %r8, %r8w,
	$1, %r9, %r9w,
	$1, %r10, %r10w,
	$1, %r11, %r11w,
	$1, %r12, %r12w,
	$1, %r13, %r13w,
	$1, %r14, %r14w,
	$1, %r15, %r15w)>)dnl

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
define(<XREG>,<ifelse(
	$1, %rax, %eax,
	$1, %rbx, %ebx,
	$1, %rcx, %ecx,
	$1, %rdx, %edx,
	$1, %rsi, %esi,
	$1, %rdi, %edi,
	$1, %rbp, %ebp,
	$1, %r8, %r8d,
	$1, %r9, %r9d,
	$1, %r10, %r10d,
	$1, %r11, %r11d,
	$1, %r12, %r12d,
	$1, %r13, %r13d,
	$1, %r14, %r14d,
	$1, %r15, %r15d)>)dnl
66 67 68 69 70 71 72 73

dnl W64_ENTRY(nargs, xmm_used)
define(<W64_ENTRY>, <
  changequote([,])dnl
  ifelse(<<<<<<<<<<<<<<< ignored; only for balancing)
  ifelse(W64_ABI,yes,[
    ifelse(eval($2 > 6), 1, [
      sub	[$]eval(8 + 16*($2 - 6)), %rsp
74
      movdqu	%xmm6, 0(%rsp)
75 76
    ])
    ifelse(eval($2 > 7), 1, [
77
      movdqu	%xmm7, 16(%rsp)
78 79
    ])
    ifelse(eval($2 > 8), 1, [
80
      movdqu	%xmm8, 32(%rsp)
81 82
    ])
    ifelse(eval($2 > 9), 1, [
83
      movdqu	%xmm9, 48(%rsp)
84 85
    ])
    ifelse(eval($2 > 10), 1, [
86
      movdqu	%xmm10, 64(%rsp)
87 88
    ])
    ifelse(eval($2 > 11), 1, [
89
      movdqu	%xmm11, 80(%rsp)
90 91
    ])
    ifelse(eval($2 > 12), 1, [
92
      movdqu	%xmm12, 96(%rsp)
93 94
    ])
    ifelse(eval($2 > 13), 1, [
95
      movdqu	%xmm13, 112(%rsp)
96 97
    ])
    ifelse(eval($2 > 14), 1, [
98
      movdqu	%xmm14, 128(%rsp)
99 100
    ])
    ifelse(eval($2 > 15), 1, [
101
      movdqu	%xmm15, 144(%rsp)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    ])
    ifelse(eval($1 >= 1), 1, [
      push	%rdi
      mov	%rcx, %rdi
    ])
    ifelse(eval($1 >= 2), 1, [
      push	%rsi
      mov	%rdx, %rsi
    ])
    ifelse(eval($1 >= 3), 1, [
      mov	%r8, %rdx
    ])
    ifelse(eval($1 >= 4), 1, [
      mov	%r9, %rcx
    ])
    ifelse(eval($1 >= 5), 1, [
      mov	56(%rsp), %r8
    ])
  ])
  changequote(<,>)dnl
>)

dnl W64_EXIT(nargs, xmm_used)
define(<W64_EXIT>, <
  changequote([,])dnl
  ifelse(<<<<<<<<<<<< ignored; only for balancing)
  ifelse(W64_ABI,yes,[
    ifelse(eval($1 >= 2), 1, [
      pop	%rsi
    ])
    ifelse(eval($1 >= 1), 1, [
      pop	%rdi
    ])
    ifelse(eval($2 > 15), 1, [
136
      movdqu	144(%rsp), %xmm15
137 138
    ])
    ifelse(eval($2 > 14), 1, [
139
      movdqu	128(%rsp), %xmm14
140 141
    ])
    ifelse(eval($2 > 13), 1, [
142
      movdqu	112(%rsp), %xmm13
143 144
    ])
    ifelse(eval($2 > 12), 1, [
145
      movdqu	96(%rsp), %xmm12
146 147
    ])
    ifelse(eval($2 > 11), 1, [
148
      movdqu	80(%rsp), %xmm11
149 150
    ])
    ifelse(eval($2 > 10), 1, [
151
      movdqu	64(%rsp), %xmm10
152 153
    ])
    ifelse(eval($2 > 9), 1, [
154
      movdqu	48(%rsp), %xmm9
155 156
    ])
    ifelse(eval($2 > 8), 1, [
157
      movdqu	32(%rsp), %xmm8
158 159
    ])
    ifelse(eval($2 > 7), 1, [
160
      movdqu	16(%rsp), %xmm7
161 162
    ])
    ifelse(eval($2 > 6), 1, [
163
      movdqu	0(%rsp), %xmm6
164 165 166 167 168
      add	[$]eval(8 + 16*($2 - 6)), %rsp
    ])
  ])
  changequote(<,>)dnl
>)