Re: [PR] libs/log2ceil: Move implementation of log2ceil to a common place [nuttx]

2023-12-14 Thread via GitHub


xiaoxiang781216 merged PR #11386:
URL: https://github.com/apache/nuttx/pull/11386


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libs/log2ceil: Move implementation of log2ceil to a common place [nuttx]

2023-12-14 Thread via GitHub


pussuw commented on code in PR #11386:
URL: https://github.com/apache/nuttx/pull/11386#discussion_r1426865904


##
libs/libc/misc/lib_log2ceil.c:
##
@@ -0,0 +1,55 @@
+/
+ * libs/libc/misc/lib_log2ceil.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+/
+ * Public Functions
+ /
+
+/
+ * Name: log2ceil
+ *
+ * Description:
+ *   Calculate the up-rounded power-of-two for input.
+ *
+ * Input Parameters:
+ *   x - Argument to calculate the power-of-two from.
+ *
+ * Returned Value:
+ *   Power-of-two for argument, rounded up.
+ *
+ /
+
+uintptr_t log2ceil(uintptr_t x)
+{
+  uintptr_t pot = 0;
+
+  for (x = x - 1; x; x >>= 1)

Review Comment:
   @xiaoxiang781216 no I think this is fine as it is.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libs/log2ceil: Move implementation of log2ceil to a common place [nuttx]

2023-12-14 Thread via GitHub


xiaoxiang781216 commented on code in PR #11386:
URL: https://github.com/apache/nuttx/pull/11386#discussion_r1426831408


##
libs/libc/misc/lib_log2ceil.c:
##
@@ -0,0 +1,55 @@
+/
+ * libs/libc/misc/lib_log2ceil.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+/
+ * Public Functions
+ /
+
+/
+ * Name: log2ceil
+ *
+ * Description:
+ *   Calculate the up-rounded power-of-two for input.
+ *
+ * Input Parameters:
+ *   x - Argument to calculate the power-of-two from.
+ *
+ * Returned Value:
+ *   Power-of-two for argument, rounded up.
+ *
+ /
+
+uintptr_t log2ceil(uintptr_t x)
+{
+  uintptr_t pot = 0;
+
+  for (x = x - 1; x; x >>= 1)

Review Comment:
   @pussuw do you plan to change the behavior?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libs/log2ceil: Move implementation of log2ceil to a common place [nuttx]

2023-12-13 Thread via GitHub


hartmannathan commented on code in PR #11386:
URL: https://github.com/apache/nuttx/pull/11386#discussion_r1425412454


##
libs/libc/misc/lib_log2ceil.c:
##
@@ -0,0 +1,55 @@
+/
+ * libs/libc/misc/lib_log2ceil.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+/
+ * Public Functions
+ /
+
+/
+ * Name: log2ceil
+ *
+ * Description:
+ *   Calculate the up-rounded power-of-two for input.
+ *
+ * Input Parameters:
+ *   x - Argument to calculate the power-of-two from.
+ *
+ * Returned Value:
+ *   Power-of-two for argument, rounded up.
+ *
+ /
+
+uintptr_t log2ceil(uintptr_t x)
+{
+  uintptr_t pot = 0;
+
+  for (x = x - 1; x; x >>= 1)

Review Comment:
   In that case, maybe better to leave it alone. This way, a too-big value (64 
or 32) can indicate "invalid".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libs/log2ceil: Move implementation of log2ceil to a common place [nuttx]

2023-12-13 Thread via GitHub


pussuw commented on code in PR #11386:
URL: https://github.com/apache/nuttx/pull/11386#discussion_r1425384725


##
libs/libc/misc/lib_log2ceil.c:
##
@@ -0,0 +1,55 @@
+/
+ * libs/libc/misc/lib_log2ceil.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+/
+ * Public Functions
+ /
+
+/
+ * Name: log2ceil
+ *
+ * Description:
+ *   Calculate the up-rounded power-of-two for input.
+ *
+ * Input Parameters:
+ *   x - Argument to calculate the power-of-two from.
+ *
+ * Returned Value:
+ *   Power-of-two for argument, rounded up.
+ *
+ /
+
+uintptr_t log2ceil(uintptr_t x)
+{
+  uintptr_t pot = 0;
+
+  for (x = x - 1; x; x >>= 1)

Review Comment:
   The result of log2(0) is undefined so I did not think it would be necessary 
to explicitly catch it. But yes doing that is one option.
   
   Like you mentioned, the loop will take uintptr_t bitwidth iterations, so did 
not think it would be a fatal issue.
   
   Whichever you guys prefer is fine by me.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libs/log2ceil: Move implementation of log2ceil to a common place [nuttx]

2023-12-13 Thread via GitHub


hartmannathan commented on code in PR #11386:
URL: https://github.com/apache/nuttx/pull/11386#discussion_r1425375424


##
libs/libc/misc/lib_log2ceil.c:
##
@@ -0,0 +1,55 @@
+/
+ * libs/libc/misc/lib_log2ceil.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+/
+ * Public Functions
+ /
+
+/
+ * Name: log2ceil
+ *
+ * Description:
+ *   Calculate the up-rounded power-of-two for input.
+ *
+ * Input Parameters:
+ *   x - Argument to calculate the power-of-two from.
+ *
+ * Returned Value:
+ *   Power-of-two for argument, rounded up.
+ *
+ /
+
+uintptr_t log2ceil(uintptr_t x)
+{
+  uintptr_t pot = 0;
+
+  for (x = x - 1; x; x >>= 1)

Review Comment:
   Just want to point out that `x = x - 1` in for-loop initialization will 
underflow. So if `x` is 0, log2ceil(0) will return 64.  (If `uintptr_t` is 32 
bit, it will return 32.) Is this the intended result?
   
   If not, then we will need to guard it with something like
   ```
   if (x == 0)
 return 0;
   ```
   
   Also, can write `x = x - 1` as `x--` or `--x`, but that's just minor nit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libs/log2ceil: Move implementation of log2ceil to a common place [nuttx]

2023-12-13 Thread via GitHub


pussuw commented on code in PR #11386:
URL: https://github.com/apache/nuttx/pull/11386#discussion_r1425332025


##
libs/libc/misc/lib_log2ceil.c:
##
@@ -0,0 +1,55 @@
+/
+ * libs/libc/misc/lib_log2ceil.c

Review Comment:
   Yes, forgot that. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libs/log2ceil: Move implementation of log2ceil to a common place [nuttx]

2023-12-13 Thread via GitHub


xiaoxiang781216 commented on code in PR #11386:
URL: https://github.com/apache/nuttx/pull/11386#discussion_r1425330041


##
libs/libc/misc/lib_log2ceil.c:
##
@@ -0,0 +1,55 @@
+/
+ * libs/libc/misc/lib_log2ceil.c

Review Comment:
   need add to Make.defs and CMakelist.txt



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org