forked from llvm-mirror/libclc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
%opencl.image2d_t = type opaque | ||
|
||
declare <4 x float> @llvm.R600.tex(<4 x float>, i32, i32, i32, i32, i32, i32, | ||
i32, i32, i32) readnone | ||
declare i32 @llvm.OpenCL.image.get.resource.id.2d( | ||
%opencl.image2d_t addrspace(1)*) nounwind readnone | ||
declare i32 @llvm.OpenCL.sampler.get.resource.id(i32) readnone | ||
|
||
define <4 x float> @__clc_v4f_from_v2f(<2 x float> %v) alwaysinline { | ||
%e0 = extractelement <2 x float> %v, i32 0 | ||
%e1 = extractelement <2 x float> %v, i32 1 | ||
%res.0 = insertelement <4 x float> undef, float %e0, i32 0 | ||
%res.1 = insertelement <4 x float> %res.0, float %e1, i32 1 | ||
%res.2 = insertelement <4 x float> %res.1, float 0.0, i32 2 | ||
%res.3 = insertelement <4 x float> %res.2, float 0.0, i32 3 | ||
ret <4 x float> %res.3 | ||
} | ||
|
||
define <4 x float> @__clc_read_imagef_tex( | ||
%opencl.image2d_t addrspace(1)* nocapture %img, | ||
i32 %sampler, <2 x float> %coord) alwaysinline { | ||
entry: | ||
%coord_v4 = call <4 x float> @__clc_v4f_from_v2f(<2 x float> %coord) | ||
%smp_id = call i32 @llvm.OpenCL.sampler.get.resource.id(i32 %sampler) | ||
%img_id = call i32 @llvm.OpenCL.image.get.resource.id.2d( | ||
%opencl.image2d_t addrspace(1)* %img) | ||
%tex_id = add i32 %img_id, 2 ; First 2 IDs are reserved. | ||
|
||
%coord_norm = and i32 %sampler, 1 | ||
%is_norm = icmp eq i32 %coord_norm, 1 | ||
br i1 %is_norm, label %NormCoord, label %UnnormCoord | ||
NormCoord: | ||
%data.norm = call <4 x float> @llvm.R600.tex( | ||
<4 x float> %coord_v4, | ||
i32 0, i32 0, i32 0, ; Offset. | ||
i32 2, i32 %smp_id, | ||
i32 1, i32 1, i32 1, i32 1) ; Normalized coords. | ||
ret <4 x float> %data.norm | ||
UnnormCoord: | ||
%data.unnorm = call <4 x float> @llvm.R600.tex( | ||
<4 x float> %coord_v4, | ||
i32 0, i32 0, i32 0, ; Offset. | ||
i32 %tex_id, i32 %smp_id, | ||
i32 0, i32 0, i32 0, i32 0) ; Unnormalized coords. | ||
ret <4 x float> %data.unnorm | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <clc/clc.h> | ||
|
||
_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2); | ||
|
||
_CLC_OVERLOAD _CLC_DEF float4 read_imagef(image2d_t image, sampler_t sampler, | ||
int2 coord) { | ||
float2 coord_float = (float2)(coord.x, coord.y); | ||
return __clc_read_imagef_tex(image, sampler, coord_float); | ||
} | ||
|
||
_CLC_OVERLOAD _CLC_DEF float4 read_imagef(image2d_t image, sampler_t sampler, | ||
float2 coord) { | ||
return __clc_read_imagef_tex(image, sampler, coord); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <clc/clc.h> | ||
|
||
_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2); | ||
|
||
int4 __clc_reinterpret_v4f_to_v4i(float4 v) { | ||
union { | ||
int4 v4i; | ||
float4 v4f; | ||
} res = { .v4f = v}; | ||
return res.v4i; | ||
} | ||
|
||
_CLC_OVERLOAD _CLC_DEF int4 read_imagei(image2d_t image, sampler_t sampler, | ||
int2 coord) { | ||
float2 coord_float = (float2)(coord.x, coord.y); | ||
return __clc_reinterpret_v4f_to_v4i( | ||
__clc_read_imagef_tex(image, sampler, coord_float)); | ||
} | ||
_CLC_OVERLOAD _CLC_DEF int4 read_imagei(image2d_t image, sampler_t sampler, | ||
float2 coord) { | ||
return __clc_reinterpret_v4f_to_v4i( | ||
__clc_read_imagef_tex(image, sampler, coord)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <clc/clc.h> | ||
|
||
_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2); | ||
|
||
uint4 __clc_reinterpret_v4f_to_v4ui(float4 v) { | ||
union { | ||
uint4 v4ui; | ||
float4 v4f; | ||
} res = { .v4f = v}; | ||
return res.v4ui; | ||
} | ||
|
||
_CLC_OVERLOAD _CLC_DEF uint4 read_imageui(image2d_t image, sampler_t sampler, | ||
int2 coord) { | ||
float2 coord_float = (float2)(coord.x, coord.y); | ||
return __clc_reinterpret_v4f_to_v4ui( | ||
__clc_read_imagef_tex(image, sampler, coord_float)); | ||
} | ||
_CLC_OVERLOAD _CLC_DEF uint4 read_imageui(image2d_t image, sampler_t sampler, | ||
float2 coord) { | ||
return __clc_reinterpret_v4f_to_v4ui( | ||
__clc_read_imagef_tex(image, sampler, coord)); | ||
} |