Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

24
LINES

< > BotCompany Repo | #1036056 // countDifferingBits_vectorAPI [for JDK 19, OK but slower than unvectorized]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Compilation Failed (56L/1K).

1  
import jdk.incubator.vector.*;
2  
3  
static int countDifferingBits_vectorAPI(long[] array1, long[] array2, int i1) {
4  
  VectorSpecies<Long> SPECIES = LongVector.SPECIES_PREFERRED;
5  
  
6  
  int diff = 0;
7  
  int n = array1.length;
8  
  var upperBound = SPECIES.loopBound(n);
9  
10  
  var i = 0;
11  
  for (; i < upperBound; i += SPECIES.length()) {
12  
    var vector1 = LongVector.fromArray(SPECIES, array1, i);
13  
    var vector2 = LongVector.fromArray(SPECIES, array2, i1+i);
14  
    var xored = vector1.lanewise(VectorOperators.XOR, vector2);
15  
    var bitCount = xored.lanewise(VectorOperators.BIT_COUNT);
16  
    diff += (int) bitCount.reduceLanes(VectorOperators.ADD);
17  
  } 
18  
  
19  
  // Compute elements not fitting in the vector alignment.
20  
  for (; i < n; i++)
21  
    diff += Long.bitCount(array1[i]^array2[i1+i]);
22  
23  
  ret diff;
24  
}

Author comment

Began life as a copy of #1030540

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036056
Snippet name: countDifferingBits_vectorAPI [for JDK 19, OK but slower than unvectorized]
Eternal ID of this version: #1036056/19
Text MD5: cd0bcc9c44bdb6f682bb5a9a45e9b764
Transpilation MD5: 1d3886404fdefec873ec7ef6ee8a0bf6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-06 23:32:03
Source code size: 809 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 158 / 275
Version history: 18 change(s)
Referenced in: [show references]