fork/rust
git clone https://git.julia.blue/fork/rust
5e1a799842b
1.41.0
1#include <assert.h> 2#include <stdint.h> 3 4struct Rect { 5 int32_t a; 6 int32_t b; 7 int32_t c; 8 int32_t d; 9}; 10 11struct BiggerRect { 12 struct Rect s; 13 int32_t a; 14 int32_t b; 15}; 16 17struct FloatRect { 18 int32_t a; 19 int32_t b; 20 double c; 21}; 22 23struct Huge { 24 int32_t a; 25 int32_t b; 26 int32_t c; 27 int32_t d; 28 int32_t e; 29}; 30 31struct FloatPoint { 32 double x; 33 double y; 34}; 35 36struct FloatOne { 37 double x; 38}; 39 40struct IntOdd { 41 int8_t a; 42 int8_t b; 43 int8_t c; 44}; 45 46// System V x86_64 ABI: 47// a, b, c, d, e should be in registers 48// s should be byval pointer 49// 50// Win64 ABI: 51// a, b, c, d should be in registers 52// e should be on the stack 53// s should be byval pointer 54void byval_rect(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, struct Rect s) { 55 assert(a == 1); 56 assert(b == 2); 57 assert(c == 3); 58 assert(d == 4); 59 assert(e == 5); 60 assert(s.a == 553); 61 assert(s.b == 554); 62 assert(s.c == 555); 63 assert(s.d == 556); 64} 65 66// System V x86_64 ABI: 67// a, b, c, d, e, f should be in registers 68// s should be byval pointer on the stack 69// 70// Win64 ABI: 71// a, b, c, d should be in registers 72// e, f should be on the stack 73// s should be byval pointer on the stack 74void byval_many_rect(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, 75 int32_t f, struct Rect s) { 76 assert(a == 1); 77 assert(b == 2); 78 assert(c == 3); 79 assert(d == 4); 80 assert(e == 5); 81 assert(f == 6); 82 assert(s.a == 553); 83 assert(s.b == 554); 84 assert(s.c == 555); 85 assert(s.d == 556); 86} 87 88// System V x86_64 ABI: 89// a, b, c, d, e, f, g should be in sse registers 90// s should be split across 2 registers 91// t should be byval pointer 92// 93// Win64 ABI: 94// a, b, c, d should be in sse registers 95// e, f, g should be on the stack 96// s should be on the stack (treated as 2 i64's) 97// t should be on the stack (treated as an i64 and a double) 98void byval_rect_floats(float a, float b, double c, float d, float e, 99 float f, double g, struct Rect s, struct FloatRect t) { 100 assert(a == 1.); 101 assert(b == 2.); 102 assert(c == 3.); 103 assert(d == 4.); 104 assert(e == 5.); 105 assert(f == 6.); 106 assert(g == 7.); 107 assert(s.a == 553); 108 assert(s.b == 554); 109 assert(s.c == 555); 110 assert(s.d == 556); 111 assert(t.a == 3489); 112 assert(t.b == 3490); 113 assert(t.c == 8.); 114} 115 116// System V x86_64 ABI: 117// a, b, d, e, f should be in registers 118// c passed via sse registers 119// s should be byval pointer 120// 121// Win64 ABI: 122// a, b, d should be in registers 123// c passed via sse registers 124// e, f should be on the stack 125// s should be byval pointer 126void byval_rect_with_float(int32_t a, int32_t b, float c, int32_t d, 127 int32_t e, int32_t f, struct Rect s) { 128 assert(a == 1); 129 assert(b == 2); 130 assert(c == 3.); 131 assert(d == 4); 132 assert(e == 5); 133 assert(f == 6); 134 assert(s.a == 553); 135 assert(s.b == 554); 136 assert(s.c == 555); 137 assert(s.d == 556); 138} 139 140// System V x86_64 ABI: 141// a, b, d, e, f should be byval pointer (on the stack) 142// g passed via register (fixes #41375) 143// 144// Win64 ABI: 145// a, b, d, e, f, g should be byval pointer 146void byval_rect_with_many_huge(struct Huge a, struct Huge b, struct Huge c, 147 struct Huge d, struct Huge e, struct Huge f, 148 struct Rect g) { 149 assert(g.a == 123); 150 assert(g.b == 456); 151 assert(g.c == 789); 152 assert(g.d == 420); 153} 154 155// System V x86_64 & Win64 ABI: 156// a, b should be in registers 157// s should be split across 2 integer registers 158void split_rect(int32_t a, int32_t b, struct Rect s) { 159 assert(a == 1); 160 assert(b == 2); 161 assert(s.a == 553); 162 assert(s.b == 554); 163 assert(s.c == 555); 164 assert(s.d == 556); 165} 166 167// System V x86_64 & Win64 ABI: 168// a, b should be in sse registers 169// s should be split across integer & sse registers 170void split_rect_floats(float a, float b, struct FloatRect s) { 171 assert(a == 1.); 172 assert(b == 2.); 173 assert(s.a == 3489); 174 assert(s.b == 3490); 175 assert(s.c == 8.); 176} 177 178// System V x86_64 ABI: 179// a, b, d, f should be in registers 180// c, e passed via sse registers 181// s should be split across 2 registers 182// 183// Win64 ABI: 184// a, b, d should be in registers 185// c passed via sse registers 186// e, f should be on the stack 187// s should be on the stack (treated as 2 i64's) 188void split_rect_with_floats(int32_t a, int32_t b, float c, 189 int32_t d, float e, int32_t f, struct Rect s) { 190 assert(a == 1); 191 assert(b == 2); 192 assert(c == 3.); 193 assert(d == 4); 194 assert(e == 5.); 195 assert(f == 6); 196 assert(s.a == 553); 197 assert(s.b == 554); 198 assert(s.c == 555); 199 assert(s.d == 556); 200} 201 202// System V x86_64 & Win64 ABI: 203// a, b, c should be in registers 204// s should be split across 2 registers 205// t should be a byval pointer 206void split_and_byval_rect(int32_t a, int32_t b, int32_t c, struct Rect s, struct Rect t) { 207 assert(a == 1); 208 assert(b == 2); 209 assert(c == 3); 210 assert(s.a == 553); 211 assert(s.b == 554); 212 assert(s.c == 555); 213 assert(s.d == 556); 214 assert(t.a == 553); 215 assert(t.b == 554); 216 assert(t.c == 555); 217 assert(t.d == 556); 218} 219 220// System V x86_64 & Win64 ABI: 221// a, b should in registers 222// s and return should be split across 2 registers 223struct Rect split_ret_byval_struct(int32_t a, int32_t b, struct Rect s) { 224 assert(a == 1); 225 assert(b == 2); 226 assert(s.a == 553); 227 assert(s.b == 554); 228 assert(s.c == 555); 229 assert(s.d == 556); 230 return s; 231} 232 233// System V x86_64 & Win64 ABI: 234// a, b, c, d should be in registers 235// return should be in a hidden sret pointer 236// s should be a byval pointer 237struct BiggerRect sret_byval_struct(int32_t a, int32_t b, int32_t c, int32_t d, struct Rect s) { 238 assert(a == 1); 239 assert(b == 2); 240 assert(c == 3); 241 assert(d == 4); 242 assert(s.a == 553); 243 assert(s.b == 554); 244 assert(s.c == 555); 245 assert(s.d == 556); 246 247 struct BiggerRect t; 248 t.s = s; t.a = 27834; t.b = 7657; 249 return t; 250} 251 252// System V x86_64 & Win64 ABI: 253// a, b should be in registers 254// return should be in a hidden sret pointer 255// s should be split across 2 registers 256struct BiggerRect sret_split_struct(int32_t a, int32_t b, struct Rect s) { 257 assert(a == 1); 258 assert(b == 2); 259 assert(s.a == 553); 260 assert(s.b == 554); 261 assert(s.c == 555); 262 assert(s.d == 556); 263 264 struct BiggerRect t; 265 t.s = s; t.a = 27834; t.b = 7657; 266 return t; 267} 268 269// System V x86_64 & Win64 ABI: 270// s should be byval pointer (since sizeof(s) > 16) 271// return should in a hidden sret pointer 272struct Huge huge_struct(struct Huge s) { 273 assert(s.a == 5647); 274 assert(s.b == 5648); 275 assert(s.c == 5649); 276 assert(s.d == 5650); 277 assert(s.e == 5651); 278 279 return s; 280} 281 282// System V x86_64 ABI: 283// p should be in registers 284// return should be in registers 285// 286// Win64 ABI and 64-bit PowerPC ELFv1 ABI: 287// p should be a byval pointer 288// return should be in a hidden sret pointer 289struct FloatPoint float_point(struct FloatPoint p) { 290 assert(p.x == 5.); 291 assert(p.y == -3.); 292 293 return p; 294} 295 296// 64-bit PowerPC ELFv1 ABI: 297// f1 should be in a register 298// return should be in a hidden sret pointer 299struct FloatOne float_one(struct FloatOne f1) { 300 assert(f1.x == 7.); 301 302 return f1; 303} 304 305// 64-bit PowerPC ELFv1 ABI: 306// i should be in the least-significant bits of a register 307// return should be in a hidden sret pointer 308struct IntOdd int_odd(struct IntOdd i) { 309 assert(i.a == 1); 310 assert(i.b == 2); 311 assert(i.c == 3); 312 313 return i; 314}