diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2016-01-27 14:52:10 +0000 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2016-01-27 14:52:10 +0000 |
commit | dc330a37a302063f2f541f397b3b00a2d384d290 (patch) | |
tree | bac9270c2c9da4bf4d5a5ad74de91fcd9bb9649e | |
parent | eaab502afbf2f58d933584b3787f681b5f19473f (diff) |
Implement modf math builtin
V2: use the reference implementation as suggested by Matt Arsenault
Patch By: Pavel Ondračka
git-svn-id: https://llvm.org/svn/llvm-project/libclc/trunk@258933 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | generic/include/clc/clc.h | 1 | ||||
-rw-r--r-- | generic/include/clc/math/modf.h | 24 | ||||
-rw-r--r-- | generic/include/clc/math/modf.inc | 25 | ||||
-rw-r--r-- | generic/lib/SOURCES | 1 | ||||
-rw-r--r-- | generic/lib/math/modf.cl | 32 | ||||
-rw-r--r-- | generic/lib/math/modf.inc | 37 |
6 files changed, 120 insertions, 0 deletions
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h index fea578a..bd2f67f 100644 --- a/generic/include/clc/clc.h +++ b/generic/include/clc/clc.h @@ -67,6 +67,7 @@ #include <clc/math/log1p.h> #include <clc/math/log2.h> #include <clc/math/mad.h> +#include <clc/math/modf.h> #include <clc/math/nextafter.h> #include <clc/math/pow.h> #include <clc/math/pown.h> diff --git a/generic/include/clc/math/modf.h b/generic/include/clc/math/modf.h new file mode 100644 index 0000000..f0fb6ca --- /dev/null +++ b/generic/include/clc/math/modf.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define __CLC_BODY <clc/math/modf.inc> +#include <clc/math/gentype.inc> diff --git a/generic/include/clc/math/modf.inc b/generic/include/clc/math/modf.inc new file mode 100644 index 0000000..42bcf62 --- /dev/null +++ b/generic/include/clc/math/modf.inc @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2014, 2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, global __CLC_GENTYPE *iptr); +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, local __CLC_GENTYPE *iptr); +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, private __CLC_GENTYPE *iptr); diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES index b186301..1daae8d 100644 --- a/generic/lib/SOURCES +++ b/generic/lib/SOURCES @@ -96,6 +96,7 @@ math/log10.cl math/log1p.cl math/log2.cl math/mad.cl +math/modf.cl math/native_log.cl math/native_log2.cl math/tables.cl diff --git a/generic/lib/math/modf.cl b/generic/lib/math/modf.cl new file mode 100644 index 0000000..3294fbc --- /dev/null +++ b/generic/lib/math/modf.cl @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <clc/clc.h> + +#include "math.h" + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif + +#define __CLC_BODY <modf.inc> +#include <clc/math/gentype.inc> diff --git a/generic/lib/math/modf.inc b/generic/lib/math/modf.inc new file mode 100644 index 0000000..1486b76 --- /dev/null +++ b/generic/lib/math/modf.inc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, __CLC_GENTYPE *iptr) { + *iptr = trunc(x); + return copysign(isinf(x) ? 0.0f : x - *iptr, x); +} + +#define MODF_DEF(addrspace) \ + _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, addrspace __CLC_GENTYPE *iptr) { \ + __CLC_GENTYPE private_iptr; \ + __CLC_GENTYPE ret = modf(x, &private_iptr); \ + *iptr = private_iptr; \ + return ret; \ +} + +MODF_DEF(local); +MODF_DEF(global); |