15a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines/*
25a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * Copyright (C) 2013 The Android Open Source Project
35a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *
45a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * Licensed under the Apache License, Version 2.0 (the "License");
55a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * you may not use this file except in compliance with the License.
65a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * You may obtain a copy of the License at
75a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *
85a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *      http://www.apache.org/licenses/LICENSE-2.0
95a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines *
105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * Unless required by applicable law or agreed to in writing, software
115a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * distributed under the License is distributed on an "AS IS" BASIS,
125a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * See the License for the specific language governing permissions and
145a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines * limitations under the License.
155a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines */
165a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
17be2163801c33d6849ae580d42b919b8803d55095Jean-Luc Brouillet#include "rs_core.rsh"
185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
19d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samstypedef unsigned long long ull;
20d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samstypedef unsigned long long ull2 __attribute__((ext_vector_type(2)));
21d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samstypedef unsigned long long ull3 __attribute__((ext_vector_type(3)));
22d8b8f8a16415496acc9844a89599ce7f377bd04dJason Samstypedef unsigned long long ull4 __attribute__((ext_vector_type(4)));
23d8b8f8a16415496acc9844a89599ce7f377bd04dJason Sams
245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define S_CLAMP(T) \
255a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T __attribute__((overloadable)) clamp(T amount, T low, T high) {             \
265a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return amount < low ? low : (amount > high ? high : amount);                    \
275a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
285a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
2954cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarS_CLAMP(half);
305a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines//_CLAMP(float);  implemented in .ll
315a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(double);
325a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(char);
335a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(uchar);
345a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(short);
355a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(ushort);
365a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(int);
375a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(uint);
385a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(long);
395a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(ulong);
405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef S_CLAMP
425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                                                                                    \
455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define V_CLAMP(T) \
465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##2 __attribute__((overloadable)) clamp(T##2 amount, T##2 low, T##2 high) { \
475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    T##2 r;                                                                         \
485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);       \
495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);       \
505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                                       \
515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                                   \
525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                                                                                    \
535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##3 __attribute__((overloadable)) clamp(T##3 amount, T##3 low, T##3 high) { \
545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    T##3 r;                                                                         \
555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);       \
565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);       \
575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z);       \
585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                                       \
595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                                   \
605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                                                                                    \
615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##4 __attribute__((overloadable)) clamp(T##4 amount, T##4 low, T##4 high) { \
625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    T##4 r;                                                                         \
635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);       \
645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);       \
655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z);       \
665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = amount.w < low.w ? low.w : (amount.w > high.w ? high.w : amount.w);       \
675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                                       \
685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                                   \
695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                                                                                    \
705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##2 __attribute__((overloadable)) clamp(T##2 amount, T low, T high) {       \
715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    T##2 r;                                                                         \
725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);               \
735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);               \
745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                                       \
755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                                   \
765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                                                                                    \
775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##3 __attribute__((overloadable)) clamp(T##3 amount, T low, T high) {       \
785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    T##3 r;                                                                         \
795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);               \
805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);               \
815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);               \
825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                                       \
835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}                                                                                   \
845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines                                                                                    \
855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##4 __attribute__((overloadable)) clamp(T##4 amount, T low, T high) {       \
865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    T##4 r;                                                                         \
875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);               \
885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);               \
895a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);               \
905a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);               \
915a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    return r;                                                                       \
925a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines}
935a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
9454cd5d1771ea5c95e181befc66ef8e2a2c1b78cdPirama Arumuga NainarV_CLAMP(half);
955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines//V_CLAMP(float);  implemented in .ll
965a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(double);
975a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(char);
985a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(uchar);
995a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(short);
1005a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(ushort);
101974467797f45a7e4ac191eb158edb78492a48e56Tim Murray#if !defined(ARCH_ARM_HAVE_NEON) && !defined (ARCH_ARM64_HAVE_NEON)
1025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    V_CLAMP(int);  //implemented in .ll
1035a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines    V_CLAMP(uint);  //implemented in .ll
1045a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#endif
105974467797f45a7e4ac191eb158edb78492a48e56Tim Murray
1065a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(long);
1075a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(ulong);
108d8b8f8a16415496acc9844a89599ce7f377bd04dJason SamsV_CLAMP(ull);
1095a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines
1105a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef _CLAMP
111