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 175a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#include "rs_types.rsh" 185a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 195a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define S_CLAMP(T) \ 205a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T __attribute__((overloadable)) clamp(T amount, T low, T high) { \ 215a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return amount < low ? low : (amount > high ? high : amount); \ 225a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 235a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 245a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines//_CLAMP(float); implemented in .ll 255a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(double); 265a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(char); 275a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(uchar); 285a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(short); 295a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(ushort); 305a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(int); 315a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(uint); 325a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(long); 335a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesS_CLAMP(ulong); 345a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 355a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef S_CLAMP 365a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 375a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 385a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines \ 395a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#define V_CLAMP(T) \ 405a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##2 __attribute__((overloadable)) clamp(T##2 amount, T##2 low, T##2 high) { \ 415a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T##2 r; \ 425a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x); \ 435a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y); \ 445a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 455a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 465a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines \ 475a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##3 __attribute__((overloadable)) clamp(T##3 amount, T##3 low, T##3 high) { \ 485a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T##3 r; \ 495a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x); \ 505a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y); \ 515a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z); \ 525a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 535a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 545a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines \ 555a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##4 __attribute__((overloadable)) clamp(T##4 amount, T##4 low, T##4 high) { \ 565a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T##4 r; \ 575a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x); \ 585a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y); \ 595a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z); \ 605a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = amount.w < low.w ? low.w : (amount.w > high.w ? high.w : amount.w); \ 615a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 625a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 635a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines \ 645a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##2 __attribute__((overloadable)) clamp(T##2 amount, T low, T high) { \ 655a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T##2 r; \ 665a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); \ 675a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); \ 685a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 695a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 705a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines \ 715a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##3 __attribute__((overloadable)) clamp(T##3 amount, T low, T high) { \ 725a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T##3 r; \ 735a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); \ 745a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); \ 755a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = amount.z < low ? low : (amount.z > high ? high : amount.z); \ 765a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 775a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} \ 785a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines \ 795a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hinesextern T##4 __attribute__((overloadable)) clamp(T##4 amount, T low, T high) { \ 805a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines T##4 r; \ 815a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); \ 825a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); \ 835a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.z = amount.z < low ? low : (amount.z > high ? high : amount.z); \ 845a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines r.w = amount.w < low ? low : (amount.w > high ? high : amount.w); \ 855a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines return r; \ 865a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines} 875a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 885a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines//V_CLAMP(float); implemented in .ll 895a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(double); 905a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(char); 915a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(uchar); 925a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(short); 935a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(ushort); 945a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#ifndef ARCH_ARM_HAVE_NEON 955a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines V_CLAMP(int); //implemented in .ll 965a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines V_CLAMP(uint); //implemented in .ll 975a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#endif 985a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(long); 995a47020542c52af3e879c1cd67674ca979ff0a18Stephen HinesV_CLAMP(ulong); 1005a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 1015a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines#undef _CLAMP 1025a47020542c52af3e879c1cd67674ca979ff0a18Stephen Hines 103