@@ -327,107 +327,6 @@ VAL MKB64(VM* vm, uint64_t bits64) {
327327 return cl;
328328}
329329
330−VAL MKB8x16const(VM* vm,
331− uint8_t v0, uint8_t v1, uint8_t v2, uint8_t v3,
332− uint8_t v4, uint8_t v5, uint8_t v6, uint8_t v7,
333− uint8_t v8, uint8_t v9, uint8_t v10, uint8_t v11,
334− uint8_t v12, uint8_t v13, uint8_t v14, uint8_t v15) {
335− Closure* cl = allocate(sizeof(Closure) + sizeof(__m128i), 1);
336− SETTY(cl, BITS8X16);
337−
338− cl->info.bits128p = (__m128i*)ALIGN((uintptr_t)cl + sizeof(Closure), 16);
339− assert ((uintptr_t)cl->info.bits128p % 16 == 0);
340−
341− uint8_t data[16];
342− data[0]=v0; data[1]=v1; data[2]=v2; data[3]=v3;
343− data[4]=v4; data[5]=v5; data[6]=v6; data[7]=v7;
344− data[8]=v8; data[9]=v9; data[10]=v10; data[11]=v11;
345− data[12]=v12; data[13]=v13; data[14]=v14; data[15]=v15;
346−
347− *cl->info.bits128p = _mm_loadu_si128((__m128i*)&data);
348−
349− return cl;
350−}
351−
352−VAL MKB8x16(VM* vm,
353− VAL v0, VAL v1, VAL v2, VAL v3,
354− VAL v4, VAL v5, VAL v6, VAL v7,
355− VAL v8, VAL v9, VAL v10, VAL v11,
356− VAL v12, VAL v13, VAL v14, VAL v15) {
357− return MKB8x16const(vm,
358− v0->info.bits8, v1->info.bits8, v2->info.bits8, v3->info.bits8,
359− v4->info.bits8, v5->info.bits8, v6->info.bits8, v7->info.bits8,
360− v8->info.bits8, v9->info.bits8, v10->info.bits8, v11->info.bits8,
361− v12->info.bits8, v13->info.bits8, v14->info.bits8, v15->info.bits8);
362−}
363−
364−VAL MKB16x8const(VM* vm,
365− uint16_t v0, uint16_t v1, uint16_t v2, uint16_t v3,
366− uint16_t v4, uint16_t v5, uint16_t v6, uint16_t v7) {
367− Closure* cl = allocate(sizeof(Closure) + sizeof(__m128i), 1);
368− SETTY(cl, BITS16X8);
369−
370− cl->info.bits128p = (__m128i*)ALIGN((uintptr_t)cl + sizeof(Closure), 16);
371− assert ((uintptr_t)cl->info.bits128p % 16 == 0);
372−
373− uint16_t data[8];
374− data[0]=v0; data[1]=v1; data[2]=v2; data[3]=v3;
375− data[4]=v4; data[5]=v5; data[6]=v6; data[7]=v7;
376−
377− *cl->info.bits128p = _mm_loadu_si128((__m128i*)&data);
378− return cl;
379−
380−}
381−
382−VAL MKB16x8(VM* vm,
383− VAL v0, VAL v1, VAL v2, VAL v3,
384− VAL v4, VAL v5, VAL v6, VAL v7) {
385− return MKB16x8const(vm,
386− v0->info.bits16, v1->info.bits16, v2->info.bits16, v3->info.bits16,
387− v4->info.bits16, v5->info.bits16, v6->info.bits16, v7->info.bits16);
388−}
389−
390−VAL MKB32x4const(VM* vm,
391− uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3) {
392− Closure* cl = allocate(sizeof(Closure) + 16 + sizeof(__m128i), 1);
393− SETTY(cl, BITS64X2);
394−
395− cl->info.bits128p = (__m128i*)ALIGN((uintptr_t)cl + sizeof(Closure), 16);
396− assert ((uintptr_t)cl->info.bits128p % 16 == 0);
397−
398− uint32_t data[4];
399− data[0]=v0; data[1]=v1; data[2]=v2; data[3]=v3;
400−
401− *cl->info.bits128p = _mm_loadu_si128((__m128i*)&data);
402− return cl;
403−}
404−
405−VAL MKB32x4(VM* vm,
406− VAL v0, VAL v1, VAL v2, VAL v3) {
407− return MKB32x4const(vm,
408− v0->info.bits32, v1->info.bits32, v2->info.bits32, v3->info.bits32);
409−}
410−
411−VAL MKB64x2const(VM* vm, uint64_t v0, uint64_t v1) {
412− Closure* cl = allocate(sizeof(Closure) + 16 + sizeof(__m128i), 1);
413− SETTY(cl, BITS64X2);
414−
415− cl->info.bits128p = (__m128i*)ALIGN((uintptr_t)cl + sizeof(Closure), 16);
416− assert ((uintptr_t)cl->info.bits128p % 16 == 0);
417−
418− uint64_t data[2];
419− data[0]=v0; data[1]=v1;
420−
421− *cl->info.bits128p = _mm_loadu_si128((__m128i*)&data);
422− return cl;
423−}
424−
425−VAL MKB64x2(VM* vm, VAL v0, VAL v1) {
426− return MKB64x2const(vm,
427− v0->info.bits64,
428− v1->info.bits64);
429−}
430−
431330void PROJECT(VM* vm, VAL r, int loc, int arity) {
432331 int i;
433332 for(i = 0; i < arity; ++i) {
@@ -740,240 +639,6 @@ VAL idris_systemInfo(VM* vm, VAL index) {
740639 return MKSTR(vm, "");
741640}
742641
743−VAL MKBUFFERc(VM* vm, Buffer* buf) {
744− Closure* cl = allocate(sizeof(Closure) + sizeof *buf + buf->cap, 1);
745− SETTY(cl, BUFFER);
746− cl->info.buf = (Buffer*)((void*)cl + sizeof(Closure));
747− memmove(cl->info.buf, buf, sizeof *buf + buf->fill);
748− return cl;
749−}
750−
751−static VAL internal_allocate(VM *vm, size_t hint) {
752− size_t size = hint + sizeof(Closure) + sizeof(Buffer);
753−
754− // Round up to a power of 2
755− --size;
756− size_t i;
757− for (i = 0; i <= sizeof size; ++i)
758− size |= size >> (1 << i);
759− ++size;
760−
761− Closure* cl = allocate(size, 0);
762− SETTY(cl, BUFFER);
763− cl->info.buf = (Buffer*)((void*)cl + sizeof(Closure));
764− cl->info.buf->cap = size - (sizeof(Closure) + sizeof(Buffer));
765− return cl;
766−}
767−
768−// Following functions cast uint64_t to size_t, which may narrow!
769−VAL idris_buffer_allocate(VM* vm, VAL hint) {
770− Closure* cl = internal_allocate(vm, hint->info.bits64);
771− cl->info.buf->fill = 0;
772− return cl;
773−}
774−
775−static void internal_memset(void *dest, const void *src, size_t size, size_t num) {
776− while (num--) {
777− memmove(dest, src, size);
778− dest += size;
779− }
780−}
781−
782−static VAL internal_prepare_append(VM* vm, VAL buf, size_t bufLen, size_t appLen) {
783− size_t totalLen = bufLen + appLen;
784− Closure* cl;
785− if (bufLen != buf->info.buf->fill ||
786− totalLen > buf->info.buf->cap) {
787− // We're not at the fill or are over cap, so need a new buffer
788− cl = internal_allocate(vm, totalLen);
789− memmove(cl->info.buf->store,
790− buf->info.buf->store,
791− bufLen);
792− cl->info.buf->fill = totalLen;
793− } else {
794− // Hooray, can just bump the fill
795− cl = buf;
796− cl->info.buf->fill += appLen;
797− }
798− return cl;
799−}
800−
801−VAL idris_appendBuffer(VM* vm, VAL fst, VAL fstLen, VAL cnt, VAL sndLen, VAL sndOff, VAL snd) {
802− size_t firstLength = fstLen->info.bits64;
803− size_t secondLength = sndLen->info.bits64;
804− size_t count = cnt->info.bits64;
805− size_t offset = sndOff->info.bits64;
806− Closure* cl = internal_prepare_append(vm, fst, firstLength, count * secondLength);
807− internal_memset(cl->info.buf->store + firstLength, snd->info.buf->store + offset, secondLength, count);
808− return cl;
809−}
810−
811−// Special cased because we can use memset
812−VAL idris_appendB8Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
813− size_t bufLen = len->info.bits64;
814− size_t count = cnt->info.bits64;
815− Closure* cl = internal_prepare_append(vm, buf, bufLen, count);
816− memset(cl->info.buf->store + bufLen, val->info.bits8, count);
817− return cl;
818−}
819−
820−static VAL internal_append_bits(VM* vm, VAL buf, VAL bufLen, VAL cnt, const void* val, size_t val_len) {
821− size_t len = bufLen->info.bits64;
822− size_t count = cnt->info.bits64;
823− Closure* cl = internal_prepare_append(vm, buf, len, count * val_len);
824− internal_memset(cl->info.buf->store + len, val, val_len, count);
825− return cl;
826−}
827−
828−VAL idris_appendB16Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
829− return internal_append_bits(vm, buf, len, cnt, &val->info.bits16, sizeof val->info.bits16);
830−}
831−
832−VAL idris_appendB16LE(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
833− // On gcc 4.8 -O3 compiling for x86_64, using leVal like this is
834− // optimized away. Presumably the same holds for other sizes and
835− // conversly on BE systems
836− unsigned char leVal[sizeof val] = { val->info.bits16
837− , (val->info.bits16 >> 8)
838− };
839− return internal_append_bits(vm, buf, len, cnt, leVal, sizeof leVal);
840−}
841−
842−VAL idris_appendB16BE(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
843− unsigned char beVal[sizeof val] = { (val->info.bits16 >> 8)
844− , val->info.bits16
845− };
846− return internal_append_bits(vm, buf, len, cnt, beVal, sizeof beVal);
847−}
848−
849−VAL idris_appendB32Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
850− return internal_append_bits(vm, buf, len, cnt, &val->info.bits32, sizeof val->info.bits32);
851−}
852−
853−VAL idris_appendB32LE(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
854− unsigned char leVal[sizeof val] = { val->info.bits32
855− , (val->info.bits32 >> 8)
856− , (val->info.bits32 >> 16)
857− , (val->info.bits32 >> 24)
858− };
859− return internal_append_bits(vm, buf, len, cnt, leVal, sizeof leVal);
860−}
861−
862−VAL idris_appendB32BE(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
863− unsigned char beVal[sizeof val] = { (val->info.bits32 >> 24)
864− , (val->info.bits32 >> 16)
865− , (val->info.bits32 >> 8)
866− , val->info.bits32
867− };
868− return internal_append_bits(vm, buf, len, cnt, beVal, sizeof beVal);
869−}
870−
871−VAL idris_appendB64Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
872− return internal_append_bits(vm, buf, len, cnt, &val->info.bits64, sizeof val->info.bits64);
873−}
874−
875−VAL idris_appendB64LE(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
876− unsigned char leVal[sizeof val] = { val->info.bits64
877− , (val->info.bits64 >> 8)
878− , (val->info.bits64 >> 16)
879− , (val->info.bits64 >> 24)
880− , (val->info.bits64 >> 32)
881− , (val->info.bits64 >> 40)
882− , (val->info.bits64 >> 48)
883− , (val->info.bits64 >> 56)
884− };
885− return internal_append_bits(vm, buf, len, cnt, leVal, sizeof leVal);
886−}
887−
888−VAL idris_appendB64BE(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
889− unsigned char beVal[sizeof val] = { (val->info.bits64 >> 56)
890− , (val->info.bits64 >> 48)
891− , (val->info.bits64 >> 40)
892− , (val->info.bits64 >> 32)
893− , (val->info.bits64 >> 24)
894− , (val->info.bits64 >> 16)
895− , (val->info.bits64 >> 8)
896− , val->info.bits64
897− };
898− return internal_append_bits(vm, buf, len, cnt, beVal, sizeof beVal);
899−}
900−
901−VAL idris_peekB8Native(VM* vm, VAL buf, VAL off) {
902− size_t offset = off->info.bits64;
903− uint8_t *val = buf->info.buf->store + offset;
904− return MKB8(vm, *val);
905−}
906−
907−VAL idris_peekB16Native(VM* vm, VAL buf, VAL off) {
908− size_t offset = off->info.bits64;
909− uint16_t *val = (uint16_t *) (buf->info.buf->store + offset);
910− return MKB16(vm, *val);
911−}
912−
913−VAL idris_peekB16LE(VM* vm, VAL buf, VAL off) {
914− size_t offset = off->info.bits64;
915− return MKB16(vm, ((uint16_t) buf->info.buf->store[offset]) +
916− (((uint16_t) buf->info.buf->store[offset + 1]) << 8));
917−}
918−
919−VAL idris_peekB16BE(VM* vm, VAL buf, VAL off) {
920− size_t offset = off->info.bits64;
921− return MKB16(vm, ((uint16_t) buf->info.buf->store[offset + 1]) +
922− (((uint16_t) buf->info.buf->store[offset]) << 8));
923−}
924−
925−VAL idris_peekB32Native(VM* vm, VAL buf, VAL off) {
926− size_t offset = off->info.bits64;
927− uint32_t *val = (uint32_t *) (buf->info.buf->store + offset);
928− return MKB32(vm, *val);
929−}
930−
931−VAL idris_peekB32LE(VM* vm, VAL buf, VAL off) {
932− size_t offset = off->info.bits64;
933− return MKB32(vm, ((uint32_t) buf->info.buf->store[offset]) +
934− (((uint32_t) buf->info.buf->store[offset + 1]) << 8) +
935− (((uint32_t) buf->info.buf->store[offset + 2]) << 16) +
936− (((uint32_t) buf->info.buf->store[offset + 3]) << 24));
937−}
938−
939−VAL idris_peekB32BE(VM* vm, VAL buf, VAL off) {
940− size_t offset = off->info.bits64;
941− return MKB32(vm, ((uint32_t) buf->info.buf->store[offset + 3]) +
942− (((uint32_t) buf->info.buf->store[offset + 2]) << 8) +
943− (((uint32_t) buf->info.buf->store[offset + 1]) << 16) +
944− (((uint32_t) buf->info.buf->store[offset]) << 24));
945−}
946−
947−VAL idris_peekB64Native(VM* vm, VAL buf, VAL off) {
948− size_t offset = off->info.bits64;
949− uint64_t *val = (uint64_t *) (buf->info.buf->store + offset);
950− return MKB64(vm, *val);
951−}
952−
953−VAL idris_peekB64LE(VM* vm, VAL buf, VAL off) {
954− size_t offset = off->info.bits64;
955− return MKB64(vm, ((uint64_t) buf->info.buf->store[offset]) +
956− (((uint64_t) buf->info.buf->store[offset + 1]) << 8) +
957− (((uint64_t) buf->info.buf->store[offset + 2]) << 16) +
958− (((uint64_t) buf->info.buf->store[offset + 3]) << 24) +
959− (((uint64_t) buf->info.buf->store[offset + 4]) << 32) +
960− (((uint64_t) buf->info.buf->store[offset + 5]) << 40) +
961− (((uint64_t) buf->info.buf->store[offset + 6]) << 48) +
962− (((uint64_t) buf->info.buf->store[offset + 7]) << 56));
963−}
964−
965−VAL idris_peekB64BE(VM* vm, VAL buf, VAL off) {
966− size_t offset = off->info.bits64;
967− return MKB64(vm, ((uint64_t) buf->info.buf->store[offset + 7]) +
968− (((uint64_t) buf->info.buf->store[offset + 6]) << 8) +
969− (((uint64_t) buf->info.buf->store[offset + 5]) << 16) +
970− (((uint64_t) buf->info.buf->store[offset + 4]) << 24) +
971− (((uint64_t) buf->info.buf->store[offset + 3]) << 32) +
972− (((uint64_t) buf->info.buf->store[offset + 2]) << 40) +
973− (((uint64_t) buf->info.buf->store[offset + 1]) << 48) +
974− (((uint64_t) buf->info.buf->store[offset]) << 56));
975−}
976−
977642typedef struct {
978643 VM* vm; // thread's VM
979644 VM* callvm; // calling thread's VM
@@ -1058,9 +723,6 @@ VAL doCopyTo(VM* vm, VAL x) {
1058723 case STRING:
1059724 cl = MKSTRc(vm, x->info.str);
1060725 break;
1061− case BUFFER:
1062− cl = MKBUFFERc(vm, x->info.buf);
1063− break;
1064726 case BIGINT:
1065727 cl = MKBIGMc(vm, x->info.ptr);
1066728 break;