Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tests: line: Use fixed-point arithmetic #107

Merged
merged 1 commit into from
Jan 20, 2023
Merged

tests: line: Use fixed-point arithmetic #107

merged 1 commit into from
Jan 20, 2023

Conversation

maromaSamsa
Copy link
Contributor

Instructions: https://hackmd.io/@maromaSamsa/HkjefPbFs

Optimize the performance by replacing floating arithmetic with fixed-point arithmetic counterpart.

@jserv jserv changed the title Optimize: fixed-point arithmetic tests: line: Use fixed-point arithmetic Jan 15, 2023
tests/line.c Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
tests/line.c Show resolved Hide resolved
@maromaSamsa
Copy link
Contributor Author

Hi @jserv, I have formatted the code in clang-format-12 and done the changes you proposed above. Please check.

Thank you

tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use git rebase -i to squash and read the article How to Write a Git Commit Message
carefully.

You shall mention the benefits (with measurements) of the proposed changes.

tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated
}

/* return the nonnegative square root of x */
static inline q_fmt sqrtq(q_fmt x)
Copy link
Contributor

@jserv jserv Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check the following materials accordingly?

I would expect the high-level descriptions for square root implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have read the following article, it seems that the fastest algorithm which the article recommended is converting the fixed point value to the floating point value to do 'sqrtf()', and then converting back to the fixed point value result.

Should I change the algorithm into this way? Or just use the original one I made (converging bit by bit)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always measure if something is in doubt.

Copy link
Contributor Author

@maromaSamsa maromaSamsa Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have already measured the performance between them in my previous term project:

For performing each algorithm 1000 times and compare their clock cycle:

Convert to floating point and call sqrtf(): 228442
My algorithm: 462650

The problem I concern is that our mission is getting rid of floating point arithmetic, this is not a good idea of still using them.

tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
@maromaSamsa
Copy link
Contributor Author

Except for the high-level descriptions for square root implementation, several annotations have been added. For bit-wise operation of signedness, x = ~x+1 can replace x *= -1.

I will squash those commit to one if all adjustments are finished.

tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
tests/line.c Outdated Show resolved Hide resolved
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve the git commit message. You shall express the motivation and benefits of the proposed changes. Show the numbers.

@jserv jserv merged commit 033312c into sysprog21:master Jan 20, 2023
@jserv
Copy link
Contributor

jserv commented Jan 20, 2023

Thank @maromaSamsa for contributing!

@maromaSamsa
Copy link
Contributor Author

Thank @jserv let me have an opportunity contributing to this great work.

Optimize the performance by replacing floating arithmetic with
fixed-point arithmetic counterpart, which allows the embedded
microprocessors that didn't have floating-point unit (FPU) doing
mechanical calculation in high speed and/or low power consumption way.

This change will reduce program execution time by 14%.

Reference: https://hackmd.io/@maromaSamsa/HkjefPbFs
vestata pushed a commit to vestata/rv32emu that referenced this pull request Jan 24, 2025
Replace floating-point arithmetic with its fixed-point equivalent to
apermit microprocessors without a floating-point unit (FPU) to perform
practical calculations efficiently.

The improvement will result in a 14% faster program execution time.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants