SWARUtil.java — netty Source File
Architecture documentation for SWARUtil.java, a java file in the netty codebase.
Entity Profile
Relationship Graph
Source Code
/*
* Copyright 2024 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.netty.util.internal;
/**
* Utility class for SWAR (SIMD within a register) operations.
*/
public final class SWARUtil {
/**
* Compiles given byte into a long pattern suitable for SWAR operations.
*/
public static long compilePattern(byte byteToFind) {
return (byteToFind & 0xFFL) * 0x101010101010101L;
}
/**
* Applies a compiled pattern to given word.
* Returns a word where each byte that matches the pattern has the highest bit set.
*
* @param word the word to apply the pattern to
* @param pattern the pattern to apply
* @return a word where each byte that matches the pattern has the highest bit set
*/
public static long applyPattern(final long word, final long pattern) {
long input = word ^ pattern;
long tmp = (input & 0x7F7F7F7F7F7F7F7FL) + 0x7F7F7F7F7F7F7F7FL;
return ~(tmp | input | 0x7F7F7F7F7F7F7F7FL);
}
/**
* Returns the index of the first occurrence of byte that specificied in the pattern.
* If no pattern is found, returns 8.
*
* @param word the return value of {@link #applyPattern(long, long)}
* @param isBigEndian if true, if given word is big endian
* if false, if given word is little endian
* @return the index of the first occurrence of the specified pattern in the specified word.
* If no pattern is found, returns 8.
*/
public static int getIndex(final long word, final boolean isBigEndian) {
final int zeros = isBigEndian? Long.numberOfLeadingZeros(word) : Long.numberOfTrailingZeros(word);
return zeros >>> 3;
}
/**
* Returns a word where each ASCII uppercase byte has the highest bit set.
// ... (117 more lines)
Domain
Subdomains
Classes
Source
Frequently Asked Questions
What does SWARUtil.java do?
SWARUtil.java is a source file in the netty codebase, written in java. It belongs to the CommonUtil domain, Internal subdomain.
Where is SWARUtil.java in the architecture?
SWARUtil.java is located at common/src/main/java/io/netty/util/internal/SWARUtil.java (domain: CommonUtil, subdomain: Internal, directory: common/src/main/java/io/netty/util/internal).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free