简体   繁体   English

使用std :: bitset还是相同大小的基本类型?

[英]Use a std::bitset or a fundamental type of the same size?

I'm creating a Chess Solver and have decided to use bitboards. 我正在创建一个国际象棋求解器,并决定使用位板。 Conveniently there are 64 squares on a standard chess board. 方便地,在标准棋盘上有64个正方形。 This is nice since the prevalence of 64-bit operating systems a single bitboard can fit into a single register. 很好,因为在64位操作系统中,单个位板可以放入单个寄存器中。

That said, are there fundamental differences (size (memory and code), speed, complexity, memory usage, etc) in using a std::bitset<64> and the functions therein or the fundamental type of the "same" size unsigned long long and performing the bit twiddling manually? 也就是说,在使用std::bitset<64>及其功能或“ same”大小的基本类型( unsigned long long )方面存在根本区别(大小(内存和代码),速度,复杂性,内存使用等)。 unsigned long long ,手动执行旋转?

uint64_t probably. uint64_t You'll want to perform operations that are not available on std::bitset , including almost all arithmetic operations, bitscan, using parts of the board as index into an array, and SSE intrinsics if you get serious about it. 您将要执行std::bitset上不可用的操作,包括几乎所有算术运算,bitscan,使用开发板的一部分作为数组的索引,以及认真对待SSE内部函数。

For example (not an exhaustive list by any means, just some simple examples) in o^(o-2r) (and its cousin ), the more advanced Hyperbola Quintessence, as part of extracting the lowest set bit, etc. 例如, o ^(o-2r) (及其表亲 )中的(无论如何不是详尽的列表,仅是一些简单的例子),更高级的双曲线型精华,作为提取最低位的一部分,等等。

You could use std::bitset but you'd be converting it back to some type of integer a lot. 您可以使用std::bitset但是会大量地将其转换回某种类型的整数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM