1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
|
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file cm_mem.h
//! \brief Contains CM memory function definitions
//!
#pragma once
#include <mmintrin.h>
#include <xmmintrin.h>
#include <emmintrin.h>
#include "cm_debug.h"
#include "mos_utilities.h"
enum CPU_INSTRUCTION_LEVEL
{
CPU_INSTRUCTION_LEVEL_UNKNOWN,
CPU_INSTRUCTION_LEVEL_MMX,
CPU_INSTRUCTION_LEVEL_SSE,
CPU_INSTRUCTION_LEVEL_SSE2,
CPU_INSTRUCTION_LEVEL_SSE3,
CPU_INSTRUCTION_LEVEL_SSE4,
CPU_INSTRUCTION_LEVEL_SSE4_1,
NUM_CPU_INSTRUCTION_LEVELS
};
typedef __m128 DQWORD; // 128-bits, 16-bytes
typedef uint32_t PREFETCH[8]; // 32-bytes
typedef uint32_t CACHELINE[8]; // 32-bytes
typedef uint16_t DHWORD[32]; // 512-bits, 64-bytes
#define CmSafeDeleteArray(_ptr) {if(_ptr != nullptr) {delete[] (_ptr); (_ptr)=nullptr;}}
#define CmSafeDelete(_ptr) {if(_ptr != nullptr) {delete (_ptr);(_ptr)=nullptr;}}
#define MosSafeDeleteArray(_ptr) {MOS_DeleteArray(_ptr); (_ptr)=nullptr;}
#define MosSafeDelete(_ptr) {MOS_Delete(_ptr); (_ptr)=nullptr;}
inline void CmSafeMemSet( void* dst, const int data, const size_t bytes );
inline void CmDwordMemSet( void* dst, const uint32_t data, const size_t bytes );
inline void CmSafeMemCopy( void* pdst, const void *psrc, const size_t bytes );
inline int CmSafeMemCompare( const void*, const void*, const size_t );
inline bool IsPowerOfTwo( const size_t number );
inline void* Align( void* const ptr, const size_t alignment );
inline size_t GetAlignmentOffset( void* const ptr, const size_t alignSize );
inline bool IsAligned( void * ptr, const size_t alignSize );
inline size_t Round( const size_t value, const size_t size );
inline void CmFastMemCopy( void* dst, const void* src, const size_t bytes );
inline void CmFastMemCopyWC( void* dst, const void* src, const size_t bytes );
inline void CmFastMemCopyFromWC( void* dst, const void* src, const size_t bytes, CPU_INSTRUCTION_LEVEL cpuInstructionLevel );
inline void Prefetch( const void* ptr );
inline void FastMemCopy_SSE2( void* dst, void* src, const size_t doubleQuadWords );
inline void FastMemCopy_SSE2_movntdq_movdqa( void* dst, void* src, const size_t doubleQuadWords );
inline void FastMemCopy_SSE2_movdqu_movdqa( void* dst, void* src, const size_t doubleQuadWords );
inline void FastMemCopy_SSE2_movntdq_movdqu( void* dst, const void* src, const size_t doubleQuadWords);
/*****************************************************************************\
MACROS:
EMIT_R_MR
Example: movntdqa xmm1, xmmword ptr [eax]
EMIT_R_MR_OFFSET
Example: movntdqa xmm1, xmmword ptr [eax + 0x10]
Description:
Used to encode SSE4.1 instructions with parametrs
\*****************************************************************************/
#define EMIT_R_MR(OPCODE, X, Y ) \
OPCODE \
__asm _emit (0x00 + X*8 + Y)
#define EMIT_R_MR_OFFSET(OPCODE, X, Y, OFFSET) \
OPCODE \
__asm _emit (0x80 + X*8 + Y) \
__asm _emit (OFFSET&0xFF) \
__asm _emit ((OFFSET>>8)&0xFF) \
__asm _emit ((OFFSET>>16)&0xFF) \
__asm _emit ((OFFSET>>24)&0xFF)
/*****************************************************************************\
MACROS:
MOVNTDQA_OP
MOVNTDQA_R_MR
MOVNTDQA_R_MRB
Description:
Used to emit SSE4_1 movntdqa (streaming load) instructions
SRC - XMM Register, destination data is to be stored
DST - General Purpose Register containing source address
OFFSET - Offset to be added to the source address
\*****************************************************************************/
#define MOVNTDQA_OP \
_asm _emit 0x66 \
_asm _emit 0x0F \
_asm _emit 0x38 \
_asm _emit 0x2A
#define MOVNTDQA_R_MR(DST, SRC) \
EMIT_R_MR(MOVNTDQA_OP, DST, SRC)
#define MOVNTDQA_R_MR_OFFSET(DST, SRC, OFFSET) \
EMIT_R_MR_OFFSET(MOVNTDQA_OP, DST, SRC, OFFSET)
#ifndef BIT
#define BIT( n ) ( 1 << (n) )
#endif
#include "cm_mem_os.h"
/*****************************************************************************\
Inline Function:
CmSafeMemSet
Description:
Memory set
\*****************************************************************************/
inline void CmSafeMemSet( void* dst, const int data, const size_t bytes )
{
#if defined(_DEBUG)
__try
#endif
{
::memset( dst, data, bytes );
}
#if defined(_DEBUG)
// catch exceptions here so they are easily debugged
__except( EXCEPTION_EXECUTE_HANDLER )
{
CM_ASSERTMESSAGE("Error: Memory Set failure.");
}
#endif
}
/*****************************************************************************\
Inline Function:
CmDwordMemSet
Description:
uint32_t memory set
\*****************************************************************************/
inline void CmDwordMemSet( void* dst, const uint32_t data, const size_t bytes )
{
uint32_t *ptr = reinterpret_cast<uint32_t*>( dst );
uint32_t sizeInDwords = (uint32_t)(bytes >> 2); // divide by 4 byte to dword
uint32_t *maxPtr = ptr + sizeInDwords;
while(ptr < maxPtr)
*ptr++ = data;
}
/*****************************************************************************\
Inline Function:
CmSafeMemCopy
Description:
Memory Copy
\*****************************************************************************/
inline void CmSafeMemCopy( void* dst, const void *src, const size_t bytes )
{
uint8_t *cacheDst = (uint8_t*)dst;
uint8_t *cacheSrc = (uint8_t*)src;
#if defined(_DEBUG)
__try
#endif
{
MOS_SecureMemcpy( cacheDst, bytes, cacheSrc, bytes );
}
#if defined(_DEBUG)
// catch exceptions here so they are easily debugged
__except( EXCEPTION_EXECUTE_HANDLER )
{
CM_ASSERTMESSAGE("Error: Memory Copy failure.");
}
#endif
}
/*****************************************************************************\
Inline Function:
CmSafeMemCompare
Description:
Exception Handler Memory Compare function
\*****************************************************************************/
inline int CmSafeMemCompare( const void* dst, const void* src, const size_t bytes )
{
#if defined(_DEBUG)
__try
#endif
{
return ::memcmp( dst, src, bytes );
}
#if defined(_DEBUG)
// catch exceptions here so they are easily debugged
__except(EXCEPTION_EXECUTE_HANDLER)
{
CM_ASSERTMESSAGE("Error: Memory Compare failure.");
return -1;
}
#endif
}
/*****************************************************************************\
Inline Function:
GetCpuInstructionLevel
Description:
Returns the highest level of IA32 intruction extensions supported by the CPU
( i.e. SSE, SSE2, SSE4, etc )
Output:
CPU_INSTRUCTION_LEVEL - highest level of IA32 instruction extension(s) supported
by CPU
\*****************************************************************************/
inline CPU_INSTRUCTION_LEVEL GetCpuInstructionLevel( void )
{
int cpuInfo[4];
memset( cpuInfo, 0, 4*sizeof(int) );
GetCPUID(cpuInfo, 1);
CPU_INSTRUCTION_LEVEL cpuInstructionLevel = CPU_INSTRUCTION_LEVEL_UNKNOWN;
if( (cpuInfo[2] & BIT(19)) && TestSSE4_1() )
{
cpuInstructionLevel = CPU_INSTRUCTION_LEVEL_SSE4_1;
}
else if( cpuInfo[2] & BIT(1) )
{
cpuInstructionLevel = CPU_INSTRUCTION_LEVEL_SSE3;
}
else if( cpuInfo[3] & BIT(26) )
{
cpuInstructionLevel = CPU_INSTRUCTION_LEVEL_SSE2;
}
else if( cpuInfo[3] & BIT(25) )
{
cpuInstructionLevel = CPU_INSTRUCTION_LEVEL_SSE;
}
else if( cpuInfo[3] & BIT(23) )
{
cpuInstructionLevel = CPU_INSTRUCTION_LEVEL_MMX;
}
return cpuInstructionLevel;
}
/*****************************************************************************\
Inline Function:
Round
Description:
Rounds an unsigned integer to the next multiple of (power-2) size
\*****************************************************************************/
inline size_t Round( const size_t value, const size_t size )
{
CM_ASSERT( IsPowerOfTwo(size) );
size_t mask = size - 1;
size_t roundedValue = ( value + mask ) & ~( mask );
return roundedValue;
}
/*****************************************************************************\
Inline Template Function:
Max
Description:
Returns the max of the two values
\*****************************************************************************/
__inline size_t Max( size_t var0, size_t var1 )
{
return ( var0 >= var1 ) ? var0 : var1;
}
/*****************************************************************************\
Inline Function:
IsAligned
Description:
Determines if the given size is aligned to the given size
\*****************************************************************************/
inline bool IsAligned( void * ptr, const size_t alignSize )
{
return ( ( (size_t)ptr % alignSize ) == 0 );
}
/*****************************************************************************\
Inline Function:
IsPowerOfTwo
Description:
Determines if the given value is a power of two.
\*****************************************************************************/
inline bool IsPowerOfTwo( const size_t number )
{
return ( ( number & ( number - 1 ) ) == 0 );
}
/*****************************************************************************\
Inline Function:
GetAlignmentOffset
Description:
Returns the size in bytes needed to align the given size to the
given alignment size
\*****************************************************************************/
inline size_t GetAlignmentOffset( void* const ptr, const size_t alignSize )
{
CM_ASSERT( alignSize );
uint32_t offset = 0;
if( IsPowerOfTwo(alignSize) )
{ // can recast 'ptr' to uint32_t, since offset is uint32_t
offset = uint32_t( uintptr_t( Align(ptr, alignSize) ) - (uintptr_t)(ptr) );
}
else
{
const uint32_t modulo = (uint32_t)(uintptr_t(ptr) % alignSize);
if( modulo )
{
offset = (uint32_t)alignSize - modulo;
}
}
return offset;
}
/*****************************************************************************\
Inline Function:
Align
Description:
Type-safe (power-2) alignment of a pointer.
\*****************************************************************************/
inline void* Align( void* const ptr, const size_t alignment )
{
CM_ASSERT( IsPowerOfTwo(alignment) );
return (void*)( ( ((size_t)ptr) + alignment-1 ) & ~( alignment-1 ) );
}
/*****************************************************************************\
Inline Function:
FastMemCopy_SSE2_movntdq_movdqa
Description:
Intel C++ Compiler Memory Copy function using Streaming SIMD Extensions 2
Input:
dst - 16-byte aligned pointer to destination buffer
src - 16-byte aligned pointer to source buffer
doubleQuadWords - number of DoubleQuadWords to copy
\*****************************************************************************/
inline void FastMemCopy_SSE2_movntdq_movdqa(
void* dst,
void* src,
const size_t doubleQuadWords )
{
CM_ASSERT( IsAligned( dst, sizeof(DQWORD) ) );
CM_ASSERT( IsAligned( src, sizeof(DQWORD) ) );
const size_t doubleQuadWordsPerPrefetch = sizeof(PREFETCH) / sizeof(DQWORD);
// Prefetch the src data
Prefetch( (uint8_t*)src );
Prefetch( (uint8_t*)src + sizeof(PREFETCH) );
// Convert to SSE2 registers
__m128i* dst128i = (__m128i*)dst;
__m128i* src128i = (__m128i*)src;
size_t count = doubleQuadWords;
// Copies a cacheline per loop iteration
while( count >= doubleQuadWordsPerPrefetch )
{
Prefetch( (uint8_t*)src128i + 2 * sizeof(PREFETCH) );
count -= doubleQuadWordsPerPrefetch;
// Copy cacheline of data
for( size_t i = 0; i < doubleQuadWordsPerPrefetch; i++ )
{
_mm_stream_si128( dst128i++,
_mm_load_si128( src128i++ ) );
}
}
// Copy DQWORD if not cacheline multiple
while( count-- )
{
_mm_stream_si128( dst128i++,
_mm_load_si128( src128i++ ) );
}
}
/*****************************************************************************\
Inline Function:
FastMemCopy_SSE2_movdqu_movdqa
Description:
Intel C++ Compiler Memory Copy function using Streaming SIMD Extensions 2
Input:
dst - pointer to destination buffer
src - 16-byte aligned pointer to source buffer
doubleQuadWords - number of DoubleQuadWords to copy
\*****************************************************************************/
inline void FastMemCopy_SSE2_movdqu_movdqa(
void* dst,
void* src,
const size_t doubleQuadWords )
{
CM_ASSERT( IsAligned( src, sizeof(DQWORD) ) );
const size_t doubleQuadWordsPerPrefetch = sizeof(PREFETCH) / sizeof(DQWORD);
// Prefetch the src data
Prefetch( (uint8_t*)src );
Prefetch( (uint8_t*)src + sizeof(PREFETCH) );
// Convert to SSE2 registers
__m128i* dst128i = (__m128i*)dst;
__m128i* src128i = (__m128i*)src;
size_t count = doubleQuadWords;
// Copies a cacheline per loop iteration
while( count >= doubleQuadWordsPerPrefetch )
{
Prefetch( (uint8_t*)src128i + 2 * sizeof(PREFETCH) );
count -= doubleQuadWordsPerPrefetch;
// Copy cacheline of data
for( size_t i = 0; i < doubleQuadWordsPerPrefetch; i++ )
{
_mm_storeu_si128( dst128i++,
_mm_load_si128( src128i++ ) );
}
}
// Copy DQWORD if not cacheline multiple
while( count-- )
{
_mm_storeu_si128( dst128i++,
_mm_load_si128( src128i++ ) );
}
}
/*****************************************************************************\
Inline Function:
FastMemCopy_SSE2_movntdq_movdqu
Description:
Intel C++ Compiler Memory Copy function using Streaming SIMD Extensions 2
Input:
dst - 16-byte aligned pointer to destination buffer
src - pointer to source buffer
doubleQuadWords - number of DoubleQuadWords to copy
\*****************************************************************************/
inline void FastMemCopy_SSE2_movntdq_movdqu(
void* dst,
const void* src,
const size_t doubleQuadWords )
{
CM_ASSERT( IsAligned( dst, sizeof(DQWORD) ) );
const size_t doubleQuadWordsPerPrefetch = sizeof(PREFETCH) / sizeof(DQWORD);
// Prefetch the src data
Prefetch( (uint8_t*)src );
Prefetch( (uint8_t*)src + sizeof(PREFETCH) );
// Convert to SSE2 registers
__m128i* dst128i = (__m128i*)dst;
__m128i* src128i = (__m128i*)src;
size_t count = doubleQuadWords;
// Copies a cacheline per loop iteration
while( count >= doubleQuadWordsPerPrefetch )
{
Prefetch( (uint8_t*)src128i + 2 * sizeof(PREFETCH) );
count -= doubleQuadWordsPerPrefetch;
// Copy cacheline of data
for( size_t i = 0; i < doubleQuadWordsPerPrefetch; i++ )
{
_mm_stream_si128( dst128i++,
_mm_loadu_si128( src128i++ ) );
}
}
// Copy DQWORD if not cacheline multiple
while( count-- )
{
_mm_stream_si128( dst128i++,
_mm_loadu_si128( src128i++ ) );
}
}
/*****************************************************************************\
Inline Function:
FastMemCopy_SSE2_movdqu_movdqu
Description:
Intel C++ Compiler Memory Copy function using Streaming SIMD Extensions 2
Input:
dst - pointer to destination buffer
src - pointer to source buffer
doubleQuadWords - number of DoubleQuadWords to copy
\*****************************************************************************/
inline void FastMemCopy_SSE2_movdqu_movdqu(
void* dst,
const void* src,
const size_t doubleQuadWords )
{
const size_t doubleQuadWordsPerPrefetch = sizeof(PREFETCH) / sizeof(DQWORD);
// Prefetch the src data
Prefetch( (uint8_t*)src );
Prefetch( (uint8_t*)src + sizeof(PREFETCH) );
// Convert to SSE2 registers
__m128i* dst128i = (__m128i*)dst;
__m128i* src128i = (__m128i*)src;
size_t count = doubleQuadWords;
// Copies a cacheline per loop iteration
while( count >= doubleQuadWordsPerPrefetch )
{
Prefetch( (uint8_t*)src128i + 2 * sizeof(PREFETCH) );
count -= doubleQuadWordsPerPrefetch;
// Copy cacheline of data
for( size_t i = 0; i < doubleQuadWordsPerPrefetch; i++ )
{
_mm_storeu_si128( dst128i++,
_mm_loadu_si128( src128i++ ) );
}
}
// Copy DQWORD if not cacheline multiple
while( count-- )
{
_mm_storeu_si128( dst128i++,
_mm_loadu_si128( src128i++ ) );
}
}
/*****************************************************************************\
Inline Function:
FastMemCopy_SSE2
Description:
Intel C++ Compiler Memory Copy function using Streaming SIMD Extensions 2
Input:
dst - pointer to destination buffer
src - pointer to source buffer
doubleQuadWords - number of DoubleQuadWords to copy
\*****************************************************************************/
inline void FastMemCopy_SSE2(
void* dst,
void* src,
const size_t doubleQuadWords )
{
// Determine if the source and destination addresses are 128-bit aligned
const bool isDstDoubleQuadWordAligned = IsAligned( dst, sizeof(DQWORD) );
const bool isSrcDoubleQuadWordAligned = IsAligned( src, sizeof(DQWORD) );
if( isSrcDoubleQuadWordAligned && isDstDoubleQuadWordAligned )
{
FastMemCopy_SSE2_movntdq_movdqa( dst, src, doubleQuadWords );
}
else if( isDstDoubleQuadWordAligned )
{
FastMemCopy_SSE2_movntdq_movdqu( dst, src, doubleQuadWords );
}
else if( isSrcDoubleQuadWordAligned )
{
FastMemCopy_SSE2_movdqu_movdqa( dst, src, doubleQuadWords );
}
else // if( !isSrcDoubleQuadWordAligned && !isDstDoubleQuadWordAligned )
{
FastMemCopy_SSE2_movdqu_movdqu( dst, src, doubleQuadWords );
}
}
/*****************************************************************************\
Inline Function:
CmFastMemCopy
Description:
Intel C++ Compiler Memory Copy function for large amounts of data
Input:
dst - pointer to destination buffer
src - pointer to source buffer
bytes - number of bytes to copy
\*****************************************************************************/
inline void CmFastMemCopy( void* dst, const void* src, const size_t bytes )
{
// Cache pointers to memory
uint8_t *cacheDst = (uint8_t*)dst;
uint8_t *cacheSrc = (uint8_t*)src;
size_t count = bytes;
// Get the number of DQWORDs to be copied
const size_t doubleQuadWords = count / sizeof(DQWORD);
if( count >= CM_CPU_FASTCOPY_THRESHOLD && doubleQuadWords )
{
FastMemCopy_SSE2( cacheDst, cacheSrc, doubleQuadWords );
cacheDst += doubleQuadWords * sizeof(DQWORD);
cacheSrc += doubleQuadWords * sizeof(DQWORD);
count -= doubleQuadWords * sizeof(DQWORD);
}
// Copy remaining uint8_t(s)
if( count )
{
MOS_SecureMemcpy( cacheDst, count, cacheSrc, count );
}
}
/*****************************************************************************\
Inline Function:
CmFastMemCopyWC
Description:
Intel C++ Compiler Memory Copy function for large amounts of data, just now prefetch
compared with FastMemCopyWC. It is the same as the FastMemCopyWC_NoPf in CMRT@APP.
Input:
dst - pointer to write-combined destination buffer
src - pointer to source buffer
bytes - number of bytes to copy
\*****************************************************************************/
inline void CmFastMemCopyWC( void* dst, const void* src, const size_t bytes )
{
// Cache pointers to memory
uint8_t *cacheDst = (uint8_t*)dst;
uint8_t *cacheSrc = (uint8_t*)src;
size_t count = bytes;
if( count >= CM_CPU_FASTCOPY_THRESHOLD )
{
const size_t doubleQuadwordAlignBytes =
GetAlignmentOffset( cacheDst, sizeof(DQWORD) );
// The destination pointer should be 128-bit aligned
if( doubleQuadwordAlignBytes )
{
MOS_SecureMemcpy( cacheDst, doubleQuadwordAlignBytes,cacheSrc, doubleQuadwordAlignBytes );
cacheDst += doubleQuadwordAlignBytes;
cacheSrc += doubleQuadwordAlignBytes;
count -= doubleQuadwordAlignBytes;
}
// Get the number of DQWORDs to be copied
const size_t doubleQuadWords = count / sizeof(DQWORD);
if( doubleQuadWords && count >= sizeof(PREFETCH))
{
// Determine if the source and destination addresses are
// 128-bit aligned
CM_ASSERT( IsAligned( cacheDst, sizeof(DQWORD) ) );
const bool isSrcDoubleQuadWordAligned =
IsAligned( cacheSrc, sizeof(DQWORD) );
if( isSrcDoubleQuadWordAligned )
{
FastMemCopy_SSE2_movntdq_movdqa( cacheDst, cacheSrc,
doubleQuadWords );
}
else
{
FastMemCopy_SSE2_movntdq_movdqu( cacheDst, cacheSrc,
doubleQuadWords );
}
cacheDst += doubleQuadWords * sizeof(DQWORD);
cacheSrc += doubleQuadWords * sizeof(DQWORD);
count -= doubleQuadWords * sizeof(DQWORD);
}
}
// Copy remaining uint8_t(s)
if( count )
{
MOS_SecureMemcpy( cacheDst, count, cacheSrc, count );
}
}
|