@@ -36,18 +36,16 @@ extern volatile uint64_t mld_ct_opt_blocker_u64;
3636static MLD_INLINE uint64_t mld_ct_get_optblocker_u64 (void )
3737__contract__ (ensures (return_value == 0 )) { return mld_ct_opt_blocker_u64 ; }
3838
39- /* TODO: proof */
4039static MLD_INLINE int64_t mld_ct_get_optblocker_i64 (void )
4140__contract__ (ensures (return_value == 0 )) { return (int64_t )mld_ct_get_optblocker_u64 (); }
42- /* TODO: proof */
41+
4342static MLD_INLINE uint32_t mld_ct_get_optblocker_u32 (void )
4443__contract__ (ensures (return_value == 0 )) { return (uint32_t )mld_ct_get_optblocker_u64 (); }
4544
4645/* Opt-blocker based implementation of value barriers */
47- /* TODO: proof */
4846static MLD_INLINE int64_t mld_value_barrier_i64 (int64_t b )
4947__contract__ (ensures (return_value == b )) { return (b ^ mld_ct_get_optblocker_i64 ()); }
50- /* TODO: proof */
48+
5149static MLD_INLINE uint32_t mld_value_barrier_u32 (uint32_t b )
5250__contract__ (ensures (return_value == b )) { return (b ^ mld_ct_get_optblocker_u32 ()); }
5351
@@ -68,6 +66,18 @@ __contract__(ensures(return_value == b))
6866}
6967#endif /* MLD_USE_ASM_VALUE_BARRIER */
7068
69+
70+ /*
71+ * The mld_ct_sel_int32 function below makes deliberate use of unsigned
72+ * to signed integer conversion, which is implementation-defined
73+ * behaviour. Here, we assume that uint16_t -> int16_t is inverse
74+ * to int16_t -> uint16_t.
75+ */
76+ #ifdef CBMC
77+ #pragma CPROVER check push
78+ #pragma CPROVER check disable "conversion"
79+ #endif
80+
7181/*************************************************
7282 * Name: mld_ct_sel_int32
7383 *
@@ -93,6 +103,23 @@ __contract__(
93103 return (int32_t )res ;
94104}
95105
106+ /* Put unsigned-to-signed warnings in CBMC back into scope */
107+ #ifdef CBMC
108+ #pragma CPROVER check pop
109+ #endif
110+
111+
112+
113+ /*
114+ * The mld_ct_cmask_neg_i32 function below makes deliberate use of
115+ * signed to unsigned integer conversion, which is fully defined
116+ * behaviour in C. It is thus safe to disable this warning.
117+ */
118+ #ifdef CBMC
119+ #pragma CPROVER check push
120+ #pragma CPROVER check disable "conversion"
121+ #endif
122+
96123
97124/*************************************************
98125 * Name: mld_ct_cmask_neg_i32
@@ -111,6 +138,11 @@ __contract__(ensures(return_value == ((x < 0) ? 0xFFFFFFFF : 0)))
111138 return (uint32_t )tmp ;
112139}
113140
141+ /* Put signed-to-unsigned warnings in CBMC back into scope */
142+ #ifdef CBMC
143+ #pragma CPROVER check pop
144+ #endif
145+
114146/*************************************************
115147 * Name: mld_ct_abs_i32
116148 *
@@ -121,7 +153,10 @@ __contract__(ensures(return_value == ((x < 0) ? 0xFFFFFFFF : 0)))
121153 **************************************************/
122154/* TODO: proof */
123155static MLD_INLINE uint32_t mld_ct_abs_i32 (int32_t x )
124- __contract__ (ensures (return_value == ((x < 0 ) ? - x : x )))
156+ __contract__ (
157+ requires (x >= - INT32_MAX )
158+ ensures (return_value == ((x < 0 ) ? - x : x ))
159+ )
125160{
126161 return mld_ct_sel_int32 (- x , x , mld_ct_cmask_neg_i32 (x ));
127162}
0 commit comments