Skip to content

Commit ed696ef

Browse files
author
kevyuu
committed
Fix unary_minus_operator
1 parent 527129f commit ed696ef

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

include/nbl/builtin/hlsl/emulated/int64_t.hlsl

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ struct emulated_int64_t
5151
constexpr explicit emulated_int64_t(const emulated_uint64_t& other);
5252
#endif
5353

54-
NBL_CONSTEXPR_FUNC emulated_int64_t operator-() NBL_CONST_MEMBER_FUNC;
54+
NBL_CONSTEXPR_FUNC emulated_int64_t operator-() NBL_CONST_MEMBER_FUNC
55+
{
56+
storage_t inverted = ~data;
57+
return create(_static_cast<storage_t>(inverted)) + _static_cast<this_t>(1);
58+
}
5559

5660
};
5761

@@ -377,27 +381,6 @@ NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR emulated_uint64_t minus_assign<emulated_uint
377381
template<>
378382
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR emulated_int64_t minus_assign<emulated_int64_t>::identity = minus<emulated_int64_t>::identity;
379383

380-
// --------------------------------- Unary operators ------------------------------------------
381-
// Specializations of the structs found in functional.hlsl
382-
template<>
383-
struct unary_minus_operator<emulated_int64_t>
384-
{
385-
using type_t = emulated_int64_t;
386-
387-
NBL_CONSTEXPR_FUNC type_t operator()(NBL_CONST_REF_ARG(type_t) operand)
388-
{
389-
using storage_t = type_t::storage_t;
390-
storage_t inverted = ~operand.data;
391-
return type_t::create(_static_cast<storage_t>(inverted)) + _static_cast<type_t>(1);
392-
}
393-
};
394-
395-
NBL_CONSTEXPR_INLINE_FUNC emulated_int64_t emulated_int64_t::operator-() NBL_CONST_MEMBER_FUNC
396-
{
397-
unary_minus_operator<emulated_int64_t> unaryMinus;
398-
return unaryMinus(NBL_DEREF_THIS);
399-
}
400-
401384
} //namespace nbl
402385
} //namespace hlsl
403386

include/nbl/builtin/hlsl/functional.hlsl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,17 @@ struct unary_minus_operator
495495

496496
NBL_CONSTEXPR_FUNC T operator()(NBL_CONST_REF_ARG(T) operand)
497497
{
498-
return -operand;
498+
return operand.operator-();
499+
}
500+
};
501+
502+
template<typename T> NBL_PARTIAL_REQ_TOP(is_fundamental_v<T>)
503+
struct unary_minus_operator<T NBL_PARTIAL_REQ_BOT(is_fundamental_v<T>) >
504+
{
505+
using type_t = T;
506+
NBL_CONSTEXPR_FUNC T operator()(const T operand)
507+
{
508+
return -operand;
499509
}
500510
};
501511

0 commit comments

Comments
 (0)