1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #pragma version(1)
18 #pragma rs java_package_name(com.android.rs.jnibranchingfuncalls)
19 
20 static bool is_neg(int a)
21 {
22     if(a < 0)
23         return true;
24     else
25         return false;
26 }
27 
28 static bool is_pos(int a)
29 {
30     if(a > 0)
31         return true;
32     else
33         return false;
34 }
35 
36 static void set_i(int * a, int b)
37 {
38     int tmp = b;
39     *a = tmp;
40 }
41 
42 static void modify_f(float * f)
43 {
44     *f *= 0.5f;
45 }
46 
47 static void modify_i(int * i)
48 {
49     int j = *i;
50     int cutoff = 2 << 6;
51     if(j > cutoff)
52         j = cutoff;
53     if(is_neg(j))
54         set_i(i, 0);
55     else if(is_pos(j))
56         set_i(i, j);
57     else
58         set_i(i, cutoff);
59 }
60 
61 int __attribute__((kernel)) simple_kernel(int in)
62 {
63     int i = in;
64     float f = (float) i;
65     modify_f(&f);
66     modify_i(&i);
67     int ret = (int) f;
68     return in * ret;
69 }
70 
71 int glob = 123;
72 
73 void addToGlobal(int arg)
74 {
75     glob += arg;
76 }
77