Skip to content

Commit 655151a

Browse files
authored
[libclc] Move (fast) length & distance to CLC library (llvm#139701)
This commit also refactors how geometric builtins are defined and declared, by sharing more helpers. It also removes an unnecessary gentype-like helper in favour of the more complete math/gentype.inc. There are no changes to the IR for any of these four builtins. The 'normalize' builtin will follow in a subsequent commit because it would involve the addition of missing halfn-type overloads for completeness.
1 parent 49ee674 commit 655151a

35 files changed

+365
-284
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Geometric functions are only defined for scalar, vec2, vec3 and vec4
10+
#if (__CLC_VECSIZE_OR_1 == 1 || __CLC_VECSIZE_OR_1 == 2 || \
11+
__CLC_VECSIZE_OR_1 == 3 || __CLC_VECSIZE_OR_1 == 4)
12+
13+
_CLC_OVERLOAD _CLC_DECL __CLC_SCALAR_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE a,
14+
__CLC_GENTYPE b);
15+
16+
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <clc/utils.h>
10+
11+
#ifndef __CLC_FUNCTION
12+
#define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
13+
#endif
14+
15+
// Geometric functions are only defined for scalar, vec2, vec3 and vec4
16+
#if (__CLC_VECSIZE_OR_1 == 1 || __CLC_VECSIZE_OR_1 == 2 || \
17+
__CLC_VECSIZE_OR_1 == 3 || __CLC_VECSIZE_OR_1 == 4)
18+
19+
_CLC_OVERLOAD _CLC_DEF __CLC_SCALAR_GENTYPE FUNCTION(__CLC_GENTYPE a,
20+
__CLC_GENTYPE b) {
21+
return __CLC_FUNCTION(FUNCTION)(a, b);
22+
}
23+
24+
#endif
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_GEOMETRIC_CLC_DISTANCE_H__
10+
#define __CLC_GEOMETRIC_CLC_DISTANCE_H__
11+
12+
#define __CLC_FUNCTION __clc_distance
13+
#define __CLC_BODY <clc/geometric/binary_decl.inc>
14+
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_FUNCTION
18+
19+
#endif // __CLC_GEOMETRIC_CLC_DISTANCE_H__

libclc/clc/include/clc/geometric/clc_dot.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
#ifndef __CLC_GEOMETRIC_CLC_DOT_H__
1010
#define __CLC_GEOMETRIC_CLC_DOT_H__
1111

12-
#define __CLC_BODY <clc/geometric/clc_dot.inc>
13-
#include <clc/geometric/floatn.inc>
12+
#define __CLC_FUNCTION __clc_dot
13+
#define __CLC_BODY <clc/geometric/binary_decl.inc>
14+
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_FUNCTION
1418

1519
#endif // __CLC_GEOMETRIC_CLC_DOT_H__
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_GEOMETRIC_CLC_FAST_DISTANCE_H__
10+
#define __CLC_GEOMETRIC_CLC_FAST_DISTANCE_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_fast_distance
14+
#define __CLC_BODY <clc/geometric/binary_decl.inc>
15+
16+
#include <clc/math/gentype.inc>
17+
18+
#undef __FLOAT_ONLY
19+
#undef __CLC_FUNCTION
20+
21+
#endif // __CLC_GEOMETRIC_CLC_FAST_DISTANCE_H__
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_GEOMETRIC_CLC_FAST_LENGTH_H__
10+
#define __CLC_GEOMETRIC_CLC_FAST_LENGTH_H__
11+
12+
#define __FLOAT_ONLY
13+
#define __CLC_FUNCTION __clc_fast_length
14+
#define __CLC_BODY <clc/geometric/unary_decl.inc>
15+
16+
#include <clc/math/gentype.inc>
17+
18+
#undef __FLOAT_ONLY
19+
#undef __CLC_FUNCTION
20+
21+
#endif // __CLC_GEOMETRIC_CLC_FAST_LENGTH_H__

libclc/generic/include/clc/geometric/dot.inc renamed to libclc/clc/include/clc/geometric/clc_length.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __CLC_FLOAT dot(__CLC_FLOATN p0, __CLC_FLOATN p1);
9+
#ifndef __CLC_GEOMETRIC_CLC_LENGTH_H__
10+
#define __CLC_GEOMETRIC_CLC_LENGTH_H__
11+
12+
#define __CLC_FUNCTION __clc_length
13+
#define __CLC_BODY <clc/geometric/unary_decl.inc>
14+
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_FUNCTION
18+
19+
#endif // __CLC_GEOMETRIC_CLC_LENGTH_H__

libclc/clc/include/clc/geometric/floatn.inc

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Geometric functions are only defined for scalar, vec2, vec3 and vec4
10+
#if (__CLC_VECSIZE_OR_1 == 1 || __CLC_VECSIZE_OR_1 == 2 || \
11+
__CLC_VECSIZE_OR_1 == 3 || __CLC_VECSIZE_OR_1 == 4)
12+
13+
_CLC_OVERLOAD _CLC_DECL
14+
#ifdef __CLC_GEOMETRIC_RET_GENTYPE
15+
__CLC_GENTYPE
16+
#else
17+
__CLC_SCALAR_GENTYPE
18+
#endif
19+
__CLC_FUNCTION(__CLC_GENTYPE a);
20+
21+
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <clc/utils.h>
10+
11+
#ifndef __CLC_FUNCTION
12+
#define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
13+
#endif
14+
15+
// Geometric functions are only defined for scalar, vec2, vec3 and vec4
16+
#if (__CLC_VECSIZE_OR_1 == 1 || __CLC_VECSIZE_OR_1 == 2 || \
17+
__CLC_VECSIZE_OR_1 == 3 || __CLC_VECSIZE_OR_1 == 4)
18+
19+
_CLC_OVERLOAD _CLC_DEF
20+
#ifdef __CLC_GEOMETRIC_RET_GENTYPE
21+
__CLC_GENTYPE
22+
#else
23+
__CLC_SCALAR_GENTYPE
24+
#endif
25+
FUNCTION(__CLC_GENTYPE a) {
26+
return __CLC_FUNCTION(FUNCTION)(a);
27+
}
28+
29+
#endif

0 commit comments

Comments
 (0)