Skip to content

Commit 19ea49c

Browse files
committed
Misc fixes + tests
1 parent 7b32b75 commit 19ea49c

File tree

11 files changed

+790
-15
lines changed

11 files changed

+790
-15
lines changed

bin/c_success_coretests.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ net::socket_addr::set_scope_id
628628
net::socket_addr::socket_v4_to_str
629629
net::socket_addr::socket_v6_to_str
630630
nonzero::nonzero_const
631+
nonzero::nonzero_leading_zeros
632+
nonzero::nonzero_trailing_zeros
631633
nonzero::test_create_nonzero_instance
632634
nonzero::test_from_nonzero
633635
nonzero::test_from_signed_nonzero
@@ -645,6 +647,8 @@ nonzero::test_nonzero_bitor_assign
645647
nonzero::test_nonzero_fmt
646648
nonzero::test_nonzero_from_int_on_err
647649
nonzero::test_nonzero_from_int_on_success
650+
nonzero::test_nonzero_isolate_least_significant_one
651+
nonzero::test_nonzero_isolate_most_significant_one
648652
nonzero::test_nonzero_uint_div
649653
nonzero::test_nonzero_uint_rem
650654
nonzero::test_signed_nonzero_neg
@@ -723,13 +727,16 @@ num::i128::test_borrowing_sub
723727
num::i128::test_carrying_add
724728
num::i128::test_checked_next_multiple_of
725729
num::i128::test_count_ones
730+
num::i128::test_count_zeros
726731
num::i128::test_div_ceil
727732
num::i128::test_div_floor
728733
num::i128::test_from_str
729734
num::i128::test_is_negative
730735
num::i128::test_is_positive
731736
num::i128::test_isolate_least_significant_one
737+
num::i128::test_isolate_most_significant_one
732738
num::i128::test_le
739+
num::i128::test_leading_trailing_ones
733740
num::i128::test_midpoint
734741
num::i128::test_next_multiple_of
735742
num::i128::test_num
@@ -887,6 +894,9 @@ num::ieee754::neg_infinity_to_str
887894
num::ieee754::preserve_signed_infinity
888895
num::ieee754::preserve_signed_zero
889896
num::ieee754::qnan_from_str
897+
num::int_log::checked_ilog
898+
num::int_log::checked_ilog10
899+
num::int_log::checked_ilog2
890900
num::int_log::ilog0_of_1_panic
891901
num::int_log::ilog10_of_0_panic
892902
num::int_log::ilog10_u128
@@ -897,6 +907,8 @@ num::int_log::ilog10_u8
897907
num::int_log::ilog1_of_1_panic
898908
num::int_log::ilog2_of_0_panic
899909
num::int_log::ilog3_of_0_panic
910+
num::int_sqrt::i128::isqrt
911+
num::int_sqrt::i128::isqrt_extended
900912
num::int_sqrt::i16::isqrt
901913
num::int_sqrt::i16::isqrt_extended
902914
num::int_sqrt::i32::isqrt
@@ -1137,12 +1149,15 @@ num::u128::test_borrowing_sub
11371149
num::u128::test_carrying_add
11381150
num::u128::test_checked_next_multiple_of
11391151
num::u128::test_count_ones
1152+
num::u128::test_count_zeros
11401153
num::u128::test_div_ceil
11411154
num::u128::test_div_floor
11421155
num::u128::test_from_str
11431156
num::u128::test_is_next_multiple_of
11441157
num::u128::test_isolate_least_significant_one
1158+
num::u128::test_isolate_most_significant_one
11451159
num::u128::test_le
1160+
num::u128::test_leading_trailing_ones
11461161
num::u128::test_midpoint
11471162
num::u128::test_next_multiple_of
11481163
num::u128::test_num

cilly/src/bin/linker/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ fn main() {
470470
"pthread_join",
471471
"pthread_setspecific",
472472
"ldexpf",
473+
"ldexp",
473474
] {
474475
externs.insert(fnc, LIBC.clone());
475476
}

cilly/src/v2/c_exporter/c_header.h

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,25 @@ static inline int32_t System_Numerics_BitOperations_TrailingZeroCountusizei32(ui
363363
static inline int32_t System_Numerics_BitOperations_TrailingZeroCountu32i32(uint32_t val) {if (val == 0) return sizeof(uint32_t) * 8; return (int32_t) __builtin_ctzl((uint32_t)val);}
364364
static inline int32_t System_Numerics_BitOperations_TrailingZeroCounti32i32(int32_t val) {if (val == 0) return sizeof(int32_t) * 8; return (int32_t) __builtin_ctzl((uint32_t)val);}
365365
static inline int32_t System_Numerics_BitOperations_TrailingZeroCountu64i32(uint64_t val) {if (val == 0) return sizeof(uint64_t) * 8; return (int32_t) __builtin_ctzl((uint64_t)val);}
366-
static inline int32_t System_UInt128_TrailingZeroCountu128u128(__uint128_t val) {if (val == 0) return sizeof(__uint128_t) * 8; return (int32_t) __builtin_ctzl((__uint128_t)val);}
366+
static inline int32_t System_UInt128_TrailingZeroCountu128u128(__uint128_t val) {
367+
if (val == 0) return sizeof(__uint128_t) * 8;
368+
if (((uint64_t)val) == 0){
369+
return (int32_t) System_Numerics_BitOperations_TrailingZeroCountu64i32((uint64_t)(val >> 64)) + 64;
370+
}
371+
else{
372+
return (int32_t) System_Numerics_BitOperations_TrailingZeroCountu64i32((uint64_t)(val));
373+
}
374+
}
367375
static inline int32_t System_Numerics_BitOperations_LeadingZeroCountu64i32(uint64_t val) { if (val == 0) return 64; return __builtin_clzl(val); }
368376
static inline int32_t System_Numerics_BitOperations_LeadingZeroCountusizei32(uintptr_t val) { if (val == 0) return sizeof(uintptr_t) * 8; return __builtin_clzl((uint64_t)val); }
369377
#endif
370378

371379
#define System_Numerics_BitOperations_PopCountusizei32(val) __builtin_popcountl((uint64_t)val)
372380
#define System_Numerics_BitOperations_PopCountu32i32(val) __builtin_popcountl((uint32_t)val)
373381
#define System_Numerics_BitOperations_PopCountu64i32(val) __builtin_popcountl((uint64_t)val)
374-
#define System_UInt128_PopCountu128u128(val) __builtin_popcountl((uint64_t)val)
382+
static inline __uint128_t System_UInt128_PopCountu128u128(__uint128_t val) {
383+
return __builtin_popcountl((uint64_t)val) + __builtin_popcountl((uint64_t)(val>>64));
384+
}
375385

376386
#define System_Console_WriteLinev() printf("\n")
377387
#define System_Console_WriteLinestv(msg) printf("%s\n", msg)
@@ -582,12 +592,24 @@ static inline double System_Double_Expf64f64(double input){
582592
return exp(input);
583593
}
584594
#endif
585-
BUILTIN_UNSUPORTED(System_Double_Log10f64f64,double,(double input))
586-
BUILTIN_UNSUPORTED(System_Single_Logf32f32,float,(float input))
587-
BUILTIN_UNSUPORTED(System_Single_Log2f32f32,float,(float input))
588-
BUILTIN_UNSUPORTED(System_Single_Log10f32f32,float,(float input))
589-
BUILTIN_UNSUPORTED(System_Double_Logf64f64,double,(double input))
590-
BUILTIN_UNSUPORTED(System_Double_Log2f64f64,double,(double input))
595+
static inline float System_Single_Log2f32f32(float input){
596+
return log2f(input);
597+
}
598+
static inline float System_Double_Log2f64f64(float input){
599+
return log2(input);
600+
}
601+
static inline float System_Single_Log10f32f32(float input){
602+
return log10f(input);
603+
}
604+
static inline float System_Double_Log10f64f64(float input){
605+
return log10(input);
606+
}
607+
static inline float System_Single_Logf32f32(float input){
608+
return logf(input);
609+
}
610+
static inline float System_Double_Logf64f64(float input){
611+
return log(input);
612+
}
591613
#define System_Math_Roundf64f64(input) round(input)
592614
#define System_Math_Floorf64f64(input) floor(input)
593615
#define System_Math_Sqrtf64f64(input) sqrt(input)
@@ -748,7 +770,15 @@ static inline uint8_t System_Byte_RotateLeftu8i32u8(uint8_t val, int32_t amount)
748770
return ((val << amount) | (val >> ( (sizeof(uint8_t)*8) - amount)));
749771
}
750772
#if !(defined(__SDCC) || defined(__LCC__))
751-
static inline unsigned __int128 System_UInt128_LeadingZeroCountu128u128(unsigned __int128 val){ if (val == 0) return 128; return __builtin_clzl(val); }
773+
static inline unsigned __int128 System_UInt128_LeadingZeroCountu128u128(__uint128_t val) {
774+
if (val == 0) return sizeof(__uint128_t) * 8;
775+
if ((val>>64) == 0){
776+
return (unsigned __int128) System_Numerics_BitOperations_LeadingZeroCountu64i32((uint64_t)(val)) + 64;
777+
}
778+
else{
779+
return (unsigned __int128) System_Numerics_BitOperations_LeadingZeroCountu64i32((uint64_t)(val >> 64));
780+
}
781+
}
752782
#endif
753783
static inline uint32_t System_Math_Minu32u32u32(uint32_t lhs, uint32_t rhs)
754784
{

rustc_codegen_clr_place/src/body.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ fn body_field<'a>(
140140
},
141141
)
142142
}
143+
143144
}
144145
}
145146
pub fn place_elem_body_index<'tcx>(
@@ -255,6 +256,13 @@ pub fn place_elem_body<'tcx>(
255256
parrent_node,
256257
*index,
257258
),
259+
PlaceElem::Subtype(tpe) => {
260+
if body_ty_is_by_adress(curr_type.as_ty().unwrap(), ctx) {
261+
(PlaceTy::Ty(*tpe),super::deref_op((*tpe).into(), ctx, parrent_node))
262+
} else {
263+
(PlaceTy::Ty(*tpe),parrent_node)
264+
}
265+
}
258266
PlaceElem::ConstantIndex {
259267
offset,
260268
min_length: _,

rustc_codegen_clr_place/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn deref_op<'tcx>(
118118
| TyKind::Tuple(_)
119119
| TyKind::Array(_, _)
120120
| TyKind::FnPtr(_, _)
121-
| TyKind::Closure(_, _) => {
121+
| TyKind::Closure(_, _) | TyKind::Coroutine(_, _)=> {
122122
let derefed_type = ctx.type_from_cache(derefed_type);
123123

124124
CILNode::LdObj {
@@ -154,7 +154,7 @@ pub fn deref_op<'tcx>(
154154
}
155155
}
156156
}
157-
157+
158158
_ => todo!("TODO: can't deref type {derefed_type:?} yet"),
159159
}
160160
} else {

src/compile_test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ run_test! {alloc,abox,stable}
757757
run_test! {alloc,raw_vec,stable}
758758
run_test! {alloc,slice_to_owned,stable}
759759
run_test! {arthm,add,stable}
760+
run_test! {arthm,ctlz,stable}
760761
run_test! {arthm,ptr,stable}
761762
run_test! {arthm,cmp,stable}
762763
run_test! {arthm,greater_than,stable}
@@ -819,6 +820,8 @@ run_test! {std,tlocal_key_test,stable}
819820
run_test! {std,uninit_fill,stable}
820821

821822
run_test! {core,ascii_align,stable}
823+
run_test! {core,floatfmt,unstable}
824+
run_test! {core,flt2dec,unstable}
822825
run_test! {core,from_raw_parts,stable}
823826
run_test! {core,tuple_ord,stable}
824827
run_test! {core,zst_iter,stable}

src/utilis/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub fn get_discr<'tcx>(
329329
Type::Int(Int::I128) => {
330330
let mref = MethodRef::new(
331331
main_module,
332-
ctx.alloc_string("in128_eq"),
332+
ctx.alloc_string("eq_i128"),
333333
ctx.sig([Type::Int(Int::I128), Type::Int(Int::I128)], Type::Bool),
334334
MethodKind::Static,
335335
vec![].into(),

test/arthm/add.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
)]
88
#![allow(internal_features, incomplete_features, unused_variables, dead_code)]
99
#[allow(dead_code)]
10-
struct Test<T> {
11-
data: T,
12-
}
1310
include!("../common.rs");
1411
#[inline(never)]
1512
#[no_mangle]

test/arthm/ctlz.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(
2+
lang_items,
3+
adt_const_params,
4+
associated_type_defaults,
5+
core_intrinsics,
6+
unsized_const_params
7+
)]
8+
#![allow(internal_features, incomplete_features, unused_variables, dead_code)]
9+
#[allow(dead_code)]
10+
include!("../common.rs");
11+
fn main() {
12+
const A: u128 = 0b0101_1111_u128;
13+
test_eq!(A.trailing_ones(), 5);
14+
unsafe{printf(c"%u\n".as_ptr(),(!A).leading_ones() as u32)};
15+
test_eq!((!A).leading_ones(), u128::BITS - 7);
16+
17+
test_eq!(A.reverse_bits().leading_ones(), 5);
18+
19+
test_eq!((!0_u128).leading_ones(), u128::BITS);
20+
test_eq!((!0_u128).trailing_ones(), u128::BITS);
21+
22+
test_eq!(((!0_u128) << 1).trailing_ones(), 0);
23+
test_eq!(((!0_u128) >> 1).leading_ones(), 0);
24+
25+
test_eq!(((!0_u128) << 1).leading_ones(), u128::BITS - 1);
26+
test_eq!(((!0_u128) >> 1).trailing_ones(), u128::BITS - 1);
27+
28+
test_eq!(0_u128.leading_ones(), 0);
29+
test_eq!(0_u128.trailing_ones(), 0);
30+
31+
const X: u128 = 0b0010_1100_u128;
32+
test_eq!(X.leading_ones(), 0);
33+
test_eq!(X.trailing_ones(), 0);
34+
}

0 commit comments

Comments
 (0)