Răsfoiți Sursa

added -D hl-check-align support for FPU alignment (required for ARMv7-)

ncannasse 6 ani în urmă
părinte
comite
6c2184d468
2 a modificat fișierele cu 35 adăugiri și 5 ștergeri
  1. 24 2
      std/hl/_std/haxe/io/Bytes.hx
  2. 11 3
      std/hl/_std/haxe/io/BytesBuffer.hx

+ 24 - 2
std/hl/_std/haxe/io/Bytes.hx

@@ -72,22 +72,44 @@ class Bytes {
 		return r;
 	}
 
+	#if hl_check_align
+	static var alignBuffer : hl.Bytes = new hl.Bytes(8);
+	#end
+
 	public function getDouble( pos : Int ) : Float {
-		return if( out(pos + 7) ) 0. else b.getF64(pos);
+		if( out(pos + 7) ) return 0.;
+		#if hl_check_align
+		return if( pos & 3 == 0 ) b.getF64(pos) else { alignBuffer.blit(0, b, pos, 8); alignBuffer.getF64(0); }
+		#else
+		return b.getF64(pos);
+		#end
 	}
 
 	public function getFloat( pos : Int ) : Float {
-		return if( out(pos + 3) ) 0. else b.getF32(pos);
+		if( out(pos + 3) ) return 0.;
+		#if hl_check_align
+		return if( pos & 3 == 0 ) b.getF32(pos) else { alignBuffer.blit(0, b, pos, 4); alignBuffer.getF32(0); }
+		#else
+		return b.getF32(pos);
+		#end
 	}
 
 	public function setDouble( pos : Int, v : Float ) : Void {
 		if( out(pos + 7) ) throw Error.OutsideBounds;
+		#if hl_check_align
+		if( pos & 7 == 0 ) b.setF64(pos, v); else { alignBuffer.setF64(0,v); b.blit(pos,alignBuffer,0,8); } 
+		#else
 		b.setF64(pos, v);
+		#end
 	}
 
 	public function setFloat( pos : Int, v : Float ) : Void {
 		if( out(pos + 3) ) throw Error.OutsideBounds;
+		#if hl_check_align
+		if( pos & 3 == 0 ) b.setF32(pos, v); else { alignBuffer.setF32(0,v); b.blit(pos,alignBuffer,0,4); } 
+		#else
 		b.setF32(pos, v);
+		#end
 	}
 
 	public inline function getUInt16( pos : Int ) : Int {

+ 11 - 3
std/hl/_std/haxe/io/BytesBuffer.hx

@@ -82,15 +82,23 @@ class BytesBuffer {
 		pos += 8;
 	}
 
-	public inline function addFloat( v : Float ) : Void {
+	public inline function addFloat( v : Float ) : Void { 
 		if( pos + 4 > size ) __expand(0);
+		#if hl_check_align
+		if( pos & 3 == 0 ) b.setF32(pos, v); else @:privateAccess { haxe.io.Bytes.alignBuffer.setF32(0,v); b.blit(pos,haxe.io.Bytes.alignBuffer,0,4); } 
+		#else
 		b.setF32(pos, v);
-		pos += 4;
+		#end
+		pos += 4; 
 	}
-
+	
 	public inline function addDouble( v : Float ) : Void {
 		if( pos + 8 > size ) __expand(0);
+		#if hl_check_align
+		if( pos & 7 == 0 ) b.setF64(pos, v); else @:privateAccess { haxe.io.Bytes.alignBuffer.setF64(0,v); b.blit(pos,haxe.io.Bytes.alignBuffer,0,8); } 
+		#else
 		b.setF64(pos, v);
+		#end
 		pos += 8;
 	}