Skip to content

Commit 89d0810

Browse files
committed
cpu: tidy: bugprone-macro-parentheses
1 parent 1e53027 commit 89d0810

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

src/cpu/cpu_primitive.hpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
#include "cpu/ref_io_helper.hpp"
3131

32+
//NOLINTBEGIN(bugprone-macro-parentheses)
33+
// These macros are actual pieces of code, can't put certain pieces into `()`.
34+
// TODO: consider making them functions.
3235
#define DEFINE_ARG_SCALES_BUFFER_ATTR(attr, scales, arg) \
3336
alignas(16) float CONCAT2(scales, _buf16)[16] = {0}; \
3437
const float *scales {nullptr}; \
@@ -37,18 +40,19 @@
3740
utils::array_set(CONCAT2(scales, _buf16), 1.0f, 16); \
3841
scales = CONCAT2(scales, _buf16); \
3942
} else { \
40-
scales = CTX_IN_MEM(const float *, DNNL_ARG_ATTR_SCALES | arg); \
43+
scales = CTX_IN_MEM(const float *, DNNL_ARG_ATTR_SCALES | (arg)); \
4144
VCHECK_ATTR(scales != nullptr, \
42-
"Scales buffer for arg %d is missing", arg); \
43-
const auto scales_d = ctx.memory_mdw(DNNL_ARG_ATTR_SCALES | arg); \
45+
"Scales buffer for arg %d is missing", (arg)); \
46+
const auto scales_d \
47+
= ctx.memory_mdw(DNNL_ARG_ATTR_SCALES | (arg)); \
4448
VCHECK_ATTR( \
4549
utils::one_of(scales_d.data_type(), data_type::f32, \
4650
data_type::f16, data_type::bf16, data_type::e8m0), \
4751
"Unsupported scales data type"); \
4852
if (scales_d.nelems() == 1) { \
4953
const float s = cpu::io::load_float_value( \
5054
scales_d.data_type(), scales, 0); \
51-
if (utils::one_of(arg, DNNL_ARG_DST, \
55+
if (utils::one_of((arg), DNNL_ARG_DST, \
5256
DNNL_ARG_ATTR_POST_OP_DW | DNNL_ARG_DST)) { \
5357
utils::array_set(CONCAT2(scales, _buf16), 1.f / s, 16); \
5458
} else { \
@@ -61,7 +65,7 @@
6165
MAYBE_UNUSED(scales);
6266

6367
#define DEFINE_ARG_SCALES_BUFFER(scales, arg) \
64-
DEFINE_ARG_SCALES_BUFFER_ATTR(pd()->attr(), scales, arg)
68+
DEFINE_ARG_SCALES_BUFFER_ATTR(pd()->attr(), scales, (arg))
6569

6670
#define DEFINE_ZERO_POINTS_BUFFER_ATTR(attr, zero_points_ptr, arg) \
6771
int32_t CONCAT2(default_zero_point_, arg) = 0; \
@@ -74,11 +78,11 @@
7478
* Accessing `zero_points_ptr` by index will lead to a crash for
7579
* datatypes different from s32. */ \
7680
zero_points_ptr = CTX_IN_MEM( \
77-
const int32_t *, DNNL_ARG_ATTR_ZERO_POINTS | arg); \
81+
const int32_t *, DNNL_ARG_ATTR_ZERO_POINTS | (arg)); \
7882
VCHECK_ATTR(zero_points_ptr != nullptr, \
79-
"Zero points buffer for arg %d is missing", arg); \
83+
"Zero points buffer for arg %d is missing", (arg)); \
8084
const auto zero_points_d \
81-
= ctx.memory_mdw(DNNL_ARG_ATTR_ZERO_POINTS | arg); \
85+
= ctx.memory_mdw(DNNL_ARG_ATTR_ZERO_POINTS | (arg)); \
8286
VCHECK_ATTR(utils::one_of(zero_points_d.data_type(), \
8387
data_type::s32, data_type::s8, data_type::u8, \
8488
data_type::s4, data_type::u4), \
@@ -132,4 +136,6 @@
132136
#define DEFINE_ZERO_POINT_VALUE(zero_point, mem_arg) \
133137
DEFINE_ZERO_POINT_VALUE_ATTR(pd()->attr(), zero_point, mem_arg)
134138

139+
//NOLINTEND(bugprone-macro-parentheses)
140+
135141
#endif // CPU_CPU_PRIMITIVE_HPP

src/cpu/rnn/postgemm_dispatcher.hpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,25 @@ struct rnn_postgemm_dispatcher {
253253
&& !mayiuse(avx512_core))
254254
return status::success;
255255

256+
//NOLINTBEGIN(bugprone-macro-parentheses)
257+
// Can't put types into `()`:
258+
// error: expected type-specifier before ‘)’ token
256259
#define CREATE_WITH_DIR(k, ker_t) \
257260
do { \
258261
if (mayiuse(avx512_core)) \
259-
k.reset(new ker_t<avx512_core, src_type, scratch_type>(rnn, pd_)); \
262+
(k).reset( \
263+
new ker_t<avx512_core, src_type, scratch_type>(rnn, pd_)); \
260264
else if (mayiuse(avx2)) \
261-
k.reset(new ker_t<avx2, src_type, scratch_type>(rnn, pd_)); \
265+
(k).reset(new ker_t<avx2, src_type, scratch_type>(rnn, pd_)); \
262266
else \
263-
k.reset(new ker_t<sse41, src_type, scratch_type>(rnn, pd_)); \
267+
(k).reset(new ker_t<sse41, src_type, scratch_type>(rnn, pd_)); \
264268
} while (0)
265269
#define CREATE(k, ker_t) \
266270
do { \
267-
if (jit_fwd) CREATE_WITH_DIR(k, CONCAT2(ker_t, _fwd)); \
268-
if (jit_bwd) CREATE_WITH_DIR(k, CONCAT2(ker_t, _bwd)); \
271+
if (jit_fwd) CREATE_WITH_DIR((k), CONCAT2(ker_t, _fwd)); \
272+
if (jit_bwd) CREATE_WITH_DIR((k), CONCAT2(ker_t, _bwd)); \
269273
} while (0)
274+
//NOLINTEND(bugprone-macro-parentheses)
270275

271276
if (pd_->cell_kind() == alg_kind::vanilla_lstm) {
272277
CREATE(rnn_postgemm_, jit_uni_lstm_cell_postgemm);

src/cpu/x64/gemm/s8x8s32/common_u8.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include "cpu/x64/jit_generator.hpp"
2323

2424
#define PADD_BYTESIZE_ONPAGE(x, size) \
25-
(((x) * (size) + PAGE_4K - 1) / PAGE_4K) * PAGE_4K
26-
#define NEXT_THR_STRIDE(x, size) (PADD_BYTESIZE_ONPAGE(x, size)) / size
25+
((((x) * (size) + PAGE_4K - 1) / PAGE_4K) * PAGE_4K)
26+
#define NEXT_THR_STRIDE(x, size) (PADD_BYTESIZE_ONPAGE(x, (size)) / (size))
2727

2828
namespace dnnl {
2929
namespace impl {

0 commit comments

Comments
 (0)