Opened 12 years ago

Last modified 14 months ago

#2129 new enhancement

Optimization: Helping gcc with function attributes

Reported by: tqh Owned by: bonefish
Priority: normal Milestone: Unscheduled
Component: System/Kernel Version: R1/pre-alpha1
Keywords: Cc: anevilyak
Blocked By: Blocking:
Platform: x86


I wanted to experiment with gcc's attribute((fastcall)) which makes the functions two first arguments being passed in registers. I added it to kernel functions I thought would be called a lot. The resulting OS seems to be very responsive, although no measurements have been done.

My patch is just for inspiration, it is ugly and I did not really care about compability or if I break any API. Providing it here for those interested. It is used A LOT in Mozilla sources btw although hidden behind macros. It might be useful along with other function attributes in critical parts.

Function attributes are described here:

Attachments (2)

ugly-fastcall.patch (14.5 KB ) - added by tqh 12 years ago.
Ugly fastcall patch
ugly-fastcall.r25229.patch (16.4 KB ) - added by tqh 12 years ago.
Ugly fastcall patch against hrev25229

Download all attachments as: .zip

Change History (10)

by tqh, 12 years ago

Attachment: ugly-fastcall.patch added

Ugly fastcall patch

comment:1 by tqh, 12 years ago

attribute has two underscores in front and after that went missing in the submission.

comment:2 by anevilyak, 12 years ago

Cc: anevilyak added

by tqh, 12 years ago

Attachment: ugly-fastcall.r25229.patch added

Ugly fastcall patch against hrev25229

comment:3 by korli, 12 years ago

Ingo, would you mind giving an eye to this enhancement ? It might be a bad idea on public functions though.

comment:4 by korli, 12 years ago

Cc: bonefish added

comment:5 by tqh, 12 years ago

Not sure they provide much speedup. Although I still keep them around in my tree.

comment:6 by bonefish, 12 years ago

Cc: bonefish removed
Owner: changed from axeld to bonefish

This kind of optimization can make sense; I would wait with trying it a bit longer, though. "fastcall" saves only a few cycles by passing arguments via registers instead of via the stack, but we're still looking for optimization potential of several hundred percent for certain use cases.

At any rate I would use a macro instead of hardcoding the gcc attribute.

Assigning the ticket to myself, so it won't be forgotten...

comment:7 by pulkomandy, 6 years ago

Milestone: R1Unscheduled

comment:8 by waddlesplash, 14 months ago

The x86_64 ABI has the first 8 (?) arguments passed in via registers, so this is only useful on 32-bit, right? I think ARM does the same too, so this may not be so valuable.

Note: See TracTickets for help on using tickets.