Changeset 15347


Ignore:
Timestamp:
07/22/20 07:33:26 (3 years ago)
Author:
Mark Evenson
Message:

Further (INCOMPLETE) work on byte vectors

GOAL: completely remove allocation of any UnsignedByte32 in

make_array.java. Surprised that it mostly works this way…

Fix directAllocation in SimpleArray_CharBuffer.java

TODO: finish checking the directAllocation for types

TODO: finish refactoring lisp.coerce…method names

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Lisp.java

    r15305 r15347  
    16531653  }
    16541654
     1655  // TODO rename to coerceToJavaChar
    16551656  public static final char coerceLispObjectToJavaChar(LispObject obj) {
    16561657    return (char)Fixnum.getValue(obj);
    16571658  }
    16581659
     1660  // TODO rename to coerceToJavaByte
    16591661  public static final byte coerceLispObjectToJavaByte(LispObject obj)
    1660 
    16611662  {
    16621663          return (byte)Fixnum.getValue(obj);
    16631664  }
    16641665
     1666  public static final int coerceToJavaUnsignedInt(LispObject obj) {
     1667    return (int) (obj.longValue() & 0xffffffffL);
     1668  }
     1669  // TODO rename to coerceFromJavaByte
    16651670  public static final LispObject coerceJavaByteToLispObject(byte b)
    16661671  {
  • trunk/abcl/src/org/armedbear/lisp/SimpleArray_CharBuffer.java

    r15305 r15347  
    5656    this.directAllocation = directAllocation;
    5757    if (directAllocation) {
    58       ByteBuffer b = ByteBuffer.allocate(totalSize * 2);
     58      ByteBuffer b = ByteBuffer.allocateDirect(totalSize * 2);
    5959      data = b.asCharBuffer();
    6060    } else {
  • trunk/abcl/src/org/armedbear/lisp/SimpleArray_UnsignedByte32.java

    r15143 r15347  
    3535
    3636import static org.armedbear.lisp.Lisp.*;
     37
     38/*
     39 N.b. this implementation has problems somewhere with converting bytes
     40
     41      Not fixing currently, as this type is unused with NIO
     42
     43(let* ((unspecialized
     44         #(2025373960 3099658457 3238582529 148439321
     45           3099658456 3238582528 3000000000 1000000000
     46           2000000000 2900000000 2400000000 2800000000
     47           0 1))
     48       (array
     49         (make-array (length unspecialized)
     50                     :element-type '(unsigned-byte 32)
     51                     :initial-contents unspecialized)))
     52  (prove:plan (length array))
     53  (loop :for i :below (length array)
     54        :doing
     55           (let ((x0
     56                   (elt unspecialized i))
     57                 (x1
     58                   (elt array i)))
     59           (prove:ok
     60            (equal x0 x1)
     61            (format nil "~a: ~a equals ~a" i x0 x1)))))
     62*/
    3763
    3864public final class SimpleArray_UnsignedByte32 extends AbstractArray
  • trunk/abcl/src/org/armedbear/lisp/make_array.java

    r15307 r15347  
    112112                // an abstract array doesn't have a directAllocation  ???
    113113                v = new ComplexVector_ByteBuffer(dimv[0], array, displacement, directAllocation);
    114               } else if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY)) {
     114              } else { // if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY))
    115115                v = new ComplexVector_UnsignedByte8(dimv[0], array, displacement);
    116116              }
    117117            } else if (arrayElementType.equal(UNSIGNED_BYTE_32)) {
    118               v = new ComplexVector_UnsignedByte32(dimv[0], array, displacement);
     118              if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
     119                // an abstract array doesn't have a directAllocation  ???
     120                v = new ComplexVector_IntBuffer(dimv[0], array, displacement, directAllocation);
     121              } else { //if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY))
     122                v = new ComplexVector_UnsignedByte32(dimv[0], array, displacement);
     123              }
    119124            } else {
    120125              v = new ComplexVector(dimv[0], array, displacement);
     
    208213            defaultInitialElement = Fixnum.ZERO;
    209214          }
    210         else if (upgradedType.equal(UNSIGNED_BYTE_32))
    211           {
    212             if (fillPointer != NIL || adjustable != NIL)
    213               v = new ComplexVector_UnsignedByte32(size);
    214             else {
    215               if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
    216                 v = new BasicVector_IntBuffer(size, directAllocation);
    217               } else { //if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY)) {
    218                 v = new BasicVector_UnsignedByte32(size);
    219               }
    220             }
    221             defaultInitialElement = Fixnum.ZERO;
    222           }
     215        else if (upgradedType.equal(UNSIGNED_BYTE_32)) {
     216          if (fillPointer != NIL || adjustable != NIL) {
     217            v = new ComplexVector_UnsignedByte32(size);
     218          } else {
     219            if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
     220              v = new BasicVector_IntBuffer(size, directAllocation);
     221            } else { //if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY)) {
     222              v = new BasicVector_UnsignedByte32(size);
     223            }
     224          }
     225          defaultInitialElement = Fixnum.ZERO;
     226        }
    223227        else if (upgradedType == NIL)
    224228          {
     
    315319          }
    316320        }
    317         // N.b. There is no implementation of SimpleArray with
    318         // contents (unsigned-byte 32) using either a
    319         // primitive array or an nio.Buffer
    320         else if (upgradedType.equal(UNSIGNED_BYTE_32))
    321           {
    322             if (initialContents != NIL)
    323               {
    324                 array = new SimpleArray_UnsignedByte32(dimv, initialContents);
    325               }
    326             else
    327               {
    328                 array = new SimpleArray_UnsignedByte32(dimv);
    329                 if (initialElementProvided != NIL)
    330                   array.fill(initialElement);
    331                 else
    332                   array.fill(Fixnum.ZERO);
    333               }
    334           }
    335         else
     321        else if (upgradedType.equal(UNSIGNED_BYTE_32)) {
     322          if (initialContents != NIL) {
     323            if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
     324              array = new SimpleArray_IntBuffer(dimv, initialContents, directAllocation);
     325            } else { //if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY)) {
     326              array = new SimpleArray_UnsignedByte32(dimv, initialContents);
     327            }
     328          } else {
     329            if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
     330              array = new SimpleArray_IntBuffer(dimv, directAllocation);
     331            } else {
     332              array = new SimpleArray_UnsignedByte32(dimv);
     333            }
     334            if (initialElementProvided != NIL) {
     335              array.fill(initialElement);
     336            } else {
     337              array.fill(Fixnum.ZERO);
     338            }
     339          }
     340        } else
    336341          {
    337342            if (initialContents != NIL)
     
    372377              }
    373378          }
    374         else if (upgradedType.equal(UNSIGNED_BYTE_32))
    375           {
    376             if (initialContents != NIL)
    377               {
    378                 array = new ComplexArray_UnsignedByte32(dimv, initialContents);
    379               }
    380             else
    381               {
    382                 array = new ComplexArray_UnsignedByte32(dimv);
    383                 if (initialElementProvided != NIL)
    384                   array.fill(initialElement);
    385                 else
    386                   array.fill(Fixnum.ZERO);
    387               }
    388           }
     379        else if (upgradedType.equal(UNSIGNED_BYTE_32)) {
     380          if (initialContents != NIL) {
     381            if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
     382              array = new ComplexArray_IntBuffer(dimv, initialContents, directAllocation);
     383            } else {  //if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY)) {
     384              array = new ComplexArray_UnsignedByte32(dimv, initialContents);
     385            }
     386          } else {
     387            if (Java.Buffers.active.equals(AllocationPolicy.NIO)) {
     388              array = new ComplexArray_IntBuffer(dimv, directAllocation);
     389            } else {  //if (Java.Buffers.active.equals(AllocationPolicy.PRIMITIVE_ARRAY)) {
     390              array = new ComplexArray_UnsignedByte32(dimv);
     391            }
     392            if (initialElementProvided != NIL) {
     393              array.fill(initialElement);
     394            } else {
     395              array.fill(Fixnum.ZERO);
     396            }
     397          }
     398        }
    389399        else
    390400          {
Note: See TracChangeset for help on using the changeset viewer.