| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/quic/quic_fec_group_interface.h" | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/stl_util.h" | |
| 11 | |
| 12 namespace net { | |
| 13 | |
| 14 void QuicFecGroupInterface::XorBuffers(const char* input, | |
| 15 size_t size_in_bytes, | |
| 16 char* output) { | |
| 17 #if defined(__i386__) || defined(__x86_64__) | |
| 18 // On x86, alignment is not required and casting bytes to words is safe. | |
| 19 | |
| 20 // size_t is a reasonable approximation of how large a general-purpose | |
| 21 // register is for the platforms and compilers Chrome is built on. | |
| 22 typedef size_t platform_word; | |
| 23 const size_t size_in_words = size_in_bytes / sizeof(platform_word); | |
| 24 | |
| 25 const platform_word* input_words = | |
| 26 reinterpret_cast<const platform_word*>(input); | |
| 27 platform_word* output_words = reinterpret_cast<platform_word*>(output); | |
| 28 | |
| 29 // Handle word-sized part of the buffer. | |
| 30 size_t offset_in_words = 0; | |
| 31 for (; offset_in_words < size_in_words; offset_in_words++) { | |
| 32 output_words[offset_in_words] ^= input_words[offset_in_words]; | |
| 33 } | |
| 34 | |
| 35 // Handle the tail which does not fit into the word. | |
| 36 for (size_t offset_in_bytes = offset_in_words * sizeof(platform_word); | |
| 37 offset_in_bytes < size_in_bytes; offset_in_bytes++) { | |
| 38 output[offset_in_bytes] ^= input[offset_in_bytes]; | |
| 39 } | |
| 40 #else | |
| 41 // On ARM and most other plaforms, the code above could fail due to the | |
| 42 // alignment errors. Stick to byte-by-byte comparison. | |
| 43 for (size_t offset = 0; offset < size_in_bytes; offset++) { | |
| 44 output[offset] ^= input[offset]; | |
| 45 } | |
| 46 #endif /* defined(__i386__) || defined(__x86_64__) */ | |
| 47 } | |
| 48 | |
| 49 } // namespace net | |
| OLD | NEW |