• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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 package android.renderscript.cts;
18 
19 import com.android.cts.stub.R;
20 import android.renderscript.Allocation;
21 import android.renderscript.RSRuntimeException;
22 
23 public class TruncTest extends RSBaseCompute {
24     private ScriptC_trunc_f32 script_f32;
25     private ScriptC_trunc_f32_relaxed script_f32_relaxed;
26 
27     @Override
setUp()28     protected void setUp() throws Exception {
29         super.setUp();
30         script_f32 = new ScriptC_trunc_f32(mRS);
31         script_f32_relaxed = new ScriptC_trunc_f32_relaxed(mRS);
32     }
33 
34     @Override
forEach(int testId, Allocation mIn, Allocation mOut)35     public void forEach(int testId, Allocation mIn, Allocation mOut) throws RSRuntimeException {
36         switch (testId) {
37         case TEST_F32:
38             script_f32.forEach_trunc_f32_1(mIn, mOut);
39             break;
40         case TEST_F32_2:
41             script_f32.forEach_trunc_f32_2(mIn, mOut);
42             break;
43         case TEST_F32_3:
44             script_f32.forEach_trunc_f32_3(mIn, mOut);
45             break;
46         case TEST_F32_4:
47             script_f32.forEach_trunc_f32_4(mIn, mOut);
48             break;
49 
50         case TEST_RELAXED_F32:
51             script_f32_relaxed.forEach_trunc_f32_1(mIn, mOut);
52             break;
53         case TEST_RELAXED_F32_2:
54             script_f32_relaxed.forEach_trunc_f32_2(mIn, mOut);
55             break;
56         case TEST_RELAXED_F32_3:
57             script_f32_relaxed.forEach_trunc_f32_3(mIn, mOut);
58             break;
59         case TEST_RELAXED_F32_4:
60             script_f32_relaxed.forEach_trunc_f32_4(mIn, mOut);
61             break;
62         }
63     }
64 
65     @Override
getRefArray(float[] inArray, int input_size, int stride, int skip)66     protected float[] getRefArray(float[] inArray, int input_size, int stride, int skip) {
67         float[] ref = new float[input_size * stride];
68         for (int i = 0; i < input_size; i++) {
69             for (int j = 0; j < stride - skip; j++) {
70                 int idxSrc = i * stride + j;
71                 int idxDst = i * (stride - skip) + j;
72                 int sign = ((Float.floatToIntBits(inArray[idxSrc]) >> 31) & 0x01);
73                 float trunc = (int)inArray[idxSrc];
74                 if (sign == 1 && trunc == +0.0f) {
75                     trunc = -0.0f;
76                 }
77                 ref[idxDst] = trunc;
78             }
79         }
80         return ref;
81     }
82 
83     /**
84      * trunc test for float
85      */
testTruncF32()86     public void testTruncF32() {
87         doF32(0x12345678, 0);
88     }
89 
testTruncF32_relaxed()90     public void testTruncF32_relaxed() {
91         doF32_relaxed(0x12345678, 0);
92     }
93 
94     /**
95      * trunc test for float2
96      */
testTruncF32_2()97     public void testTruncF32_2() {
98         doF32_2(0x12345a78, 0);
99     }
100 
testTruncF32_2_relaxed()101     public void testTruncF32_2_relaxed() {
102         doF32_2_relaxed(0x12345a78, 0);
103     }
104 
105     /**
106      * trunc test for float3
107      */
testTruncF32_3()108     public void testTruncF32_3() {
109         doF32_3(0x12f45678, 0);
110     }
111 
testTruncF32_3_relaxed()112     public void testTruncF32_3_relaxed() {
113         doF32_3_relaxed(0x12f45678, 0);
114     }
115 
116     /**
117      * trunc test for float4
118      */
testTruncF32_4()119     public void testTruncF32_4() {
120         doF32_4(0x123c5678, 0);
121     }
122 
testTruncF32_4_relaxed()123     public void testTruncF32_4_relaxed() {
124         doF32_4_relaxed(0x123c5678, 0);
125     }
126 
127 }
128