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

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: rebase 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
« no previous file with comments | « crosstest/test_stacksave.h ('k') | crosstest/test_stacksave_main.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 static uint32_t __attribute__((noinline)) foo(uint32_t x) {
33 return x * x;
34 }
35
36 /* NOTE: This has 1 stacksave, because the vla is in a loop and should
37 * be freed before the next iteration.
38 */
39 uint32_t test_vla_in_loop(uint32_t size, uint32_t start, uint32_t inc) {
40 uint32_t sum = 0;
41 for (uint32_t i = start; i < size; ++i) {
42 uint32_t size1 = size - i;
43 uint32_t vla[size1];
44 for (uint32_t j = 0; j < size1; ++j) {
45 /* Adjust stack again with a function call. */
46 vla[j] = foo(start * j + inc);
47 }
48 for (uint32_t j = 0; j < size1; ++j) {
49 sum += vla[j];
50 }
51 }
52 return sum;
53 }
54
55 uint32_t test_two_vlas_in_loops(uint32_t size, uint32_t start, uint32_t inc) {
56 uint32_t sum = 0;
57 for (uint32_t i = start; i < size; ++i) {
58 uint32_t size1 = size - i;
59 uint32_t vla1[size1];
60 for (uint32_t j = 0; j < size1; ++j) {
61 uint32_t size2 = size - j;
62 uint32_t start2 = 0;
63 uint32_t mid2 = size2 / 2;
64 uint32_t vla2[size2];
65 for (uint32_t k = start2; k < size2; ++k) {
66 /* Adjust stack again with a function call. */
67 vla2[k] = foo(start * k + inc);
68 }
69 vla1[j] = (vla2[start2] << 2) + (vla2[mid2] << 1) + vla2[size2 - 1];
70 }
71 for (uint32_t j = 0; j < size1; ++j) {
72 sum += vla1[j];
73 }
74 }
75 return sum;
76 }
OLDNEW
« no previous file with comments | « crosstest/test_stacksave.h ('k') | crosstest/test_stacksave_main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698