Skip to content

Commit

Permalink
Update BLIS_*_INITIALIZER macros for C++ compatibility. (#802)
Browse files Browse the repository at this point in the history
Details:
- Remove designated initializer syntax. This isn't officially supported 
  until C++20.
- Arrange initializers in the order in which they are defined in the 
  struct. Even with standard or extension support for designated 
  initializers, initializing non-static members out-of-order is an 
  error in C++.
- Remove the conditional code which uses '-1' as the default value of 
  the 'pack_buf' member of 'mem_t' in C, but 'BLIS_BUFFER_FOR_GEN_USE' 
  in C++. Simply use the latter as a common-sense default.
  • Loading branch information
devinamatthews authored Mar 26, 2024
1 parent 1a8c818 commit 664cc6b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 79 deletions.
29 changes: 5 additions & 24 deletions frame/base/bli_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,38 +136,19 @@ BLIS_INLINE void bli_mem_set_size( siz_t size, mem_t* mem )
// removed from the mem_t type definition. An alternative to the initializer is
// calling bli_mem_clear() at runtime.

#ifdef __cplusplus
#define BLIS_MEM_INITIALIZER \
{ \
.pblk = BLIS_PBLK_INITIALIZER, \
/* When using C++, which is strongly typed, we avoid use of -1 as a
packbuf_t value since it will result in a compile-time error. */ \
.buf_type = BLIS_BUFFER_FOR_GEN_USE, \
.pool = NULL, \
.size = 0, \
/* .pblk = */ BLIS_PBLK_INITIALIZER, \
/* .buf_type = */ BLIS_BUFFER_FOR_GEN_USE, \
/* .pool = */ NULL, \
/* .size = */ 0, \
}
#else // C99
#define BLIS_MEM_INITIALIZER \
{ \
.pblk = BLIS_PBLK_INITIALIZER, \
.buf_type = -1, \
.pool = NULL, \
.size = 0, \
}
#endif


BLIS_INLINE void bli_mem_clear( mem_t* mem )
{
bli_mem_set_buffer( NULL, mem );
#ifdef __cplusplus
const packbuf_t pb = BLIS_BUFFER_FOR_GEN_USE;
// When using C++, which is strongly typed, we avoid use of -1 as a
// packbuf_t value since it will result in a compile-time error.
bli_mem_set_buf_type( pb, mem );
#else
bli_mem_set_buf_type( ( packbuf_t )-1, mem );
#endif
bli_mem_set_buf_type( BLIS_BUFFER_FOR_GEN_USE, mem );
bli_mem_set_pool( NULL, mem );
bli_mem_set_size( 0, mem );
}
Expand Down
4 changes: 2 additions & 2 deletions frame/base/bli_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ BLIS_INLINE void bli_pblk_set_block_size( siz_t block_size, pblk_t* pblk )

#define BLIS_PBLK_INITIALIZER \
{ \
.buf = NULL, \
.block_size = 0, \
/* .buf = */ NULL, \
/* .block_size = */ 0, \
} \

BLIS_INLINE void bli_pblk_clear( pblk_t* pblk )
Expand Down
16 changes: 9 additions & 7 deletions frame/base/bli_rntm.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,15 @@ BLIS_INLINE void bli_rntm_clear_l3_sup( rntm_t* rntm )

#define BLIS_RNTM_INITIALIZER \
{ \
.thread_impl = BLIS_SINGLE, \
.num_threads = 1, \
.thrloop = { 1, 1, 1, 1, 1, 1 }, \
.auto_factor = FALSE, \
.pack_a = FALSE, \
.pack_b = FALSE, \
.l3_sup = TRUE, \
/* .thread_impl */ = BLIS_SINGLE, \
\
/* .auto_factor */ = FALSE, \
\
/* .num_threads */ = 1, \
/* .thrloop */ = { 1, 1, 1, 1, 1, 1 }, \
/* .pack_a */ = FALSE, \
/* .pack_b */ = FALSE, \
/* .l3_sup */ = TRUE, \
} \

#if 0
Expand Down
92 changes: 46 additions & 46 deletions frame/include/bli_type_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1292,68 +1292,68 @@ typedef struct obj_s

#define BLIS_OBJECT_INITIALIZER \
{ \
.root = NULL, \
/* .root */ = NULL, \
\
.off = { 0, 0 }, \
.dim = { 0, 0 }, \
.diag_off = 0, \
/* .off */ = { 0, 0 }, \
/* .dim */ = { 0, 0 }, \
/* .diag_off */ = 0, \
\
.info = 0x0 | BLIS_BITVAL_DENSE | \
BLIS_BITVAL_GENERAL, \
.info2 = 0x0, \
.elem_size = sizeof( float ), /* this is changed later. */ \
/* .info */ = 0x0 | BLIS_BITVAL_DENSE | \
/* */ BLIS_BITVAL_GENERAL, \
/* .info2 */ = 0x0, \
/* .elem_size */ = sizeof( float ), /* this is changed later. */ \
\
.buffer = NULL, \
.rs = 0, \
.cs = 0, \
.is = 1, \
/* .buffer */ = NULL, \
/* .rs */ = 0, \
/* .cs */ = 0, \
/* .is */ = 1, \
\
.scalar = { 0.0, 0.0 }, \
/* .scalar */ = { 0.0, 0.0 }, \
\
.m_padded = 0, \
.n_padded = 0, \
.ps = 0, \
.pd = 0, \
.m_panel = 0, \
.n_panel = 0, \
/* .m_padded */ = 0, \
/* .n_padded */ = 0, \
/* .ps */ = 0, \
/* .pd */ = 0, \
/* .m_panel */ = 0, \
/* .n_panel */ = 0, \
\
.pack_fn = NULL, \
.pack_params = NULL, \
.ker_fn = NULL, \
.ker_params = NULL \
/* .pack_fn */ = NULL, \
/* .pack_params */ = NULL, \
/* .ker_fn */ = NULL, \
/* .ker_params */ = NULL \
}

#define BLIS_OBJECT_INITIALIZER_1X1 \
{ \
.root = NULL, \
/* .root */ = NULL, \
\
.off = { 0, 0 }, \
.dim = { 1, 1 }, \
.diag_off = 0, \
/* .off */ = { 0, 0 }, \
/* .dim */ = { 1, 1 }, \
/* .diag_off */ = 0, \
\
.info = 0x0 | BLIS_BITVAL_DENSE | \
BLIS_BITVAL_GENERAL, \
.info2 = 0x0, \
.elem_size = sizeof( float ), /* this is changed later. */ \
/* .info */ = 0x0 | BLIS_BITVAL_DENSE | \
/* */ BLIS_BITVAL_GENERAL, \
/* .info2 */ = 0x0, \
/* .elem_size */ = sizeof( float ), /* this is changed later. */ \
\
.buffer = NULL, \
.rs = 0, \
.cs = 0, \
.is = 1, \
/* .buffer */ = NULL, \
/* .rs */ = 0, \
/* .cs */ = 0, \
/* .is */ = 1, \
\
.scalar = { 0.0, 0.0 }, \
/* .scalar */ = { 0.0, 0.0 }, \
\
.m_padded = 0, \
.n_padded = 0, \
.ps = 0, \
.pd = 0, \
.m_panel = 0, \
.n_panel = 0, \
/* .m_padded */ = 0, \
/* .n_padded */ = 0, \
/* .ps */ = 0, \
/* .pd */ = 0, \
/* .m_panel */ = 0, \
/* .n_panel */ = 0, \
\
.pack_fn = NULL, \
.pack_params = NULL, \
.ker_fn = NULL, \
.ker_params = NULL \
/* .pack_fn */ = NULL, \
/* .pack_params */ = NULL, \
/* .ker_fn */ = NULL, \
/* .ker_params */ = NULL \
}

// Define these macros here since they must be updated if contents of
Expand Down

0 comments on commit 664cc6b

Please sign in to comment.