1*e1eccf28SAndroid Build Coastguard Worker /*
2*e1eccf28SAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project
3*e1eccf28SAndroid Build Coastguard Worker *
4*e1eccf28SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*e1eccf28SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*e1eccf28SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*e1eccf28SAndroid Build Coastguard Worker *
8*e1eccf28SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*e1eccf28SAndroid Build Coastguard Worker *
10*e1eccf28SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*e1eccf28SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*e1eccf28SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e1eccf28SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*e1eccf28SAndroid Build Coastguard Worker * limitations under the License.
15*e1eccf28SAndroid Build Coastguard Worker */
16*e1eccf28SAndroid Build Coastguard Worker
17*e1eccf28SAndroid Build Coastguard Worker #include "Utils.h"
18*e1eccf28SAndroid Build Coastguard Worker
19*e1eccf28SAndroid Build Coastguard Worker #include <cpu-features.h>
20*e1eccf28SAndroid Build Coastguard Worker
21*e1eccf28SAndroid Build Coastguard Worker #include "RenderScriptToolkit.h"
22*e1eccf28SAndroid Build Coastguard Worker
23*e1eccf28SAndroid Build Coastguard Worker namespace android {
24*e1eccf28SAndroid Build Coastguard Worker namespace renderscript {
25*e1eccf28SAndroid Build Coastguard Worker
26*e1eccf28SAndroid Build Coastguard Worker #define LOG_TAG "renderscript.toolkit.Utils"
27*e1eccf28SAndroid Build Coastguard Worker
cpuSupportsSimd()28*e1eccf28SAndroid Build Coastguard Worker bool cpuSupportsSimd() {
29*e1eccf28SAndroid Build Coastguard Worker AndroidCpuFamily family = android_getCpuFamily();
30*e1eccf28SAndroid Build Coastguard Worker uint64_t features = android_getCpuFeatures();
31*e1eccf28SAndroid Build Coastguard Worker
32*e1eccf28SAndroid Build Coastguard Worker if (family == ANDROID_CPU_FAMILY_ARM && (features & ANDROID_CPU_ARM_FEATURE_NEON)) {
33*e1eccf28SAndroid Build Coastguard Worker // ALOGI("Arm with Neon");
34*e1eccf28SAndroid Build Coastguard Worker return true;
35*e1eccf28SAndroid Build Coastguard Worker } else if (family == ANDROID_CPU_FAMILY_ARM64 && (features & ANDROID_CPU_ARM64_FEATURE_ASIMD)) {
36*e1eccf28SAndroid Build Coastguard Worker // ALOGI("Arm64 with ASIMD");
37*e1eccf28SAndroid Build Coastguard Worker return true;
38*e1eccf28SAndroid Build Coastguard Worker } else if ((family == ANDROID_CPU_FAMILY_X86 || family == ANDROID_CPU_FAMILY_X86_64) &&
39*e1eccf28SAndroid Build Coastguard Worker (features & ANDROID_CPU_X86_FEATURE_SSSE3)) {
40*e1eccf28SAndroid Build Coastguard Worker // ALOGI("x86* with SSE3");
41*e1eccf28SAndroid Build Coastguard Worker return true;
42*e1eccf28SAndroid Build Coastguard Worker }
43*e1eccf28SAndroid Build Coastguard Worker // ALOGI("Not simd");
44*e1eccf28SAndroid Build Coastguard Worker return false;
45*e1eccf28SAndroid Build Coastguard Worker }
46*e1eccf28SAndroid Build Coastguard Worker
47*e1eccf28SAndroid Build Coastguard Worker #ifdef ANDROID_RENDERSCRIPT_TOOLKIT_VALIDATE
validRestriction(const char * tag,size_t sizeX,size_t sizeY,const Restriction * restriction)48*e1eccf28SAndroid Build Coastguard Worker bool validRestriction(const char* tag, size_t sizeX, size_t sizeY, const Restriction* restriction) {
49*e1eccf28SAndroid Build Coastguard Worker if (restriction == nullptr) {
50*e1eccf28SAndroid Build Coastguard Worker return true;
51*e1eccf28SAndroid Build Coastguard Worker }
52*e1eccf28SAndroid Build Coastguard Worker if (restriction->startX >= sizeX || restriction->endX > sizeX) {
53*e1eccf28SAndroid Build Coastguard Worker ALOGE("%s. sizeX should be greater than restriction->startX and greater or equal to "
54*e1eccf28SAndroid Build Coastguard Worker "restriction->endX. %zu, %zu, and %zu were provided respectively.",
55*e1eccf28SAndroid Build Coastguard Worker tag, sizeX, restriction->startX, restriction->endY);
56*e1eccf28SAndroid Build Coastguard Worker return false;
57*e1eccf28SAndroid Build Coastguard Worker }
58*e1eccf28SAndroid Build Coastguard Worker if (restriction->startY >= sizeY && restriction->endY > sizeY) {
59*e1eccf28SAndroid Build Coastguard Worker ALOGE("%s. sizeY should be greater than restriction->startY and greater or equal to "
60*e1eccf28SAndroid Build Coastguard Worker "restriction->endY. %zu, %zu, and %zu were provided respectively.",
61*e1eccf28SAndroid Build Coastguard Worker tag, sizeY, restriction->startY, restriction->endY);
62*e1eccf28SAndroid Build Coastguard Worker return false;
63*e1eccf28SAndroid Build Coastguard Worker }
64*e1eccf28SAndroid Build Coastguard Worker if (restriction->startX >= restriction->endX) {
65*e1eccf28SAndroid Build Coastguard Worker ALOGE("%s. Restriction startX should be less than endX. "
66*e1eccf28SAndroid Build Coastguard Worker "%zu and %zu were provided respectively.",
67*e1eccf28SAndroid Build Coastguard Worker tag, restriction->startX, restriction->endX);
68*e1eccf28SAndroid Build Coastguard Worker return false;
69*e1eccf28SAndroid Build Coastguard Worker }
70*e1eccf28SAndroid Build Coastguard Worker if (restriction->startY >= restriction->endY) {
71*e1eccf28SAndroid Build Coastguard Worker ALOGE("%s. Restriction startY should be less than endY. "
72*e1eccf28SAndroid Build Coastguard Worker "%zu and %zu were provided respectively.",
73*e1eccf28SAndroid Build Coastguard Worker tag, restriction->startY, restriction->endY);
74*e1eccf28SAndroid Build Coastguard Worker return false;
75*e1eccf28SAndroid Build Coastguard Worker }
76*e1eccf28SAndroid Build Coastguard Worker return true;
77*e1eccf28SAndroid Build Coastguard Worker }
78*e1eccf28SAndroid Build Coastguard Worker #endif
79*e1eccf28SAndroid Build Coastguard Worker
80*e1eccf28SAndroid Build Coastguard Worker } // namespace renderscript
81*e1eccf28SAndroid Build Coastguard Worker } // namespace android
82