This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PopCntBenchmark extends SimpleBenchmark | |
{ | |
public int timeIntegerBitCount(int iterations) | |
{ | |
int result = 0; | |
for (int i = 0; i < iterations; i++) | |
{ | |
result += Integer.bitCount(i); | |
} | |
return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
popcnt %r11d,%ebx | |
add 0x8(%rsi),%ebx ;*iadd | |
; - PopCntTest::main@12 (line 9) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mov %r11d,%r8d | |
shr %r8d | |
and $0x55555555,%r8d | |
sub %r8d,%r11d ;*isub | |
; - java.lang.Integer::bitCount@7 (line 1143) | |
; - PopCntTest::main@9 (line 9) | |
mov %r11d,%r8d | |
shr $0x2,%r8d | |
and $0x33333333,%r11d | |
and $0x33333333,%r8d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Integer | |
{ | |
public static int bitCount(int i) | |
{ | |
// HD, Figure 5-2 | |
i = i - ((i >>> 1) & 0x55555555); | |
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333); | |
i = (i + (i >>> 4)) & 0x0f0f0f0f; | |
i = i + (i >>> 8); | |
i = i + (i >>> 16); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PopCntTest | |
{ | |
public static void main(String[] args) | |
{ | |
int result = 0; | |
for (int i = 0; i < 1000000000; i++) | |
{ | |
result += Integer.bitCount(i); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lmax.disruptor; | |
import java.util.concurrent.BrokenBarrierException; | |
import java.util.concurrent.CyclicBarrier; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.TimeUnit; | |
import org.junit.Test; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" { | |
/* from sys/osfmk/i386/mp.c */ | |
extern void mp_rendezvous(void (*setup_func)(void *), | |
void (*action_func)(void *), | |
void (*teardown_func)(void *), | |
void *arg); | |
extern int cpu_number(void); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
static void cpuid(int op1, int op2, int *data) { | |
asm("cpuid" | |
: "=a" (data[0]), "=b" (data[1]), "=c" (data[2]), "=d" (data[3]) | |
: "a"(op1), "c"(op2)); | |
} | |
int main (int argc, const char * argv[]) { | |
int values[4]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
static void cpuid(int op1, int op2, int *data) { | |
asm("cpuid" | |
: "=a" (data[0]), "=b" (data[1]), "=c" (data[3]), "=d" (data[2]) | |
: "a"(op1), "c"(op2)); | |
} | |
int main(int argc, char** argv) { | |
int values[5]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void serialisePublishing(final long sequence, | |
final Sequence cursor, | |
final int batchSize) { | |
// Guard condition, limit the number of pending publications | |
int counter = RETRIES; | |
while (sequence - cursor.get() > pendingPublication.length()) { | |
if (--counter == 0) { | |
Thread.yield(); | |
counter = RETRIES; |