swar-c99-6.5.2.3-union.c 1.32 KB
/* -----------------------------------------------------------------------------
 *  Copyright (C) 2018-2020 daiteq s.r.o.                http://www.daiteq.com
 *
 *  This program is distributed WITHOUT ANY WARRANTY; without even
 *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE.
 *
 * -----------------------------------------------------------------------------
 *  Filename    : swar-c99-6.5.2.3-union.c
 *  Authors     : Roman Bartosinski
 *  Description : simple test of clang/LLVM compiler with SWAR extension
 *  Release     :
 *  Version     :
 *  Date        :
 * -----------------------------------------------------------------------------
 */

//A: --has-swar
//C: -daiteq-swar-enable

#define SWAR_USE_UNSIGNED_TYPES
#define SWAR_USE_SIGNED_TYPES
#include "swar-c99.h"

// swar only
typedef union swar_union {
  su32x1b   u1;
  ss32x1b   s1;
  su16x2b   u2;
  ss16x2b   s2;
  su10x3b   u3;
  ss10x3b   s3;
  su8x4b    u4;
  ss8x4b    s4;
  su4x8b    u8;
  ss4x8b    s8;
  su2x16b   u16;
  ss2x16b   s16;
} swar_union_t;

// mixed
typedef union mixed_union {
  unsigned int ui;
  int           i;
  su10x3b      u3;
  ss10x3b      s3;
} mixed_union_t;

int main(void)
{
  swar_union_t  u;
  mixed_union_t m;

  int sz = sizeof(u);
  sz += sizeof(m);

  m.u3 = (su10x3b) u.s3;
  u.s3 = m.s3;

  return sz;
}