mlib_c_ImageCopy.c revision 2362
0N/A/*
0N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/A
0N/A/*
0N/A * FUNCTIONS
0N/A * mlib_ImageCopy - Direct copy from one image to another.
0N/A *
0N/A * SYNOPSIS
0N/A * mlib_status mlib_ImageCopy(mlib_image *dst,
0N/A * const mlib_image *src);
0N/A *
0N/A * ARGUMENT
0N/A * dst pointer to output or destination image
0N/A * src pointer to input or source image
0N/A *
0N/A * RESTRICTION
0N/A * src and dst must have the same size, type and number of channels.
0N/A * They can have 1, 2, 3 or 4 channels of MLIB_BIT, MLIB_BYTE, MLIB_SHORT,
0N/A * MLIB_USHORT, MLIB_INT, MLIB_FLOAT or MLIB_DOUBLE data type.
0N/A *
0N/A * DESCRIPTION
0N/A * Direct copy from one image to another
0N/A */
0N/A
0N/A#include <stdlib.h>
0N/A#include "mlib_image.h"
0N/A#include "mlib_ImageCheck.h"
0N/A#include "mlib_ImageCopy.h"
0N/A
0N/A/***************************************************************/
0N/A#ifdef _MSC_VER
0N/A#pragma optimize("", off) /* Fix bug 4195132 */
0N/A#endif /* _MSC_VER */
0N/A
0N/A/***************************************************************/
0N/A/* do not perform the coping by mlib_d64 data type for x86 */
0N/A#ifdef i386
0N/A
0N/Atypedef struct {
0N/A mlib_s32 int0, int1;
0N/A} two_int;
0N/A
0N/A#define TYPE_64BIT two_int
0N/A
0N/A#else /* i386 */
0N/A
0N/A#define TYPE_64BIT mlib_d64
0N/A#endif /* i386 */
0N/A
0N/A/***************************************************************/
0N/Astatic void mlib_c_ImageCopy_u8(const mlib_image *src,
0N/A mlib_image *dst);
0N/Astatic void mlib_c_ImageCopy_s16(const mlib_image *src,
0N/A mlib_image *dst);
0N/Astatic void mlib_c_ImageCopy_s32(const mlib_image *src,
0N/A mlib_image *dst);
0N/Astatic void mlib_c_ImageCopy_d64(const mlib_image *src,
0N/A mlib_image *dst);
0N/Astatic void mlib_c_ImageCopy_a1(const TYPE_64BIT *sp,
0N/A TYPE_64BIT *dp,
0N/A mlib_s32 size);
0N/A
0N/A/***************************************************************/
0N/Amlib_status mlib_ImageCopy(mlib_image *dst,
0N/A const mlib_image *src)
0N/A{
0N/A mlib_s32 s_offset, d_offset;
0N/A mlib_s32 size, s_stride, d_stride;
0N/A mlib_s32 width; /* width in bytes of src and dst */
0N/A mlib_s32 height; /* height in lines of src and dst */
0N/A mlib_u8 *sa, *da;
0N/A mlib_s32 j;
0N/A
0N/A MLIB_IMAGE_CHECK(src);
0N/A MLIB_IMAGE_CHECK(dst);
0N/A MLIB_IMAGE_TYPE_EQUAL(src, dst);
0N/A MLIB_IMAGE_CHAN_EQUAL(src, dst);
0N/A MLIB_IMAGE_SIZE_EQUAL(src, dst);
0N/A
0N/A switch (mlib_ImageGetType(dst)) {
0N/A case MLIB_BIT:
0N/A width = mlib_ImageGetWidth(dst) * mlib_ImageGetChannels(dst); /* size in bits */
0N/A height = mlib_ImageGetHeight(src);
0N/A sa = (mlib_u8 *) mlib_ImageGetData(src);
0N/A da = (mlib_u8 *) mlib_ImageGetData(dst);
0N/A
0N/A if (!mlib_ImageIsNotOneDvector(src) && !mlib_ImageIsNotOneDvector(dst)) {
0N/A size = height * (width >> 3);
0N/A if (!mlib_ImageIsNotAligned8(src) && !mlib_ImageIsNotAligned8(dst) && ((size & 7) == 0)) {
0N/A
0N/A mlib_c_ImageCopy_a1((TYPE_64BIT *) sa, (TYPE_64BIT *) da, size >> 3);
0N/A }
0N/A else {
0N/A
0N/A mlib_ImageCopy_na(sa, da, size);
0N/A }
0N/A }
0N/A else {
0N/A s_stride = mlib_ImageGetStride(src);
0N/A d_stride = mlib_ImageGetStride(dst);
0N/A s_offset = mlib_ImageGetBitOffset(src); /* in bits */
0N/A d_offset = mlib_ImageGetBitOffset(dst); /* in bits */
0N/A if (s_offset == d_offset) {
0N/A for (j = 0; j < height; j++) {
0N/A mlib_ImageCopy_bit_al(sa, da, width, s_offset);
0N/A sa += s_stride;
0N/A da += d_stride;
0N/A }
0N/A }
0N/A else {
0N/A for (j = 0; j < height; j++) {
0N/A mlib_ImageCopy_bit_na(sa, da, width, s_offset, d_offset);
0N/A sa += s_stride;
0N/A da += d_stride;
0N/A }
0N/A }
0N/A }
0N/A
0N/A break;
0N/A case MLIB_BYTE:
0N/A mlib_c_ImageCopy_u8(src, dst);
0N/A break;
0N/A case MLIB_SHORT:
0N/A case MLIB_USHORT:
0N/A mlib_c_ImageCopy_s16(src, dst);
0N/A break;
0N/A case MLIB_INT:
0N/A case MLIB_FLOAT:
0N/A mlib_c_ImageCopy_s32(src, dst);
0N/A break;
0N/A case MLIB_DOUBLE:
0N/A mlib_c_ImageCopy_d64(src, dst);
0N/A break;
0N/A default:
0N/A return MLIB_FAILURE; /* MLIB_BIT is not supported here */
0N/A }
0N/A
0N/A return MLIB_SUCCESS;
0N/A}
0N/A
0N/A/***************************************************************/
0N/A#define PREPAREVARS(type) \
0N/A type *psrc = (type *) mlib_ImageGetData(src); \
0N/A type *pdst = (type *) mlib_ImageGetData(dst); \
0N/A mlib_s32 src_height = mlib_ImageGetHeight(src); \
0N/A mlib_s32 src_width = mlib_ImageGetWidth(src); \
0N/A mlib_s32 src_stride = mlib_ImageGetStride(src) / sizeof(type); \
0N/A mlib_s32 dst_stride = mlib_ImageGetStride(dst) / sizeof(type); \
0N/A mlib_s32 chan = mlib_ImageGetChannels(dst); \
0N/A mlib_s32 i, j; \
0N/A \
0N/A src_width *= chan; \
0N/A if (src_width == src_stride && src_width == dst_stride) { \
0N/A src_width *= src_height; \
0N/A src_height = 1; \
0N/A }
0N/A
0N/A/***************************************************************/
0N/A#define STRIP(pd, ps, w, h, data_type) { \
0N/A data_type s0, s1; \
0N/A for ( i = 0; i < h; i++ ) { \
0N/A if (j = w & 1) \
0N/A pd[i * dst_stride] = ps[i * src_stride]; \
0N/A for (; j < w; j += 2) { \
0N/A s0 = ps[i * src_stride + j]; \
0N/A s1 = ps[i * src_stride + j + 1]; \
0N/A pd[i * dst_stride + j] = s0; \
0N/A pd[i * dst_stride + j + 1] = s1; \
0N/A } \
0N/A } \
0N/A}
0N/A
0N/A/***************************************************************/
0N/A/*
0N/A * Both bit offsets of source and distination are the same
0N/A */
0N/A
0N/Avoid mlib_ImageCopy_bit_al(const mlib_u8 *sa,
0N/A mlib_u8 *da,
0N/A mlib_s32 size,
0N/A mlib_s32 offset)
0N/A{
0N/A mlib_s32 b_size, i, j;
0N/A TYPE_64BIT *sp, *dp;
0N/A mlib_u8 mask0 = 0xFF;
0N/A mlib_u8 src, mask;
0N/A
0N/A if (size <= 0) return;
0N/A
0N/A if (size <= (8 - offset)) {
0N/A mask = mask0 << (8 - size);
0N/A mask >>= offset;
0N/A src = da[0];
0N/A da[0] = (src & (~mask)) | (sa[0] & mask);
0N/A return;
0N/A }
0N/A
0N/A mask = mask0 >> offset;
0N/A src = da[0];
0N/A da[0] = (src & (~mask)) | (sa[0] & mask);
0N/A da++;
0N/A sa++;
0N/A size = size - 8 + offset;
0N/A b_size = size >> 3; /* size in bytes */
0N/A
0N/A for (j = 0; (j < b_size) && (((mlib_addr) da & 7) != 0); j++)
0N/A *da++ = *sa++;
0N/A
0N/A if ((((mlib_addr) sa ^ (mlib_addr) da) & 7) == 0) {
0N/A sp = (TYPE_64BIT *) sa;
0N/A dp = (TYPE_64BIT *) da;
0N/A#ifdef __SUNPRO_C
0N/A#pragma pipeloop(0)
0N/A#endif /* __SUNPRO_C */
0N/A for (i = 0; j <= (b_size - 8); j += 8, i++) {
0N/A dp[i] = sp[i];
0N/A }
0N/A
0N/A sa += i << 3;
0N/A da += i << 3;
0N/A }
0N/A else {
0N/A#ifdef _NO_LONGLONG
0N/A if ((((mlib_addr) sa ^ (mlib_addr) da) & 3) == 0) {
0N/A mlib_u32 *pws, *pwd;
0N/A
0N/A pws = (mlib_u32 *) sa;
0N/A pwd = (mlib_u32 *) da;
0N/A#ifdef __SUNPRO_C
0N/A#pragma pipeloop(0)
0N/A#endif /* __SUNPRO_C */
0N/A for (i = 0; j <= (b_size - 4); j += 4, i++) {
0N/A pwd[i] = pws[i];
0N/A }
0N/A
0N/A sa += i << 2;
0N/A da += i << 2;
0N/A }
0N/A else {
0N/A mlib_u32 *pws, *pwd, src0, src1;
0N/A mlib_s32 lshift = (mlib_addr) sa & 3, rshift;
0N/A
0N/A pwd = (mlib_u32 *) da;
0N/A pws = (mlib_u32 *) (sa - lshift);
0N/A lshift <<= 3;
0N/A rshift = 32 - lshift;
0N/A
0N/A src1 = pws[0];
0N/A#ifdef __SUNPRO_C
0N/A#pragma pipeloop(0)
0N/A#endif /* __SUNPRO_C */
0N/A for (i = 0; j <= (b_size - 4); j += 4, i++) {
0N/A src0 = src1;
0N/A src1 = pws[i + 1];
0N/A#ifdef _LITTLE_ENDIAN
0N/A pwd[i] = (src0 >> lshift) | (src1 << rshift);
0N/A#else
0N/A pwd[i] = (src0 << lshift) | (src1 >> rshift);
0N/A#endif /* _LITTLE_ENDIAN */
0N/A }
0N/A
0N/A sa += i << 2;
0N/A da += i << 2;
0N/A }
0N/A
0N/A#else
0N/A mlib_u64 *pws, *pwd, src0, src1;
0N/A mlib_s32 lshift = (mlib_s32) ((mlib_addr) sa & 7), rshift;
0N/A
0N/A pwd = (mlib_u64 *) da;
0N/A pws = (mlib_u64 *) (sa - lshift);
0N/A lshift <<= 3;
0N/A rshift = 64 - lshift;
0N/A
0N/A src1 = pws[0];
0N/A#ifdef __SUNPRO_C
0N/A#pragma pipeloop(0)
0N/A#endif /* __SUNPRO_C */
0N/A for (i = 0; j <= (b_size - 8); j += 8, i++) {
0N/A src0 = src1;
0N/A src1 = pws[i + 1];
0N/A pwd[i] = (src0 << lshift) | (src1 >> rshift);
0N/A }
0N/A
0N/A sa += i << 3;
0N/A da += i << 3;
0N/A#endif /* _NO_LONGLONG */
0N/A }
0N/A
0N/A for (; j < b_size; j++)
0N/A *da++ = *sa++;
0N/A
0N/A j = size & 7;
0N/A
0N/A if (j > 0) {
0N/A mask = mask0 << (8 - j);
0N/A src = da[0];
0N/A da[0] = (src & (~mask)) | (sa[0] & mask);
0N/A }
0N/A}
0N/A
0N/A/***************************************************************/
0N/Avoid mlib_c_ImageCopy_u8(const mlib_image *src,
0N/A mlib_image *dst)
0N/A{
0N/A PREPAREVARS(mlib_u8);
0N/A if (src_width < 16) {
0N/A STRIP(pdst, psrc, src_width, src_height, mlib_u8);
0N/A return;
0N/A }
0N/A
0N/A for (i = 0; i < src_height; i++) {
0N/A mlib_u8 *psrc_row = psrc + i * src_stride, *pdst_row = pdst + i * dst_stride;
0N/A
0N/A if (!(((mlib_addr) psrc_row ^ (mlib_addr) pdst_row) & 7)) {
0N/A for (j = 0; j < (mlib_s32) ((8 - (mlib_addr) psrc_row) & 7); j++) {
0N/A pdst_row[j] = psrc_row[j];
0N/A }
0N/A
0N/A#ifdef __SUNPRO_C
0N/A#pragma pipeloop(0)
0N/A#endif /* __SUNPRO_C */
0N/A for (; j <= (src_width - 8); j += 8) {
0N/A TYPE_64BIT dsrc0 = *((TYPE_64BIT *) (psrc_row + j));
0N/A
0N/A *((TYPE_64BIT *) (pdst_row + j)) = dsrc0;
0N/A }
0N/A }
0N/A else {
0N/A
0N/A#ifdef _NO_LONGLONG
0N/A
0N/A for (j = 0; j < (mlib_s32) ((4 - (mlib_addr) pdst_row) & 3); j++) {
pdst_row[j] = psrc_row[j];
}
if (!(((mlib_addr) psrc_row ^ (mlib_addr) pdst_row) & 3)) {
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 4); j += 4) {
*((mlib_s32 *) (pdst_row + j)) = *((mlib_s32 *) (psrc_row + j));
}
}
else {
mlib_u32 *ps, shl, shr, src0, src1;
ps = (mlib_u32 *) (psrc_row + j);
shl = (mlib_addr) ps & 3;
ps = (mlib_u32 *) ((mlib_addr) ps - shl);
shl <<= 3;
shr = 32 - shl;
src1 = ps[0];
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 4); j += 4) {
src0 = src1;
src1 = ps[1];
#ifdef _LITTLE_ENDIAN
*((mlib_s32 *) (pdst_row + j)) = (src0 >> shl) | (src1 << shr);
#else
*((mlib_s32 *) (pdst_row + j)) = (src0 << shl) | (src1 >> shr);
#endif /* _LITTLE_ENDIAN */
ps++;
}
}
#else
for (j = 0; j < (mlib_s32) ((8 - (mlib_addr) pdst_row) & 7); j++) {
pdst_row[j] = psrc_row[j];
}
{
mlib_s32 shl, shr;
mlib_u64 *ps, src0, src1;
ps = (mlib_u64 *) (psrc_row + j);
/* shl and shr are in range [0, 64] */
shl = (mlib_s32) ((mlib_addr) ps & 7);
ps = (mlib_u64 *) ((mlib_addr) ps - shl);
shl <<= 3;
shr = 64 - shl;
src1 = ps[0];
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 8); j += 8) {
src0 = src1;
src1 = ps[1];
#ifdef _LITTLE_ENDIAN
*((mlib_s64 *) (pdst_row + j)) = (src0 >> shl) | (src1 << shr);
#else
*((mlib_s64 *) (pdst_row + j)) = (src0 << shl) | (src1 >> shr);
#endif /* _LITTLE_ENDIAN */
ps++;
}
}
#endif /* _NO_LONGLONG */
}
for (; j < src_width; j++)
pdst_row[j] = psrc_row[j];
}
}
/***************************************************************/
void mlib_c_ImageCopy_s16(const mlib_image *src,
mlib_image *dst)
{
PREPAREVARS(mlib_u16);
if (src_width < 8) {
STRIP(pdst, psrc, src_width, src_height, mlib_u16);
return;
}
for (i = 0; i < src_height; i++) {
mlib_u16 *psrc_row = psrc + i * src_stride, *pdst_row = pdst + i * dst_stride;
if (!(((mlib_addr) psrc_row ^ (mlib_addr) pdst_row) & 7)) {
for (j = 0; j < (mlib_s32) (((8 - (mlib_addr) psrc_row) & 7) >> 1); j++) {
pdst_row[j] = psrc_row[j];
}
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 4); j += 4) {
TYPE_64BIT dsrc0 = *((TYPE_64BIT *) (psrc_row + j));
*((TYPE_64BIT *) (pdst_row + j)) = dsrc0;
}
}
else {
#ifdef _NO_LONGLONG
if (j = (((mlib_addr) pdst_row & 2) != 0)) {
pdst_row[0] = psrc_row[0];
}
if (!(((mlib_addr) psrc_row ^ (mlib_addr) pdst_row) & 3)) {
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 2); j += 2) {
*((mlib_s32 *) (pdst_row + j)) = *((mlib_s32 *) (psrc_row + j));
}
}
else {
mlib_u32 *ps, src0, src1;
ps = (mlib_u32 *) (psrc_row + j - 1);
src1 = ps[0];
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 2); j += 2) {
src0 = src1;
src1 = ps[1];
#ifdef _LITTLE_ENDIAN
*((mlib_s32 *) (pdst_row + j)) = (src0 >> 16) | (src1 << 16);
#else
*((mlib_s32 *) (pdst_row + j)) = (src0 << 16) | (src1 >> 16);
#endif /* _LITTLE_ENDIAN */
ps++;
}
}
#else
for (j = 0; j < (mlib_s32) (((8 - (mlib_addr) pdst_row) & 7) >> 1); j++) {
pdst_row[j] = psrc_row[j];
}
{
mlib_s32 shl, shr;
mlib_u64 *ps, src0, src1;
ps = (mlib_u64 *) (psrc_row + j);
shl = (mlib_s32) ((mlib_addr) ps & 7);
ps = (mlib_u64 *) ((mlib_addr) ps - shl);
shl <<= 3;
shr = 64 - shl;
src1 = ps[0];
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 4); j += 4) {
src0 = src1;
src1 = ps[1];
#ifdef _LITTLE_ENDIAN
*((mlib_s64 *) (pdst_row + j)) = (src0 >> shl) | (src1 << shr);
#else
*((mlib_s64 *) (pdst_row + j)) = (src0 << shl) | (src1 >> shr);
#endif /* _LITTLE_ENDIAN */
ps++;
}
}
#endif /* _NO_LONGLONG */
}
for (; j < src_width; j++)
pdst_row[j] = psrc_row[j];
}
}
/***************************************************************/
void mlib_c_ImageCopy_s32(const mlib_image *src,
mlib_image *dst)
{
PREPAREVARS(mlib_u32);
if (src_width < 4) {
STRIP(pdst, psrc, src_width, src_height, mlib_u32);
return;
}
for (i = 0; i < src_height; i++) {
mlib_u32 *psrc_row = psrc + i * src_stride, *pdst_row = pdst + i * dst_stride;
if (!(((mlib_addr) psrc_row ^ (mlib_addr) pdst_row) & 7)) {
if (j = ((mlib_s32) ((mlib_addr) psrc_row & 4) >> 2)) {
pdst_row[0] = psrc_row[0];
}
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 2); j += 2) {
TYPE_64BIT dsrc0 = *((TYPE_64BIT *) (psrc_row + j));
*((TYPE_64BIT *) (pdst_row + j)) = dsrc0;
}
}
else {
#ifdef _NO_LONGLONG
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (j = 0; j <= (src_width - 1); j++) {
*((mlib_s32 *) (pdst_row + j)) = *((mlib_s32 *) (psrc_row + j));
}
#else
{
mlib_u64 *ps, src0, src1;
if (j = ((mlib_s32) ((mlib_addr) pdst_row & 4) >> 2))
pdst_row[0] = psrc_row[0];
ps = (mlib_u64 *) (psrc_row + j - 1);
src1 = ps[0];
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; j <= (src_width - 2); j += 2) {
src0 = src1;
src1 = ps[1];
#ifdef _LITTLE_ENDIAN
*((mlib_s64 *) (pdst_row + j)) = (src0 >> 32) | (src1 << 32);
#else
*((mlib_s64 *) (pdst_row + j)) = (src0 << 32) | (src1 >> 32);
#endif /* _LITTLE_ENDIAN */
ps++;
}
}
#endif /* _NO_LONGLONG */
}
for (; j < src_width; j++)
pdst_row[j] = psrc_row[j];
}
}
/***************************************************************/
void mlib_c_ImageCopy_d64(const mlib_image *src,
mlib_image *dst)
{
PREPAREVARS(mlib_d64);
for (i = 0; i < src_height; i++) {
mlib_d64 *psrc_row = psrc + i * src_stride, *pdst_row = pdst + i * dst_stride;
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (j = 0; j < src_width; j++)
*((mlib_d64 *) (pdst_row + j)) = *((mlib_d64 *) (psrc_row + j));
}
}
/***************************************************************/
/*
* Both source and destination image data are 1 - d vectors and
* 8 - byte aligned. And size is in 8 - bytes.
*/
void mlib_c_ImageCopy_a1(const TYPE_64BIT *sp,
TYPE_64BIT *dp,
mlib_s32 size)
{
mlib_s32 i;
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (i = 0; i < size; i++) {
*dp++ = *sp++;
}
}
/***************************************************************/
#ifndef _NO_LONGLONG
#define TYPE mlib_u64
#define BSIZE 64
#define SIZE 8
#else
#define TYPE mlib_u32
#define BSIZE 32
#define SIZE 4
#endif /* _NO_LONGLONG */
/***************************************************************/
void mlib_ImageCopy_na(const mlib_u8 *sp,
mlib_u8 *dp,
mlib_s32 n)
{
mlib_s32 shr, shl;
TYPE *tmp, s0, s1;
if (((mlib_addr) sp ^ (mlib_addr) dp) & 7) {
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; (n > 0) && (mlib_addr) dp & (SIZE - 1); n--)
*dp++ = *sp++;
#ifdef _NO_LONGLONG
if (((mlib_addr) sp & (SIZE - 1)) == 0) {
for (; n > SIZE; n -= SIZE) {
*(TYPE *) dp = *(TYPE *) sp;
dp += SIZE;
sp += SIZE;
}
}
else
#endif /* _NO_LONGLONG */
{
tmp = (TYPE *) ((mlib_addr) sp & ~(SIZE - 1));
/* shl and shr do not exceed 64 here */
shl = (mlib_s32) (((mlib_addr) sp & (SIZE - 1)) << 3);
shr = BSIZE - shl;
s0 = *tmp++;
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; n > SIZE; n -= SIZE) {
s1 = *tmp++;
#ifdef _LITTLE_ENDIAN
*(TYPE *) dp = (s0 >> shl) | (s1 << shr);
#else
*(TYPE *) dp = (s0 << shl) | (s1 >> shr);
#endif /* _LITTLE_ENDIAN */
s0 = s1;
dp += SIZE;
sp += SIZE;
}
}
}
else {
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; (n > 0) && (mlib_addr) dp & 7; n--)
*dp++ = *sp++;
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; n > 8; n -= 8) {
*(TYPE_64BIT *) dp = *(TYPE_64BIT *) sp;
dp += 8;
sp += 8;
}
}
#ifdef __SUNPRO_C
#pragma pipeloop(0)
#endif /* __SUNPRO_C */
for (; n > 0; n--)
*dp++ = *sp++;
}
/***************************************************************/
#ifdef _MSC_VER
#pragma optimize("", on)
#endif /* _MSC_VER */
/***************************************************************/