Skip to content

Commit

Permalink
Fix/count trailing zeroes (rust-lang#95)
Browse files Browse the repository at this point in the history
* Fix count trailing zeroes
* Fix pop count
* Fix bit reverse
  • Loading branch information
antoyo authored Sep 28, 2021
1 parent 63608ac commit 11c2023
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 162 deletions.
22 changes: 22 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ pub trait SignType<'gcc, 'tcx> {
fn is_signed(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_unsigned(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn to_signed(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc>;
fn to_unsigned(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc>;
}

impl<'gcc, 'tcx> SignType<'gcc, 'tcx> for Type<'gcc> {
Expand Down Expand Up @@ -333,6 +334,27 @@ impl<'gcc, 'tcx> SignType<'gcc, 'tcx> for Type<'gcc> {
self.clone()
}
}

fn to_unsigned(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
if self.is_i8(cx) {
cx.u8_type
}
else if self.is_i16(cx) {
cx.u16_type
}
else if self.is_i32(cx) {
cx.u32_type
}
else if self.is_i64(cx) {
cx.u64_type
}
else if self.is_i128(cx) {
cx.u128_type
}
else {
self.clone()
}
}
}

pub trait TypeReflection<'gcc, 'tcx> {
Expand Down
Loading

0 comments on commit 11c2023

Please sign in to comment.