std::vector< uint8_t > ncap_base_record_t::to_disk(uint64_t id, uint64_t type, std::vector< uint8_t >& vec) { std::vector< uint8_t > r; uint64_t t(NCAP_MAGIC); uint64_t l(vec.size()); r.resize(sizeof(t) + sizeof(id) + sizeof(type) + sizeof(l) + l); /* * MAGIC * ID * TYPE * LENGTH * DATA */ std::memcpy(r.data(), &t, sizeof(uint64_t)); t = byte_swap(id); std::memcpy(r.data()+sizeof(uint64_t), &t, sizeof(id)); t = byte_swap(type); std::memcpy(r.data()+sizeof(uint64_t)+sizeof(id), &t, sizeof(t)); t = byte_swap(l); std::memcpy(r.data()+sizeof(t)+sizeof(id)+sizeof(type), &t, sizeof(l)); std::memcpy(r.data()+sizeof(t)+sizeof(id)+sizeof(type)+sizeof(l), vec.data(), l); return r; }
void byte_swap_header(ATS_HEADER *hed, int flag) { double aux; if(flag==TRUE) { //may be already swapped aux=hed->mag; hed->mag=byte_swap(&aux); } aux=hed->sr; hed->sr = byte_swap(&aux); aux=hed->fs; hed->fs= byte_swap(&aux); aux=hed->ws; hed->ws= byte_swap(&aux); aux=hed->par; hed->par= byte_swap(&aux); aux=hed->fra; hed->fra= byte_swap(&aux); aux=hed->ma; hed->ma= byte_swap(&aux); aux=hed->mf; hed->mf= byte_swap(&aux); aux=hed->dur; hed->dur= byte_swap(&aux); aux=hed->typ; hed->typ= byte_swap(&aux); return; }
void * Loader::registerUnimplementedFunction(const std::string& name) { auto thunkIter = mUnimplementedFunctions.find(name); if (thunkIter != mUnimplementedFunctions.end()) { return thunkIter->second; } uint32_t syscallId = gSystem.registerUnimplementedFunction(name.c_str()); uint32_t *thunkAddr = static_cast<uint32_t*>(OSAllocFromSystem(8, 4)); // Write syscall thunk auto kc = gInstructionTable.encode(InstructionID::kc); kc.li = syscallId; kc.aa = 0; *(thunkAddr + 0) = byte_swap(kc.value); auto bclr = gInstructionTable.encode(InstructionID::bclr); bclr.bo = 0x1f; *(thunkAddr + 1) = byte_swap(bclr.value); mUnimplementedFunctions.emplace(name, thunkAddr); return thunkAddr; }
uint64_t DMAECopyMem(virt_ptr<void> dst, virt_ptr<void> src, uint32_t numWords, DMAEEndianSwapMode endian) { coreinit::OSLockMutex(virt_addrof(sRingData->mutex)); if (endian == DMAEEndianSwapMode::None) { std::memcpy(dst.get(), src.get(), numWords * 4); } else if (endian == DMAEEndianSwapMode::Swap8In16) { auto dstWords = reinterpret_cast<uint16_t *>(dst.get()); auto srcWords = reinterpret_cast<uint16_t *>(src.get()); for (auto i = 0u; i < numWords * 2; ++i) { *dstWords++ = byte_swap(*srcWords++); } } else if (endian == DMAEEndianSwapMode::Swap8In32) { auto dstDwords = reinterpret_cast<uint32_t *>(dst.get()); auto srcDwords = reinterpret_cast<uint32_t *>(src.get()); for (auto i = 0u; i < numWords; ++i) { *dstDwords++ = byte_swap(*srcDwords++); } } auto timestamp = coreinit::OSGetTime(); sRingData->lastSubmittedTimestamp = timestamp; coreinit::OSUnlockMutex(virt_addrof(sRingData->mutex)); return timestamp; }
int UDP_Socket::sendID(int dbTag, int commitTag, const ID &theID, ChannelAddress *theAddress) { // set up the address of the Socket to which data will be sent if (theAddress != 0) { SocketAddress *theSocketAddress = 0; if (theAddress->getType() == SOCKET_TYPE) { theSocketAddress = (SocketAddress *)theAddress; bcopy((char *) &theSocketAddress->address.addr, (char *) &other_Addr.addr, theSocketAddress->addrLength); addrLength = theSocketAddress->addrLength; } else { opserr << "UDP_Socket::sendID() - a UDP_Socket "; opserr << "can only communicate with a UDP_Socket"; opserr << " address given is not of type SocketAddress\n"; return -1; } } // send the data int size; int *data = theID.data; char *gMsg = (char *)data;; size = theID.sz * sizeof(int); #ifndef _WIN32 if (endiannessProblem) { void *array = (void *)data; byte_swap(array, theID.sz, sizeof(int)); } #endif while (size > 0) { if (size <= MAX_UDP_DATAGRAM) { sendto(sockfd, gMsg, size, 0, &other_Addr.addr, addrLength); size = 0; } else { sendto(sockfd, gMsg, MAX_UDP_DATAGRAM, 0, &other_Addr.addr, addrLength); gMsg += MAX_UDP_DATAGRAM; size -= MAX_UDP_DATAGRAM; } } #ifndef _WIN32 if (endiannessProblem) { void *array = (void *)data; byte_swap(array, theID.sz, sizeof(int)); } #endif return 0; }
int main() { // start with a block header struct block_header header; // we need a place to store the checksums unsigned char hash1[SHA256_DIGEST_LENGTH]; unsigned char hash2[SHA256_DIGEST_LENGTH]; // you should be able to reuse these, but openssl sha256 is slow, so your probbally not going to implement this anyway SHA256_CTX sha256_pass1, sha256_pass2; // we are going to supply the block header with the values from the generation block 0 header.version = 1; hex2bin(header.prev_block, "0000000000000000000000000000000000000000000000000000000000000000"); hex2bin(header.merkle_root, "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"); header.timestamp = 1231006505; header.bits = 486604799; header.nonce = 2083236893; // the endianess of the checksums needs to be little, this swaps them form the big endian format you normally see in block explorer byte_swap(header.prev_block, 32); byte_swap(header.merkle_root, 32); // dump out some debug data to the terminal printf("sizeof(block_header) = %d\n", (int) sizeof(block_header)); printf("Block header (in human readable hexadecimal representation): "); hexdump((unsigned char*)&header, sizeof(block_header)); // Use SSL's sha256 functions, it needs to be initialized SHA256_Init(&sha256_pass1); // then you 'can' feed data to it in chuncks, but here were just making one pass cause the data is so small SHA256_Update(&sha256_pass1, (unsigned char*)&header, sizeof(block_header)); // this ends the sha256 session and writes the checksum to hash1 SHA256_Final(hash1, &sha256_pass1); // to display this, we want to swap the byte order to big endian byte_swap(hash1, SHA256_DIGEST_LENGTH); printf("Useless First Pass Checksum: "); hexdump(hash1, SHA256_DIGEST_LENGTH); // but to calculate the checksum again, we need it in little endian, so swap it back byte_swap(hash1, SHA256_DIGEST_LENGTH); //same as above SHA256_Init(&sha256_pass2); SHA256_Update(&sha256_pass2, hash1, SHA256_DIGEST_LENGTH); SHA256_Final(hash2, &sha256_pass2); byte_swap(hash2, SHA256_DIGEST_LENGTH); printf("Target Second Pass Checksum: "); hexdump(hash2, SHA256_DIGEST_LENGTH); return 0; }
// void Send(Matrix &): // Method to send a Matrix to an address given by other_Addr.addr_in. int TCP_Socket::sendMatrix(int dbTag, int commitTag, const Matrix &theMatrix, ChannelAddress *theAddress) { // first check address is the only address a TCP_socket can send to SocketAddress *theSocketAddress = 0; if (theAddress != 0) { if (theAddress->getType() == SOCKET_TYPE) theSocketAddress = (SocketAddress *)theAddress; else { opserr << "TCP_Socket::sendMatrix() - a TCP_Socket "; opserr << "can only communicate with a TCP_Socket"; opserr << " address given is not of type SocketAddress\n"; return -1; } SocketAddress *theSocketAddress = 0; if (bcmp((char *) &other_Addr.addr_in, (char *) &theSocketAddress->address.addr_in, theSocketAddress->addrLength) != 0) { opserr << "TCP_Socket::sendMatrix() - a TCP_Socket "; opserr << "can only communicate with one other TCP_Socket\n"; return -1; } } // if o.k. get a pointer to the data in the Matrix and // place the incoming data there int nwrite, nleft; double *data = theMatrix.data; char *gMsg = (char *)data; nleft = theMatrix.dataSize * sizeof(double); #ifndef _WIN32 if (endiannessProblem) { void *array = (void *)data; byte_swap(array, theMatrix.dataSize, sizeof(double)); } #endif while (nleft > 0) { nwrite = send(sockfd,gMsg,nleft,0); nleft -= nwrite; gMsg += nwrite; } #ifndef _WIN32 if (endiannessProblem) { void *array = (void *)data; byte_swap(array, theMatrix.dataSize, sizeof(double)); } #endif return 0; }
void GLDriver::drawIndex2(const pm4::DrawIndex2 &data) { if (!checkReadyDraw()) { return; } auto vgt_primitive_type = getRegister<latte::VGT_PRIMITIVE_TYPE>(latte::Register::VGT_PRIMITIVE_TYPE); auto sq_vtx_base_vtx_loc = getRegister<latte::SQ_VTX_BASE_VTX_LOC>(latte::Register::SQ_VTX_BASE_VTX_LOC); auto vgt_dma_index_type = getRegister<latte::VGT_DMA_INDEX_TYPE>(latte::Register::VGT_DMA_INDEX_TYPE); auto vgt_dma_num_instances = getRegister<latte::VGT_DMA_NUM_INSTANCES>(latte::Register::VGT_DMA_NUM_INSTANCES); auto vgt_strmout_en = getRegister<latte::VGT_STRMOUT_EN>(latte::Register::VGT_STRMOUT_EN); // Swap and indexBytes are separate because you can have 32-bit swap, // but 16-bit indices in some cases... This is also why we pre-swap // the data before intercepting QUAD and POLYGON draws. if (vgt_dma_index_type.SWAP_MODE() == latte::VGT_DMA_SWAP_16_BIT) { auto *src = static_cast<uint16_t*>(data.addr.get()); auto indices = std::vector<uint16_t>(data.count); if (vgt_dma_index_type.INDEX_TYPE() != latte::VGT_INDEX_16) { decaf_abort(fmt::format("Unexpected INDEX_TYPE {} for VGT_DMA_SWAP_16_BIT", vgt_dma_index_type.INDEX_TYPE())); } for (auto i = 0u; i < data.count; ++i) { indices[i] = byte_swap(src[i]); } drawPrimitives(data.count, indices.data(), vgt_dma_index_type.INDEX_TYPE()); } else if (vgt_dma_index_type.SWAP_MODE() == latte::VGT_DMA_SWAP_32_BIT) { auto *src = static_cast<uint32_t*>(data.addr.get()); auto indices = std::vector<uint32_t>(data.count); if (vgt_dma_index_type.INDEX_TYPE() != latte::VGT_INDEX_32) { decaf_abort(fmt::format("Unexpected INDEX_TYPE {} for VGT_DMA_SWAP_32_BIT", vgt_dma_index_type.INDEX_TYPE())); } for (auto i = 0u; i < data.count; ++i) { indices[i] = byte_swap(src[i]); } drawPrimitives(data.count, indices.data(), vgt_dma_index_type.INDEX_TYPE()); } else if (vgt_dma_index_type.SWAP_MODE() == latte::VGT_DMA_SWAP_NONE) { drawPrimitives(data.count, data.addr, vgt_dma_index_type.INDEX_TYPE()); } else { decaf_abort(fmt::format("Unimplemented vgt_dma_index_type.SWAP_MODE {}", vgt_dma_index_type.SWAP_MODE())); } }
static __m128i AES_encrypt(__m128i in, const __m128i* expkey) { int j; __m128i tmp = byte_swap(in) ^ expkey[0]; for (j=1; j <10; j++){ tmp = _mm_aesenc_si128 (tmp,expkey[j]); } tmp = _mm_aesenclast_si128 (tmp,expkey[10]); return byte_swap(tmp); }
static int elf_hdr_match(const char *region, uint16_t match, int ei_data) { /* * It is OK to use Elf32_Ehdr here because fields accessed * in this function are same in both 64-bit and 32-bit ELF formats. */ Elf32_Ehdr *ehdr = (Elf32_Ehdr *)region; int swap; if (ehdr->e_ident[EI_DATA] != ei_data) return 0; #ifdef WORDS_BIGENDIAN swap = (ei_data == ELFDATA2LSB); #else swap = (ei_data == ELFDATA2MSB); #endif if (swap && ehdr->e_machine == byte_swap(match)) return 1; if (!swap && ehdr->e_machine == match) return 1; return 0; }
static void stridedMemcpy2(void *srcBuffer, void *dstBuffer, size_t size, size_t offset, size_t stride, bool endian) { auto src = reinterpret_cast<uint8_t *>(srcBuffer) + offset; auto dst = reinterpret_cast<uint8_t *>(dstBuffer) + offset; auto end = reinterpret_cast<uint8_t *>(srcBuffer) + size; if (endian) { while (src < end) { auto srcPtr = reinterpret_cast<Type *>(src); auto dstPtr = reinterpret_cast<Type *>(dst); for (auto i = 0u; i < N; ++i) { *dstPtr++ = byte_swap(*srcPtr++); } src += stride; dst += stride; } } else { while (src < end) { memcpy(src, dst, sizeof(Type) * N); src += stride; dst += stride; } } }
// Returns address of trampoline for target static ppcaddr_t getTrampAddress(LoadedModule *loadedMod, SequentialMemoryTracker &codeSeg, TrampolineMap &trampolines, void *target, const std::string& symbolName) { auto trampAddr = codeSeg.getCurrentAddr(); auto targetAddr = mem::untranslate(target); auto trampIter = trampolines.find(targetAddr); if (trampIter != trampolines.end()) { return trampIter->second; } auto tramp = mem::translate<uint32_t>(trampAddr); auto delta = static_cast<ptrdiff_t>(targetAddr) - static_cast<ptrdiff_t>(trampAddr); if (delta > -0x1FFFFFCll && delta < 0x1FFFFFCll) { tramp = static_cast<uint32_t*>(codeSeg.get(4)); // Short jump using b auto b = espresso::encodeInstruction(espresso::InstructionID::b); b.li = delta >> 2; b.lk = 0; b.aa = 0; *tramp = byte_swap(b.value); } else if (targetAddr < 0x03fffffc) {
int main (int ac, char **av) { if(ac != 4) { printf("Usage: objcopy_convert <infile> <outfile> <number_of_words>\n"); return 1; } FILE* ifile = fopen(av[1], "rb"); FILE* ofile = fopen(av[2], "w"); if(ifile == NULL) { printf("ERROR: Can't open file <%s>\n", av[1]); return 2; } if(ofile == NULL) { printf("ERROR: Can't open file <%s>\n", av[2]); return 2; } fseek(ifile, 0, SEEK_END); int ifile_size = ftell(ifile); rewind(ifile); if(ifile_size % 4) { printf("ERROR: Input file size (%d) is not a multiple of four!\n", ifile_size); fclose(ifile); fclose(ofile); return 3; } int words_in = ifile_size / 4; int words_out = atoi(av[3]); if(words_out == 0) { printf("ERROR: Requested output size <%s> is zero or cannot be parsed!\n", av[3]); fclose(ifile); fclose(ofile); return 4; } if(words_in > words_out) { printf("ERROR: Number of words (%d) in file <%s> is greater than requested! (%d)\n", words_in, av[1], words_out); fclose(ifile); fclose(ofile); return 5; } printf("\tFYI: %d out of %d words used for <%s>\n", words_in, words_out, av[1]); int * buf = malloc(4*words_out); for(int i = 0; i < words_out; ++i) buf[i] = 0; fread(buf, 4, words_in, ifile); for(int i = 0; i < words_out; ++i) fprintf(ofile, "%08X\n", byte_swap(buf[i])); free(buf); fclose(ifile); fclose(ofile); return 0; }
__INLINE void u32_out(uint8_t x[], const uint32_t v){ if(tnet_is_BE()){ *(uint32_t*)x = byte_swap(v); } else{ (*(uint32_t*)(x) = v); } }
__INLINE uint32_t u32_in(const uint8_t x[]){ if(tnet_is_BE()){ return byte_swap(*(uint32_t*)x); } else{ return (*(uint32_t*)(x)); } }
void triifiedDraw(GX2PrimitiveMode::Mode mode, uint32_t numVertices, IndexType *indices, uint32_t offset, uint32_t numInstances) { gDX.commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); uint32_t newNumIndices = 0; switch (mode) { case GX2PrimitiveMode::Quads: newNumIndices = numVertices * 6 / 4; break; case GX2PrimitiveMode::QuadStrip: // Don't actually know how to handle a quad strip... // How the hell do you strip a quad list :S throw; default: // Nobody should be calling me with other modes... throw; } // Always 32-bit indices for now to save scanning the input // indices to see if they will fit into 16-bit indices after expansion. auto indexAlloc = gDX.ppcVertexBuffer->get(DXGI_FORMAT_R32_UINT, newNumIndices * sizeof(uint32_t), nullptr); auto indicesOut = reinterpret_cast<uint32_t*>(static_cast<uint8_t*>(indexAlloc)); for (auto i = 0u; i < numVertices / 4; ++i) { auto index_tl = byte_swap(*indices++); auto index_tr = byte_swap(*indices++); auto index_bl = byte_swap(*indices++); auto index_br = byte_swap(*indices++); *indicesOut++ = index_tl; *indicesOut++ = index_tr; *indicesOut++ = index_bl; *indicesOut++ = index_bl; *indicesOut++ = index_br; *indicesOut++ = index_tl; } gDX.commandList->IASetIndexBuffer(indexAlloc); gDX.commandList->DrawIndexedInstanced(newNumIndices, numInstances, 0, offset, 0); }
void GX2SetVertexUniformReg(uint32_t offset, uint32_t count, void *data) { float *floatData = (float*)data; for (auto i = 0u; i < count; ++i) { gDX.state.uniforms[offset + i] = byte_swap(floatData[i]); } }
int UDP_Socket::recvID(int dbTag, int commitTag, ID &theID, ChannelAddress *theAddress) { // if o.k. get a pointer to the data in the message and // place the incoming data there int size; int *data = theID.data; char *gMsg = (char *)data;; size = theID.sz * sizeof(int); while (size > 0) { if (size <= MAX_UDP_DATAGRAM) { recvfrom(sockfd, gMsg, size, 0, &other_Addr.addr, &addrLength); size = 0; } else { recvfrom(sockfd, gMsg, MAX_UDP_DATAGRAM, 0, &other_Addr.addr, &addrLength); gMsg += MAX_UDP_DATAGRAM; size -= MAX_UDP_DATAGRAM; } } #ifndef _WIN32 if (endiannessProblem) { void *array = (void *)data; byte_swap(array, theID.sz, sizeof(int)); } #endif // check the address that message came from was correct if (theAddress != 0) { SocketAddress *theSocketAddress = 0; if (theAddress->getType() == SOCKET_TYPE) { theSocketAddress = (SocketAddress *)theAddress; if (memcmp((char *) &theSocketAddress->address.addr, (char *) &other_Addr.addr, theSocketAddress->addrLength) != 0) { opserr << "UDP_Socket::recvMsg() - a UDP_Socket "; opserr << "can only look at first incoming message\n"; opserr << "The last message did not come from write scource\n"; return -1; } } else { opserr << "UDP_Socket::recvID() - a UDP_Socket "; opserr << "can only communicate with a UDP_Socket"; opserr << " address given is not of type SocketAddress\n"; return -1; } } return 0; }
/* Byte swap an incoming packet. */ void swap_in_packet(struct tf_packet *packet) { int size = (get_u16_raw(packet) + 1) & ~1; if(size > MAXIMUM_PACKET_SIZE) { size = MAXIMUM_PACKET_SIZE; }; byte_swap((__u8 *) packet, size); }
void padCommandBuffer(pm4::Buffer *buffer) { // Display list is meant to be padded to 32 bytes auto alignedSize = align_up(buffer->curSize, 32 / 4); decaf_check(alignedSize <= buffer->maxSize); while (buffer->curSize < alignedSize) { buffer->buffer[buffer->curSize++] = byte_swap(0xBEEF2929); } }
static guint64 get_timestamp(guint8 *bytes, gint len) { guint64 ts; guint64 trans; int it; if(len != 8) { printf("FATAL! timestamps always consist of 64 bits!\n"); } byte_swap(bytes, 4); byte_swap(bytes+4, 4); ts = 0; for(it = 0 ; it < 8 ; it++) { ts = ts << 8; trans = (guint64) bytes[it]; ts = ts | trans; } return (ts); }
/* * check_sac_nvhdr * * Description: Determine the byte order of the SAC file * * IN: * const int nvhdr : nvhdr from header * * Return: * FALSE no byte order swap is needed * TRUE byte order swap is needed * -1 not in sac format ( nvhdr != SAC_HEADER_MAJOR_VERSION ) * */ static int check_sac_nvhdr(const int nvhdr) { int lswap = FALSE; if (nvhdr != SAC_HEADER_MAJOR_VERSION) { byte_swap((char*) &nvhdr, SAC_DATA_SIZEOF); if (nvhdr == SAC_HEADER_MAJOR_VERSION) lswap = TRUE; else lswap = -1; } return lswap; }
static unsigned long long get_timestamp(guint8 *bytes, gint len) { unsigned long long ts; unsigned long long trans; int it; if(len != sizeof(unsigned long long)){ printf(LOG_HEADER"FATAL! timestamps always consist of 64 bits!\n"); } byte_swap(bytes + 0, 4); byte_swap(bytes + 4, 4); ts = 0; for(it = 0; it < 8; it++){ ts = ts << 8; trans = (guint64) bytes[it]; ts = ts | trans; } return (ts); }
void OSScreenClearBufferEx(OSScreenID id, uint32_t colour) { decaf_check(id < OSScreenID::Max); auto size = OSScreenGetBufferSizeEx(id) / 4; auto buffer = sBuffers[id]; // Force alpha to 255 colour = byte_swap(colour) | 0xff000000; for (auto i = 0u; i < size; ++i) { buffer[i] = colour; } }
int TCP_Socket::recvID(int dbTag, int commitTag, ID &theID, ChannelAddress *theAddress) { // first check address is the only address a TCP_socket can send to SocketAddress *theSocketAddress = 0; if (theAddress != 0) { if (theAddress->getType() == SOCKET_TYPE) theSocketAddress = (SocketAddress *)theAddress; else { opserr << "TCP_Socket::recvID() - a TCP_Socket "; opserr << "can only communicate with a TCP_Socket"; opserr << " address given is not of type SocketAddress\n"; return -1; } if (bcmp((char *) &other_Addr.addr_in, (char *) &theSocketAddress->address.addr_in, theSocketAddress->addrLength) != 0) { opserr << "TCP_Socket::recvID() - a TCP_Socket "; opserr << "can only communicate with one other TCP_Socket\n"; return -1; } } // if o.k. get a pointer to the data in the ID and // place the incoming data there int nleft,nread; int *data = theID.data; char *gMsg = (char *)data;; nleft = theID.sz * sizeof(int); while (nleft > 0) { nread = recv(sockfd,gMsg,nleft,0); nleft -= nread; gMsg += nread; } #ifndef _WIN32 if (endiannessProblem) { void *array = (void *)data; byte_swap(array, theID.sz, sizeof(int)); } #endif return 0; }
void OSScreenPutPixelEx(OSScreenID id, uint32_t x, uint32_t y, uint32_t colour) { decaf_check(id < OSScreenID::Max); auto buffer = sBuffers[id]; auto size = sScreenSizes[id]; // Force alpha to 255 colour = byte_swap(colour) | 0xff000000; if (buffer && x < size.width && y < size.height) { auto offset = x + y * size.pitch; buffer[offset] = colour; } }
void _GX2DrawIndexedEx(GX2PrimitiveMode::Mode mode, uint32_t numVertices, GX2IndexType::Type indexType, void *indices, uint32_t offset, uint32_t numInstances) { // TODO: GX2DrawIndexedEx dx::updateRenderTargets(); dx::updatePipeline(); dx::updateBuffers(); if (mode == GX2PrimitiveMode::Quads) { switch (indexType) { case GX2IndexType::U16: return triifiedDraw(mode, numVertices, static_cast<uint16_t*>(indices), offset, numInstances); default: throw; } } gDX.commandList->IASetPrimitiveTopology( dx12MakePrimitiveTopology(mode)); switch (indexType) { case GX2IndexType::U16: { auto indexAlloc = gDX.ppcVertexBuffer->get(DXGI_FORMAT_R16_UINT, numVertices * sizeof(uint16_t), nullptr); auto indexBuffer = reinterpret_cast<uint16_t*>(static_cast<uint8_t*>(indexAlloc)); auto inBuffer = static_cast<uint16_t*>(indices); for (auto i = 0u; i < numVertices; ++i) { *indexBuffer++ = byte_swap(*inBuffer++); } gDX.commandList->IASetIndexBuffer(indexAlloc); break; } default: throw; } gDX.commandList->DrawIndexedInstanced(numVertices, numInstances, 0, offset, 0); }
uint64_t DMAEFillMem(virt_ptr<void> dst, uint32_t value, uint32_t numDwords) { coreinit::OSLockMutex(virt_addrof(sRingData->mutex)); auto dstValue = byte_swap(value); auto dstDwords = reinterpret_cast<uint32_t *>(dst.get()); for (auto i = 0u; i < numDwords; ++i) { dstDwords[i] = dstValue; } auto timestamp = coreinit::OSGetTime(); sRingData->lastSubmittedTimestamp = timestamp; coreinit::OSUnlockMutex(virt_addrof(sRingData->mutex)); return timestamp; }
void stridedMemcpy3(uint8_t *src, uint8_t *dest, size_t size, uint32_t stride, uint32_t offset) { uint32_t extraStride = stride - (sizeof(Type) * N); Type *s = (Type*)(src + offset); Type *d = (Type*)(dest + offset); Type *sEnd = (Type*)(src + size); while (s < sEnd) { if (EndianSwap) { for (auto i = 0u; i < N; ++i) { *d++ = byte_swap(*s++); } *((uint8_t**)&s) += extraStride; *((uint8_t**)&d) += extraStride; } else { memcpy(s, d, sizeof(Type) * N); *((uint8_t**)&s) += stride; *((uint8_t**)&d) += stride; } } }
int ILDGReader::read(double *buffer, unsigned int size){ _Message(DEBUG_VERB_LEVEL, "ILDG Reader...\n"); //Read just as it is //order is (in, ex, sites) n_uint64_t bytes_to_read = sizeof(double)*size; n_uint64_t read = bytes_to_read; limeReaderReadData(buffer, &read, LimeR); #ifndef BIG_ENDIAN_TYPE byte_swap(buffer, size); #endif /* #ifdef DEBUG_VERB_LEVEL for (int i = 0; i < bytes_to_read; i++){ std::cout << "buffer["<<i<<"] = "<< buffer[i] << "\n"; } #endif */ }