Sumit6307 commented on PR #18506:
URL: https://github.com/apache/nuttx/pull/18506#issuecomment-4037447488

   > > > Verification of
   > > > mfs_clz
   > > > logic: I verified the portable binary search implementation of
   > > > mfs_clz
   > > > using a standalone test script to ensure correctness across various 
edge cases (0, powers of 2, boundary conditions).
   > > > Verification Logs:
   > > > text
   > > > Value: 0x00000000 | Leading Zeros: 32
   > > > Value: 0x00000001 | Leading Zeros: 31
   > > > Value: 0x00000002 | Leading Zeros: 30
   > > > Value: 0x00000010 | Leading Zeros: 27
   > > > Value: 0x00000100 | Leading Zeros: 23
   > > > Value: 0x00010000 | Leading Zeros: 15
   > > > Value: 0x10000000 | Leading Zeros: 3
   > > > Value: 0x80000000 | Leading Zeros: 0
   > > > Value: 0xFFFFFFFF | Leading Zeros: 0
   > > > Value: 0x0000FFFF | Leading Zeros: 16
   > > 
   > > 
   > > Nice! Could you attach this script in your test section?
   > > > Build Configuration: The code was compiled targeting the standard 
sim:nsh (Simulator) configuration to ensure build consistency within the NuttX 
tree. Configuration used:
   > > > bash
   > > > ./tools/configure.sh sim:nsh
   > > > make
   > > > Simulator Testing: I verified that the
   > > > mnemofs
   > > > module compiles without errors under the sim:nsh configuration. This 
PR primarily targets foundational bit-logic (Count Leading Zeros) and removes 
redundant code as per internal TODO suggestions.
   > > 
   > > 
   > > Okay! I don't think sim:nsh has mnemofs enabled though, can you let us 
know what configuration options you selected to get it to build?
   > 
   > Requesting change for requested information above ^
   ````
   Hi @linguini1 , thank you for the feedback. 
   
   **1. Standalone Verification Script**
   As requested, here is the standalone C script I used to verify the portable 
mfs_clz and mfs_ctz implementations across various edge cases (0, powers of 2, 
boundary conditions).
   
   <details>
   <summary>Click to view standalone test script (C)</summary>
   
   ```c
   #include <stdio.h>
   #include <stdint.h>
   
   typedef uint32_t mfs_t;
   #define predict_false(x) (x)
   
   static inline mfs_t mfs_ctz(const uint32_t x)
   {
     if (predict_false(x == 0)) return 0;
     uint32_t c;
     if (x & 0x1) c = 0;
     else
       {
         uint32_t y = x;
         c = 1;
         if ((y & 0xffff) == 0) { y >>= 16; c += 16; }
         if ((y & 0xff) == 0)   { y >>= 8;  c += 8;  }
         if ((y & 0xf) == 0)    { y >>= 4;  c += 4;  }
         if ((y & 0x3) == 0)    { y >>= 2;  c += 2;  }
         c -= y & 0x1;
       }
     return c;
   }
   
   static inline mfs_t mfs_clz(const uint32_t x)
   {
     if (predict_false(x == UINT32_MAX)) return 0;
     uint32_t n = 0;
     uint32_t x_tmp = x;
     if (x_tmp == 0) return 32;
     if (x_tmp <= 0x0000ffff) { n += 16; x_tmp <<= 16; }
     if (x_tmp <= 0x00ffffff) { n += 8;  x_tmp <<= 8;  }
     if (x_tmp <= 0x0fffffff) { n += 4;  x_tmp <<= 4;  }
     if (x_tmp <= 0x3fffffff) { n += 2;  x_tmp <<= 2;  }
     if (x_tmp <= 0x7fffffff) { n += 1; }
     return n;
   }
   
   int main()
   {
     uint32_t test_values[] = {
       0x00000000, 0x00000001, 0x00000002, 0x00000010,
       0x00000100, 0x00010000, 0x10000000, 0x80000000,
       0xFFFFFFFF, 0x0000FFFF
     };
     printf("Verification of mfs_clz and mfs_ctz logic:\n\n");
     for (int i = 0; i < sizeof(test_values)/sizeof(test_values[0]); i++)
       {
         uint32_t val = test_values[i];
         printf("Value: 0x%08X | Leading Zeros: %2u | Trailing Zeros: %2u\n", 
                val, mfs_clz(val), mfs_ctz(val));
       }
     return 0;
   }
   ````
   
   </details>
   
   **Verification Logs:**
   
   ```
   Value: 0x00000000 | Leading Zeros: 32 | Trailing Zeros:  0
   Value: 0x00000001 | Leading Zeros: 31 | Trailing Zeros:  0
   Value: 0x00000002 | Leading Zeros: 30 | Trailing Zeros:  1
   Value: 0x00000100 | Leading Zeros: 23 | Trailing Zeros:  8
   Value: 0x00010000 | Leading Zeros: 15 | Trailing Zeros: 16
   Value: 0xFFFFFFFF | Leading Zeros:  0 | Trailing Zeros:  0
   ```
   
   **2. Build Configuration**
   
   To build `mnemofs` in the simulator, I am using the `sim:mnemofs` board 
configuration. While `sim:nsh` is the default, `sim:mnemofs` is pre-configured 
with the required NAND flash stack and MTD dependencies:
   
   * `CONFIG_FS_MNEMOFS=y`
   * `CONFIG_MTD_NAND=y`
   * `CONFIG_MTD_NAND_RAM=y`
   * `CONFIG_ALLOW_BSD_COMPONENTS=y`
   
   **Steps to build:**
   
   ```
   ./tools/configure.sh sim:mnemofs
   make
   ```
   
   I have also fixed the "Long line found" style issue on line 355 by splitting 
the credit URL. The PR should be ready for review now.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to