sctincman / freeocl

OpenCL 1.2 implementation targeting CPUs, utilizing an external C++ compiler
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Full builtin type coverage #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In reference to bug #18, the integer builtins do not have full type coverage 
([u]char, [u]short, and some [u]long), along with the vector equivalents.

I've attached a patch that expands to [almost] fully cover the builtin 
functions and types (including vectors).

This is a rather larger patch, but was difficult to do incrementally.

vectors.h was expanded to cover [u]char, [u]short, and [u]long. The 
VECTOR_IMPLEMENTATION_FROM_SCALAR_IMPLEMENTATION#_[I/U](F) macro was abstracted 
to a VECTOR_IMPLEMENTATION_FROM_SCALAR_IMPLEMENTATION#_T(X, F) macro that 
accepts the type (Instead of using a separate macro for each type). This is 
accompanied by proper #undefs in opencl_c.h

integer.h is where the largest amount of changes happened.
1)Expansion of most functions to the full integer types (with certain functions 
requiring a different manual overload if function differs between types)
2) Custom VECTOR_IMPLEMENTATION_FROM_SCALAR macros for functions with weird 
type signatures (abs, abs_diff, upsample, and clamp). I could not for the life 
of me find a template that would work for these.

These changes required changes to the parser and image*.h (where abs is used).
1) The parser was generating extraneous type signatures for abs()/abs_diff(), 
such as "__char2 abs (__uchar2)", that was causing parser errors in certain 
cases.
2) The parser was also not generating the full vector type signatures for 
upsample (which has a weird type signature to begin with). As this is an 
exception, I just manually added all permutations for vector types.
3) image#d_*.h had assignment from abs() to a signed type. This was causing 
compile time errors for vector types, so this needed to be edited to manually 
cast/convert from unsigned to signed vector types.

The one exception I could not get working were a subset of the [u]long builtin 
functions (such as mul_hi, *_sat, mad_hi, hadd), which required casting to a 
higher type to avoid overflow (due to the lack of a 128-bit type :P). I'm not 
sure how to accomplish this...

Original issue reported on code.google.com by sctinc...@gmail.com on 11 Aug 2014 at 5:10

Attachments:

GoogleCodeExporter commented 9 years ago
Patch has been merged into trunk.

Original comment by zuzu...@gmail.com on 15 Aug 2014 at 10:37

GoogleCodeExporter commented 9 years ago
With r387 I've added long versions of the xxx_sat builtins, and I think we have 
this covered :]

There's likely a lot of room for improvement, but concerning correctness before 
performance, I think this works. Closing.

Original comment by sctinc...@gmail.com on 14 Sep 2014 at 2:55