I checked out the SWAR algorithm (SIMD Within A Register) for reversing bit order of unsigned ints. Is there something similar for signed int?
Signed INT Conversion of MSB ->LSB and LSB->MSB in C++
1.4k views Asked by Doug At
2
There are 2 answers
0
Ben Voigt
On
The algorithm only works on unsigned integers, since sign-extension during bit-shifting is not wanted.
Since the algorithm uses only the binary representation, not the numeric value, you can just cast to an unsigned integer of equal size (it will have identical representation), use the algorithm, and cast back to signed. These conversions won't turn into any assembly instructions, they just cause the compiler to produce logical shift right instead of arithmetic shift right.
Related Questions in C++
- How to immediately apply DISPLAYCONFIG_SCALING display scaling mode with SetDisplayConfig and DISPLAYCONFIG_PATH_TARGET_INFO
- Why can't I use templates members in its specialization?
- How to fix "Access violation executing location" when using GLFW and GLAD
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- How do I apply the interface concept with the base-class in design?
- File refuses to compile std::erase() even if using -std=g++23
- How can I do a successful map when the number of elements to be mapped is not consistent in Thrust C++
- Can std::bit_cast be applied to an empty object?
- Unexpected inter-thread happens-before relationships from relaxed memory ordering
- How i can move element of dynamic vector in argument of function push_back for dynamic vector
- Brick Breaker Ball Bounce
- Thread-safe lock-free min where both operands can change c++
- Watchdog Timer Reset on ESP32 using Webservers
- How to solve compiler error: no matching function for call to 'dmhFS::dmhFS()' in my case?
- Conda CMAKE CXX Compiler error while compiling Pytorch
Related Questions in BIT-MANIPULATION
- How to flip bits in one operation with c#?
- Fast BCD addition
- Choosing a sequence of bitwise operations
- receives an incomprehensible value and it is not clear how it gets it
- Wrong result for left bit shift in JS
- Find a bit with no duplicates among multiple bits in Java
- how to convert different length of bits into byte array?
- Convert Variable Width Bitstream (2-bit or 4-bit symbols) into Fixed Width
- Minimizing the number of basic arithmetic/binary operators needed to arrive at all others
- LC-3 Assembly OR operation
- Why are same conditions getting different results?
- Why does bit shifting with a large amount work in C?
- Need help to solve DSA : Find position of set bit in java
- Does this simple code not containing any loop generate a loop in assembly?
- Lua 5.1 bitwise operations using arithmetic for 64bit numbers
Related Questions in REVERSE
- how to create an array of multiples of 5 and display it in reverse
- Is range based for loop and normal index for loop are same in c++
- Why does List.reversed() work in LeetCode's Java environment but not in standard Java?
- How should I use the uncompyle6 tool to decompile Python 3.9 version .pyc files?
- do v. do*: Why does the same code produce a different result?
- Assign values based on reverse combination of two columns
- is there any one having solutions to reverse and redirect to pages in Django after submitting the form or update
- Scrolling in both directions (Right to Left <=> Left to Right) with Flutter PageView widget
- How to Reverse String in Dart: Efficient String Reversal Techniques in Dart
- Why does linked list work for node name, but not the pointer?
- Conceptualizing a linked-list post reversal
- Dynamic hostnames with Bind9 reverse lookup
- Nginx reverse proxy to hide my real servers
- Sort String Length, but reversed (longest String first)
- Is it possible to have a Captive portal pop-up on android when reverse tethering?
Related Questions in SWAR
- Can packing variables or parameters into structures/unions introduce unforseen performance penalties?
- Speed up strlen using SWAR in x86-64 assembly
- How to check if a register contains a zero byte without SIMD instructions
- Add two vectors (uint64_t type) with saturation for each int8_t element
- SIMD-within-a-register version of min/max
- Fastest way to find 16bit match in a 4 element short array?
- Multiplication of two packed signed integers in one
- Performantly reverse the order of 16-bit quantities within a 64-bit word
- bit twiddling to right pack bits
- How to implement SWAR unsigned less-than?
- How to write a SWAR comparison which puts 0xFF in a lane on matches?
- SWAR byte counting methods from 'Bit Twiddling Hacks' - why do they work?
- Can a register hold multiple values at a time?
- Subtracting packed 8-bit integers in an 64-bit integer by 1 in parallel, SWAR without hardware SIMD
- Compare 64-bit integers by segments
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
It depends on what you mean by reversing the bits of a signed integer. However, in general, if you plan to place the sign bit in the LSB position and the LSB in the sign bit (which is the normal way to swap anything) then the same algoritm could be used for both signed and unsigned integers.
If this isn't the case, please explain what you mean by reversing a signed integer.