Illegal use of FP ops in clock_ti814x.c
Dear Matt,
I hope you are the right person to address this to - if not, please help to redirect to the current responsible developer.
Function pll_sigma_delta_val() in arch/arm/cpu/armv7/am33xx/clock_ti814x.c incorrectly uses "float" data, which results in FP operations which are not permitted in U-Boot.
The actual computation appears simple enough so a rewrite of the code without using any floating point operations should be fairly easy, but I don't understand the actual logic of this code, so I'd rather leave this to someone who does.
Could you please help and clean up these three lines of code?
Thanks in advance.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Here is an Appalachian version of management's answer to those who are concerned with the fate of the project: "Don't worry about the mule. Just load the wagon." - Mike Dennison's hillbilly uncle
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 10 lines · Wolfgang Denk
Dear Matt,
I hope you are the right person to address this to - if not, please help to redirect to the current responsible developer.
Function
pll_sigma_delta_val()inarch/arm/cpu/armv7/am33xx/clock_ti814x.cincorrectly uses "float" data, which results in FP operations which are not permitted in U-Boot.
Quoted 6 lines
The actual computation appears simple enough so a rewrite of the code without using any floating point operations should be fairly easy, but I don't understand the actual logic of this code, so I'd rather leave this to someone who does.
Could you please help and clean up these three lines of code?
Matt's moved on to Linaro now (and this is a more public poke to update the maintainers entry you owe me). Care to look at this?
- --
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBAgAGBQJSbt1nAAoJENk4IS6UOR1Wdy8P/RT18/UG5TBQugaSdqAkscS1 oMRz5M35qZvUuTjRj7JwRMXs/WGhVLO4NP5zDM0eYdo6pD/Z4ZnCPXUpRa46w4X/ xvusu9m+fpKsy/+gEOeOw4+JQ1OnMCLuP0OxpJfvKYwXEOjji5mGxAhxpCTogBFX 6l6vAYiEcYYG2S58AuGFYL9l0y0x7kZNnvfAzM5xJgxNOhxmGefGABuILXWRs5mt rHQBrPlofc+E2n73BxSAxk35cqy1Fm6CP35ETuKb3NMonoYbtXebh3ADyjxaNdf6 IZHpTserTNLaSGUSq2QVrF9zOnQKj/R4fuTbV7biUI3lF5JqVLO+jsx+E5XwTJpD bkQlD+vbmSnzK5HebUG6qEFHWxChjPJ0URSvlb0WBrlQJX9TkK4Xetq9ou6FaSpR xnZ/X6zDuBiuyWdmw01D0en8WSTMHCnYHQ7yAZjL3tuvjoJ6p4xCMFe2FZJE4UUn p1pT+h3zMipwjDrZ57NureCY7mWdCsRBgIR18MTmjF7XYzo7+4F+yi2aaGifGmPu zo1zp+1ijjQCVylw2OXGp09ej6azJcVoaRVS7FBEtd5u6MaSBhgfXTvR1bSB5mqw PbxlnXgfumv+VK3S036FtFXuT8lCx6kWlSLOa9HZSHrwjO0eQv+IeuoVigUnzfq/ oMHEAwDoaJbMjPDgFE2O
=c8xm
-----END PGP SIGNATURE-----
Quoted 9 lines · Wolfgang Denk
Dear Matt,
I hope you are the right person to address this to - if not, please help to redirect to the current responsible developer.
Function
pll_sigma_delta_val()inarch/arm/cpu/armv7/am33xx/clock_ti814x.cincorrectly uses "float" data, which results in FP operations which are not permitted in U-Boot.
Quoted 6 lines
The actual computation appears simple enough so a rewrite of the code without using any floating point operations should be fairly easy, but I don't understand the actual logic of this code, so I'd rather leave this to someone who does.
Could you please help and clean up these three lines of code?
Something like this should be equivalent. That said, it looks suspiciously like it's meant to simply do a division and round up. If that is the case, +225 should be +249. It probably makes no difference for the values actually encountered.
arch/arm/cpu/armv7/am33xx/clock_ti814x.c +1 -4
@@ -211,11 +211,8 @@ static u32 pll_dco_freq_sel(u32 clkout_dco)static u32 pll_sigma_delta_val (u32 clkout_dco) {u32 sig_val =0 ; -float frac_div; - frac_div = (float ) clkout_dco /250 ; - frac_div = frac_div +0.90 ; - sig_val = (int )frac_div; + sig_val = (clkout_dco +225 ) /250 ; sig_val = sig_val <<24 ;return sig_val;
Signature · 2 lines
M?ns Rullg?rd [email protected]
Dear M?ns Rullg?rd,
Quoted 5 lines · In message <[email protected]> you wrote:
Something like this should be equivalent. That said, it looks suspiciously like it's meant to simply do a division and round up. If that is the case, +225 should be +249. It probably makes no difference for the values actually encountered.
Umm... this is the part which I do not understand.
The original code adds 90%; you add 90%, too. However, to round up, one usually adds only 50% ?
Quoted 5 lines
arch/arm/cpu/armv7/am33xx/clock_ti814x.c +0
-0
arch/arm/cpu/armv7/am33xx/clock_ti814x.c static u32 pll_dco_freq_sel(u32 clkout_dco) · line 216
Quoted 10 lines
arch/arm/cpu/armv7/am33xx/clock_ti814x.c +1
-4@@ -211,11 +211,8 @@ static u32 pll_dco_freq_sel(u32 clkout_dco)static u32 pll_sigma_delta_val (u32 clkout_dco) {u32 sig_val =0 ; -float frac_div; - frac_div = (float ) clkout_dco /250 ; - frac_div = frac_div +0.90 ; - sig_val = (int )frac_div; + sig_val = (clkout_dco +225 ) /250 ; sig_val = sig_val <<24 ;
Where are these 90% coming from? Are they in any way meaningful, or even critical?
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected] I still miss my ex-wife, but my aim is getting better.
Quoted 9 lines · Wolfgang Denk
Dear M?ns Rullg?rd,
Quoted 5 lines · In message <[email protected]> you wrote:
Something like this should be equivalent. That said, it looks suspiciously like it's meant to simply do a division and round up. If that is the case, +225 should be +249. It probably makes no difference for the values actually encountered.
Quoted 4 lines
Umm... this is the part which I do not understand.
The original code adds 90%; you add 90%, too. However, to round up, one usually adds only 50% ?
Adding 50% would round to nearest. For integer division to round up, you must add one less than the divisor.
Quoted 10 lines
Quoted 10 lines
arch/arm/cpu/armv7/am33xx/clock_ti814x.c +0
-1@@ -211,11 +211,8 @@ static u32 pll_dco_freq_sel(u32 clkout_dco)static u32 pll_sigma_delta_val (u32 clkout_dco) {u32 sig_val =0 ; -float frac_div;
Quoted 8 lines
arch/arm/cpu/armv7/am33xx/clock_ti814x.c static u32 pll_dco_freq_sel(u32 clkout_dco) · line 216
Quoted 5 lines
arch/arm/cpu/armv7/am33xx/clock_ti814x.c +1
-3- frac_div = (float ) clkout_dco /250 ; - frac_div = frac_div +0.90 ; - sig_val = (int )frac_div; + sig_val = (clkout_dco +225 ) /250 ; sig_val = sig_val <<24 ;Where are these 90% coming from? Are they in any way meaningful, or even critical?
My guess is that it was someone's approximation of 249 / 250. I don't know the hardware, so it's conceivable that it really should be this way, although it seems unlikely.
Signature · 2 lines
M?ns Rullg?rd mans at mansr.com
Dear M?ns Rullg?rd,
Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 6 lines
Quoted 5 lines
Something like this should be equivalent. That said, it looks suspiciously like it's meant to simply do a division and round up. If that is the case, +225 should be +249. It probably makes no difference for the values actually encountered.
Quoted 7 lines
Quoted 4 lines
Umm... this is the part which I do not understand.
The original code adds 90%; you add 90%, too. However, to round up, one usually adds only 50% ?
Adding 50% would round to nearest. For integer division to round up, you must add one less than the divisor.
Agreed. But do we want to round up? The original code used +90%, which is something else, too...
Quoted 6 lines
Quoted 2 lines
Where are these 90% coming from? Are they in any way meaningful, or even critical?
My guess is that it was someone's approximation of 249 / 250. I don't know the hardware, so it's conceivable that it really should be this way, although it seems unlikely.
Are you able to test such a modificationon actual hardware?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "The X11 source code style is ATROCIOUS and should not be used as a model." - Doug Gwyn
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 12 lines · Wolfgang Denk
Dear M?ns Rullg?rd,
Quoted 9 lines · In message <[email protected]> you wrote:
Quoted 9 lines
Quoted 6 lines
Something like this should be equivalent. That said, it looks suspiciously like it's meant to simply do a division and round up. If that is the case, +225 should be +249. It probably makes no difference for the values actually encountered.
Umm... this is the part which I do not understand.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The original code adds 90%; you add 90%, too. However, to round up, one usually adds only 50% ?
Adding 50% would round to nearest. For integer division to round up, you must add one less than the divisor.
Agreed. But do we want to round up? The original code used +90%, which is something else, too...
And I imagine it's unlikely the original author of the code is around anymore, or recalls exactly why. I'm pretty sure Matt just lifted the code from the vendor tree and since it wasn't throwing warnings didn't notice the floating point part.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Where are these 90% coming from? Are they in any way meaningful, or even critical?
My guess is that it was someone's approximation of 249 / 250. I don't know the hardware, so it's conceivable that it really should be this way, although it seems unlikely.
Are you able to test such a modificationon actual hardware?
I suspect Matt can, after Linaro Connect. I don't have one of these platforms handy but I think he still does.
- --
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBAgAGBQJSb6iqAAoJENk4IS6UOR1W+JkP/j7MJ2s9RxNCpRTi+nvXgSL1 A9SWL0rAbgl6ggiYU1tIE1NUxrNmlaLJxzP/VKciJ7wPeHkmiZN4gsL5JmsbIj9y eWh1eqyXPI8Tv69x0v8JsDBC8hHHBgnWqe8afsLN0ZspU77GGgFAx0Dq7lfaaGZt GopTHbBEf9pePbE8X3y11kxtjyF5SJfdfvPsEFbNeuR5fkfqcanvNPi6uhYDnwgz UwW0htFyAO3vmZHv7Yhh5XhF+sIgHzEsYzZBZ0KVf+pDpyMd2Ni8RG1RTt66UHqE kuPLIU9EwZYBUTh0DGtx/QFYOHCAUTpAYV5OhLL2ycIpzF3CRj/cBdnhiDk7LPPz 5G5heIJmRxyTkvjdm4Lh552NQBo6oWVJP+NFIejYG3aD632lH+cp1lDxjPzk3LGQ qVwyE+rRiY96VW6qMeBzFxBJ3J4k73zxdyY4eM9Ka2uzWqM3rykZ1EESaDTrDTQ9 DnI9E1QVuXQLjaTZ0RjKVw8XA/yPlBZ/LVIQDpEUr0WV9+Qgjs94B6H1flkygcqW DLyg+PpB5czNNtMdAbj55wzXNmAX39MIKHkR0OWm5HEGg26u/zjlYF1kk1YeuQNT mgWhNohtRARkJMfUXmSu5M9e2S3elNcv61GnOzRajgTzO8XjkXO4LYjyfarIzGdK FitrvVe8n00RGK3u6M9j
=hWQX
-----END PGP SIGNATURE-----
Matt Porter
Acked-byQuoted 33 lines · Tom Rini
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 12 lines · Wolfgang Denk
Dear M?ns Rullg?rd,
Quoted 9 lines · In message <[email protected]> you wrote:
Quoted 9 lines
Quoted 6 lines
Something like this should be equivalent. That said, it looks suspiciously like it's meant to simply do a division and round up. If that is the case, +225 should be +249. It probably makes no difference for the values actually encountered.
Umm... this is the part which I do not understand.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The original code adds 90%; you add 90%, too. However, to round up, one usually adds only 50% ?
Adding 50% would round to nearest. For integer division to round up, you must add one less than the divisor.
Agreed. But do we want to round up? The original code used +90%, which is something else, too...
And I imagine it's unlikely the original author of the code is around anymore, or recalls exactly why. I'm pretty sure Matt just lifted the code from the vendor tree and since it wasn't throwing warnings didn't notice the floating point part.
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Where are these 90% coming from? Are they in any way meaningful, or even critical?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
My guess is that it was someone's approximation of 249 / 250. I don't know the hardware, so it's conceivable that it really should be this way, although it seems unlikely.
Are you able to test such a modificationon actual hardware?
I suspect Matt can, after Linaro Connect. I don't have one of these platforms handy but I think he still does.
Thankfully Tom reminded me of this because I lost some of the list traffic due to some local mail issues.
Although not explicitly mentioned in the TRM or any application notes I can find, the 90% appears to come from jitter compensation for the delta sigma fractional divider. I see some comments that imply this in various old vendor kernel tree clock implementations where they are rounding various pll constants. I can't be 100% sure without some insight from TI folks. Given that it's working for our known users, I'd like to preserve that until we get somebody that can shed some light on that.
As Tom guessed, I low-level cherry-picked a lot of pieces from long-lost authors in this area. I obviously missed this floating point math in the cleanup.
I tested this patch on my TI8148 EVM and it works as expected.
-Matt
Quoted 11 lines · Wolfgang Denk
Dear M?ns Rullg?rd,
Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 8 lines
Quoted 5 lines
Something like this should be equivalent. That said, it looks suspiciously like it's meant to simply do a division and round up. If that is the case, +225 should be +249. It probably makes no difference for the values actually encountered.
Umm... this is the part which I do not understand.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The original code adds 90%; you add 90%, too. However, to round up, one usually adds only 50% ?
Adding 50% would round to nearest. For integer division to round up, you must add one less than the divisor.
Agreed. But do we want to round up? The original code used +90%, which is something else, too...
That rounds fractions >= 0.1 up while < 0.1 is rounded down. It's an unusual thing to do, which is why I suspect it's not quite correct in the first place.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Where are these 90% coming from? Are they in any way meaningful, or even critical?
My guess is that it was someone's approximation of 249 / 250. I don't know the hardware, so it's conceivable that it really should be this way, although it seems unlikely.
Are you able to test such a modificationon actual hardware?
No.
Signature · 2 lines
M?ns Rullg?rd mans at mansr.com
Quoted 32 lines · M?ns Rullg?rd
Quoted 9 lines · Wolfgang Denk
Dear Matt,
I hope you are the right person to address this to - if not, please help to redirect to the current responsible developer.
Function
pll_sigma_delta_val()inarch/arm/cpu/armv7/am33xx/clock_ti814x.cincorrectly uses "float" data, which results in FP operations which are not permitted in U-Boot.Quoted 6 lines
The actual computation appears simple enough so a rewrite of the code without using any floating point operations should be fairly easy, but I don't understand the actual logic of this code, so I'd rather leave this to someone who does.
Could you please help and clean up these three lines of code?
Something like this should be equivalent. That said, it looks suspiciously like it's meant to simply do a division and round up. If that is the case, +225 should be +249. It probably makes no difference for the values actually encountered.
Acked-by Matt Porter <[email protected]>arch/arm/cpu/armv7/am33xx/clock_ti814x.c +0
-0@@ -211,11 +211,8 @@ static u32 pll_dco_freq_sel(u32 clkout_dco)static u32 pll_sigma_delta_val (u32 clkout_dco) {
arch/arm/cpu/armv7/am33xx/clock_ti814x.c static u32 pll_dco_freq_sel(u32 clkout_dco) · line 218
Quoted 10 lines
arch/arm/cpu/armv7/am33xx/clock_ti814x.c +1
-4u32 sig_val =0 ; -float frac_div; - frac_div = (float ) clkout_dco /250 ; - frac_div = frac_div +0.90 ; - sig_val = (int )frac_div; + sig_val = (clkout_dco +225 ) /250 ; sig_val = sig_val <<24 ;return sig_val;
With a massively re-worded commit message, applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140221/6faf9ab1/attachment.pgp>