Page MenuHomeFreeBSD

linuxkpi: Add `int_sqrt()`
ClosedPublic

Authored by dumbbell on Jul 15 2026, 8:17 AM.
Referenced Files
F172690212: D58251.diff
Sun, Sep 20, 6:28 AM
Unknown Object (File)
Fri, Sep 18, 3:16 AM
Unknown Object (File)
Wed, Sep 16, 8:50 AM
Unknown Object (File)
Mon, Sep 14, 10:23 AM
Unknown Object (File)
Sun, Sep 13, 12:56 PM
Unknown Object (File)
Sun, Sep 13, 2:41 AM
Unknown Object (File)
Sat, Sep 12, 1:12 PM
Unknown Object (File)
Sat, Sep 12, 4:55 AM
Subscribers

Details

Reviewers
bz
Group Reviewers
linuxkpi
Commits
rGd4820dc1e6cb: linuxkpi: Add `int_sqrt()`
Summary

The implementation comes from isqrt64() in sys/cam/cam_iosched.c. It is modified to take an unsigned long and return an unsigned int.

The i915 DRM driver started to use it in Linux 6.15.

Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bz requested changes to this revision.Sat, Sep 5, 9:28 AM
bz added a subscriber: bz.
bz added inline comments.
sys/compat/linuxkpi/common/include/linux/math.h
67

I believe int_sqrt returns an unsigned long in Linux.

sys/compat/linuxkpi/common/src/linux_math.c
10

Based on? instead of copied as it's not a 1:1 copy thought it may become if we do return the unsigned long? Otherwise also credit @imp in the (c)?

Also do you want to fix style for LinuxKPI?

This revision now requires changes to proceed.Sat, Sep 5, 9:28 AM

Based on the feedback from @bz:

  • Fix return type, it should have been unsigned long.
  • Improve comment to explain the source of the code.
sys/compat/linuxkpi/common/src/linux_math.c
15

This is not common style for FreeBSD. Usually we take the license/copyright from the file and then keep it at the top.
However, if we expect more functions in this file one day then I actually like this idea (which will give a lot of tools sieving for copyright and licenses a headache) to mark just that part of the code.
However I have no clue if that actually makes a difference.

@imp this is your code and you know all the other bits related to this.

dumbbell marked an inline comment as done.

Address concern from @bz

sys/compat/linuxkpi/common/src/linux_math.c
15

I moved the copyright at the top like in all other places.

sys/compat/linuxkpi/common/src/linux_math.c
5

And now I have to ask for forgiveness.
The file of the commit ( ba6c22ce938ed ) says "Copyright (c) 2015 Netflix, Inc."

Address feedback from @bz.

I also messed up my git-blame(1) invocation…

This revision is now accepted and ready to land.Thu, Sep 10, 7:31 PM
This revision was automatically updated to reflect the committed changes.