Lines Matching full:x
76 /* Ensure that the compiler cannot know the value of x (i.e., cannot optimise
90 * \param x The value to hide from the compiler.
93 * x = mbedtls_ct_compiler_opaque(1), x will be unknown).
100 static inline mbedtls_ct_uint_t mbedtls_ct_compiler_opaque(mbedtls_ct_uint_t x) in mbedtls_ct_compiler_opaque() argument
103 asm volatile ("" : [x] "+r" (x) :); in mbedtls_ct_compiler_opaque()
104 return x; in mbedtls_ct_compiler_opaque()
106 return x ^ mbedtls_ct_zero; in mbedtls_ct_compiler_opaque()
135 static inline mbedtls_ct_condition_t mbedtls_ct_bool(mbedtls_ct_uint_t x) in mbedtls_ct_bool() argument
147 asm volatile ("neg %x[s], %x[x] \n\t" in mbedtls_ct_bool()
148 "orr %x[x], %x[s], %x[x] \n\t" in mbedtls_ct_bool()
149 "asr %x[x], %x[x], 63 \n\t" in mbedtls_ct_bool()
152 [x] "+&r" (x) in mbedtls_ct_bool()
156 return (mbedtls_ct_condition_t) x; in mbedtls_ct_bool()
160 "negs %[s], %[x] \n\t" in mbedtls_ct_bool()
161 "orrs %[x], %[x], %[s] \n\t" in mbedtls_ct_bool()
162 "asrs %[x], %[x], #31 \n\t" in mbedtls_ct_bool()
166 [x] "+&l" (x) in mbedtls_ct_bool()
171 return (mbedtls_ct_condition_t) x; in mbedtls_ct_bool()
174 asm volatile ("mov %[x], %[s] \n\t" in mbedtls_ct_bool()
176 "or %[x], %[s] \n\t" in mbedtls_ct_bool()
181 [x] "D" (x) in mbedtls_ct_bool()
187 asm volatile ("mov %[x], %[s] \n\t" in mbedtls_ct_bool()
189 "or %[s], %[x] \n\t" in mbedtls_ct_bool()
190 "sar $31, %[x] \n\t" in mbedtls_ct_bool()
193 [x] "+&a" (x) in mbedtls_ct_bool()
197 return (mbedtls_ct_condition_t) x; in mbedtls_ct_bool()
199 const mbedtls_ct_uint_t xo = mbedtls_ct_compiler_opaque(x); in mbedtls_ct_bool()
206 // y is negative (i.e., top bit set) iff x is non-zero in mbedtls_ct_bool()
209 // extract only the sign bit of y so that y == 1 (if x is non-zero) or 0 (if x is zero) in mbedtls_ct_bool()
212 // -y has all bits set (if x is non-zero), or all bits clear (if x is zero) in mbedtls_ct_bool()
225 asm volatile ("and %x[if1], %x[if1], %x[condition] \n\t" in mbedtls_ct_if()
226 "mvn %x[condition], %x[condition] \n\t" in mbedtls_ct_if()
227 "and %x[condition], %x[condition], %x[if0] \n\t" in mbedtls_ct_if()
228 "orr %x[condition], %x[if1], %x[condition]" in mbedtls_ct_if()
286 static inline mbedtls_ct_condition_t mbedtls_ct_uint_lt(mbedtls_ct_uint_t x, mbedtls_ct_uint_t y) in mbedtls_ct_uint_lt() argument
290 asm volatile ("eor %x[s1], %x[y], %x[x] \n\t" in mbedtls_ct_uint_lt()
291 "sub %x[x], %x[x], %x[y] \n\t" in mbedtls_ct_uint_lt()
292 "bic %x[x], %x[x], %x[s1] \n\t" in mbedtls_ct_uint_lt()
293 "and %x[s1], %x[s1], %x[y] \n\t" in mbedtls_ct_uint_lt()
294 "orr %x[s1], %x[x], %x[s1] \n\t" in mbedtls_ct_uint_lt()
295 "asr %x[x], %x[s1], 63" in mbedtls_ct_uint_lt()
298 [x] "+&r" (x) in mbedtls_ct_uint_lt()
303 return (mbedtls_ct_condition_t) x; in mbedtls_ct_uint_lt()
309 "movs %[s1], %[x] \n\t" in mbedtls_ct_uint_lt()
312 "eors %[s1], %[x], %[y] \n\t" in mbedtls_ct_uint_lt()
314 "subs %[x], %[x], %[y] \n\t" in mbedtls_ct_uint_lt()
315 "bics %[x], %[x], %[s1] \n\t" in mbedtls_ct_uint_lt()
317 "orrs %[x], %[x], %[y] \n\t" in mbedtls_ct_uint_lt()
318 "asrs %[x], %[x], #31 \n\t" in mbedtls_ct_uint_lt()
322 [x] "+&l" (x), in mbedtls_ct_uint_lt()
328 return (mbedtls_ct_condition_t) x; in mbedtls_ct_uint_lt()
331 asm volatile ("mov %[x], %[s] \n\t" in mbedtls_ct_uint_lt()
333 "sub %[y], %[x] \n\t" in mbedtls_ct_uint_lt()
336 "and %[s], %[x] \n\t" in mbedtls_ct_uint_lt()
337 "or %[y], %[x] \n\t" in mbedtls_ct_uint_lt()
338 "sar $63, %[x] \n\t" in mbedtls_ct_uint_lt()
341 [x] "+&D" (x), in mbedtls_ct_uint_lt()
346 return (mbedtls_ct_condition_t) x; in mbedtls_ct_uint_lt()
349 asm volatile ("mov %[x], %[s] \n\t" in mbedtls_ct_uint_lt()
351 "sub %[y], %[x] \n\t" in mbedtls_ct_uint_lt()
354 "and %[s], %[x] \n\t" in mbedtls_ct_uint_lt()
355 "or %[y], %[x] \n\t" in mbedtls_ct_uint_lt()
356 "sar $31, %[x] \n\t" in mbedtls_ct_uint_lt()
359 [x] "+&a" (x), in mbedtls_ct_uint_lt()
364 return (mbedtls_ct_condition_t) x; in mbedtls_ct_uint_lt()
366 /* Ensure that the compiler cannot optimise the following operations over x and y, in mbedtls_ct_uint_lt()
367 * even if it knows the value of x and y. in mbedtls_ct_uint_lt()
369 const mbedtls_ct_uint_t xo = mbedtls_ct_compiler_opaque(x); in mbedtls_ct_uint_lt()
378 * If the MSB are the same then the difference x-y will be negative (and in mbedtls_ct_uint_lt()
379 * have its MSB set to 1 during conversion to unsigned) if and only if x<y. in mbedtls_ct_uint_lt()
382 * bigger. (That is if y has MSB of 1, then x<y is true and it is false if in mbedtls_ct_uint_lt()
386 // Select either y, or x - y in mbedtls_ct_uint_lt()
397 static inline mbedtls_ct_condition_t mbedtls_ct_uint_ne(mbedtls_ct_uint_t x, mbedtls_ct_uint_t y) in mbedtls_ct_uint_ne() argument
399 /* diff = 0 if x == y, non-zero otherwise */ in mbedtls_ct_uint_ne()
400 const mbedtls_ct_uint_t diff = mbedtls_ct_compiler_opaque(x) ^ mbedtls_ct_compiler_opaque(y); in mbedtls_ct_uint_ne()
402 /* all ones if x != y, 0 otherwise */ in mbedtls_ct_uint_ne()
414 /* low_mask is: 0 if low <= c, 0x...ff if low > c */ in mbedtls_ct_uchar_in_range_if()
416 /* high_mask is: 0 if c <= high, 0x...ff if c > high */ in mbedtls_ct_uchar_in_range_if()
504 static inline mbedtls_ct_condition_t mbedtls_ct_uint_eq(mbedtls_ct_uint_t x, in mbedtls_ct_uint_eq() argument
507 return ~mbedtls_ct_uint_ne(x, y); in mbedtls_ct_uint_eq()
510 static inline mbedtls_ct_condition_t mbedtls_ct_uint_gt(mbedtls_ct_uint_t x, in mbedtls_ct_uint_gt() argument
513 return mbedtls_ct_uint_lt(y, x); in mbedtls_ct_uint_gt()
516 static inline mbedtls_ct_condition_t mbedtls_ct_uint_ge(mbedtls_ct_uint_t x, in mbedtls_ct_uint_ge() argument
519 return ~mbedtls_ct_uint_lt(x, y); in mbedtls_ct_uint_ge()
522 static inline mbedtls_ct_condition_t mbedtls_ct_uint_le(mbedtls_ct_uint_t x, in mbedtls_ct_uint_le() argument
525 return ~mbedtls_ct_uint_gt(x, y); in mbedtls_ct_uint_le()
528 static inline mbedtls_ct_condition_t mbedtls_ct_bool_ne(mbedtls_ct_condition_t x, in mbedtls_ct_bool_ne() argument
531 return (mbedtls_ct_condition_t) (x ^ y); in mbedtls_ct_bool_ne()
534 static inline mbedtls_ct_condition_t mbedtls_ct_bool_and(mbedtls_ct_condition_t x, in mbedtls_ct_bool_and() argument
537 return (mbedtls_ct_condition_t) (x & y); in mbedtls_ct_bool_and()
540 static inline mbedtls_ct_condition_t mbedtls_ct_bool_or(mbedtls_ct_condition_t x, in mbedtls_ct_bool_or() argument
543 return (mbedtls_ct_condition_t) (x | y); in mbedtls_ct_bool_or()
546 static inline mbedtls_ct_condition_t mbedtls_ct_bool_not(mbedtls_ct_condition_t x) in mbedtls_ct_bool_not() argument
548 return (mbedtls_ct_condition_t) (~x); in mbedtls_ct_bool_not()