1 /*
   2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2012, 2013 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #ifndef CPU_PPC_VM_COPY_PPC_HPP
  27 #define CPU_PPC_VM_COPY_PPC_HPP
  28 
  29 #ifndef PPC64
  30 #error "copy currently only implemented for PPC64"
  31 #endif
  32 
  33 // Inline functions for memory copy and fill.
  34 
  35 static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
  36   (void)memmove(to, from, count * HeapWordSize);
  37 }
  38 
  39 static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
  40   switch (count) {
  41   case 8:  to[7] = from[7];
  42   case 7:  to[6] = from[6];
  43   case 6:  to[5] = from[5];
  44   case 5:  to[4] = from[4];
  45   case 4:  to[3] = from[3];
  46   case 3:  to[2] = from[2];
  47   case 2:  to[1] = from[1];
  48   case 1:  to[0] = from[0];
  49   case 0:  break;
  50   default: (void)memcpy(to, from, count * HeapWordSize);
  51            break;
  52   }
  53 }
  54 
  55 static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
  56   switch (count) {
  57   case 8:  to[7] = from[7];
  58   case 7:  to[6] = from[6];
  59   case 6:  to[5] = from[5];
  60   case 5:  to[4] = from[4];
  61   case 4:  to[3] = from[3];
  62   case 3:  to[2] = from[2];
  63   case 2:  to[1] = from[1];
  64   case 1:  to[0] = from[0];
  65   case 0:  break;
  66   default: while (count-- > 0) {
  67              *to++ = *from++;
  68            }
  69            break;
  70   }
  71 }
  72 
  73 static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
  74   (void)memmove(to, from, count * HeapWordSize);
  75 }
  76 
  77 static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
  78   pd_disjoint_words(from, to, count);
  79 }
  80 
  81 static void pd_conjoint_bytes(void* from, void* to, size_t count) {
  82   (void)memmove(to, from, count);
  83 }
  84 
  85 static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
  86   (void)memmove(to, from, count);
  87 }
  88 
  89 // Template for atomic, element-wise copy.
  90 template <class T>
  91 static void copy_conjoint_atomic(T* from, T* to, size_t count) {
  92   if (from > to) {
  93     while (count-- > 0) {
  94       // Copy forwards
  95       *to++ = *from++;
  96     }
  97   } else {
  98     from += count - 1;
  99     to   += count - 1;
 100     while (count-- > 0) {
 101       // Copy backwards
 102       *to-- = *from--;
 103     }
 104   }
 105 }
 106 
 107 static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
 108   copy_conjoint_atomic<jshort>(from, to, count);
 109 }
 110 
 111 static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
 112   copy_conjoint_atomic<jint>(from, to, count);
 113 }
 114 
 115 static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
 116   copy_conjoint_atomic<jlong>(from, to, count);
 117 }
 118 
 119 static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
 120   copy_conjoint_atomic<oop>(from, to, count);
 121 }
 122 
 123 static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
 124   pd_conjoint_bytes_atomic(from, to, count);
 125 }
 126 
 127 static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
 128   pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
 129 }
 130 
 131 static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
 132   pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
 133 }
 134 
 135 static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
 136   pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
 137 }
 138 
 139 static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
 140   pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
 141 }
 142 
 143 static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
 144   julong* to = (julong*)tohw;
 145   julong  v  = ((julong)value << 32) | value;
 146   while (count-- > 0) {
 147     *to++ = v;
 148   }
 149 }
 150 
 151 static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) {
 152   pd_fill_to_words(tohw, count, value);
 153 }
 154 
 155 static void pd_fill_to_bytes(void* to, size_t count, jubyte value) {
 156   (void)memset(to, value, count);
 157 }
 158 
 159 static void pd_zero_to_words(HeapWord* tohw, size_t count) {
 160   pd_fill_to_words(tohw, count, 0);
 161 }
 162 
 163 static void pd_zero_to_bytes(void* to, size_t count) {
 164   (void)memset(to, 0, count);
 165 }
 166 
 167 #endif // CPU_PPC_VM_COPY_PPC_HPP