clk: k210: Fix error calculation on 32bit
PATCH 1/1 clk: k210: Fix error calculation on 32bit
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
---
drivers/clk/clk_k210.c | 2 +- test/dm/k210_pll.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk_k210.c +1 -1
@@ -846,7 +846,7 @@ again: error =DIV_ROUND_CLOSEST_ULL (f * inv_ratio, r * od);/* The lower 16 bits are spurious */ - error =abs ((error -BIT (32 ))) >>16 ; + error =abs ((error >>16 ) -BIT (32 -16 ));if (error < best_error) { best->r = r;
test/dm/k210_pll.c +1 -1
@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error =DIV_ROUND_CLOSEST_ULL (f * inv_ratio, r * od);/* The lower 16 bits are spurious */ - error =abs ((error -BIT (32 ))) >>16 ; + error =abs ((error >>16 ) -BIT (32 -16 ));if (error < best_error) { best->r = r; best->f = f;
Signature · 1 line
2.37.3
Quoted 5 lines · Michal Suchanek
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
Also see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Quoted 37 lines
Signed-off-by Michal Suchanek <[email protected]>---
drivers/clk/clk_k210.c | 2 +- test/dm/k210_pll.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/clk/clk_k210.c +1
-1@@ -846,7 +846,7 @@ again: error =DIV_ROUND_CLOSEST_ULL (f * inv_ratio, r * od);/* The lower 16 bits are spurious */ - error =abs ((error -BIT (32 ))) >>16 ; + error =abs ((error >>16 ) -BIT (32 -16 ));if (error < best_error) { best->r = r;test/dm/k210_pll.c +1
-1@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error =DIV_ROUND_CLOSEST_ULL (f * inv_ratio, r * od);/* The lower 16 bits are spurious */ - error =abs ((error -BIT (32 ))) >>16 ; + error =abs ((error >>16 ) -BIT (32 -16 ));if (error < best_error) { best->r = r; best->f = f;Signature · 1 line
2.37.3
Quoted 24 lines · Michal Suchánek
Quoted 5 lines · Michal Suchanek
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
Also see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Quoted 14 lines
Signed-off-by Michal Suchanek <[email protected]>---
drivers/clk/clk_k210.c | 2 +- test/dm/k210_pll.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/clk/clk_k210.c +0
-0@@ -846,7 +846,7 @@ again:
Quoted 4 lines
drivers/clk/clk_k210.c again: · line 849
Quoted 4 lines
drivers/clk/clk_k210.c +1
-1error =DIV_ROUND_CLOSEST_ULL (f * inv_ratio, r * od);/* The lower 16 bits are spurious */ - error =abs ((error -BIT (32 ))) >>16 ; + error =abs ((error >>16 ) -BIT (32 -16 ));
Your patch changes the results. Replacing BIT() by BIT_ULL() does not change the result:
error = -1 = 0xffffffffffffffff
before
error - BIT(32) = -4294967297 = 0xfffffffeffffffff abs(error - BIT(32)) = 4294967297 = 0x100000001 abs(error - BIT(32)) >> 16 = 65536 = 0x10000 after
error >> 16 = -1 = 0xffffffffffffffff
(error >> 16) - BIT(32 - 16) = -65537 = 0xfffffffffffeffff abs((error >> 16) - BIT(32 - 16)) = 65537 = 0x10001 using BIT_ULLabs(error - BIT_ULL(32)) >> 16 = 65536 = 0x10000
error = 70000 = 0x11170
before
error - BIT(32) = -4294897296 = 0xffffffff00011170 abs(error - BIT(32)) = 4294897296 = 0xfffeee90 abs(error - BIT(32)) >> 16 = 65534 = 0xfffe
after
error >> 16 = 1 = 0x1
(error >> 16) - BIT(32 - 16) = -65535 = 0xffffffffffff0001 abs((error >> 16) - BIT(32 - 16)) = 65535 = 0xffff using BIT_ULLabs(error - BIT_ULL(32)) >> 16 = 65534 = 0xfffe
I assume this change of results is unintended.
We also replace abs() by abs64() to get correct results on a 32bit system:
error = -1 = 0xffffffffffffffffabs(error - BIT_ULL(32)) >> 16 = 0 = 0x0 abs64(error - BIT_ULL(32)) >> 16 = 65536 = 0x10000 error = 70000 = 0x11170abs(error - BIT_ULL(32)) >> 16 = 1 = 0x1 abs64(error - BIT_ULL(32)) >> 16 = 65534 = 0xfffe
Best regards
Heinrich
Quoted 19 lines
Quoted 19 lines
drivers/clk/clk_k210.c +0
-0if (error < best_error) { best->r = r;test/dm/k210_pll.c +1
-1@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error =DIV_ROUND_CLOSEST_ULL (f * inv_ratio, r * od);/* The lower 16 bits are spurious */ - error =abs ((error -BIT (32 ))) >>16 ; + error =abs ((error >>16 ) -BIT (32 -16 ));if (error < best_error) { best->r = r; best->f = f;Signature · 1 line
2.37.3
Quoted 83 lines · Heinrich Schuchardt
Quoted 18 lines · Michal Suchánek
Quoted 5 lines · Michal Suchanek
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
Also see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Quoted 8 lines
Signed-off-by Michal Suchanek <[email protected]>---
drivers/clk/clk_k210.c| 2 +-
test/dm/k210_pll.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)Quoted 9 lines
drivers/clk/clk_k210.c again: · line 848
Quoted 9 lines
drivers/clk/clk_k210.c +1
-1@@ -846,7 +846,7 @@ again: error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16));Your patch changes the results. Replacing
BIT()byBIT_ULL()does not change the result:error = -1 =
0xffffffffffffffff
before
error - BIT(32) = -4294967297 =0xfffffffeffffffffabs(error - BIT(32)) = 4294967297 =0x100000001abs(error - BIT(32)) >> 16 = 65536 =0x10000after
error >> 16 = -1 =0xffffffffffffffff
(error >> 16) - BIT(32 - 16) = -65537 =0xfffffffffffeffffabs((error >> 16) - BIT(32 - 16)) = 65537 =0x10001usingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =
0x11170
before
error - BIT(32) = -4294897296 =0xffffffff00011170abs(error - BIT(32)) = 4294897296 =0xfffeee90abs(error - BIT(32)) >> 16 = 65534 =0xfffe
after
error >> 16 = 1 =0x1
(error >> 16) - BIT(32 - 16) = -65535 =0xffffffffffff0001abs((error >> 16) - BIT(32 - 16)) = 65535 =0xffffusingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65534 =0xfffeI assume this change of results is unintended.
We also replace
abs()byabs64()to get correct results on a 32bit system:error = -1 =
0xffffffffffffffffabs(error - BIT_ULL(32))>> 16 = 0 =0x0abs64(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =0x11170abs(error - BIT_ULL(32))>> 16 = 1 =0x1abs64(error - BIT_ULL(32))>> 16 = 65534 =0xfffeBest regards
Heinrich
Quoted 10 lines
Quoted 10 lines
drivers/clk/clk_k210.c +0
-0if (error < best_error) { best->r = r;test/dm/k210_pll.c +0
-0@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
test/dm/k210_pll.c +1
-1- error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16)); if (error < best_error) { best->r = r; best->f = f;Signature · 1 line
2.37.3
IMO the driver should just be changed to depend on 64-bit. The k210 is 64-bit, and I didn't write anything with 32-bit in mind.
--Sean
Quoted 88 lines · Sean Anderson
Quoted 87 lines · Heinrich Schuchardt
Quoted 18 lines · Michal Suchánek
Quoted 5 lines · Michal Suchanek
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
Also see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Quoted 8 lines
Signed-off-by Michal Suchanek <[email protected]>---
drivers/clk/clk_k210.c| 2 +-
test/dm/k210_pll.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)Quoted 9 lines
drivers/clk/clk_k210.c again: · line 848
Quoted 9 lines
drivers/clk/clk_k210.c +1
-1@@ -846,7 +846,7 @@ again: error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16));Your patch changes the results. Replacing
BIT()byBIT_ULL()does not change the result:error = -1 =
0xffffffffffffffff
before
error - BIT(32) = -4294967297 =0xfffffffeffffffffabs(error - BIT(32)) = 4294967297 =0x100000001abs(error - BIT(32)) >> 16 = 65536 =0x10000after
error >> 16 = -1 =0xffffffffffffffff
(error >> 16) - BIT(32 - 16) = -65537 =0xfffffffffffeffffabs((error >> 16) - BIT(32 - 16)) = 65537 =0x10001usingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =
0x11170
before
error - BIT(32) = -4294897296 =0xffffffff00011170abs(error - BIT(32)) = 4294897296 =0xfffeee90abs(error - BIT(32)) >> 16 = 65534 =0xfffe
after
error >> 16 = 1 =0x1
(error >> 16) - BIT(32 - 16) = -65535 =0xffffffffffff0001abs((error >> 16) - BIT(32 - 16)) = 65535 =0xffffusingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65534 =0xfffeI assume this change of results is unintended.
We also replace
abs()byabs64()to get correct results on a 32bit system:error = -1 =
0xffffffffffffffffabs(error - BIT_ULL(32))>> 16 = 0 =0x0abs64(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =0x11170abs(error - BIT_ULL(32))>> 16 = 1 =0x1abs64(error - BIT_ULL(32))>> 16 = 65534 =0xfffeBest regards
Heinrich
Quoted 14 lines
Quoted 14 lines
drivers/clk/clk_k210.c +0
-0if (error < best_error) { best->r = r;test/dm/k210_pll.c +1
-1@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate,u32 rate_in, error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16)); if (error < best_error) {
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
test/dm/k210_pll.c +0
-0best->r = r;
best->f= f;Signature · 1 line
2.37.3IMO the driver should just be changed to depend on 64-bit. The k210 is 64-bit, and I didn't write anything with 32-bit in mind.
Michal, Simon, and I are striving to get the sandbox working on ilp32 systems.
Do you suggest to remove the driver from sandbox_defconfig?
This would imply that the unit test is not executed on Gitlab CI. You will still be able to execute it on the actual hardware.
Best regards
Heinrich
Quoted 99 lines · Heinrich Schuchardt
Quoted 87 lines · Sean Anderson
Quoted 86 lines · Heinrich Schuchardt
Quoted 18 lines · Michal Suchánek
Quoted 5 lines · Michal Suchanek
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
Also see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Quoted 8 lines
Signed-off-by Michal Suchanek <[email protected]>---
drivers/clk/clk_k210.c| 2 +-
test/dm/k210_pll.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)Quoted 9 lines
drivers/clk/clk_k210.c again: · line 848
Quoted 9 lines
drivers/clk/clk_k210.c +1
-1@@ -846,7 +846,7 @@ again: error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16));Your patch changes the results. Replacing
BIT()byBIT_ULL()does not change the result:error = -1 =
0xffffffffffffffff
before
error - BIT(32) = -4294967297 =0xfffffffeffffffffabs(error - BIT(32)) = 4294967297 =0x100000001abs(error - BIT(32)) >> 16 = 65536 =0x10000after
error >> 16 = -1 =0xffffffffffffffff
(error >> 16) - BIT(32 - 16) = -65537 =0xfffffffffffeffffabs((error >> 16) - BIT(32 - 16)) = 65537 =0x10001usingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =
0x11170
before
error - BIT(32) = -4294897296 =0xffffffff00011170abs(error - BIT(32)) = 4294897296 =0xfffeee90abs(error - BIT(32)) >> 16 = 65534 =0xfffe
after
error >> 16 = 1 =0x1
(error >> 16) - BIT(32 - 16) = -65535 =0xffffffffffff0001abs((error >> 16) - BIT(32 - 16)) = 65535 =0xffffusingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65534 =0xfffeI assume this change of results is unintended.
We also replace
abs()byabs64()to get correct results on a 32bit system:error = -1 =
0xffffffffffffffffabs(error - BIT_ULL(32))>> 16 = 0 =0x0abs64(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =0x11170abs(error - BIT_ULL(32))>> 16 = 1 =0x1abs64(error - BIT_ULL(32))>> 16 = 65534 =0xfffeBest regards
Heinrich
Quoted 13 lines
Quoted 13 lines
drivers/clk/clk_k210.c +0
-0if (error < best_error) { best->r = r;test/dm/k210_pll.c +1
-1@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16)); if (error < best_error) {Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
test/dm/k210_pll.c +0
-0best->r = r; best->f = f;Signature · 1 line
2.37.3IMO the driver should just be changed to depend on 64-bit. The k210 is 64-bit, and I didn't write anything with 32-bit in mind.
Quoted 5 lines
Michal, Simon, and I are striving to get the sandbox working on ilp32 systems.
Do you suggest to remove the driver from
sandbox_defconfig?This would imply that the unit test is not executed on Gitlab CI. You will still be able to execute it on the actual hardware.
It's still enabled for sandbox64, so it should still be executed there.
--Sean
Quoted 101 lines · Sean Anderson
Quoted 100 lines · Heinrich Schuchardt
Quoted 96 lines · Sean Anderson
Quoted 84 lines · Heinrich Schuchardt
Quoted 18 lines · Michal Suchánek
Quoted 5 lines · Michal Suchanek
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
Also see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Quoted 8 lines
Signed-off-by Michal Suchanek <[email protected]>---
drivers/clk/clk_k210.c| 2 +-
test/dm/k210_pll.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)Quoted 9 lines
drivers/clk/clk_k210.c again: · line 848
Quoted 9 lines
drivers/clk/clk_k210.c +1
-1@@ -846,7 +846,7 @@ again: error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16));Your patch changes the results. Replacing
BIT()byBIT_ULL()does not change the result:error = -1 =
0xffffffffffffffff
before
error - BIT(32) = -4294967297 =0xfffffffeffffffffabs(error - BIT(32)) = 4294967297 =0x100000001abs(error - BIT(32)) >> 16 = 65536 =0x10000after
error >> 16 = -1 =0xffffffffffffffff
(error >> 16) - BIT(32 - 16) = -65537 =0xfffffffffffeffffabs((error >> 16) - BIT(32 - 16)) = 65537 =0x10001usingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =
0x11170
before
error - BIT(32) = -4294897296 =0xffffffff00011170abs(error - BIT(32)) = 4294897296 =0xfffeee90abs(error - BIT(32)) >> 16 = 65534 =0xfffe
after
error >> 16 = 1 =0x1
(error >> 16) - BIT(32 - 16) = -65535 =0xffffffffffff0001abs((error >> 16) - BIT(32 - 16)) = 65535 =0xffffusingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65534 =0xfffeI assume this change of results is unintended.
We also replace
abs()byabs64()to get correct results on a 32bit system:error = -1 =
0xffffffffffffffffabs(error - BIT_ULL(32))>> 16 = 0 =0x0abs64(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =0x11170abs(error - BIT_ULL(32))>> 16 = 1 =0x1abs64(error - BIT_ULL(32))>> 16 = 65534 =0xfffeBest regards
Heinrich
Quoted 11 lines
Quoted 11 lines
drivers/clk/clk_k210.c +0
-0if (error < best_error) { best->r = r;test/dm/k210_pll.c +0
-0@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
test/dm/k210_pll.c +1
-1- error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16)); if (error < best_error) { best->r = r;
best->f= f;Signature · 1 line
2.37.3IMO the driver should just be changed to depend on 64-bit. The k210 is 64-bit, and I didn't write anything with 32-bit in mind.
Quoted 7 lines
Quoted 5 lines
Michal, Simon, and I are striving to get the sandbox working on ilp32 systems.
Do you suggest to remove the driver from
sandbox_defconfig?This would imply that the unit test is not executed on Gitlab CI. You will still be able to execute it on the actual hardware.
It's still enabled for sandbox64, so it should still be executed there.
No, the sandbox64 is also to be compiled on ilp32. It models physical address extension (PAE).
Best regards
Heinrich
Quoted 105 lines · Heinrich Schuchardt
Quoted 102 lines · Sean Anderson
Quoted 101 lines · Heinrich Schuchardt
Quoted 87 lines · Sean Anderson
Quoted 86 lines · Heinrich Schuchardt
Quoted 18 lines · Michal Suchánek
Quoted 5 lines · Michal Suchanek
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
Also see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Quoted 8 lines
Signed-off-by Michal Suchanek <[email protected]>---
drivers/clk/clk_k210.c| 2 +-
test/dm/k210_pll.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)Quoted 9 lines
drivers/clk/clk_k210.c again: · line 848
Quoted 9 lines
drivers/clk/clk_k210.c +1
-1@@ -846,7 +846,7 @@ again: error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16));Your patch changes the results. Replacing
BIT()byBIT_ULL()does not change the result:error = -1 =
0xffffffffffffffff
before
error - BIT(32) = -4294967297 =0xfffffffeffffffffabs(error - BIT(32)) = 4294967297 =0x100000001abs(error - BIT(32)) >> 16 = 65536 =0x10000after
error >> 16 = -1 =0xffffffffffffffff
(error >> 16) - BIT(32 - 16) = -65537 =0xfffffffffffeffffabs((error >> 16) - BIT(32 - 16)) = 65537 =0x10001usingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =
0x11170
before
error - BIT(32) = -4294897296 =0xffffffff00011170abs(error - BIT(32)) = 4294897296 =0xfffeee90abs(error - BIT(32)) >> 16 = 65534 =0xfffe
after
error >> 16 = 1 =0x1
(error >> 16) - BIT(32 - 16) = -65535 =0xffffffffffff0001abs((error >> 16) - BIT(32 - 16)) = 65535 =0xffffusingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65534 =0xfffeI assume this change of results is unintended.
We also replace
abs()byabs64()to get correct results on a 32bit system:error = -1 =
0xffffffffffffffffabs(error - BIT_ULL(32))>> 16 = 0 =0x0abs64(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =0x11170abs(error - BIT_ULL(32))>> 16 = 1 =0x1abs64(error - BIT_ULL(32))>> 16 = 65534 =0xfffeBest regards
Heinrich
Quoted 13 lines
Quoted 13 lines
drivers/clk/clk_k210.c +0
-0if (error < best_error) { best->r = r;test/dm/k210_pll.c +1
-1@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16)); if (error < best_error) {Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
test/dm/k210_pll.c +0
-0best->r = r; best->f = f;Signature · 1 line
2.37.3IMO the driver should just be changed to depend on 64-bit. The k210 is 64-bit, and I didn't write anything with 32-bit in mind.
Michal, Simon, and I are striving to get the sandbox working on ilp32 systems.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Do you suggest to remove the driver from
sandbox_defconfig?This would imply that the unit test is not executed on Gitlab CI. You will still be able to execute it on the actual hardware.
It's still enabled for sandbox64, so it should still be executed there.
No, the sandbox64 is also to be compiled on ilp32. It models physical address extension (PAE).
Do we have a config for word size? PHYS_64BIT seems to be for the address size.
--Sean
Quoted 109 lines · Sean Anderson
Quoted 108 lines · Heinrich Schuchardt
Quoted 105 lines · Sean Anderson
Quoted 104 lines · Heinrich Schuchardt
Quoted 88 lines · Sean Anderson
Quoted 87 lines · Heinrich Schuchardt
Quoted 18 lines · Michal Suchánek
Quoted 5 lines · Michal Suchanek
k210 is 64bit but the driver and tests are also built in sandbox, and that can be built 32bit.
BIT(32) does not work on 32bit, shift before subtraction to fit into 32bit integer with BIT values.
Also see
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Quoted 8 lines
Signed-off-by Michal Suchanek <[email protected]>---
drivers/clk/clk_k210.c| 2 +-
test/dm/k210_pll.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)Quoted 9 lines
drivers/clk/clk_k210.c again: · line 848
Quoted 9 lines
drivers/clk/clk_k210.c +1
-1@@ -846,7 +846,7 @@ again: error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16));Your patch changes the results. Replacing
BIT()byBIT_ULL()does not change the result:error = -1 =
0xffffffffffffffff
before
error - BIT(32) = -4294967297 =0xfffffffeffffffffabs(error - BIT(32)) = 4294967297 =0x100000001abs(error - BIT(32)) >> 16 = 65536 =0x10000after
error >> 16 = -1 =0xffffffffffffffff
(error >> 16) - BIT(32 - 16) = -65537 =0xfffffffffffeffffabs((error >> 16) - BIT(32 - 16)) = 65537 =0x10001usingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =
0x11170
before
error - BIT(32) = -4294897296 =0xffffffff00011170abs(error - BIT(32)) = 4294897296 =0xfffeee90abs(error - BIT(32)) >> 16 = 65534 =0xfffe
after
error >> 16 = 1 =0x1
(error >> 16) - BIT(32 - 16) = -65535 =0xffffffffffff0001abs((error >> 16) - BIT(32 - 16)) = 65535 =0xffffusingBIT_ULLabs(error - BIT_ULL(32))>> 16 = 65534 =0xfffeI assume this change of results is unintended.
We also replace
abs()byabs64()to get correct results on a 32bit system:error = -1 =
0xffffffffffffffffabs(error - BIT_ULL(32))>> 16 = 0 =0x0abs64(error - BIT_ULL(32))>> 16 = 65536 =0x10000error = 70000 =0x11170abs(error - BIT_ULL(32))>> 16 = 1 =0x1abs64(error - BIT_ULL(32))>> 16 = 65534 =0xfffeBest regards
Heinrich
Quoted 14 lines
Quoted 14 lines
drivers/clk/clk_k210.c +0
-0if (error < best_error) { best->r = r;test/dm/k210_pll.c +1
-1@@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 rate, u32 rate_in, error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + error = abs((error >> 16) - BIT(32 - 16)); if (error < best_error) {Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
test/dm/k210_pll.c +0
-0best->r = r;
best->f= f;Signature · 1 line
2.37.3IMO the driver should just be changed to depend on 64-bit. The k210 is 64-bit, and I didn't write anything with 32-bit in mind.
Michal, Simon, and I are striving to get the sandbox working on ilp32 systems.
Do you suggest to remove the driver from
sandbox_defconfig?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
This would imply that the unit test is not executed on Gitlab CI. You will still be able to execute it on the actual hardware.
It's still enabled for sandbox64, so it should still be executed there.
No, the sandbox64 is also to be compiled on ilp32. It models physical address extension (PAE).
Do we have a config for word size?
PHYS_64BITseems to be for the address size.
phys_addr_t is what is used to address physical memory which may be 64bit on a 32bit PAE system (CONFIG_PHYS_64BIT=y).
Compiling on armv7 yields 32bit pointers.
There are two alternative patches in review removing HOST_32BIT and HOST_64BIT:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Best regards
Heinrich
Hello,
Quoted 49 lines · Heinrich Schuchardt
Quoted 35 lines · Sean Anderson
Quoted 34 lines · Heinrich Schuchardt
Quoted 31 lines · Sean Anderson
Quoted 29 lines · Heinrich Schuchardt
Quoted 9 lines · Sean Anderson
Quoted 8 lines · Heinrich Schuchardt
Quoted 5 lines · Michal Suchánek
Quoted 4 lines · Michal Suchanek
k210 is 64bit but the driver and tests are
also built in sandbox, and
that can be built 32bit.Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
BIT(32) does not work on 32bit, shift before
subtraction to fit into
32bit integer with BIT values.IMO the driver should just be changed to depend on 64-bit. The k210 is 64-bit,
and I didn't write anything with 32-bit in mind.Michal, Simon, and I are striving to get the sandbox working on ilp32 systems.
Do you suggest to remove the driver from
sandbox_defconfig?This would imply that the unit test is not executed on Gitlab CI. You will still be able to execute it on the actual hardware.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
It's still enabled for sandbox64, so it should still be executed there.
No, the sandbox64 is also to be compiled on ilp32. It models physical address extension (PAE).
Do we have a config for word size?
PHYS_64BITseems to be for the address size.
phys_addr_tis what is used to address physical memory which may be 64bit on a 32bit PAE system (CONFIG_PHYS_64BIT=y).
Quoted 8 lines
Compiling on armv7 yields 32bit pointers.
There are two alternative patches in review removing
HOST_32BITandHOST_64BIT:https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
I don't think that we have a config option that can be used to detect that the build is 64bit. Such option may exit per platform but drivers that can be built for multiple platforms will have hard time detecting it.
I think that Heinrich's suggestion to use BIT_ULL instead of BIT and abs64 instead of abs is non-controversial. It's technically more correct way to write the expression although relevant only for 32bit.
Thanks
Michal