@@ -210,9 +210,12 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
210210
211211
212212#define REF_IS_BORROWED 1
213- #define REF_IS_INVALID 2
214- #define REF_IS_UNIQUE 4
215- #define REF_TAG_BITS 7
213+ #define REF_IS_UNIQUE 2
214+ #define REF_IS_INVALID 3
215+ #define REF_TAG_BITS 3
216+
217+ #define REF_GET_TAG (x ) ((uintptr_t)(x) & (REF_TAG_BITS))
218+ #define REF_CLEAR_TAG (x ) ((uintptr_t)(x) & (~REF_TAG_BITS))
216219
217220#define JIT_BITS_TO_PTR_MASKED (REF ) ((JitOptSymbol *)(((REF).bits) & (~REF_TAG_BITS)))
218221
@@ -234,38 +237,32 @@ PyJitRef_Wrap(JitOptSymbol *sym)
234237static inline JitOptRef
235238PyJitRef_WrapInvalid (void * ptr )
236239{
237- return (JitOptRef ){.bits = ( uintptr_t )ptr | REF_IS_INVALID };
240+ return (JitOptRef ){.bits = REF_CLEAR_TAG (( uintptr_t )ptr ) | REF_IS_INVALID };
238241}
239242
240243static inline bool
241244PyJitRef_IsInvalid (JitOptRef ref )
242245{
243- return (ref .bits & REF_IS_INVALID ) == REF_IS_INVALID ;
246+ return REF_GET_TAG (ref .bits ) == REF_IS_INVALID ;
244247}
245248
246249static inline JitOptRef
247250PyJitRef_MakeUnique (JitOptRef ref )
248251{
249- assert ((ref .bits & REF_IS_UNIQUE ) == 0 );
250- return (JitOptRef ){ ref .bits | REF_IS_UNIQUE };
251- }
252-
253- static inline JitOptRef
254- PyJitRef_RemoveUnique (JitOptRef ref )
255- {
256- return (JitOptRef ){ ref .bits & (~REF_IS_UNIQUE ) };
252+ return (JitOptRef ){ REF_CLEAR_TAG (ref .bits ) | REF_IS_UNIQUE };
257253}
258254
259255static inline bool
260256PyJitRef_IsUnique (JitOptRef ref )
261257{
262- return (ref .bits & REF_IS_UNIQUE ) == REF_IS_UNIQUE ;
258+ return REF_GET_TAG (ref .bits ) == REF_IS_UNIQUE ;
263259}
264260
265261static inline JitOptRef
266262PyJitRef_StripBorrowInfo (JitOptRef ref )
267263{
268- return (JitOptRef ){ .bits = ref .bits & ~(REF_IS_BORROWED | REF_IS_INVALID ) };
264+ if (PyJitRef_IsUnique (ref )) return ref ;
265+ return (JitOptRef ){ .bits = REF_CLEAR_TAG (ref .bits ) };
269266}
270267
271268static inline JitOptRef
@@ -277,7 +274,7 @@ PyJitRef_StripReferenceInfo(JitOptRef ref)
277274static inline JitOptRef
278275PyJitRef_Borrow (JitOptRef ref )
279276{
280- return (JitOptRef ){ .bits = ref .bits | REF_IS_BORROWED };
277+ return (JitOptRef ){ .bits = REF_CLEAR_TAG ( ref .bits ) | REF_IS_BORROWED };
281278}
282279
283280static const JitOptRef PyJitRef_NULL = {.bits = REF_IS_BORROWED };
@@ -291,7 +288,7 @@ PyJitRef_IsNull(JitOptRef ref)
291288static inline int
292289PyJitRef_IsBorrowed (JitOptRef ref )
293290{
294- return (ref .bits & REF_IS_BORROWED ) == REF_IS_BORROWED ;
291+ return REF_GET_TAG (ref .bits ) == REF_IS_BORROWED ;
295292}
296293
297294extern bool _Py_uop_sym_is_null (JitOptRef sym );
0 commit comments