std::bits fixes.

This commit is contained in:
Dmitry Atamanov
2023-07-22 11:55:32 +05:00
committed by Christoffer Lerno
parent d7d7fd3a10
commit e72ec2f605
3 changed files with 118 additions and 90 deletions

View File

@@ -1,6 +1,5 @@
module std::bits;
/**
* @require types::is_intlike($typeof(i)) `The input must be an integer or integer vector`
**/
@@ -11,7 +10,6 @@ macro reverse(i) => $$bitreverse(i);
**/
macro bswap(i) @builtin => $$bswap(i);
macro uint[<*>].popcount(self) => $$popcount(self);
macro uint[<*>].ctz(self) => $$ctz(self);
macro uint[<*>].clz(self) => $$clz(self);
@@ -28,133 +26,133 @@ macro int[<*>] int[<*>].fshr(int[<*>] hi, int[<*>] lo, int[<*>] shift) => $$fshr
macro int[<*>] int[<*>].rotl(self, int[<*>] shift) => $$fshl(self, self, shift);
macro int[<*>] int[<*>].rotr(self, int[<*>] shift) => $$fshr(self, self, shift);
macro ushort[<*>].popcount(ushort[<*>] i) => $$popcount(i);
macro ushort[<*>].ctz(ushort[<*>] i) => $$ctz(i);
macro ushort[<*>].clz(ushort[<*>] i) => $$clz(i);
macro ushort[<*>].popcount(ushort[<*>] self) => $$popcount(self);
macro ushort[<*>].ctz(ushort[<*>] self) => $$ctz(self);
macro ushort[<*>].clz(ushort[<*>] self) => $$clz(self);
macro ushort[<*>] ushort[<*>].fshl(ushort[<*>] hi, ushort[<*>] lo, ushort[<*>] shift) => $$fshl(hi, lo, shift);
macro ushort[<*>] ushort[<*>].fshr(ushort[<*>] hi, ushort[<*>] lo, ushort[<*>] shift) => $$fshr(hi, lo, shift);
macro ushort[<*>] ushort[<*>].rotl(ushort[<*>] i, ushort[<*>] shift) => $$fshl(i, i, shift);
macro ushort[<*>] ushort[<*>].rotr(ushort[<*>] i, ushort[<*>] shift) => $$fshr(i, i, shift);
macro ushort[<*>] ushort[<*>].rotl(ushort[<*>] self, ushort[<*>] shift) => $$fshl(self, self, shift);
macro ushort[<*>] ushort[<*>].rotr(ushort[<*>] self, ushort[<*>] shift) => $$fshr(self, self, shift);
macro short[<*>].popcount(short[<*>] i) => $$popcount(i);
macro short[<*>].ctz(short[<*>] i) => $$ctz(i);
macro short[<*>].clz(short[<*>] i) => $$clz(i);
macro short[<*>].popcount(short[<*>] self) => $$popcount(self);
macro short[<*>].ctz(short[<*>] self) => $$ctz(self);
macro short[<*>].clz(short[<*>] self) => $$clz(self);
macro short[<*>] short[<*>].fshl(short[<*>] hi, short[<*>] lo, short[<*>] shift) => $$fshl(hi, lo, shift);
macro short[<*>] short[<*>].fshr(short[<*>] hi, short[<*>] lo, short[<*>] shift) => $$fshr(hi, lo, shift);
macro short[<*>] short[<*>].rotl(short[<*>] i, short[<*>] shift) => $$fshl(i, i, shift);
macro short[<*>] short[<*>].rotr(short[<*>] i, short[<*>] shift) => $$fshr(i, i, shift);
macro short[<*>] short[<*>].rotl(short[<*>] self, short[<*>] shift) => $$fshl(self, self, shift);
macro short[<*>] short[<*>].rotr(short[<*>] self, short[<*>] shift) => $$fshr(self, self, shift);
macro char[<*>].popcount(char[<*>] i) => $$popcount(i);
macro char[<*>].ctz(char[<*>] i) => $$ctz(i);
macro char[<*>].clz(char[<*>] i) => $$clz(i);
macro char[<*>].popcount(char[<*>] self) => $$popcount(self);
macro char[<*>].ctz(char[<*>] self) => $$ctz(self);
macro char[<*>].clz(char[<*>] self) => $$clz(self);
macro char[<*>] char[<*>].fshl(char[<*>] hi, char[<*>] lo, char[<*>] shift) => $$fshl(hi, lo, shift);
macro char[<*>] char[<*>].fshr(char[<*>] hi, char[<*>] lo, char[<*>] shift) => $$fshr(hi, lo, shift);
macro char[<*>] char[<*>].rotl(char[<*>] i, char[<*>] shift) => $$fshl(i, i, shift);
macro char[<*>] char[<*>].rotr(char[<*>] i, char[<*>] shift) => $$fshr(i, i, shift);
macro char[<*>] char[<*>].rotl(char[<*>] self, char[<*>] shift) => $$fshl(self, self, shift);
macro char[<*>] char[<*>].rotr(char[<*>] self, char[<*>] shift) => $$fshr(self, self, shift);
macro ichar[<*>].popcount(ichar[<*>] i) => $$popcount(i);
macro ichar[<*>].ctz(ichar[<*>] i) => $$ctz(i);
macro ichar[<*>].clz(ichar[<*>] i) => $$clz(i);
macro ichar[<*>].popcount(ichar[<*>] self) => $$popcount(self);
macro ichar[<*>].ctz(ichar[<*>] self) => $$ctz(self);
macro ichar[<*>].clz(ichar[<*>] self) => $$clz(self);
macro ichar[<*>] ichar[<*>].fshl(ichar[<*>] hi, ichar[<*>] lo, ichar[<*>] shift) => $$fshl(hi, lo, shift);
macro ichar[<*>] ichar[<*>].fshr(ichar[<*>] hi, ichar[<*>] lo, ichar[<*>] shift) => $$fshr(hi, lo, shift);
macro ichar[<*>] ichar[<*>].rotl(ichar[<*>] i, ichar[<*>] shift) => $$fshl(i, i, shift);
macro ichar[<*>] ichar[<*>].rotr(ichar[<*>] i, ichar[<*>] shift) => $$fshr(i, i, shift);
macro ichar[<*>] ichar[<*>].rotl(ichar[<*>] self, ichar[<*>] shift) => $$fshl(self, self, shift);
macro ichar[<*>] ichar[<*>].rotr(ichar[<*>] self, ichar[<*>] shift) => $$fshr(self, self, shift);
macro ulong[<*>].popcount(ulong[<*>] i) => $$popcount(i);
macro ulong[<*>].ctz(ulong[<*>] i) => $$ctz(i);
macro ulong[<*>].clz(ulong[<*>] i) => $$clz(i);
macro ulong[<*>].popcount(ulong[<*>] self) => $$popcount(self);
macro ulong[<*>].ctz(ulong[<*>] self) => $$ctz(self);
macro ulong[<*>].clz(ulong[<*>] self) => $$clz(self);
macro ulong[<*>] ulong[<*>].fshl(ulong[<*>] hi, ulong[<*>] lo, ulong[<*>] shift) => $$fshl(hi, lo, shift);
macro ulong[<*>] ulong[<*>].fshr(ulong[<*>] hi, ulong[<*>] lo, ulong[<*>] shift) => $$fshr(hi, lo, shift);
macro ulong[<*>] ulong[<*>].rotl(ulong[<*>] i, ulong[<*>] shift) => $$fshl(i, i, shift);
macro ulong[<*>] ulong[<*>].rotr(ulong[<*>] i, ulong[<*>] shift) => $$fshr(i, i, shift);
macro ulong[<*>] ulong[<*>].rotl(ulong[<*>] self, ulong[<*>] shift) => $$fshl(self, self, shift);
macro ulong[<*>] ulong[<*>].rotr(ulong[<*>] self, ulong[<*>] shift) => $$fshr(self, self, shift);
macro long[<*>].popcount(long[<*>] i) => $$popcount(i);
macro long[<*>].ctz(long[<*>] i) => $$ctz(i);
macro long[<*>].clz(long[<*>] i) => $$clz(i);
macro long[<*>].popcount(long[<*>] self) => $$popcount(self);
macro long[<*>].ctz(long[<*>] self) => $$ctz(self);
macro long[<*>].clz(long[<*>] self) => $$clz(self);
macro long[<*>] long[<*>].fshl(long[<*>] hi, long[<*>] lo, long[<*>] shift) => $$fshl(hi, lo, shift);
macro long[<*>] long[<*>].fshr(long[<*>] hi, long[<*>] lo, long[<*>] shift) => $$fshr(hi, lo, shift);
macro long[<*>] long[<*>].rotl(long[<*>] i, long[<*>] shift) => $$fshl(i, i, shift);
macro long[<*>] long[<*>].rotr(long[<*>] i, long[<*>] shift) => $$fshr(i, i, shift);
macro long[<*>] long[<*>].rotl(long[<*>] self, long[<*>] shift) => $$fshl(self, self, shift);
macro long[<*>] long[<*>].rotr(long[<*>] self, long[<*>] shift) => $$fshr(self, self, shift);
macro uint128[<*>].popcount(uint128[<*>] i) => $$popcount(i);
macro uint128[<*>].ctz(uint128[<*>] i) => $$ctz(i);
macro uint128[<*>].clz(uint128[<*>] i) => $$clz(i);
macro uint128[<*>].popcount(uint128[<*>] self) => $$popcount(self);
macro uint128[<*>].ctz(uint128[<*>] self) => $$ctz(self);
macro uint128[<*>].clz(uint128[<*>] self) => $$clz(self);
macro uint128[<*>] uint128[<*>].fshl(uint128[<*>] hi, uint128[<*>] lo, uint128[<*>] shift) => $$fshl(hi, lo, shift);
macro uint128[<*>] uint128[<*>].fshr(uint128[<*>] hi, uint128[<*>] lo, uint128[<*>] shift) => $$fshr(hi, lo, shift);
macro uint128[<*>] uint128[<*>].rotl(uint128[<*>] i, uint128[<*>] shift) => $$fshl(i, i, shift);
macro uint128[<*>] uint128[<*>].rotr(uint128[<*>] i, uint128[<*>] shift) => $$fshr(i, i, shift);
macro uint128[<*>] uint128[<*>].rotl(uint128[<*>] self, uint128[<*>] shift) => $$fshl(self, self, shift);
macro uint128[<*>] uint128[<*>].rotr(uint128[<*>] self, uint128[<*>] shift) => $$fshr(self, self, shift);
macro int128[<*>].popcount(int128[<*>] i) => $$popcount(i);
macro int128[<*>].ctz(int128[<*>] i) => $$ctz(i);
macro int128[<*>].clz(int128[<*>] i) => $$clz(i);
macro int128[<*>].popcount(int128[<*>] self) => $$popcount(self);
macro int128[<*>].ctz(int128[<*>] self) => $$ctz(self);
macro int128[<*>].clz(int128[<*>] self) => $$clz(self);
macro int128[<*>] int128[<*>].fshl(int128[<*>] hi, int128[<*>] lo, int128[<*>] shift) => $$fshl(hi, lo, shift);
macro int128[<*>] int128[<*>].fshr(int128[<*>] hi, int128[<*>] lo, int128[<*>] shift) => $$fshr(hi, lo, shift);
macro int128[<*>] int128[<*>].rotl(int128[<*>] i, int128[<*>] shift) => $$fshl(i, i, shift);
macro int128[<*>] int128[<*>].rotr(int128[<*>] i, int128[<*>] shift) => $$fshr(i, i, shift);
macro int128[<*>] int128[<*>].rotl(int128[<*>] self, int128[<*>] shift) => $$fshl(self, self, shift);
macro int128[<*>] int128[<*>].rotr(int128[<*>] self, int128[<*>] shift) => $$fshr(self, self, shift);
macro uint.popcount(self) => $$popcount(i);
macro uint.ctz(self) => $$ctz(i);
macro uint.clz(self) => $$clz(i);
macro uint.popcount(self) => $$popcount(self);
macro uint.ctz(self) => $$ctz(self);
macro uint.clz(self) => $$clz(self);
macro uint uint.fshl(uint hi, uint lo, uint shift) => $$fshl(hi, lo, shift);
macro uint uint.fshr(uint hi, uint lo, uint shift) => $$fshr(hi, lo, shift);
macro uint uint.rotl(uint i, uint shift) => $$fshl(i, i, shift);
macro uint uint.rotr(uint i, uint shift) => $$fshr(i, i, shift);
macro uint uint.rotl(uint self, uint shift) => $$fshl(self, self, shift);
macro uint uint.rotr(uint self, uint shift) => $$fshr(self, self, shift);
macro int.popcount(self) => $$popcount(i);
macro int.ctz(self) => $$ctz(i);
macro int.clz(self) => $$clz(i);
macro int.popcount(self) => $$popcount(self);
macro int.ctz(self) => $$ctz(self);
macro int.clz(self) => $$clz(self);
macro int int.fshl(int hi, int lo, int shift) => $$fshl(hi, lo, shift);
macro int int.fshr(int hi, int lo, int shift) => $$fshr(hi, lo, shift);
macro int int.rotl(int i, int shift) => $$fshl(i, i, shift);
macro int int.rotr(int i, int shift) => $$fshr(i, i, shift);
macro int int.rotl(int self, int shift) => $$fshl(self, self, shift);
macro int int.rotr(int self, int shift) => $$fshr(self, self, shift);
macro ushort.popcount(self) => $$popcount(i);
macro ushort.ctz(self) => $$ctz(i);
macro ushort.clz(self) => $$clz(i);
macro ushort.popcount(self) => $$popcount(self);
macro ushort.ctz(self) => $$ctz(self);
macro ushort.clz(self) => $$clz(self);
macro ushort ushort.fshl(ushort hi, ushort lo, ushort shift) => $$fshl(hi, lo, shift);
macro ushort ushort.fshr(ushort hi, ushort lo, ushort shift) => $$fshr(hi, lo, shift);
macro ushort ushort.rotl(ushort i, ushort shift) => $$fshl(i, i, shift);
macro ushort ushort.rotr(ushort i, ushort shift) => $$fshr(i, i, shift);
macro ushort ushort.rotl(ushort self, ushort shift) => $$fshl(self, self, shift);
macro ushort ushort.rotr(ushort self, ushort shift) => $$fshr(self, self, shift);
macro short.popcount(self) => $$popcount(i);
macro short.ctz(self) => $$ctz(i);
macro short.clz(self) => $$clz(i);
macro short.popcount(self) => $$popcount(self);
macro short.ctz(self) => $$ctz(self);
macro short.clz(self) => $$clz(self);
macro short short.fshl(short hi, short lo, short shift) => $$fshl(hi, lo, shift);
macro short short.fshr(short hi, short lo, short shift) => $$fshr(hi, lo, shift);
macro short short.rotl(short i, short shift) => $$fshl(i, i, shift);
macro short short.rotr(short i, short shift) => $$fshr(i, i, shift);
macro short short.rotl(short self, short shift) => $$fshl(self, self, shift);
macro short short.rotr(short self, short shift) => $$fshr(self, self, shift);
macro char.popcount(self) => $$popcount(i);
macro char.ctz(self) => $$ctz(i);
macro char.clz(self) => $$clz(i);
macro char.popcount(self) => $$popcount(self);
macro char.ctz(self) => $$ctz(self);
macro char.clz(self) => $$clz(self);
macro char char.fshl(char hi, char lo, char shift) => $$fshl(hi, lo, shift);
macro char char.fshr(char hi, char lo, char shift) => $$fshr(hi, lo, shift);
macro char char.rotl(char i, char shift) => $$fshl(i, i, shift);
macro char char.rotr(char i, char shift) => $$fshr(i, i, shift);
macro char char.rotl(char self, char shift) => $$fshl(self, self, shift);
macro char char.rotr(char self, char shift) => $$fshr(self, self, shift);
macro ichar.popcount(self) => $$popcount(i);
macro ichar.ctz(self) => $$ctz(i);
macro ichar.clz(self) => $$clz(i);
macro ichar.popcount(self) => $$popcount(self);
macro ichar.ctz(self) => $$ctz(self);
macro ichar.clz(self) => $$clz(self);
macro ichar ichar.fshl(ichar hi, ichar lo, ichar shift) => $$fshl(hi, lo, shift);
macro ichar ichar.fshr(ichar hi, ichar lo, ichar shift) => $$fshr(hi, lo, shift);
macro ichar ichar.rotl(ichar i, ichar shift) => $$fshl(i, i, shift);
macro ichar ichar.rotr(ichar i, ichar shift) => $$fshr(i, i, shift);
macro ichar ichar.rotl(ichar self, ichar shift) => $$fshl(self, self, shift);
macro ichar ichar.rotr(ichar self, ichar shift) => $$fshr(self, self, shift);
macro ulong.popcount(self) => $$popcount(i);
macro ulong.ctz(self) => $$ctz(i);
macro ulong.clz(self) => $$clz(i);
macro ulong.popcount(self) => $$popcount(self);
macro ulong.ctz(self) => $$ctz(self);
macro ulong.clz(self) => $$clz(self);
macro ulong ulong.fshl(ulong hi, ulong lo, ulong shift) => $$fshl(hi, lo, shift);
macro ulong ulong.fshr(ulong hi, ulong lo, ulong shift) => $$fshr(hi, lo, shift);
macro ulong ulong.rotl(ulong i, ulong shift) => $$fshl(i, i, shift);
macro ulong ulong.rotr(ulong i, ulong shift) => $$fshr(i, i, shift);
macro ulong ulong.rotl(ulong self, ulong shift) => $$fshl(self, self, shift);
macro ulong ulong.rotr(ulong self, ulong shift) => $$fshr(self, self, shift);
macro long.popcount(self) => $$popcount(i);
macro long.ctz(self) => $$ctz(i);
macro long.clz(self) => $$clz(i);
macro long.popcount(self) => $$popcount(self);
macro long.ctz(self) => $$ctz(self);
macro long.clz(self) => $$clz(self);
macro long long.fshl(long hi, long lo, long shift) => $$fshl(hi, lo, shift);
macro long long.fshr(long hi, long lo, long shift) => $$fshr(hi, lo, shift);
macro long long.rotl(long i, long shift) => $$fshl(i, i, shift);
macro long long.rotr(long i, long shift) => $$fshr(i, i, shift);
macro long long.rotl(long self, long shift) => $$fshl(self, self, shift);
macro long long.rotr(long self, long shift) => $$fshr(self, self, shift);
macro uint128.popcount(self) => $$popcount(self);
macro uint128.ctz(self) => $$ctz(self);

View File

@@ -26,9 +26,9 @@ entry:
%z = alloca i8, align 1
%retparam1 = alloca i64, align 8
%varargslots2 = alloca [3 x %any], align 16
%i = alloca i8, align 1
%self = alloca i8, align 1
%taddr = alloca i8, align 1
%i3 = alloca i8, align 1
%self3 = alloca i8, align 1
%taddr4 = alloca i8, align 1
store i32 123, ptr %a, align 4
store i32 -23, ptr %b, align 4
@@ -55,9 +55,9 @@ entry:
%15 = getelementptr inbounds [3 x %any], ptr %varargslots2, i64 0, i64 0
store %any %14, ptr %15, align 16
%16 = load i8, ptr %z, align 1
store i8 %16, ptr %i, align 1
%17 = load i8, ptr %i, align 1
%18 = load i8, ptr %i, align 1
store i8 %16, ptr %self, align 1
%17 = load i8, ptr %self, align 1
%18 = load i8, ptr %self, align 1
%19 = call i8 @llvm.fshr.i8(i8 %17, i8 %18, i8 1)
store i8 %19, ptr %taddr, align 1
%20 = insertvalue %any undef, ptr %taddr, 0
@@ -65,9 +65,9 @@ entry:
%22 = getelementptr inbounds [3 x %any], ptr %varargslots2, i64 0, i64 1
store %any %21, ptr %22, align 16
%23 = load i8, ptr %z, align 1
store i8 %23, ptr %i3, align 1
%24 = load i8, ptr %i3, align 1
%25 = load i8, ptr %i3, align 1
store i8 %23, ptr %self3, align 1
%24 = load i8, ptr %self3, align 1
%25 = load i8, ptr %self3, align 1
%26 = call i8 @llvm.fshl.i8(i8 %24, i8 %25, i8 1)
store i8 %26, ptr %taddr4, align 1
%27 = insertvalue %any undef, ptr %taddr4, 0

View File

@@ -0,0 +1,30 @@
// #target: macos-x64
module test;
const char C = 0b1000_0000;
const ichar IC = 0b0100_0000;
const ushort US = 0b1000_0000_0000_0000;
const short S = 0b0100_0000_0000_0000;
const uint UI = 0b1000_0000_0000_0000_0000_0000_0000_0000;
const int I = 0b0100_0000_0000_0000_0000_0000_0000_0000;
const ulong UL = 0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;
const long L = 0b0100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;
const uint128 UI128 = 0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;
const int128 I128 = 0b0100_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;
/* #expect: test.ll
@test.C = local_unnamed_addr constant i8 -128, align 1
@test.IC = local_unnamed_addr constant i8 64, align 1
@test.US = local_unnamed_addr constant i16 -32768, align 2
@test.S = local_unnamed_addr constant i16 16384, align 2
@test.UI = local_unnamed_addr constant i32 -2147483648, align 4
@test.I = local_unnamed_addr constant i32 1073741824, align 4
@test.UL = local_unnamed_addr constant i64 -9223372036854775808, align 8
@test.L = local_unnamed_addr constant i64 4611686018427387904, align 8
@test.UI128 = local_unnamed_addr constant i128 -170141183460469231731687303715884105728, align 8
@test.I128 = local_unnamed_addr constant i128 85070591730234615865843651857942052864, align 8