If anyone is better at this than I am and wants to bother with more
analysis, here is the LIST output of compiling the below. (Note that it is
inline, so here is where it is invoked.)

*    int index = Utility::Ffs64(key);                  
          LG       r1,#SPILL0(,r13,448)                
          SRAG     r0,r1,32                            
          ST       r0,valueToTest%33=>32(,r13,416)     
          ST       r1,valueToTest%33=>32(,r13,420)     
+         LG       r0,valueToTest%33=>32(,r13,416)     
+         LTGR     r0,r0                               
+         LGR      r14,r0                              
+         BNE      @32L1392                            
          LGHI     r3,H'0'                             
          B        @32L1393                            
+@32L1392 DS       0H                                  
          L        r1,ffs_ptr(,r6,908)                 
+         LTR      r14,r14                             
+         BE       @32L1395                            
+         ST       r0,#MX_TEMP32(,r13,196)             
+         LM       r15,r0,&EPA_&WSA(r1,8)              
+         ST       r0,_CEECAA_(,r12,500)               
+         LA       r1,#MX_TEMP32(,r13,196)             
+         BASR     r14,r15                             
          LGFR     r3,r15                              
          B        @32L1393                            
+@32L1395 DS       0H                                  
+         LM       r15,r0,&EPA_&WSA(r1,8)              
+         LGHI     r2,H'0'                             
+         ST       r0,_CEECAA_(,r12,500)               
+         ST       r2,#MX_TEMP32(,r13,196)             
+         LA       r1,#MX_TEMP32(,r13,196)             
+         BASR     r14,r15                             
+         AHI      r15,H'32'                           
          LGFR     r3,r15                              
 @32L1393 DS       0H                                  

Charles

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On
Behalf Of Charles Mills
Sent: Sunday, July 21, 2013 11:57 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: Looking for help with an obscure C integer problem

Here is exact cut and paste with zero editing, complete with a typo in the
second comment. The code is unit tested on MS Visual Studio -- hence the two
#ifdef's.

        // Find First Set
        static inline int Ffs64(unsigned long long valueToTest)
        {
                // returns index of first set bit. Uses UNIX convention
where bit 1 is LSB of word for compatibilit with z/OS ffs()

                static const unsigned long long lswMask =
0x00000000ffffffff;

                // note Windows provides a _BitScanForward64() but I did it
this way to make it more z/OS-like for test purposes
                // if we ever needed Windows efficiency, or if IBM provides
an ffs64(), then this should be re-written to take advantage

                if ( valueToTest == 0 ) return 0;

                unsigned int testWord;
                testWord = valueToTest & lswMask;
                if ( testWord != 0 )
                {
                        // _BitScanForward returns base 0
#ifdef WIN32
                        unsigned long index;
                        _BitScanForward(&index, testWord);
                        return index+1;
#else
                        return ffs(testWord);
#endif
                }
                else
                {
                        testWord = valueToTest >> 32;
#ifdef WIN32
                        unsigned long index;
                        _BitScanForward(&index, testWord);
                        return index+33;
#else
                        return ffs(testWord) + 32;
#endif

                }
        }

I have strong -- but not utterly conclusive; you know what debugging a
complex program is like -- that for the value I had in the OP --
0x0034000000000000? -- the method returns 32, implying that the final ffs()
was called with testWord = 0.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to