Tcl Source Code

View Ticket
Login
2025-05-09
18:14 Closed ticket [fd1585e2a1]: Continued improvements to TclLog2() and friends and callers plus 6 other changes artifact: fc1aad6f51 user: dgp
18:13
[fd1585e2a1] Adopt efficient internal indexing calculation utility TclMSB(). check-in: e991e299b3 user: dgp tags: core-9-0-branch
18:10
[fd1585e2a1] Adopt efficient internal indexing calculation utility TclMSB(). check-in: 7d9a0d7b95 user: dgp tags: trunk, main
2025-05-05
19:37 Ticket [fd1585e2a1] Continued improvements to TclLog2() and friends and callers status still Open with 3 other changes artifact: 8089a3f95c user: dgp
11:45 Ticket [fd1585e2a1]: 3 changes artifact: 984c8b5da4 user: dgp
11:19 Ticket [fd1585e2a1]: 3 changes artifact: 7e5e07b6db user: dgp
2025-05-04
17:12 Ticket [fd1585e2a1]: 4 changes artifact: 925376ffa2 user: jan.nijtmans
2025-05-02
08:42 Ticket [fd1585e2a1]: 3 changes artifact: adaa52e3a3 user: jan.nijtmans
2025-05-01
20:04 Ticket [fd1585e2a1]: 4 changes artifact: 6a15f5405c user: oehhar
17:04 Ticket [fd1585e2a1]: 3 changes artifact: 119fdfe810 user: dgp
2025-04-23
18:40 Ticket [fd1585e2a1]: 3 changes artifact: c34b22d88b user: dgp
2025-04-16
18:12 New ticket [fd1585e2a1]. artifact: a4ce5f6312 user: dgp

Ticket UUID: fd1585e2a1a8f8900ea63bc2c723717f5871962b
Title: Continued improvements to TclLog2() and friends and callers
Type: Patch Version: 9.0+
Submitter: dgp Created on: 2025-04-16 18:12:48
Subsystem: 69. Other Assigned To: dgp
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2025-05-09 18:14:00
Resolution: Accepted Closed By: dgp
    Closed on: 2025-05-09 18:14:00
Description:
[677241c9b3] recently made changes to the internal utility routine
TclLog2() seeking optimization and confident extension to 64-bit range.

Conflicts encountered merging the changes to the dgp-refactor branch
revealed that branch holds considerably more improvements ready to
deploy.  A new branch dgp-msb has been opened to bring those changes over
to the trunk in a sequence of commits.  When the whole revision is complete,
I will be seeking review to approve accepting all the changes for merge to
trunk and backport to appropriate branches.
User Comments: dgp added on 2025-05-09 18:14:00:
Accepted into 9.0 and 9.1 development.

dgp added on 2025-05-05 19:37:41:
Answering question about the non-support for an input of 0 to TclMSB().

Since the binary representation of 0 has no set bits, it is unclear
what the correct answer should be to the question what is the index
of the most significant set bit.

A return value of 0 is effectively an assertion that the input value 0
is no different from the input value 1.  Far from clear that's an
acceptable equivalence to all callers.

A return value of -1 succeeds in treating an input value 0 as something
unlike any other input.  However, most known callers of TclMSB() have the
intent of using the return value as an index, and a negative index is not
usually welcome.  Such callers would need to post-process the return value
to treat -1 differently.  This is no better than expecting the caller to
treat an input value of 0 differently before making the TclMSB() call. 
Either way, there's a testing branch needed if the caller knows a value
of 0 is a possibility.

FWIW, it is also true that this unsupported input value reflects the
same unsupported input value in the most efficient implementations.  The
limitations of clzll(), etc. are just showing through.

dgp added on 2025-05-05 11:45:24:
Have to take care at the input range boundaries to not
be testing undefined behaviors.  Thanks!  Should be better now.

dgp added on 2025-05-05 11:19:49:
All platforms except mine I guess.  Will look into it.

jan.nijtmans added on 2025-05-04 17:12:09:

The testcases show this:

    ==== brodnik-1.0 TclMSB correctness FAILED
    ==== Contents of test case:

testmsb $v
---- Result was: -1 ---- Result should have been (exact matching): 0 ==== brodnik-1.0 FAILED

Same failure on all platforms


jan.nijtmans added on 2025-05-02 08:42:16:

I like the idea (and the implementation looks good)

I scheduled a build tonight, let's see what Github ACTIONS thinks.


oehhar added on 2025-05-01 20:04:20:

Dopnald, this is clear wizard work. I even have no idea of the purpose. There are assembler intrinsics etc.

No way for me, sorry.

Take care, Harald


dgp added on 2025-05-01 17:04:41:
Anyone willing to look?

dgp added on 2025-04-23 18:40:46:
The dgp-msb branch is ready for an independent review of suitability to
merge to trunk.