PDA

View Full Version : cl.h please avoid bitshift definitions



dbuenzli
06-15-2009, 11:39 AM
Hello,

Would it be possible to avoid constant definitions by bitshifts ? It makes it harder to extract the info from the file or reuse the cpp definitions for a non C language, e.g. to create bindings to higher level languages.

For example instead of



#define CL_DEVICE_TYPE_DEFAULT (1 << 0)
#define CL_DEVICE_TYPE_CPU (1 << 1)
#define CL_DEVICE_TYPE_GPU (1 << 2)
#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3)
#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF


define



#define CL_DEVICE_TYPE_DEFAULT 0x00000001
#define CL_DEVICE_TYPE_CPU 0x00000002
#define CL_DEVICE_TYPE_GPU 0x00000004
#define CL_DEVICE_TYPE_ACCELERATOR 0x00000008
#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF


Thanks,

Daniel

dbuenzli
06-15-2009, 05:14 PM
If you are interested here's a complete patch to fix the problem.


> diff -u cl.h.orig cl.h
--- cl.h.orig 2009-06-15 20:41:32.000000000 +0200
+++ cl.h 2009-06-15 20:46:12.000000000 +0200
@@ -154,10 +154,10 @@
#define CL_PLATFORM_EXTENSIONS 0x0904

// cl_device_type - bitfield
-#define CL_DEVICE_TYPE_DEFAULT (1 << 0)
-#define CL_DEVICE_TYPE_CPU (1 << 1)
-#define CL_DEVICE_TYPE_GPU (1 << 2)
-#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3)
+#define CL_DEVICE_TYPE_DEFAULT 0x00000001
+#define CL_DEVICE_TYPE_CPU 0x00000002
+#define CL_DEVICE_TYPE_GPU 0x00000004
+#define CL_DEVICE_TYPE_ACCELERATOR 0x00000008
#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF

// cl_device_info
@@ -213,16 +213,16 @@
#define CL_DEVICE_PLATFORM 0x1031

// cl_device_address_info - bitfield
-#define CL_DEVICE_ADDRESS_32_BITS (1 << 0)
-#define CL_DEVICE_ADDRESS_64_BITS (1 << 1)
+#define CL_DEVICE_ADDRESS_32_BITS 0x1
+#define CL_DEVICE_ADDRESS_64_BITS 0x2

// cl_device_fp_config - bitfield
-#define CL_FP_DENORM (1 << 0)
-#define CL_FP_INF_NAN (1 << 1)
-#define CL_FP_ROUND_TO_NEAREST (1 << 2)
-#define CL_FP_ROUND_TO_ZERO (1 << 3)
-#define CL_FP_ROUND_TO_INF (1 << 4)
-#define CL_FP_FMA (1 << 5)
+#define CL_FP_DENORM 0x01
+#define CL_FP_INF_NAN 0x02
+#define CL_FP_ROUND_TO_NEAREST 0x04
+#define CL_FP_ROUND_TO_ZERO 0x08
+#define CL_FP_ROUND_TO_INF 0x10
+#define CL_FP_FMA 0x20

// cl_device_mem_cache_type
#define CL_NONE 0x0
@@ -234,12 +234,12 @@
#define CL_GLOBAL 0x2

// cl_device_exec_capabilities - bitfield
-#define CL_EXEC_KERNEL (1 << 0)
-#define CL_EXEC_NATIVE_KERNEL (1 << 1)
+#define CL_EXEC_KERNEL 0x1
+#define CL_EXEC_NATIVE_KERNEL 0x2

// cl_command_queue_properties - bitfield
-#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0)
-#define CL_QUEUE_PROFILING_ENABLE (1 << 1)
+#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE 0x1
+#define CL_QUEUE_PROFILING_ENABLE 0x2

// cl_context_info
#define CL_CONTEXT_REFERENCE_COUNT 0x1080
@@ -255,12 +255,12 @@
#define CL_QUEUE_PROPERTIES 0x1093

// cl_mem_flags - bitfield
-#define CL_MEM_READ_WRITE (1 << 0)
-#define CL_MEM_WRITE_ONLY (1 << 1)
-#define CL_MEM_READ_ONLY (1 << 2)
-#define CL_MEM_USE_HOST_PTR (1 << 3)
-#define CL_MEM_ALLOC_HOST_PTR (1 << 4)
-#define CL_MEM_COPY_HOST_PTR (1 << 5)
+#define CL_MEM_READ_WRITE 0x01
+#define CL_MEM_WRITE_ONLY 0x02
+#define CL_MEM_READ_ONLY 0x04
+#define CL_MEM_USE_HOST_PTR 0x08
+#define CL_MEM_ALLOC_HOST_PTR 0x10
+#define CL_MEM_COPY_HOST_PTR 0x20

// cl_channel_order
#define CL_R 0x10B0
@@ -332,8 +332,8 @@
#define CL_SAMPLER_FILTER_MODE 0x1154

// cl_map_flags - bitfield
-#define CL_MAP_READ (1 << 0)
-#define CL_MAP_WRITE (1 << 1)
+#define CL_MAP_READ 0x1
+#define CL_MAP_WRITE 0x2

// cl_program_info
#define CL_PROGRAM_REFERENCE_COUNT 0x1160