Hoernchen has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/40721?usp=email )


Change subject: 7816 fsm: drop inverse convention lut for arm
......................................................................

7816 fsm: drop inverse convention lut for arm

3 instructions is more reliable than precious bytes and awfully slow memory.

Change-Id: I1c6f1c4b733074201cb02c0b9e7cf80a9f8dca7c
---
M ccid_common/iso7816_fsm.c
1 file changed, 21 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware 
refs/changes/21/40721/1

diff --git a/ccid_common/iso7816_fsm.c b/ccid_common/iso7816_fsm.c
index 0aa9571..269feee 100644
--- a/ccid_common/iso7816_fsm.c
+++ b/ccid_common/iso7816_fsm.c
@@ -149,6 +149,19 @@
 static struct osmo_fsm tpdu_fsm;
 static struct osmo_fsm pps_fsm;

+#if defined(__arm__)
+#define invert_flip_uint8(XX)                                                  
                                                          \
+       do {                                                                    
                                                         \
+               _Static_assert(__builtin_types_compatible_p(__typeof__(XX), 
uint8_t),                                                    \
+                              "invert_flip_uint8 argument must be uint8_t");   
                                                         \
+               /* xor to flip done by the compiler, since it might be a mvns 
instead of eor if convenient, so don't force it manually*/ \
+               XX = ~XX;                                                       
                                                         \
+               __asm__ volatile("rbit %0, %0 \n\t"                             
                                                         \
+                                "uxtb.w %0, %0, ror #24 \n\t"                  
                                                         \
+                                : "+r"(XX)::/* lsr clobbers cc, uxtb does not 
*/                                                        \
+               );                                                              
                                                         \
+       } while (0);
+#else
 /* look-up table for bit-wise inversion to convert from "inverse convention" 
to normal */
 static const uint8_t convention_convert_lut[256] = {
        0xff, 0x7f, 0xbf, 0x3f, 0xdf, 0x5f, 0x9f, 0x1f, 0xef, 0x6f, 0xaf, 0x2f, 
0xcf, 0x4f, 0x8f, 0x0f,
@@ -168,6 +181,13 @@
        0xf8, 0x78, 0xb8, 0x38, 0xd8, 0x58, 0x98, 0x18, 0xe8, 0x68, 0xa8, 0x28, 
0xc8, 0x48, 0x88, 0x08,
        0xf0, 0x70, 0xb0, 0x30, 0xd0, 0x50, 0x90, 0x10, 0xe0, 0x60, 0xa0, 0x20, 
0xc0, 0x40, 0x80, 0x00,
 };
+#define invert_flip_uint8(XX)                                                  
                                        \
+       do {                                                                    
                                       \
+               _Static_assert(__builtin_types_compatible_p(__typeof__(XX), 
uint8_t),                                  \
+                              "invert_flip_uint8 argument must be uint8_t");   
                                       \
+               XX = convention_convert_lut[XX];                                
                                       \
+       } while (0);
+#endif

 struct atr_fsm_priv {
        uint8_t hist_len;       /*!< store the number of expected historical 
bytes */
@@ -656,7 +676,7 @@

        /* apply inverse convention */
        if (ip->convention_convert)
-               byte = convention_convert_lut[byte];
+               invert_flip_uint8(byte);

        return byte;
 }

--
To view, visit https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/40721?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ccid-firmware
Gerrit-Branch: master
Gerrit-Change-Id: I1c6f1c4b733074201cb02c0b9e7cf80a9f8dca7c
Gerrit-Change-Number: 40721
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <[email protected]>

Reply via email to