Skip to content

Instantly share code, notes, and snippets.

@anbe42
Created February 17, 2021 21:14
Show Gist options
  • Save anbe42/3e3c6fadf25b0619abaa8206b46efc87 to your computer and use it in GitHub Desktop.
Save anbe42/3e3c6fadf25b0619abaa8206b46efc87 to your computer and use it in GitHub Desktop.
fix cl_long, cl_double alignment on i386
--- a/CL/cl_platform.h
+++ b/CL/cl_platform.h
@@ -223,6 +223,20 @@ typedef double cl_doubl
#include <stdint.h>
+// i386 has a default alignment of 4 even for 64-bit types
+#ifdef __i386__
+#define CL_LONG_ALIGNMENT __attribute__((aligned(8)))
+#define CL_DOUBLE_ALIGNMENT __attribute__((aligned(8)))
+#endif
+
+#ifndef CL_LONG_ALIGNMENT
+#define CL_LONG_ALIGNMENT
+#endif
+
+#ifndef CL_DOUBLE_ALIGNMENT
+#define CL_DOUBLE_ALIGNMENT
+#endif
+
/* scalar types */
typedef int8_t cl_char;
typedef uint8_t cl_uchar;
@@ -230,12 +244,15 @@ typedef int16_t cl_short;
typedef uint16_t cl_ushort;
typedef int32_t cl_int;
typedef uint32_t cl_uint;
-typedef int64_t cl_long;
-typedef uint64_t cl_ulong;
+typedef int64_t cl_long CL_LONG_ALIGNMENT;
+typedef uint64_t cl_ulong CL_LONG_ALIGNMENT;
typedef uint16_t cl_half;
typedef float cl_float;
-typedef double cl_double;
+typedef double cl_double CL_DOUBLE_ALIGNMENT;
+
+#undef CL_LONG_ALIGNMENT
+#undef CL_DOUBLE_ALIGNMENT
/* Macro names and corresponding values defined by OpenCL */
#define CL_CHAR_BIT 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment