]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[crypto] Use architecture-independent bigint_is_set()
authorMichael Brown <mcb30@ipxe.org>
Tue, 8 Oct 2024 10:52:07 +0000 (11:52 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 10 Oct 2024 14:35:16 +0000 (15:35 +0100)
Every architecture uses the same implementation for bigint_is_set(),
and there is no reason to suspect that a future CPU architecture will
provide a more efficient way to implement this operation.

Simplify the code by providing a single architecture-independent
implementation of bigint_is_set().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/arm32/include/bits/bigint.h
src/arch/arm64/include/bits/bigint.h
src/arch/loong64/include/bits/bigint.h
src/arch/riscv/include/bits/bigint.h
src/arch/x86/include/bits/bigint.h
src/include/ipxe/bigint.h

index f11ec906bfe118cb5c932908a74fde016a3a572a..39d3dc347436a3f2404597540a025190137e1cb4 100644 (file)
@@ -216,25 +216,6 @@ bigint_is_geq_raw ( const uint32_t *value0, const uint32_t *reference0,
        return ( value_i >= reference_i );
 }
 
-/**
- * Test if bit is set in big integer
- *
- * @v value0           Element 0 of big integer
- * @v size             Number of elements
- * @v bit              Bit to test
- * @ret is_set         Bit is set
- */
-static inline __attribute__ (( always_inline )) int
-bigint_bit_is_set_raw ( const uint32_t *value0, unsigned int size,
-                       unsigned int bit ) {
-       const bigint_t ( size ) __attribute__ (( may_alias )) *value =
-               ( ( const void * ) value0 );
-       unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) );
-       unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) );
-
-       return ( value->element[index] & ( 1 << subindex ) );
-}
-
 /**
  * Find highest bit set in big integer
  *
index 05095413b5b4dd9fe208ccff098e50233fbc02b8..50493499ed6a4dc1af0b38b563169a5679178997 100644 (file)
@@ -217,25 +217,6 @@ bigint_is_geq_raw ( const uint64_t *value0, const uint64_t *reference0,
        return ( value_i >= reference_i );
 }
 
-/**
- * Test if bit is set in big integer
- *
- * @v value0           Element 0 of big integer
- * @v size             Number of elements
- * @v bit              Bit to test
- * @ret is_set         Bit is set
- */
-static inline __attribute__ (( always_inline )) int
-bigint_bit_is_set_raw ( const uint64_t *value0, unsigned int size,
-                       unsigned int bit ) {
-       const bigint_t ( size ) __attribute__ (( may_alias )) *value =
-               ( ( const void * ) value0 );
-       unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) );
-       unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) );
-
-       return ( !! ( value->element[index] & ( 1UL << subindex ) ) );
-}
-
 /**
  * Find highest bit set in big integer
  *
index 2372758513e0f3a48244603ad63baa1588ec3142..234d8dfa78729d466bdb813f2044bec95eedfedb 100644 (file)
@@ -264,25 +264,6 @@ bigint_is_geq_raw ( const uint64_t *value0, const uint64_t *reference0,
        return ( value_i >= reference_i );
 }
 
-/**
- * Test if bit is set in big integer
- *
- * @v value0           Element 0 of big integer
- * @v size             Number of elements
- * @v bit              Bit to test
- * @ret is_set         Bit is set
- */
-static inline __attribute__ (( always_inline )) int
-bigint_bit_is_set_raw ( const uint64_t *value0, unsigned int size,
-                       unsigned int bit ) {
-       const bigint_t ( size ) __attribute__ (( may_alias )) *value =
-               ( ( const void * ) value0 );
-       unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) );
-       unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) );
-
-       return ( !! ( value->element[index] & ( 1UL << subindex ) ) );
-}
-
 /**
  * Find highest bit set in big integer
  *
index 58351ac0757925ccdca8a0cb314d7c70715094dc..5b22b9ac7b2581bd0e66b19f7c3f462ec9063f35 100644 (file)
@@ -259,25 +259,6 @@ bigint_is_geq_raw ( const unsigned long *value0,
        return ( value_i >= reference_i );
 }
 
-/**
- * Test if bit is set in big integer
- *
- * @v value0           Element 0 of big integer
- * @v size             Number of elements
- * @v bit              Bit to test
- * @ret is_set         Bit is set
- */
-static inline __attribute__ (( always_inline )) int
-bigint_bit_is_set_raw ( const unsigned long *value0, unsigned int size,
-                       unsigned int bit ) {
-       const bigint_t ( size ) __attribute__ (( may_alias )) *value =
-               ( ( const void * ) value0 );
-       unsigned int index = ( bit / ( 8 * sizeof ( *value0 ) ) );
-       unsigned int subindex = ( bit % ( 8 * sizeof ( *value0 ) ) );
-
-       return ( !! ( value->element[index] & ( 1UL << subindex ) ) );
-}
-
 /**
  * Find highest bit set in big integer
  *
index 512b2724d240ff1b1a3513c52d7ed05a7334b649..5580030ee276b8938eacd2a4b666288a1a8fb3d5 100644 (file)
@@ -195,25 +195,6 @@ bigint_is_geq_raw ( const uint32_t *value0, const uint32_t *reference0,
        return result;
 }
 
-/**
- * Test if bit is set in big integer
- *
- * @v value0           Element 0 of big integer
- * @v size             Number of elements
- * @v bit              Bit to test
- * @ret is_set         Bit is set
- */
-static inline __attribute__ (( always_inline )) int
-bigint_bit_is_set_raw ( const uint32_t *value0, unsigned int size,
-                       unsigned int bit ) {
-       const bigint_t ( size ) __attribute__ (( may_alias )) *value =
-               ( ( const void * ) value0 );
-       unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) );
-       unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) );
-
-       return ( value->element[index] & ( 1 << subindex ) );
-}
-
 /**
  * Find highest bit set in big integer
  *
index 19cd4e3ddff177da15a60a40fb4968e68966ed55..c556afbc164591e3f6609547481fd555672abe54 100644 (file)
@@ -285,6 +285,25 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <bits/bigint.h>
 
+/**
+ * Test if bit is set in big integer
+ *
+ * @v value0           Element 0 of big integer
+ * @v size             Number of elements
+ * @v bit              Bit to test
+ * @ret is_set         Bit is set
+ */
+static inline __attribute__ (( always_inline )) int
+bigint_bit_is_set_raw ( const bigint_element_t *value0, unsigned int size,
+                       unsigned int bit ) {
+       const bigint_t ( size ) __attribute__ (( may_alias )) *value =
+               ( ( const void * ) value0 );
+       unsigned int index = ( bit / ( 8 * sizeof ( value->element[0] ) ) );
+       unsigned int subindex = ( bit % ( 8 * sizeof ( value->element[0] ) ) );
+
+       return ( !! ( value->element[index] & ( 1UL << subindex ) ) );
+}
+
 void bigint_init_raw ( bigint_element_t *value0, unsigned int size,
                       const void *data, size_t len );
 void bigint_done_raw ( const bigint_element_t *value0, unsigned int size,