pepijnve commented on code in PR #18841:
URL: https://github.com/apache/datafusion/pull/18841#discussion_r2549456142
##########
datafusion/spark/src/function/bitwise/bit_count.rs:
##########
@@ -155,20 +156,6 @@ fn spark_bit_count(value_array: &[ArrayRef]) ->
Result<ArrayRef> {
}
}
Review Comment:
FYI, this algorithm is a SWAR hamming weight implementation. Per the code
comments in `java.lang.Long`, this comes from Hacker's Delight.
What's interesting is that the Rust compiler generates something very
similar when calling
[`count_ones()`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:rust,selection:(endColumn:19,endLineNumber:2,positionColumn:19,positionLineNumber:2,selectionStartColumn:19,selectionStartLineNumber:2,startColumn:19,startLineNumber:2),source:'pub+fn+max_array(x:+i64)+-%3E+u32+%7B%0A++++x.count_ones()%0A%7D%0A'),l:'5',n:'0',o:'Rust+source+%231',t:'0')),k:31.194424417207404,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:r1910,filters:(b:'1',binary:'1',binaryObject:'0',commentOnly:'1',debugCalls:'1',demangle:'0',directives:'1',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:rust,libs:!((name:futures,ver:'0321'),(name:tokio,ver:'1192')),options:'',overrides:!((name:edition,value:'2024'),(name:arch,value:x86_64-unknown-linux-gnu)),selection:(endColumn:1,endLine
Number:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+rustc+1.91.0+(Editor+%231)',t:'0')),k:44.686895173877765,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'rustc+1.91.0',editorid:1,fontScale:14,fontUsePx:'0',j:2,wrap:'1'),l:'5',n:'0',o:'Output+of+rustc+1.91.0+(Compiler+%232)',t:'0')),k:24.11868040891485,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4).
With a sufficiently recent target architecture though you get
[`popcnt`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:rust,selection:(endColumn:19,endLineNumber:2,positionColumn:19,positionLineNumber:2,selectionStartColumn:19,selectionStartLineNumber:2,startColumn:19,startLineNumber:2),source:'pub+fn+max_array(x:+i64)+-%3E+u32+%7B%0A++++x.count_ones()%0A%7D%0A'),l:'5',n:'0',o:'Rust+source+%231',t:'0')),k:31.194424417207404,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:r1910,filters:(b:'1',binary:'1',binaryObject:'0',commentOnly:'1',debugCalls:'1',demangle:'0',directives:'1',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:rust,libs:!((name:futures,ver:'0321'),(name:tokio,ver:'1192')),options:'-C+target_cpu%3Dx86-64-v3',overrides:!((name:edition,value:'2024'),(name:arch,value:x86_64-unknown-linux-gnu)),selection:(endColumn:1,endLineNumber:1,p
ositionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+rustc+1.91.0+(Editor+%231)',t:'0')),k:44.686895173877765,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'rustc+1.91.0',editorid:1,fontScale:14,fontUsePx:'0',j:2,wrap:'1'),l:'5',n:'0',o:'Output+of+rustc+1.91.0+(Compiler+%232)',t:'0')),k:24.11868040891485,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
instead.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]