Skip to content

On-the-fly conversion and quotient selection function#858

Open
Durchbruchswagen wants to merge 12 commits intokuznia-rdzeni:masterfrom
Durchbruchswagen:otfc_and_qsf
Open

On-the-fly conversion and quotient selection function#858
Durchbruchswagen wants to merge 12 commits intokuznia-rdzeni:masterfrom
Durchbruchswagen:otfc_and_qsf

Conversation

@Durchbruchswagen
Copy link
Copy Markdown
Contributor

@Durchbruchswagen Durchbruchswagen commented Mar 3, 2026

Implementation of:

  • QSF (quotien selection function) that selects next quotient digit based on few MSB bits of divisor and partial remainder.
  • On-the-fly conversion that performs conversion between redundant representation of quotient to non-redundant representation, by using two registers, one assuming that next digit is non-negative and the other one assuming next digit is positive, to avoid carry propagation

@awariac awariac added enhancement New feature or request nlnet The work is part of the NLnet grant labels Apr 11, 2026
@Durchbruchswagen Durchbruchswagen changed the title On the fly conversion and quotient selection function On-the-fly conversion and quotient selection function Apr 20, 2026
@Durchbruchswagen Durchbruchswagen marked this pull request as ready for review April 20, 2026 13:43
@tilk
Copy link
Copy Markdown
Member

tilk commented Apr 22, 2026

You have circular imports.

Comment on lines +105 to +108
a1 = q[1] | sign
a0 = q[0]
b1 = ((~q[1]) & (~q[0])) | (sign & q[0])
b0 = ~q[0]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These should be signals as they are used multiple times. Actually, given the usage, you could just declare two-bit signals a and b.

Comment on lines +17 to +32
test_cases = [
[(0, 1), (0, 0), (0, 0), (1, 1), (1, 2), (0, 2)],
[(0, 0), (0, 0), (0, 0), (0, 2), (1, 2), (1, 1)],
[(1, 2), (1, 2), (0, 0), (0, 1), (0, 1), (0, 1)],
[(0, 0), (0, 0), (0, 0), (0, 0), (1, 1), (0, 1)],
[(0, 2), (0, 0), (0, 0), (0, 0), (0, 1), (0, 0)],
[(0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0)],
]
results = [
1002,
23,
1557 + (3 << 12),
4093 + (3 << 12),
(1 << 11) + (1 << 2),
0,
]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are just a few cases here, so this doesn't hurt that much, but writing cases like this hurts readability and maintainability. Group test case data, e.g. like you did in test_fpu_classification.

Comment on lines +109 to +119
with m.If(divisor == Const(self.intervals[i])):
with m.If(residual < Const(self.bounds[i][0])):
m.d.av_comb += q.eq(Const(self.digits[0][1]))
m.d.av_comb += sign.eq(Const(self.digits[0][0]))
for j in range(1, len(self.bounds[i])):
with m.Elif(residual < Const(self.bounds[i][j])):
m.d.av_comb += q.eq(Const(self.digits[j][1]))
m.d.av_comb += sign.eq(Const(self.digits[j][0]))
with m.Else():
m.d.av_comb += q.eq(Const(self.digits[len(self.bounds[i])][1]))
m.d.av_comb += sign.eq(Const(self.digits[len(self.bounds[i])][0]))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are the Const uses here really needed? Looks weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request nlnet The work is part of the NLnet grant

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants