Page MenuHomePhabricator
Feed Advanced Search

Feb 4 2023

icedrocket accepted D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..

LGTM

Feb 4 2023, 7:03 AM · Restricted Project, Restricted Project
icedrocket added a comment to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..

I wrote some code to verify that u64 to f64 conversion using FILD+FADD with 53-bit precision is accurate. I tested it with 10^12 cases and the results are: u64 to f32 conversion failed frequently, but u64 to f64 conversion does not failed.

Feb 4 2023, 7:02 AM · Restricted Project, Restricted Project
icedrocket added inline comments to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..
Feb 4 2023, 4:04 AM · Restricted Project, Restricted Project

Feb 2 2023

icedrocket added inline comments to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..
Feb 2 2023, 10:14 PM · Restricted Project, Restricted Project
icedrocket added a comment to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..

Remove unrelated comment change. The line is longer than 80 columns, but isn't near code this is touching.

Feb 2 2023, 11:44 AM · Restricted Project, Restricted Project
icedrocket added inline comments to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..
Feb 2 2023, 10:44 AM · Restricted Project, Restricted Project
icedrocket added inline comments to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..
Feb 2 2023, 10:05 AM · Restricted Project, Restricted Project
icedrocket added a comment to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..

Could you update the diff? The current diff is outdated and cannot be applied to main branch automatically.

Feb 2 2023, 8:25 AM · Restricted Project, Restricted Project

Jan 24 2023

icedrocket added inline comments to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..
Jan 24 2023, 12:15 AM · Restricted Project, Restricted Project

Jan 23 2023

icedrocket added inline comments to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..
Jan 23 2023, 10:03 PM · Restricted Project, Restricted Project
icedrocket added a comment to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..
Jan 23 2023, 10:20 AM · Restricted Project, Restricted Project
icedrocket added inline comments to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..
Jan 23 2023, 6:13 AM · Restricted Project, Restricted Project

Jan 20 2023

icedrocket added a comment to D142178: [X86] Change precision control to FP80 during u64->fp32 conversion on Windows..

I tested the patch and it seems to have fixed the issue.

Jan 20 2023, 1:45 AM · Restricted Project, Restricted Project

Jan 18 2023

icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

Could someone commit this change?

Jan 18 2023, 10:22 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

@craig.topper, could you please commit this change? I don't have permission to commit.

@icedrocket Please can you provide your email address for the commit message?

Jan 18 2023, 2:52 AM · Restricted Project, Restricted Project

Jan 17 2023

icedrocket updated the summary of D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 17 2023, 11:38 PM · Restricted Project, Restricted Project
icedrocket retitled D141074: [X86] Avoid converting u64 to f32 using x87 on Windows from [X86] Avoid converting 64-bit integers to floating point using x87 on Windows to [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 17 2023, 11:37 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

@craig.topper, could you please commit this change? I don't have permission to commit.

Jan 17 2023, 10:14 PM · Restricted Project, Restricted Project

Jan 16 2023

icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 16 2023, 3:56 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 16 2023, 3:47 AM · Restricted Project, Restricted Project

Jan 15 2023

icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 15 2023, 10:11 PM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 15 2023, 9:08 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

I'm not sure why the result depends on the x87 control word, but anyway, there is a possibility that this issue is because of the rounding mode. The conversion from f64 to f32 is typically done using round to nearest, and the target to round can differ between u64 and u64 to f64. We should round over u64, not u64 to f64.

Jan 15 2023, 3:47 AM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

I'm not sure why the result depends on the x87 control word, but anyway, there is a possibility that this issue is because of the rounding mode. The conversion from f64 to f32 is typically done using round to nearest, and the target to round can differ between u64 and u64 to f64. We should round over u64, not u64 to f64.

The algorithm we use for u64 to f32 looks like this

bitcast u64 to i64
convert to i64 to 80-bit fp using FILD instruction (this conversion does not depend on the value of PC).
if bits 63 was set in the integer this conversion produces a negative number.
if bit 63 was set in the integer, add 18446744073709551616 to the negative floating point value to give it the correct positive value. With PC=64 this shouldn't result in any rounding.
round 80-bit fp value to f32 using FST.

The bug occurs because the addition of 18446744073709551616 ends up rounding unexpectedly because of PC=53.

Jan 15 2023, 1:29 AM · Restricted Project, Restricted Project

Jan 14 2023

icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

I'm not sure why the result depends on the x87 control word, but anyway, there is a possibility that this issue is because of the rounding mode. The conversion from f64 to f32 is typically done using round to nearest, and the target to round can differ between u64 and u64 to f64. We should round over u64, not u64 to f64.

Jan 14 2023, 11:57 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

The tests keep failing, but it's all RISC-V related, so the diff probably isn't wrong.

Jan 14 2023, 8:32 PM · Restricted Project, Restricted Project
icedrocket abandoned D141763: [X86] Remove unnecessary bitcasting in INT_TO_FP.

You're right, I should have checked enough before request a review.

Jan 14 2023, 4:40 PM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 14 2023, 8:23 AM · Restricted Project, Restricted Project
icedrocket requested review of D141763: [X86] Remove unnecessary bitcasting in INT_TO_FP.
Jan 14 2023, 7:08 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 14 2023, 4:02 AM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

I've checked and MSVC's implementation dynamically checks if AVX-512 is available and uses vcvtuqq2pd if available. Therefore, it seems that the result depends on whether the system supports AVX-512 or not.

Jan 14 2023, 3:28 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 14 2023, 3:21 AM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

The main reason I posted a review was because the conversion results from u64 and i64 to f32 did not match, causing problems.

Jan 14 2023, 2:34 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 14 2023, 1:38 AM · Restricted Project, Restricted Project

Jan 10 2023

icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

Change to original version of diff mentioned by @lebedev.ri.

Jan 10 2023, 7:49 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 10 2023, 3:20 PM · Restricted Project, Restricted Project

Jan 9 2023

icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

The test keeps failing, but Diff 486869 has already built and tested successfully. The only thing that has changed is the comments.

Jan 9 2023, 8:49 PM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 9 2023, 7:34 PM · Restricted Project, Restricted Project
icedrocket updated the summary of D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 9 2023, 6:22 PM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

Fix the comments

Jan 9 2023, 4:18 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 9 2023, 4:14 PM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 9 2023, 4:08 PM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 9 2023, 4:02 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

If SSE2 is available, we only need to use library calls to convert between 64-bit integers and floating point. However, if only x87 is available, precision issues are unavoidable. What I meant was to just use the x87 implementation and print a warning in this case.

Why are they unavoidable?

Jan 9 2023, 3:09 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

If SSE2 is available, we only need to use library calls to convert between 64-bit integers and floating point. However, if only x87 is available, precision issues are unavoidable. What I meant was to just use the x87 implementation and print a warning in this case.

Jan 9 2023, 2:55 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

I think the original version of the diff is reasonable and can be merged.

I don't think the concerns that we lower something to a libcall are sufficiently grounded.
We already lower many things to a libcall. Doing so for one more thing is not the end of the world,
assuming the compiler-rt exists for that configuration in the first place.

Jan 9 2023, 2:27 PM · Restricted Project, Restricted Project

Jan 6 2023

icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 6 2023, 1:33 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

On Windows 32-bit, the calling convention uses x87, so it's almost impossible to avoid using x87. So rather than avoiding the use of x87, I think it's better to add an option to inject code like an ICC option. To add this option to all LLVM-based compilers, the code must be injected into the LLVM IR. This will be done in the process of parsing or generating the LLVM IR. However, this requires refactoring a lot of code.

Jan 6 2023, 1:22 PM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 6 2023, 12:16 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

Add the pc80 option. There may be other suitable candidate names for this option, but I used the name from Intel ICC. The current implementation only applies to conversions from 64-bit integers to floating point.

The icc options injects code into main to set the PC. (Kind of ignoring that global constructors that run before main exist).

Jan 6 2023, 10:34 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

Add the pc80 option. There may be other suitable candidate names for this option, but I used the name from Intel ICC. The current implementation only applies to conversions from 64-bit integers to floating point.

Jan 6 2023, 10:18 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 6 2023, 7:10 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 6 2023, 6:05 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

Use library calls only when SSE is enabled. If SSE is disabled and x87 is enabled, the x87 implementation is used regardless of precision.

Jan 6 2023, 5:43 AM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

What to do if user changes the default precision?

Jan 6 2023, 4:51 AM · Restricted Project, Restricted Project

Jan 5 2023

icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 5 2023, 9:04 PM · Restricted Project, Restricted Project
icedrocket added a comment to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.

only on Windows 32-bit

Is the default precision control different for 64-bit?

No, but I think we use a different algorithm with a 64-bit cvtsi2ss on 64-bit targets so we don't end up using x87.

I'm mainly asking whether this needs to check for the 32-bit windows specifically, not just that it is windows. Guess not.

Jan 5 2023, 12:39 PM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 5 2023, 10:57 AM · Restricted Project, Restricted Project
icedrocket updated the diff for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 5 2023, 10:47 AM · Restricted Project, Restricted Project
icedrocket removed a project from D141074: [X86] Avoid converting u64 to f32 using x87 on Windows: Restricted Project.
Jan 5 2023, 10:45 AM · Restricted Project, Restricted Project
icedrocket added a project to D141074: [X86] Avoid converting u64 to f32 using x87 on Windows: Restricted Project.
Jan 5 2023, 10:37 AM · Restricted Project, Restricted Project
icedrocket updated the summary of D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 5 2023, 10:33 AM · Restricted Project, Restricted Project
icedrocket added a reviewer for D141074: [X86] Avoid converting u64 to f32 using x87 on Windows: craig.topper.
Jan 5 2023, 10:30 AM · Restricted Project, Restricted Project
icedrocket requested review of D141074: [X86] Avoid converting u64 to f32 using x87 on Windows.
Jan 5 2023, 10:28 AM · Restricted Project, Restricted Project
icedrocket updated icedrocket.
Jan 5 2023, 10:04 AM