Skip to content

Commit

Permalink
make byte alignment compatible with MS VS
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Mar 29, 2020
1 parent a2948be commit 48e397f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/mmc_cl_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C" {

#define RAND_SEED_WORD_LEN 4 //48 bit packed with 64bit length

typedef struct GPU_mcconfig{
typedef struct PRE_ALIGN(32) GPU_mcconfig{
cl_float3 srcpos;
cl_float3 srcdir;
cl_float tstart,tend;
Expand Down Expand Up @@ -86,11 +86,11 @@ typedef struct GPU_mcconfig{
cl_uint nbuffer;
cl_uint buffermask;
//cl_int issaveseed;
} MCXParam __attribute__ ((aligned (32)));
} MCXParam POST_ALIGN(32);

typedef struct GPU_reporter{
typedef struct POST_ALIGN(32) GPU_reporter{
float raytet;
} MCXReporter __attribute__ ((aligned (32)));
} MCXReporter POST_ALIGN(32);

void mmc_run_cl(mcconfig *cfg, tetmesh *mesh, raytracer *tracer);

Expand Down
4 changes: 2 additions & 2 deletions src/tictoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#ifndef USE_OS_TIMER

#ifdef MCX_OPENCL
#ifdef USE_OPENCL

#include <CL/cl.h>
/* use OpenCL timer */
Expand Down Expand Up @@ -69,7 +69,7 @@ unsigned int StartTimer () {
#else

static unsigned int timerRes;
#ifndef _WIN32
#ifndef _MSC_VER
#if _POSIX_C_SOURCE >= 199309L
#include <time.h> // for nanosleep
#else
Expand Down
20 changes: 14 additions & 6 deletions src/vector_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@
#ifndef _MMC_VECTOR_H
#define _MMC_VECTOR_H

#ifdef _MSC_VER
#define PRE_ALIGN(x) __declspec(align(x))
#define POST_ALIGN(x)
#else
#define PRE_ALIGN(x)
#define POST_ALIGN(x) __attribute__ ((aligned(x)))
#endif

/**
\struct MMC_float4 vector_types.h
\brief floating-point quadraplet {x,y,z,w}
the data structure is 16byte aligned to facilitate SSE operations
*/

typedef struct MMC_float4{
typedef struct PRE_ALIGN(16) MMC_float4{
float x,y,z,w;
} float4 __attribute__ ((aligned(16)));
} float4 POST_ALIGN(16);

/**
\struct MMC_float3 vector_types.h
Expand Down Expand Up @@ -55,9 +63,9 @@ typedef struct MMC_int3{
\struct MMC_int4 vector_types.h
\brief unsigned integer quadraplet {ix,iy,iz,iw}
*/
typedef struct MMC_int4{
typedef struct PRE_ALIGN(16) MMC_int4{
int x,y,z,w;
} int4 __attribute__ ((aligned(16)));
} int4 POST_ALIGN(16);

/**
\struct MMC_uint3 vector_types.h
Expand All @@ -71,9 +79,9 @@ typedef struct MMC_uint3{
\struct MMC_uint3 vector_types.h
\brief unsigned integer triplet {ix,iy,iz}
*/
typedef struct MMC_uint4{
typedef struct PRE_ALIGN(16) MMC_uint4{
unsigned int x,y,z,w;
} uint4 __attribute__ ((aligned(16)));
} uint4 POST_ALIGN(16);

/**
\struct MMC_uint2 vector_types.h
Expand Down

0 comments on commit 48e397f

Please sign in to comment.