/*1* By downloading, copying, installing or using the software you agree to this license.2* If you do not agree to this license, do not download, install,3* copy or use the software.4*5*6* License Agreement7* For Open Source Computer Vision Library8* (3-clause BSD License)9*10* Copyright (C) 2014-2015, NVIDIA Corporation, all rights reserved.11* Third party copyrights are property of their respective owners.12*13* Redistribution and use in source and binary forms, with or without modification,14* are permitted provided that the following conditions are met:15*16* * Redistributions of source code must retain the above copyright notice,17* this list of conditions and the following disclaimer.18*19* * Redistributions in binary form must reproduce the above copyright notice,20* this list of conditions and the following disclaimer in the documentation21* and/or other materials provided with the distribution.22*23* * Neither the names of the copyright holders nor the names of the contributors24* may be used to endorse or promote products derived from this software25* without specific prior written permission.26*27* This software is provided by the copyright holders and contributors "as is" and28* any express or implied warranties, including, but not limited to, the implied29* warranties of merchantability and fitness for a particular purpose are disclaimed.30* In no event shall copyright holders or contributors be liable for any direct,31* indirect, incidental, special, exemplary, or consequential damages32* (including, but not limited to, procurement of substitute goods or services;33* loss of use, data, or profits; or business interruption) however caused34* and on any theory of liability, whether in contract, strict liability,35* or tort (including negligence or otherwise) arising in any way out of36* the use of this software, even if advised of the possibility of such damage.37*/3839#ifndef CAROTENE_SRC_COMMON_HPP40#define CAROTENE_SRC_COMMON_HPP4142#include <cstddef>43#include <cstdlib>44#include <algorithm>4546#if defined WITH_NEON && (defined __ARM_NEON__ || defined __ARM_NEON)47#define CAROTENE_NEON48#endif4950#ifdef CAROTENE_NEON51#include <arm_neon.h>52#include "intrinsics.hpp"53#endif5455#include <carotene/functions.hpp>56#include "saturate_cast.hpp"5758namespace CAROTENE_NS { namespace internal {5960inline void prefetch(const void *ptr, size_t offset = 32*10)61{62#if defined __GNUC__63__builtin_prefetch(reinterpret_cast<const char*>(ptr) + offset);64#elif defined _MSC_VER && defined CAROTENE_NEON65__prefetch(reinterpret_cast<const char*>(ptr) + offset);66#else67(void)ptr;68(void)offset;69#endif70}7172template <typename T>73inline T *getRowPtr(T *base, ptrdiff_t stride, size_t row)74{75char *baseRaw = const_cast<char *>(reinterpret_cast<const char *>(base));76return reinterpret_cast<T *>(baseRaw + ptrdiff_t(row) * stride);77}7879void assertSupportedConfiguration(bool parametersSupported = true);8081ptrdiff_t borderInterpolate(ptrdiff_t _p, size_t _len, BORDER_MODE borderType, size_t startMargin = 0, size_t endMargin = 0);8283/*!84* Aligns pointer by the certain number of bytes85*86* This small inline function aligns the pointer by the certain number of bytes by shifting87* it forward by 0 or a positive offset.88*/89template<typename T> inline T* alignPtr(T* ptr, size_t n=sizeof(T))90{91return (T*)(((size_t)ptr + n-1) & -n);92}9394}}9596#endif979899