< prev index next >

test/micro/org/openjdk/bench/jdk/incubator/vector/TestLoadStoreBytes.java

Print this page
*** 1,7 ***
  /*
!  *  Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
   *  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   *  This code is free software; you can redistribute it and/or modify it
   *  under the terms of the GNU General Public License version 2 only, as
   *  published by the Free Software Foundation.
--- 1,7 ---
  /*
!  *  Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
   *  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   *  This code is free software; you can redistribute it and/or modify it
   *  under the terms of the GNU General Public License version 2 only, as
   *  published by the Free Software Foundation.

*** 21,11 ***
   *  questions.
   *
   */
  package org.openjdk.bench.jdk.incubator.vector;
  
- import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  import java.util.concurrent.TimeUnit;
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
--- 21,10 ---

*** 65,86 ***
    private byte[] srcArray;
  
    private byte[] dstArray;
  
  
!   private ByteBuffer srcBufferHeap;
  
!   private ByteBuffer dstBufferHeap;
- 
-   private ByteBuffer srcBufferNative;
- 
-   private ByteBuffer dstBufferNative;
  
  
    private ResourceScope implicitScope;
  
!   private MemorySegment srcSegmentImplicit;
- 
-   private MemorySegment dstSegmentImplicit;
  
!   private ByteBuffer srcBufferSegmentImplicit;
- 
-   private ByteBuffer dstBufferSegmentImplicit;
  
  
    private MemoryAddress srcAddress;
  
    private MemoryAddress dstAddress;
  
!   byte[] a, b, c;
  
    @Setup
    public void setup() {
      srcArray = new byte[size];
      dstArray = srcArray.clone();
      for (int i = 0; i < srcArray.length; i++) {
        srcArray[i] = (byte) i;
      }
  
! 
!     srcBufferHeap = ByteBuffer.allocate(size);
-     dstBufferHeap = ByteBuffer.allocate(size);
- 
-     srcBufferNative = ByteBuffer.allocateDirect(size);
-     dstBufferNative = ByteBuffer.allocateDirect(size);
- 
  
      implicitScope = ResourceScope.newImplicitScope();
!     srcSegmentImplicit = MemorySegment.allocateNative(size, SPECIES.vectorByteSize(), implicitScope);
!     srcBufferSegmentImplicit = srcSegmentImplicit.asByteBuffer();
-     dstSegmentImplicit = MemorySegment.allocateNative(size, SPECIES.vectorByteSize(), implicitScope);
-     dstBufferSegmentImplicit = dstSegmentImplicit.asByteBuffer();
  
! 
!     srcAddress = MemorySegment.allocateNative(size, implicitScope).address();
-     dstAddress = MemorySegment.allocateNative(size, implicitScope).address();
  
      a = new byte[size];
      b = new byte[size];
      c = new byte[size];
    }
  
  
    @Benchmark
    public void array() {
- //    final var srcArray = this.srcArray;
      for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
        var v = ByteVector.fromArray(SPECIES, srcArray, i);
        v.intoArray(dstArray, i);
      }
    }
  
-   @Benchmark
-   public void array2() {
- //    final var srcArray = this.srcArray;
-     for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
-       var v = ByteVector.fromByteArray(SPECIES, srcArray, i, ByteOrder.nativeOrder());
-       v.intoByteArray(dstArray, i, ByteOrder.nativeOrder());
-     }
-   }
- 
    @Benchmark
    public void arrayScalar() {
      for (int i = 0; i < SPECIES.loopBound(srcArray.length); i ++) {
        var v = srcArray[i];
        dstArray[i] = v;
--- 64,60 ---
    private byte[] srcArray;
  
    private byte[] dstArray;
  
  
!   private MemorySegment srcSegmentHeap;
  
!   private MemorySegment dstSegmentHeap;
  
  
    private ResourceScope implicitScope;
  
!   private MemorySegment srcSegment;
  
!   private MemorySegment dstSegment;
  
  
    private MemoryAddress srcAddress;
  
    private MemoryAddress dstAddress;
  
!   private byte[] a, b, c;
  
    @Setup
    public void setup() {
      srcArray = new byte[size];
      dstArray = srcArray.clone();
      for (int i = 0; i < srcArray.length; i++) {
        srcArray[i] = (byte) i;
      }
  
!     srcSegmentHeap = MemorySegment.ofArray(new byte[size]);
!     dstSegmentHeap = MemorySegment.ofArray(new byte[size]);
  
      implicitScope = ResourceScope.newImplicitScope();
!     srcSegment = MemorySegment.allocateNative(size, SPECIES.vectorByteSize(), implicitScope);
!     dstSegment = MemorySegment.allocateNative(size, SPECIES.vectorByteSize(), implicitScope);
  
!     srcAddress = srcSegment.address();
!     dstAddress = dstSegment.address();
  
      a = new byte[size];
      b = new byte[size];
      c = new byte[size];
    }
  
  
    @Benchmark
    public void array() {
      for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
        var v = ByteVector.fromArray(SPECIES, srcArray, i);
        v.intoArray(dstArray, i);
      }
    }
  
    @Benchmark
    public void arrayScalar() {
      for (int i = 0; i < SPECIES.loopBound(srcArray.length); i ++) {
        var v = srcArray[i];
        dstArray[i] = v;

*** 185,68 ***
        v.intoArray(dstArray, i);
      }
    }
  
    @Benchmark
!   public void bufferHeap() {
!     for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
!       var v = ByteVector.fromByteBuffer(SPECIES, srcBufferHeap, i, ByteOrder.nativeOrder());
!       v.intoByteBuffer(dstBufferHeap, i, ByteOrder.nativeOrder());
-     }
-   }
- 
-   @Benchmark
-   public void bufferHeapScalar() {
-     for (int i = 0; i < SPECIES.loopBound(srcArray.length); i++) {
-       var v = srcBufferHeap.get(i);
-       dstBufferHeap.put(i, v);
-     }
-   }
- 
-   @Benchmark
-   @CompilerControl(CompilerControl.Mode.PRINT)
-   public void bufferNative() {
-     for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
-       var v = ByteVector.fromByteBuffer(SPECIES, srcBufferNative, i, ByteOrder.nativeOrder());
-       v.intoByteBuffer(dstBufferNative, i, ByteOrder.nativeOrder());
-     }
-   }
- 
-   @Benchmark
-   public void bufferNativeScalar() {
-     for (int i = 0; i < SPECIES.loopBound(srcArray.length); i++) {
-       var v = srcBufferNative.get(i);
-       dstBufferNative.put(i, v);
-     }
-   }
- 
- 
-   @Benchmark
-   public void bufferSegmentImplicit() {
-     for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
-       var v = ByteVector.fromByteBuffer(SPECIES, srcBufferSegmentImplicit, i, ByteOrder.nativeOrder());
-       v.intoByteBuffer(dstBufferSegmentImplicit, i, ByteOrder.nativeOrder());
      }
    }
  
    @Benchmark
!   @CompilerControl(CompilerControl.Mode.PRINT)
!   public void segmentImplicitScalar() {
!     for (int i = 0; i < SPECIES.loopBound(srcArray.length); i++) {
!       var v = srcSegmentImplicit.get(JAVA_BYTE, i);
-       dstSegmentImplicit.set(JAVA_BYTE, i, v);
      }
    }
  
    @Benchmark
!   public void bufferSegmentConfined() {
      try (final var scope = ResourceScope.newConfinedScope()) {
!       final var srcBufferSegmentConfined = MemorySegment.ofAddress(srcAddress, size, scope).asByteBuffer();
!       final var dstBufferSegmentConfined = MemorySegment.ofAddress(dstAddress, size, scope).asByteBuffer();
  
!       for (int i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
!         var v = ByteVector.fromByteBuffer(SPECIES, srcBufferSegmentConfined, i, ByteOrder.nativeOrder());
!         v.intoByteBuffer(dstBufferSegmentConfined, i, ByteOrder.nativeOrder());
        }
      }
    }
  }
--- 158,33 ---
        v.intoArray(dstArray, i);
      }
    }
  
    @Benchmark
!   public void segmentHeap() {
!     for (long i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
!       var v = ByteVector.fromMemorySegment(SPECIES, srcSegmentHeap, i, ByteOrder.nativeOrder());
!       v.intoMemorySegment(dstSegmentHeap, i, ByteOrder.nativeOrder());
      }
    }
  
    @Benchmark
!   public void segmentNativeImplicit() {
!     for (long i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
!       var v = ByteVector.fromMemorySegment(SPECIES, srcSegment, i, ByteOrder.nativeOrder());
!       v.intoMemorySegment(dstSegment, i, ByteOrder.nativeOrder());
      }
    }
  
    @Benchmark
!   public void segmentNativeConfined() {
      try (final var scope = ResourceScope.newConfinedScope()) {
!       final var srcSegmentConfined = MemorySegment.ofAddress(srcAddress, size, scope);
!       final var dstSegmentConfined = MemorySegment.ofAddress(dstAddress, size, scope);
  
!       for (long i = 0; i < SPECIES.loopBound(srcArray.length); i += SPECIES.length()) {
!         var v = ByteVector.fromMemorySegment(SPECIES, srcSegmentConfined, i, ByteOrder.nativeOrder());
!         v.intoMemorySegment(dstSegmentConfined, i, ByteOrder.nativeOrder());
        }
      }
    }
  }
< prev index next >