Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: crosstest/test_stacksave.c

Issue 396993009: Lower stacksave and restore intrinsics. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: line em up Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 //===- subzero/crosstest/test_stacksave.c - Implementation for tests ------===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This aims to test that C99's VLAs (which use stacksave/stackrestore
11 // intrinsics) work fine.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include <stdint.h>
16
17 #include "test_stacksave.h"
18 DECLARE_TESTS()
19
20 /* NOTE: This has 0 stacksaves, because the vla isn't in a loop,
21 * so the vla can just be freed by the epilogue.
22 */
23 uint32_t test_basic_vla(uint32_t size, uint32_t start, uint32_t inc) {
24 uint32_t vla[size];
25 uint32_t mid = start + ((size - start) / 2);
26 for (uint32_t i = start; i < size; ++i) {
27 vla[i] = i + inc;
28 }
29 return (vla[start] << 2) + (vla[mid] << 1) + vla[size - 1];
30 }
31
32 /* NOTE: This has 1 stacksaves, because the vla is in a loop and should
Jim Stichnoth 2014/07/17 16:47:25 stacksave :)
jvoung (off chromium) 2014/07/17 20:34:51 Done.
33 * be freed before the next iteration.
34 */
35 uint32_t test_vla_in_loop(uint32_t size, uint32_t start, uint32_t inc) {
36 uint32_t saved_start = 0;
37 uint32_t saved_mid = 0;
38 uint32_t saved_last = 0;
39 uint32_t mid = start + ((size - start) / 2);
40 for (uint32_t i = start; i < size; ++i) {
41 uint32_t vla[size];
Jim Stichnoth 2014/07/17 16:47:25 It seems to me that a smart compiler could optimiz
jvoung (off chromium) 2014/07/17 20:34:51 Done. The compiler did some optimization indeed.
42 vla[i] = i + inc;
43 if (i == start)
44 saved_start = vla[i];
45 if (i == mid)
46 saved_mid = vla[i];
47 if (i == size - 1)
48 saved_last = vla[i];
49 }
50 return (saved_start << 2) + (saved_mid << 1) + saved_last;
51 }
52
53 static uint32_t __attribute__((noinline)) foo(uint32_t x) {
54 return x * x;
55 }
56
57 uint32_t test_two_vlas_in_loops(uint32_t size, uint32_t start, uint32_t inc) {
58 uint32_t saved_start = 0;
59 uint32_t saved_mid = 0;
60 uint32_t saved_last = 0;
61 uint32_t mid = start + ((size - start) / 2);
62 for (uint32_t i = start; i < size; ++i) {
63 uint32_t vla1[size];
64 uint32_t x = 0;
65 for (uint32_t j = i; j < size; j++) {
66 uint32_t size2 = size - j;
67 uint32_t start2 = 0;
68 uint32_t mid2 = size2 / 2;
69 uint32_t vla2[size2];
70 for (uint32_t k = start2; k < size2; k++) {
71 /* Adjust stack again with a function call. */
72 uint32_t x = foo(inc);
73 vla2[k] = k + x;
74 }
75 x = (vla2[start2] << 2) + (vla2[mid2] << 1) + vla2[size2 - 1];
76 }
77 vla1[i] = x;
78 if (i == start)
79 saved_start = vla1[i];
80 if (i == mid)
81 saved_mid = vla1[i];
82 if (i == size - 1)
83 saved_last = vla1[i];
84 }
85 return (saved_start << 2) + (saved_mid << 1) + saved_last;
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698